PageSourceSearch

https://www.ercot.com/static-assets/js/dashboard/common/chart.js

js ercot.com collected 2026-10-02 02:21:12 UTC 4,817 bytes, 138 lines download raw bytes

1function getGlobalChartOptions(options = {}) {
2    const commonOptions = {
3        title: { text: '' },
4        time: {
5            // timeZone is defined in template 'templates/web/common/_dashboard-resources.ftl'
6            timezone: timeZone,
7            // import resources.js before chart.js in templates. function timezoneOffset() is defined there.
8            getTimezoneOffset: function(ts) { return timezoneOffset(ts); }
9        },
10        tickInterval: {},
11        series: {
12            animation: false,
13            lineWidth: 1,
14            shadow: false,
15            states: {
16                hover: {
17                    lineWidth: 1,      // Prevent line width change on hover
18                    animation: false   // Disable hover animation
19                }
20            },
21            marker: {
22                radius: 1,
23                states: {
24                    hover: {
25                        radius: 2
26                    }
27                }
28            },
29            fillOpacity: 0.25
30        },
31        plotOptions: {
32            series: {
33                lineWidth: 1
34            }
35        },
36        column: {
37            negativeColor: '#910000',
38            borderColor: 'silver'
39        },
40        credits: {
41            enabled: false
42        },
43        legend: {
44            enabled: true
45        },
46        chart: { animation: false },
47        animation: false
48    };
49
50    console.debug('common plot options merged with param options:', { ...commonOptions, ...options });
51    return { ...commonOptions, ...options };
52}
53
54/**
55 * Initialize resize handler for a dashboard.
56 * @param dashboard The dashboard object to monitor for resize events.
57 * @param debounceDelay The debounce delay in milliseconds (default is 200ms).
58 * @param customOnResizeFn Optional custom resize function to be called on resize event instead of default.
59 */
60function initializeResizeHandler(dashboard, debounceDelay = 200, customOnResizeFn = undefined) {
61    if (!dashboard || typeof dashboard !== 'object') {
62        console.error('Invalid dashboard parameter');
63    }
64    if (typeof debounceDelay !== 'number' || debounceDelay < 0) {
65        console.error('debounceDelay must be a non-negative number');
66    }
67    if (customOnResizeFn && typeof customOnResizeFn !== 'function') {
68        console.error('customOnResizeFn must be a function');
69    }
70
71    if (!dashboard.loaded) {
72        // Remove existing handler if present
73        if (dashboard.resizeHandler) {
74            $(window).off("resize", dashboard.resizeHandler);
75        }
76
77        // Create and store new handler with debounce delay which prevents
78        // excessive calls during resize.
79        dashboard.resizeHandler = debounce(() =>
80            customOnResizeFn ? customOnResizeFn() : onResize(dashboard), debounceDelay
81        );
82
83        // Attach the resize handler to window resize event. This is global
84        // and all dashboards will share the same window resize event, but each
85        // dashboard has its own handler function and closure context.
86        $(window).on("resize", dashboard.resizeHandler);
87        dashboard.loaded = true;
88    }
89}
90/**
91 * Perform chart reflow on window resize.
92 * @param dashboard The dashboard object containing the chart to be reflowed.
93 */
94function onResize(dashboard) {
95    if (!dashboard || !dashboard.chart) {
96        console.warn('onResize called with dashboard that does not have a chart. Exiting.');
97        return;
98    }
99
100    const chart = dashboard.chart;
101    if (chart?.xAxis?.[0]) {
102        chart.xAxis[0].update({ tickInterval: getTickInterval(dashboard.fullView) });
103        chart.reflow();
104        debugLog('dashboard ['+dashboard?.chartTitle?.trim()+'] window resized, chart reflowed with updated tick interval.');
105    } else {
106        console.error('Chart xAxis[0] is undefined. Cannot update tick interval or reflow chart.');
107    }
108}
109
110/**
111 * Creates and returns a debounced version of the provided function.
112 * The debounced function delays invoking the original function until after
113 * `wait` milliseconds have elapsed since the last time it was invoked.
114 *
115 * Useful for limiting the rate at which a function can fire, such as
116 * handling window resize or scroll events.
117 *
118 * @param {Function} func - The function to debounce.
119 * @param {number} wait - The number of milliseconds to delay.
120 * @returns {Function} - A debounced version of the input function.
121 */
122function debounce(func, wait = 200) {
123    let timeout;
124    return function (...args) {
125        clearTimeout(timeout);
126        timeout = setTimeout(() => func.apply(this, args), wait);
127    };
128}
129
130/**
131 * Logs debug messages to the console if available.
132 * @param msg The message to log.
133 */
134function debugLog(msg) {
135    if (typeof console !== 'undefined' && console.debug) {
136        console.debug(msg);
137    }
138}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.