PageSourceSearch

https://www.banyuls-sur-mer.com/app/dist/banyuls-sur-mer/addons/wo…/code/es-modules/Data/DataTableCore.js

js banyuls-sur-mer.com collected 2026-10-02 06:37:00 UTC 8,742 bytes, 274 lines download raw bytes

1/* *
2 *
3 *  (c) 2009-2024 Highsoft AS
4 *
5 *  License: www.highcharts.com/license
6 *
7 *  !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
8 *
9 *  Authors:
10 *  - Sophie Bremer
11 *  - Gøran Slettemark
12 *  - Torstein Hønsi
13 *
14 * */
15'use strict';
16import U from '../Core/Utilities.js';
17const { fireEvent, isArray, objectEach, uniqueKey } = U;
18/* *
19 *
20 *  Class
21 *
22 * */
23/**
24 * Class to manage columns and rows in a table structure. It provides methods
25 * to add, remove, and manipulate columns and rows, as well as to retrieve data
26 * from specific cells.
27 *
28 * @class
29 * @name Highcharts.DataTable
30 *
31 * @param {Highcharts.DataTableOptions} [options]
32 * Options to initialize the new DataTable instance.
33 */
34class DataTableCore {
35    /**
36     * Constructs an instance of the DataTable class.
37     *
38     * @example
39     * const dataTable = new Highcharts.DataTableCore({
40     *   columns: {
41     *     year: [2020, 2021, 2022, 2023],
42     *     cost: [11, 13, 12, 14],
43     *     revenue: [12, 15, 14, 18]
44     *   }
45     * });
46
47     *
48     * @param {Highcharts.DataTableOptions} [options]
49     * Options to initialize the new DataTable instance.
50     */
51    constructor(options = {}) {
52        /**
53         * Whether the ID was automatic generated or given in the constructor.
54         *
55         * @name Highcharts.DataTable#autoId
56         * @type {boolean}
57         */
58        this.autoId = !options.id;
59        this.columns = {};
60        /**
61         * ID of the table for indentification purposes.
62         *
63         * @name Highcharts.DataTable#id
64         * @type {string}
65         */
66        this.id = (options.id || uniqueKey());
67        this.modified = this;
68        this.rowCount = 0;
69        this.versionTag = uniqueKey();
70        let rowCount = 0;
71        objectEach(options.columns || {}, (column, columnName) => {
72            this.columns[columnName] = column.slice();
73            rowCount = Math.max(rowCount, column.length);
74        });
75        this.applyRowCount(rowCount);
76    }
77    /* *
78     *
79     *  Functions
80     *
81     * */
82    /**
83     * Applies a row count to the table by setting the `rowCount` property and
84     * adjusting the length of all columns.
85     *
86     * @private
87     * @param {number} rowCount The new row count.
88     */
89    applyRowCount(rowCount) {
90        this.rowCount = rowCount;
91        objectEach(this.columns, (column) => {
92            if (isArray(column)) { // Not on typed array
93                column.length = rowCount;
94            }
95        });
96    }
97    /**
98     * Fetches the given column by the canonical column name. Simplified version
99     * of the full `DataTable.getRow` method, always returning by reference.
100     *
101     * @param {string} columnName
102     * Name of the column to get.
103     *
104     * @return {Highcharts.DataTableColumn|undefined}
105     * A copy of the column, or `undefined` if not found.
106     */
107    getColumn(columnName, 
108    // eslint-disable-next-line @typescript-eslint/no-unused-vars
109    asReference) {
110        return this.columns[columnName];
111    }
112    /**
113     * Retrieves all or the given columns. Simplified version of the full
114     * `DataTable.getColumns` method, always returning by reference.
115     *
116     * @param {Array<string>} [columnNames]
117     * Column names to retrieve.
118     *
119     * @return {Highcharts.DataTableColumnCollection}
120     * Collection of columns. If a requested column was not found, it is
121     * `undefined`.
122     */
123    getColumns(columnNames, 
124    // eslint-disable-next-line @typescript-eslint/no-unused-vars
125    asReference) {
126        return (columnNames || Object.keys(this.columns)).reduce((columns, columnName) => {
127            columns[columnName] = this.columns[columnName];
128            return columns;
129        }, {});
130    }
131    /**
132     * Retrieves the row at a given index.
133     *
134     * @param {number} rowIndex
135     * Row index to retrieve. First row has index 0.
136     *
137     * @param {Array<string>} [columnNames]
138     * Column names to retrieve.
139     *
140     * @return {Record<string, number|string|undefined>|undefined}
141     * Returns the row values, or `undefined` if not found.
142     */
143    getRow(rowIndex, columnNames) {
144        return (columnNames || Object.keys(this.columns)).map((key) => this.columns[key]?.[rowIndex]);
145    }
146    /**
147     * Sets cell values for a column. Will insert a new column, if not found.
148     *
149     * @param {string} columnName
150     * Column name to set.
151     *
152     * @param {Highcharts.DataTableColumn} [column]
153     * Values to set in the column.
154     *
155     * @param {number} [rowIndex=0]
156     * Index of the first row to change. (Default: 0)
157     *
158     * @param {Record<string, (boolean|number|string|null|undefined)>} [eventDetail]
159     * Custom information for pending events.
160     *
161     * @emits #setColumns
162     * @emits #afterSetColumns
163     */
164    setColumn(columnName, column = [], rowIndex = 0, eventDetail) {
165        this.setColumns({ [columnName]: column }, rowIndex, eventDetail);
166    }
167    /**
168     * * Sets cell values for multiple columns. Will insert new columns, if not
169     * found. Simplified version of the full `DataTable.setColumns`, limited to
170     * full replacement of the columns (undefined `rowIndex`).
171     *
172     * @param {Highcharts.DataTableColumnCollection} columns
173     * Columns as a collection, where the keys are the column names.
174     *
175     * @param {number} [rowIndex]
176     * Index of the first row to change. Keep undefined to reset.
177     *
178     * @param {Record<string, (boolean|number|string|null|undefined)>} [eventDetail]
179     * Custom information for pending events.
180     *
181     * @emits #setColumns
182     * @emits #afterSetColumns
183     */
184    setColumns(columns, rowIndex, eventDetail) {
185        let rowCount = this.rowCount;
186        objectEach(columns, (column, columnName) => {
187            this.columns[columnName] = column.slice();
188            rowCount = column.length;
189        });
190        this.applyRowCount(rowCount);
191        if (!eventDetail?.silent) {
192            fireEvent(this, 'afterSetColumns');
193            this.versionTag = uniqueKey();
194        }
195    }
196    /**
197     * Sets cell values of a row. Will insert a new row if no index was
198     * provided, or if the index is higher than the total number of table rows.
199     * A simplified version of the full `DateTable.setRow`, limited to objects.
200     *
201     * @param {Record<string, number|string|undefined>} row
202     * Cell values to set.
203     *
204     * @param {number} [rowIndex]
205     * Index of the row to set. Leave `undefind` to add as a new row.
206     *
207     * @param {boolean} [insert]
208     * Whether to insert the row at the given index, or to overwrite the row.
209     *
210     * @param {Record<string, (boolean|number|string|null|undefined)>} [eventDetail]
211     * Custom information for pending events.
212     *
213     * @emits #afterSetRows
214     */
215    setRow(row, rowIndex = this.rowCount, insert, eventDetail) {
216        const { columns } = this, indexRowCount = insert ? this.rowCount + 1 : rowIndex + 1;
217        objectEach(row, (cellValue, columnName) => {
218            const column = columns[columnName] ||
219                eventDetail?.addColumns !== false && new Array(indexRowCount);
220            if (column) {
221                if (insert) {
222                    column.splice(rowIndex, 0, cellValue);
223                }
224                else {
225                    column[rowIndex] = cellValue;
226                }
227                columns[columnName] = column;
228            }
229        });
230        if (indexRowCount > this.rowCount) {
231            this.applyRowCount(indexRowCount);
232        }
233        if (!eventDetail?.silent) {
234            fireEvent(this, 'afterSetRows');
235            this.versionTag = uniqueKey();
236        }
237    }
238}
239/* *
240 *
241 *  Default Export
242 *
243 * */
244export default DataTableCore;
245/* *
246 *
247 *  API Declarations
248 *
249 * */
250/**
251 * A column of values in a data table.
252 * @typedef {Array<boolean|null|number|string|undefined>} Highcharts.DataTableColumn
253 */ /**
254* A collection of data table columns defined by a object where the key is the
255* column name and the value is an array of the column values.
256* @typedef {Record<string, Highcharts.DataTableColumn>} Highcharts.DataTableColumnCollection
257*/
258/**
259 * Options for the `DataTable` or `DataTableCore` classes.
260 * @interface Highcharts.DataTableOptions
261 */ /**
262* The column options for the data table. The columns are defined by an object
263* where the key is the column ID and the value is an array of the column
264* values.
265*
266* @name Highcharts.DataTableOptions.columns
267* @type {Highcharts.DataTableColumnCollection|undefined}
268*/ /**
269* Custom ID to identify the new DataTable instance.
270*
271* @name Highcharts.DataTableOptions.id
272* @type {string|undefined}
273*/
274(''); // Keeps doclets above in JS file

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.