PageSourceSearch

https://www.pirineo-frances.es/app/dist/pyreneesbearnaises/addons/…/code/es-modules/Core/Axis/DateTimeAxis.js

js pirineo-frances.es collected 2026-09-26 12:48:40 UTC 5,935 bytes, 188 lines download raw bytes

vendor: 5,830 bytes, lines 1-182
1/* *
2 *
3 *  (c) 2010-2024 Torstein Honsi
4 *
5 *  License: www.highcharts.com/license
6 *
7 *  !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
8 *
9 * */
10'use strict';
11import U from '../Utilities.js';
12const { addEvent, getMagnitude, normalizeTickInterval, timeUnits } = U;
13/* *
14 *
15 *  Composition
16 *
17 * */
18/* eslint-disable valid-jsdoc */
19var DateTimeAxis;
20(function (DateTimeAxis) {
21    /* *
22     *
23     *  Declarations
24     *
25     * */
26    /* *
27     *
28     *  Functions
29     *
30     * */
31    /**
32     * Extends axis class with date and time support.
33     * @private
34     */
35    function compose(AxisClass) {
36        if (!AxisClass.keepProps.includes('dateTime')) {
37            AxisClass.keepProps.push('dateTime');
38            const axisProto = AxisClass.prototype;
39            axisProto.getTimeTicks = getTimeTicks;
40            addEvent(AxisClass, 'afterSetType', onAfterSetType);
41        }
42        return AxisClass;
43    }
44    DateTimeAxis.compose = compose;
45    /**
46     * Set the tick positions to a time unit that makes sense, for example
47     * on the first of each month or on every Monday. Return an array with
48     * the time positions. Used in datetime axes as well as for grouping
49     * data on a datetime axis.
50     *
51     * @private
52     * @function Highcharts.Axis#getTimeTicks
53     * @param {Highcharts.TimeNormalizeObject} normalizedInterval
54     * The interval in axis values (ms) and the count.
55     * @param {number} min
56     * The minimum in axis values.
57     * @param {number} max
58     * The maximum in axis values.
59     */
60    function getTimeTicks() {
61        return this.chart.time.getTimeTicks.apply(this.chart.time, arguments);
62    }
63    /**
64     * @private
65     */
66    function onAfterSetType() {
67        if (this.type !== 'datetime') {
68            this.dateTime = void 0;
69            return;
70        }
71        if (!this.dateTime) {
72            this.dateTime = new Additions(this);
73        }
74    }
75    /* *
76     *
77     *  Classes
78     *
79     * */
80    class Additions {
81        /* *
82         *
83         *  Constructors
84         *
85         * */
86        constructor(axis) {
87            this.axis = axis;
88        }
89        /* *
90         *
91         *  Functions
92         *
93         * */
94        /**
95         * Get a normalized tick interval for dates. Returns a configuration
96         * object with unit range (interval), count and name. Used to prepare
97         * data for `getTimeTicks`. Previously this logic was part of
98         * getTimeTicks, but as `getTimeTicks` now runs of segments in stock
99         * charts, the normalizing logic was extracted in order to prevent it
100         * for running over again for each segment having the same interval.
101         * #662, #697.
102         * @private
103         */
104        normalizeTimeTickInterval(tickInterval, unitsOption) {
105            const units = (unitsOption || [[
106                    // Unit name
107                    'millisecond',
108                    // Allowed multiples
109                    [1, 2, 5, 10, 20, 25, 50, 100, 200, 500]
110                ], [
111                    'second',
112                    [1, 2, 5, 10, 15, 30]
113                ], [
114                    'minute',
115                    [1, 2, 5, 10, 15, 30]
116                ], [
117                    'hour',
118                    [1, 2, 3, 4, 6, 8, 12]
119                ], [
120                    'day',
121                    [1, 2]
122                ], [
123                    'week',
124                    [1, 2]
125                ], [
126                    'month',
127                    [1, 2, 3, 4, 6]
128                ], [
129                    'year',
130                    null
131                ]]);
132            let unit = units[units.length - 1], // Default unit is years
133            interval = timeUnits[unit[0]], multiples = unit[1], i;
134            // Loop through the units to find the one that best fits the
135            // tickInterval
136            for (i = 0; i < units.length; i++) {
137                unit = units[i];
138                interval = timeUnits[unit[0]];
139                multiples = unit[1];
140                if (units[i + 1]) {
141                    // `lessThan` is in the middle between the highest multiple
142                    // and the next unit.
143                    const lessThan = (interval *
144                        multiples[multiples.length - 1] +
145                        timeUnits[units[i + 1][0]]) / 2;
146                    // Break and keep the current unit
147                    if (tickInterval <= lessThan) {
148                        break;
149                    }
150                }
151            }
152            // Prevent 2.5 years intervals, though 25, 250 etc. are allowed
153            if (interval === timeUnits.year && tickInterval < 5 * interval) {
154                multiples = [1, 2, 5];
155            }
156            // Get the count
157            const count = normalizeTickInterval(tickInterval / interval, multiples, unit[0] === 'year' ? // #1913, #2360
158                Math.max(getMagnitude(tickInterval / interval), 1) :
159                1);
160            return {
161                unitRange: interval,
162                count: count,
163                unitName: unit[0]
164            };
165        }
166        /**
167         * Get the best date format for a specific X value based on the closest
168         * point range on the axis.
169         *
170         * @private
171         */
172        getXDateFormat(x, dateTimeLabelFormats) {
173            const { axis } = this, time = axis.chart.time;
174            return axis.closestPointRange ?
175                time.getDateFormat(axis.closestPointRange, x, axis.options.startOfWeek, dateTimeLabelFormats) ||
176                    // #2546, 2581
177                    time.resolveDTLFormat(dateTimeLabelFormats.year).main :
178                time.resolveDTLFormat(dateTimeLabelFormats.day).main;
179        }
180    }
181    DateTimeAxis.Additions = Additions;
182}
182)(DateTimeAxis || (DateTimeAxis = {}));
183/* *
184 *
185 *  Default Export
186 *
187 * */
188export default DateTimeAxis;

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.