<commit_before>/*
 * This file contains the code related to loading of trading page bottom analysis
 * content. It will contain jquery so as to compatible with old code and less rewrite
 *
 * Please note that this will be removed in near future
 */

/*
 * This function is called whenever we change market, form
 * or underlying to load bet analysis for that particular event
 */
function requestTradeAnalysis() {
    'use strict';
    $.ajax({
        method: 'POST',
        url: page.url.url_for('trade/trading_analysis'),
        data: {
            underlying: sessionStorage.getItem('underlying'),
            formname: sessionStorage.getItem('formname'),
            contract_category: Offerings.form(),
            barrier: Offerings.barrier()
        }
    })
    .done(function(data) {
        var contentId = document.getElementById('trading_bottom_content');
        contentId.innerHTML = data;
        sessionStorage.setItem('currentAnalysisTab', getActiveTab());
        bindAnalysisTabEvent();
        loadAnalysisTab();
    });
}

/*
 * This function bind event to link elements of bottom content
 * navigation
 */
function bindAnalysisTabEvent() {
    'use strict';
    var analysisNavElement = document.querySelector('#trading_bottom_content #betsBottomPage');
    if (analysisNavElement) {
        analysisNavElement.addEventListener('click', function(e) {
            if (e.target && e.target.nodeName === 'A') {
                e.preventDefault();

                var clickedLink = e.target,
                    clickedElement = clickedLink.parentElement,
                    isTabActive = clickedElement.classList.contains('active');

                sessionStorage.setItem('currentAnalysisTab', clickedElement.id);

                if (!isTabActive) {
                    loadAnalysisTab();
                }
            }
        });
    }
}

/*
 * This function handles all the functionality on how to load
 * tab according to current paramerted
 */
function loadAnalysisTab() {
    'use strict';
    var currentTab = getActiveTab(),
        currentLink = document.querySelector('#' + currentTab + ' a'),
        contentId = document.getElementById(currentTab + '-content');

    var analysisNavElement = document.querySelector('#trading_bottom_content #betsBottomPage');
    toggleActiveNavMenuElement(analysisNavElement, currentLink.parentElement);
    toggleActiveAnalysisTabs();

    if (currentTab === 'tab_graph') {
        BetAnalysis.tab_live_chart.render(true);
    } else {
        var url = currentLink.getAttribute('href');
        $.ajax({
            method: 'GET',
            url: url,
        })
        .done(function(data) {
            contentId.innerHTML = data;
        });
    }
}

/*
 * function to toggle the active element for analysis menu
 */
function toggleActiveAnalysisTabs() {
    'use strict';
    var currentTab = getActiveTab(),
        analysisContainer = document.getElementById('bet_bottom_content');

    if (analysisContainer) {
        var childElements = analysisContainer.children,<commit_msg>fix livechart not loading on change of contract category<commit_after>/*
 * This file contains the code related to loading of trading page bottom analysis
 * content. It will contain jquery so as to compatible with old code and less rewrite
 *
 * Please note that this will be removed in near future
 */

/*
 * This function is called whenever we change market, form
 * or underlying to load bet analysis for that particular event
 */
function requestTradeAnalysis() {
    'use strict';
    $.ajax({
        method: 'POST',
        url: page.url.url_for('trade/trading_analysis'),
        data: {
            underlying: sessionStorage.getItem('underlying'),
            formname: sessionStorage.getItem('formname'),
            contract_category: Offerings.form(),
            barrier: Offerings.barrier()
        }
    })
    .done(function(data) {
        var contentId = document.getElementById('trading_bottom_content');
        contentId.innerHTML = data;
        sessionStorage.setItem('currentAnalysisTab', getActiveTab());
        bindAnalysisTabEvent();
        loadAnalysisTab();
    });
}

/*
 * This function bind event to link elements of bottom content
 * navigation
 */
function bindAnalysisTabEvent() {
    'use strict';
    var analysisNavElement = document.querySelector('#trading_bottom_content #betsBottomPage');
    if (analysisNavElement) {
        analysisNavElement.addEventListener('click', function(e) {
            if (e.target && e.target.nodeName === 'A') {
                e.preventDefault();

                var clickedLink = e.target,
                    clickedElement = clickedLink.parentElement,
                    isTabActive = clickedElement.classList.contains('active');

                sessionStorage.setItem('currentAnalysisTab', clickedElement.id);

                if (!isTabActive) {
                    loadAnalysisTab();
                }
            }
        });
    }
}

/*
 * This function handles all the functionality on how to load
 * tab according to current paramerted
 */
function loadAnalysisTab() {
    'use strict';
    var currentTab = getActiveTab(),
        currentLink = document.querySelector('#' + currentTab + ' a'),
        contentId = document.getElementById(currentTab + '-content');

    var analysisNavElement = document.querySelector('#trading_bottom_content #betsBottomPage');
    toggleActiveNavMenuElement(analysisNavElement, currentLink.parentElement);
    toggleActiveAnalysisTabs();

    if (currentTab === 'tab_graph') {
        BetAnalysis.tab_live_chart.reset();
        BetAnalysis.tab_live_chart.render(true);
    } else {
        var url = currentLink.getAttribute('href');
        $.ajax({
            method: 'GET',
            url: url,
        })
        .done(function(data) {
            contentId.innerHTML = data;
        });
    }
}

/*
 * function to toggle the active element for analysis menu
 */
function toggleActiveAnalysisTabs() {
    'use strict';
    var currentTab = getActiveTab(),
        analysisContainer = document.getElementById('bet_bottom_content');

    if (analysisContainer) {
        var childElements = analysisContainer.children,
{'fraction_non_alphanumeric': 0.10320399291579456, 'fraction_numerical': 0.0, 'mean_word_length': 2.6541176470588237, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2003345', 'n_tokens_mistral': 1551, 'n_tokens_neox': 1534, 'n_words': 410}