<commit_before>// Workaround the css! plugin's inability to understand '..' in
// require'd module names by defining a path that embeds the '..'
// so that css! doesn't see it.
require.config({
    paths: {
        "warum_conducive_web": "../app/warum_conducive_web"
    }
});

require([
    "splunkjs/ready!",
    "splunkjs/mvc/simplexml/ready!",
    "warum_conducive_web/components/calendarheatmap/calendarheatmap",
    "jquery",
    "splunkjs/mvc/searchmanager"
], function(
    mvc,
    ignored,
    CalendarHeatMap,
    $,
    SearchManager
) {
    var zoomChart = mvc.Components.get("zoom_chart");
    var zoomSearch = mvc.Components.get("zoom_search");
    var topDocumentsSearch = mvc.Components.get("top_documents_search");
    var topEventsSearch = mvc.Components.get("top_events_search");
    
    // TODO: Does this need to include "submitted" as well?
    //       I don't think so. Recommend collapse to defaultTokens only.
    var defaultTokens = mvc.Components.get("default");
    var submittedTokens = mvc.Components.get("submitted");
    var tokens = {
        get: function(tokenName) {
            return defaultTokens.get(tokenName);
        },
        
        set: function(tokenName, tokenValue) {
            defaultTokens.set(tokenName, tokenValue);
            submittedTokens.set(tokenName, tokenValue);
        },
        
        on: function(eventName, callback) {
            defaultTokens.on(eventName, callback);
        }
    };
    
    zoomChart.on("selection", function(e) {
        e.preventDefault();
        var time_value = {
            "earliest_time": e.startValue,
            "latest_time": e.endValue
        };
        
        // TODO: Extract prefix of these searches to postprocess prefix.
        zoomSearch.search.set(time_value);
        topDocumentsSearch.search.set(time_value);
        topEventsSearch.search.set(time_value);
        
        tokens.set("earliest_time", e.startValue);
        tokens.set("latest_time", e.endValue);
    });
    
    // TODO: Following token propagation scenarios are not behaving as expected:
    // * Change global range should update ALL panels. Currently missing bottom two panels.
    // * Change zoom range should update only the trend range. Current updating bottom two panels.
    
    // Initially propagate times from global -> zoom, trend
    tokens.set("trendTime.earliest", tokens.get("time.earliest"));
    tokens.set("zoomTime.earliest", tokens.get("time.earliest"));
    tokens.set("trendTime.latest", tokens.get("time.latest"));
    tokens.set("zoomTime.latest", tokens.get("time.latest"));
    
    // Propagate times from global -> zoom, trend
    tokens.on("change:time.earliest", function(model, value) {<commit_msg>User Activity: Fix trend chart to zoom when time range below it is changed.<commit_after>// Workaround the css! plugin's inability to understand '..' in
// require'd module names by defining a path that embeds the '..'
// so that css! doesn't see it.
require.config({
    paths: {
        "warum_conducive_web": "../app/warum_conducive_web"
    }
});

require([
    "splunkjs/ready!",
    "splunkjs/mvc/simplexml/ready!",
    "warum_conducive_web/components/calendarheatmap/calendarheatmap",
    "jquery",
    "splunkjs/mvc/searchmanager"
], function(
    mvc,
    ignored,
    CalendarHeatMap,
    $,
    SearchManager
) {
    var zoomChart = mvc.Components.get("zoom_chart");
    var zoomSearch = mvc.Components.get("zoom_search");
    var topDocumentsSearch = mvc.Components.get("top_documents_search");
    var topEventsSearch = mvc.Components.get("top_events_search");
    
    // TODO: Does this need to include "submitted" as well?
    //       I don't think so. Recommend collapse to defaultTokens only.
    var defaultTokens = mvc.Components.get("default");
    var submittedTokens = mvc.Components.get("submitted");
    var tokens = {
        get: function(tokenName) {
            return defaultTokens.get(tokenName);
        },
        
        set: function(tokenName, tokenValue) {
            defaultTokens.set(tokenName, tokenValue);
            submittedTokens.set(tokenName, tokenValue);
        },
        
        on: function(eventName, callback) {
            defaultTokens.on(eventName, callback);
        }
    };
    
    zoomChart.on("selection", function(e) {
        // Prevent the zoom chart from automatically zooming to the selection
        e.preventDefault();
        
        // Update trend chart's time range
        tokens.set({
            "trendTime.earliest": e.startValue,
            "trendTime.latest": e.endValue
        });
    });
    
    // TODO: Following token propagation scenarios are not behaving as expected:
    // * Change global range should update ALL panels. Currently missing bottom two panels.
    // * Change zoom range should update only the trend range. Current updating bottom two panels.
    
    // Initially propagate times from global -> zoom, trend
    tokens.set("trendTime.earliest", tokens.get("time.earliest"));
    tokens.set("zoomTime.earliest", tokens.get("time.earliest"));
    tokens.set("trendTime.latest", tokens.get("time.latest"));
    tokens.set("zoomTime.latest", tokens.get("time.latest"));
    
    // Propagate times from global -> zoom, trend
    tokens.on("change:time.earliest", function(model, value) {
{'fraction_non_alphanumeric': 0.12063134160090191, 'fraction_numerical': 0.0, 'mean_word_length': 2.767162066525124, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2009400', 'n_tokens_mistral': 1536, 'n_tokens_neox': 1516, 'n_words': 369}