@highcharts/grid-pro 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +6 -0
- package/README.md +15 -9
- package/css/grid-pro.css +1262 -1122
- package/css/modules/grid-base-variables.css +131 -0
- package/css/modules/grid-button-variables.css +140 -0
- package/css/modules/grid-caption-variables.css +11 -0
- package/css/modules/grid-description-variables.css +11 -0
- package/css/modules/grid-input-variables.css +114 -0
- package/css/modules/grid-link-variables.css +18 -0
- package/css/modules/grid-menu-variables.css +50 -0
- package/css/modules/grid-pagination-variables.css +12 -0
- package/css/modules/grid-popup-variables.css +24 -0
- package/css/modules/grid-pro.css +234 -0
- package/css/modules/grid-table-variables.css +385 -0
- package/css/modules/grid-theme-default.css +55 -0
- package/es-modules/Accessibility/A11yI18n.js +1 -2
- package/es-modules/Accessibility/Accessibility.js +1 -2
- package/es-modules/Accessibility/AccessibilityComponent.d.ts +2 -2
- package/es-modules/Accessibility/Components/InfoRegionsComponent.js +5 -6
- package/es-modules/Accessibility/Components/LegendComponent.js +1 -2
- package/es-modules/Accessibility/Components/MenuComponent.js +1 -2
- package/es-modules/Accessibility/Components/NavigatorComponent.js +3 -4
- package/es-modules/Accessibility/Components/RangeSelectorComponent.js +1 -2
- package/es-modules/Accessibility/Components/SeriesComponent/ForcedMarkers.js +1 -2
- package/es-modules/Accessibility/Components/SeriesComponent/NewDataAnnouncer.js +3 -4
- package/es-modules/Accessibility/Components/SeriesComponent/SeriesDescriber.js +3 -4
- package/es-modules/Accessibility/Components/SeriesComponent/SeriesKeyboardNavigation.js +1 -2
- package/es-modules/Accessibility/Components/ZoomComponent.js +1 -2
- package/es-modules/Accessibility/FocusBorder.js +1 -2
- package/es-modules/Accessibility/KeyboardNavigation.js +1 -2
- package/es-modules/Accessibility/KeyboardNavigationHandler.js +1 -2
- package/es-modules/Accessibility/Options/A11yDefaults.d.ts +11 -0
- package/es-modules/Accessibility/Options/A11yDefaults.js +11 -0
- package/es-modules/Accessibility/Options/DeprecatedOptions.d.ts +58 -0
- package/es-modules/Accessibility/Options/DeprecatedOptions.js +7 -2
- package/es-modules/Accessibility/Options/LangDefaults.js +9 -0
- package/es-modules/Accessibility/ProxyElement.js +2 -5
- package/es-modules/Accessibility/ProxyProvider.js +1 -2
- package/es-modules/Accessibility/Utils/Announcer.js +2 -3
- package/es-modules/Accessibility/Utils/ChartUtilities.js +1 -2
- package/es-modules/Accessibility/Utils/EventProvider.d.ts +2 -2
- package/es-modules/Accessibility/Utils/EventProvider.js +6 -2
- package/es-modules/Accessibility/Utils/HTMLUtilities.js +1 -2
- package/es-modules/Core/Animation/AnimationUtilities.js +1 -2
- package/es-modules/Core/Animation/Fx.js +1 -2
- package/es-modules/Core/Callback.d.ts +9 -2
- package/es-modules/Core/Chart/Chart.js +48 -41
- package/es-modules/Core/Chart/Chart3D.js +1 -2
- package/es-modules/Core/Chart/ChartDefaults.js +11 -0
- package/es-modules/Core/Chart/ChartOptions.d.ts +8 -0
- package/es-modules/Core/Chart/GanttChart.js +1 -2
- package/es-modules/Core/Chart/MapChart.js +1 -2
- package/es-modules/Core/Chart/StockChart.js +2 -3
- package/es-modules/Core/Color/Color.js +1 -2
- package/es-modules/Core/Defaults.js +36 -9
- package/es-modules/Core/Delaunay.d.ts +52 -0
- package/es-modules/Core/Delaunay.js +310 -0
- package/es-modules/Core/Foundation.js +1 -2
- package/es-modules/Core/Geometry/CircleUtilities.js +1 -2
- package/es-modules/Core/Globals.js +1 -1
- package/es-modules/Core/HttpUtilities.js +1 -2
- package/es-modules/Core/MSPointer.js +1 -2
- package/es-modules/Core/Math3D.js +1 -2
- package/es-modules/Core/Options.d.ts +6 -2
- package/es-modules/Core/Pointer.js +23 -4
- package/es-modules/Core/PointerEvent.d.ts +2 -0
- package/es-modules/Core/Renderer/HTML/AST.js +2 -2
- package/es-modules/Core/Renderer/HTML/HTMLElement.js +1 -2
- package/es-modules/Core/Renderer/RendererUtilities.js +34 -19
- package/es-modules/Core/Responsive.d.ts +4 -2
- package/es-modules/Core/Responsive.js +10 -4
- package/es-modules/Core/Templating.d.ts +1 -1
- package/es-modules/Core/Templating.js +3 -4
- package/es-modules/Core/Time.d.ts +8 -0
- package/es-modules/Core/Time.js +2 -2
- package/es-modules/Core/Tooltip.d.ts +4 -8
- package/es-modules/Core/Tooltip.js +100 -81
- package/es-modules/Core/TooltipOptions.d.ts +44 -1
- package/es-modules/Core/Utilities.d.ts +25 -665
- package/es-modules/Core/Utilities.js +17 -1398
- package/es-modules/Data/ColumnUtils.d.ts +83 -80
- package/es-modules/Data/ColumnUtils.js +103 -113
- package/es-modules/Data/Connectors/CSVConnector.d.ts +9 -14
- package/es-modules/Data/Connectors/CSVConnector.js +3 -4
- package/es-modules/Data/Connectors/DataConnector.d.ts +52 -54
- package/es-modules/Data/Connectors/DataConnector.js +33 -52
- package/es-modules/Data/Connectors/GoogleSheetsConnector.d.ts +40 -42
- package/es-modules/Data/Connectors/GoogleSheetsConnector.js +73 -88
- package/es-modules/Data/Connectors/GoogleSheetsConnectorOptions.d.ts +4 -2
- package/es-modules/Data/Connectors/HTMLTableConnector.d.ts +23 -28
- package/es-modules/Data/Connectors/HTMLTableConnector.js +3 -4
- package/es-modules/Data/Connectors/JSONConnector.d.ts +9 -14
- package/es-modules/Data/Connectors/JSONConnector.js +3 -4
- package/es-modules/Data/Converters/CSVConverter.d.ts +5 -5
- package/es-modules/Data/Converters/CSVConverter.js +3 -4
- package/es-modules/Data/Converters/CSVConverterOptions.d.ts +2 -2
- package/es-modules/Data/Converters/DataConverter.d.ts +76 -78
- package/es-modules/Data/Converters/DataConverter.js +26 -53
- package/es-modules/Data/Converters/DataConverterUtils.d.ts +88 -81
- package/es-modules/Data/Converters/DataConverterUtils.js +169 -181
- package/es-modules/Data/Converters/GoogleSheetsConverter.d.ts +4 -4
- package/es-modules/Data/Converters/GoogleSheetsConverter.js +3 -3
- package/es-modules/Data/Converters/GoogleSheetsConverterOptions.d.ts +2 -2
- package/es-modules/Data/Converters/HTMLTableConverter.d.ts +4 -4
- package/es-modules/Data/Converters/HTMLTableConverter.js +2 -3
- package/es-modules/Data/Converters/HTMLTableConverterOptions.d.ts +2 -2
- package/es-modules/Data/Converters/JSONConverter.d.ts +7 -7
- package/es-modules/Data/Converters/JSONConverter.js +6 -6
- package/es-modules/Data/Converters/JSONConverterOptions.d.ts +2 -2
- package/es-modules/Data/DataCursor.d.ts +65 -70
- package/es-modules/Data/DataCursor.js +119 -139
- package/es-modules/Data/DataEvent.d.ts +55 -57
- package/es-modules/Data/DataPool.d.ts +10 -17
- package/es-modules/Data/DataPool.js +20 -9
- package/es-modules/Data/DataTable.d.ts +111 -113
- package/es-modules/Data/DataTable.js +3 -3
- package/es-modules/Data/DataTableCore.d.ts +9 -9
- package/es-modules/Data/DataTableCore.js +2 -2
- package/es-modules/Data/Formula/FormulaParser.js +1 -2
- package/es-modules/Data/Formula/FormulaProcessor.js +1 -2
- package/es-modules/Data/Modifiers/ChainModifier.d.ts +29 -34
- package/es-modules/Data/Modifiers/ChainModifier.js +7 -8
- package/es-modules/Data/Modifiers/DataModifier.d.ts +36 -41
- package/es-modules/Data/Modifiers/DataModifier.js +31 -53
- package/es-modules/Data/Modifiers/FilterModifier.d.ts +4 -4
- package/es-modules/Data/Modifiers/FilterModifier.js +3 -4
- package/es-modules/Data/Modifiers/FilterModifierOptions.d.ts +3 -2
- package/es-modules/Data/Modifiers/InvertModifier.d.ts +4 -4
- package/es-modules/Data/Modifiers/InvertModifier.js +3 -4
- package/es-modules/Data/Modifiers/MathModifier.d.ts +5 -4
- package/es-modules/Data/Modifiers/RangeModifier.d.ts +4 -4
- package/es-modules/Data/Modifiers/RangeModifier.js +3 -4
- package/es-modules/Data/Modifiers/SortModifier.d.ts +6 -11
- package/es-modules/Data/Modifiers/SortModifier.js +3 -4
- package/es-modules/Data/Modifiers/SortModifierOptions.d.ts +3 -3
- package/es-modules/Grid/Core/Accessibility/Accessibility.d.ts +1 -1
- package/es-modules/Grid/Core/Accessibility/Accessibility.js +5 -6
- package/es-modules/Grid/Core/Data/DataProvider.d.ts +97 -0
- package/es-modules/Grid/Core/Data/DataProvider.js +89 -0
- package/es-modules/Grid/Core/Data/DataProviderRegistry.d.ts +20 -0
- package/es-modules/Grid/Core/Data/DataProviderRegistry.js +52 -0
- package/es-modules/Grid/Core/Data/DataProviderType.d.ts +19 -0
- package/es-modules/Grid/Core/Data/DataProviderType.js +15 -0
- package/es-modules/Grid/Core/Data/LocalDataProvider.d.ts +165 -0
- package/es-modules/Grid/Core/Data/LocalDataProvider.js +341 -0
- package/es-modules/Grid/Core/Defaults.js +4 -2
- package/es-modules/Grid/Core/Globals.d.ts +20 -16
- package/es-modules/Grid/Core/Globals.js +10 -8
- package/es-modules/Grid/Core/Grid.d.ts +31 -22
- package/es-modules/Grid/Core/Grid.js +214 -136
- package/es-modules/Grid/Core/GridUtils.d.ts +33 -0
- package/es-modules/Grid/Core/GridUtils.js +50 -3
- package/es-modules/Grid/Core/Options.d.ts +145 -4
- package/es-modules/Grid/Core/Pagination/Pagination.d.ts +3 -0
- package/es-modules/Grid/Core/Pagination/Pagination.js +63 -23
- package/es-modules/Grid/Core/Pagination/PaginationOptions.d.ts +4 -0
- package/es-modules/Grid/Core/Querying/FilteringController.js +1 -2
- package/es-modules/Grid/Core/Querying/PaginationController.d.ts +2 -2
- package/es-modules/Grid/Core/Querying/PaginationController.js +3 -3
- package/es-modules/Grid/Core/Querying/QueryingController.d.ts +1 -1
- package/es-modules/Grid/Core/Querying/QueryingController.js +2 -26
- package/es-modules/Grid/Core/Responsive/ResponsiveComposition.d.ts +53 -0
- package/es-modules/Grid/Core/Responsive/ResponsiveComposition.js +229 -0
- package/es-modules/Grid/Core/Responsive/ResponsiveOptions.d.ts +58 -0
- package/es-modules/Grid/Core/Responsive/ResponsiveOptions.js +15 -0
- package/es-modules/Grid/Core/Table/Actions/ColumnFiltering/ColumnFiltering.js +2 -3
- package/es-modules/Grid/Core/Table/Actions/ColumnFiltering/FilterCell.d.ts +1 -1
- package/es-modules/Grid/Core/Table/Actions/ColumnFiltering/FilterCell.js +3 -4
- package/es-modules/Grid/Core/Table/Actions/ColumnFiltering/FilterRow.d.ts +1 -1
- package/es-modules/Grid/Core/Table/Actions/ColumnFiltering/FilterRow.js +2 -2
- package/es-modules/Grid/Core/Table/Actions/ColumnSorting.d.ts +17 -1
- package/es-modules/Grid/Core/Table/Actions/ColumnSorting.js +58 -15
- package/es-modules/Grid/Core/Table/Actions/ColumnsResizer.js +1 -3
- package/es-modules/Grid/Core/Table/Actions/RowsVirtualizer.d.ts +57 -3
- package/es-modules/Grid/Core/Table/Actions/RowsVirtualizer.js +397 -118
- package/es-modules/Grid/Core/Table/Body/CellContextMenu.d.ts +11 -0
- package/es-modules/Grid/Core/Table/Body/CellContextMenu.js +84 -0
- package/es-modules/Grid/Core/Table/Body/TableCell.d.ts +27 -13
- package/es-modules/Grid/Core/Table/Body/TableCell.js +74 -25
- package/es-modules/Grid/Core/Table/Body/TableRow.d.ts +7 -15
- package/es-modules/Grid/Core/Table/Body/TableRow.js +24 -19
- package/es-modules/Grid/Core/Table/Cell.d.ts +16 -3
- package/es-modules/Grid/Core/Table/Cell.js +36 -3
- package/es-modules/Grid/Core/Table/CellContent/TextContent.js +3 -8
- package/es-modules/Grid/Core/Table/Column.d.ts +10 -4
- package/es-modules/Grid/Core/Table/Column.js +23 -34
- package/es-modules/Grid/Core/Table/ColumnResizing/IndependentResizingMode.js +9 -8
- package/es-modules/Grid/Core/Table/ColumnResizing/ResizingMode.js +4 -3
- package/es-modules/Grid/Core/Table/Header/ColumnToolbar/ColumnToolbar.d.ts +5 -0
- package/es-modules/Grid/Core/Table/Header/ColumnToolbar/ColumnToolbar.js +7 -2
- package/es-modules/Grid/Core/Table/Header/ColumnToolbar/FilterPopup.js +1 -2
- package/es-modules/Grid/Core/Table/Header/ColumnToolbar/MenuButtons/FilterMenuButton.js +1 -2
- package/es-modules/Grid/Core/Table/Header/ColumnToolbar/MenuButtons/SortMenuButton.js +2 -3
- package/es-modules/Grid/Core/Table/Header/ColumnToolbar/ToolbarButtons/FilterToolbarButton.js +1 -2
- package/es-modules/Grid/Core/Table/Header/ColumnToolbar/ToolbarButtons/MenuToolbarButton.js +1 -2
- package/es-modules/Grid/Core/Table/Header/ColumnToolbar/ToolbarButtons/SortToolbarButton.d.ts +0 -1
- package/es-modules/Grid/Core/Table/Header/ColumnToolbar/ToolbarButtons/SortToolbarButton.js +4 -14
- package/es-modules/Grid/Core/Table/Header/HeaderCell.d.ts +6 -1
- package/es-modules/Grid/Core/Table/Header/HeaderCell.js +33 -13
- package/es-modules/Grid/Core/Table/Header/HeaderRow.js +4 -5
- package/es-modules/Grid/Core/Table/Header/TableHeader.d.ts +1 -1
- package/es-modules/Grid/Core/Table/Header/TableHeader.js +3 -3
- package/es-modules/Grid/Core/Table/Row.d.ts +1 -1
- package/es-modules/Grid/Core/Table/Row.js +2 -2
- package/es-modules/Grid/Core/Table/Table.d.ts +38 -12
- package/es-modules/Grid/Core/Table/Table.js +184 -91
- package/es-modules/Grid/Core/UI/ContextMenuButton.d.ts +6 -7
- package/es-modules/Grid/Core/UI/ContextMenuButton.js +5 -3
- package/es-modules/Grid/Core/UI/Popup.js +7 -9
- package/es-modules/Grid/Core/UI/SvgIcons.d.ts +42 -7
- package/es-modules/Grid/Core/UI/SvgIcons.js +206 -33
- package/es-modules/Grid/Core/UI/Toolbar.d.ts +5 -0
- package/es-modules/Grid/Core/UI/ToolbarButton.d.ts +4 -12
- package/es-modules/Grid/Core/UI/ToolbarButton.js +8 -26
- package/es-modules/Grid/Pro/CellEditing/CellEditMode.d.ts +2 -2
- package/es-modules/Grid/Pro/CellEditing/CellEditing.js +10 -10
- package/es-modules/Grid/Pro/CellEditing/CellEditingComposition.js +1 -2
- package/es-modules/Grid/Pro/CellRendering/CellRenderersComposition.d.ts +1 -1
- package/es-modules/Grid/Pro/CellRendering/CellRenderersComposition.js +4 -2
- package/es-modules/Grid/Pro/CellRendering/ContentTypes/CheckboxContent.d.ts +2 -2
- package/es-modules/Grid/Pro/CellRendering/ContentTypes/NumberInputContent.js +1 -2
- package/es-modules/Grid/Pro/CellRendering/ContentTypes/SelectContent.d.ts +2 -2
- package/es-modules/Grid/Pro/CellRendering/ContentTypes/SparklineContent.js +1 -2
- package/es-modules/Grid/Pro/CellRendering/ContentTypes/TextInputContent.d.ts +2 -2
- package/es-modules/Grid/Pro/CellRendering/ContentTypes/TextInputContent.js +1 -2
- package/es-modules/Grid/Pro/CellRendering/Renderers/CheckboxRenderer.js +1 -2
- package/es-modules/Grid/Pro/CellRendering/Renderers/DateInputRenderer.js +1 -2
- package/es-modules/Grid/Pro/CellRendering/Renderers/DateTimeInputRenderer.js +1 -2
- package/es-modules/Grid/Pro/CellRendering/Renderers/NumberInputRenderer.js +1 -2
- package/es-modules/Grid/Pro/CellRendering/Renderers/SelectRenderer.js +1 -2
- package/es-modules/Grid/Pro/CellRendering/Renderers/SparklineRenderer.d.ts +2 -2
- package/es-modules/Grid/Pro/CellRendering/Renderers/SparklineRenderer.js +1 -2
- package/es-modules/Grid/Pro/CellRendering/Renderers/TextInputRenderer.js +1 -2
- package/es-modules/Grid/Pro/CellRendering/Renderers/TextRenderer.js +1 -2
- package/es-modules/Grid/Pro/CellRendering/Renderers/TimeInputRenderer.js +1 -2
- package/es-modules/Grid/Pro/ColumnTypes/Validator.js +34 -32
- package/es-modules/Grid/Pro/ColumnTypes/ValidatorComposition.d.ts +1 -1
- package/es-modules/Grid/Pro/ColumnTypes/ValidatorComposition.js +3 -4
- package/es-modules/Grid/Pro/Credits/CreditsProComposition.js +1 -3
- package/es-modules/Grid/Pro/Data/DataSourceHelper.d.ts +74 -0
- package/es-modules/Grid/Pro/Data/DataSourceHelper.js +246 -0
- package/es-modules/Grid/Pro/Data/QuerySerializer.d.ts +46 -0
- package/es-modules/Grid/Pro/Data/QuerySerializer.js +169 -0
- package/es-modules/Grid/Pro/Data/RemoteDataProvider.d.ts +187 -0
- package/es-modules/Grid/Pro/Data/RemoteDataProvider.js +500 -0
- package/es-modules/Grid/Pro/Export/Exporting.js +1 -2
- package/es-modules/Grid/Pro/Export/ExportingComposition.js +1 -2
- package/es-modules/Grid/Pro/GridEvents.js +1 -2
- package/es-modules/Grid/Pro/Pagination/PaginationComposition.d.ts +0 -1
- package/es-modules/Grid/Pro/Pagination/PaginationComposition.js +1 -2
- package/es-modules/Shared/BaseForm.js +1 -2
- package/es-modules/Shared/DownloadURL.js +1 -2
- package/es-modules/Shared/TimeBase.js +3 -3
- package/es-modules/Shared/Types.d.ts +7 -0
- package/es-modules/Shared/Utilities.d.ts +576 -0
- package/es-modules/Shared/Utilities.js +1368 -0
- package/es-modules/masters/grid-pro.src.d.ts +15 -11
- package/es-modules/masters/grid-pro.src.js +12 -5
- package/grid-pro.d.ts +15 -11
- package/grid-pro.js +3 -3
- package/grid-pro.js.map +1 -1
- package/grid-pro.src.d.ts +15 -11
- package/grid-pro.src.js +10408 -8009
- package/package.json +1 -1
- package/es-modules/Grid/Core/Pagination/Icons.d.ts +0 -7
- package/es-modules/Grid/Core/Pagination/Icons.js +0 -7
|
@@ -0,0 +1,1368 @@
|
|
|
1
|
+
/* *
|
|
2
|
+
*
|
|
3
|
+
* (c) 2009-2026 Highsoft AS
|
|
4
|
+
*
|
|
5
|
+
* A commercial license may be required depending on use.
|
|
6
|
+
* See www.highcharts.com/license
|
|
7
|
+
*
|
|
8
|
+
*
|
|
9
|
+
* */
|
|
10
|
+
import H from '../Core/Globals.js';
|
|
11
|
+
const { doc, win } = H;
|
|
12
|
+
/* eslint-disable valid-jsdoc */
|
|
13
|
+
/**
|
|
14
|
+
* Add an event listener.
|
|
15
|
+
*
|
|
16
|
+
* @function Highcharts.addEvent<T>
|
|
17
|
+
*
|
|
18
|
+
* @param {Highcharts.Class<T>|T} el
|
|
19
|
+
* The element or object to add a listener to. It can be a
|
|
20
|
+
* {@link HTMLDOMElement}, an {@link SVGElement} or any other object.
|
|
21
|
+
*
|
|
22
|
+
* @param {string} type
|
|
23
|
+
* The event type.
|
|
24
|
+
*
|
|
25
|
+
* @param {Highcharts.EventCallbackFunction<T>|Function} fn
|
|
26
|
+
* The function callback to execute when the event is fired.
|
|
27
|
+
*
|
|
28
|
+
* @param {Highcharts.EventOptionsObject} [options]
|
|
29
|
+
* Options for adding the event.
|
|
30
|
+
*
|
|
31
|
+
* @sample highcharts/members/addevent
|
|
32
|
+
* Use a general `render` event to draw shapes on a chart
|
|
33
|
+
*
|
|
34
|
+
* @return {Function}
|
|
35
|
+
* A callback function to remove the added event.
|
|
36
|
+
*/
|
|
37
|
+
export function addEvent(el, type, fn, options = {}) {
|
|
38
|
+
/* eslint-enable valid-jsdoc */
|
|
39
|
+
// Add hcEvents to either the prototype (in case we're running addEvent on a
|
|
40
|
+
// class) or the instance. If hasOwnProperty('hcEvents') is false, it is
|
|
41
|
+
// inherited down the prototype chain, in which case we need to set the
|
|
42
|
+
// property on this instance (which may itself be a prototype).
|
|
43
|
+
const owner = typeof el === 'function' && el.prototype || el;
|
|
44
|
+
if (!Object.hasOwnProperty.call(owner, 'hcEvents')) {
|
|
45
|
+
owner.hcEvents = {};
|
|
46
|
+
}
|
|
47
|
+
const events = owner.hcEvents;
|
|
48
|
+
// Allow click events added to points, otherwise they will be prevented by
|
|
49
|
+
// the TouchPointer.pinch function after a pinch zoom operation (#7091).
|
|
50
|
+
if (H.Point && // Without H a dependency loop occurs
|
|
51
|
+
el instanceof H.Point &&
|
|
52
|
+
el.series &&
|
|
53
|
+
el.series.chart) {
|
|
54
|
+
el.series.chart.runTrackerClick = true;
|
|
55
|
+
}
|
|
56
|
+
// Handle DOM events
|
|
57
|
+
// If the browser supports passive events, add it to improve performance
|
|
58
|
+
// on touch events (#11353).
|
|
59
|
+
const addEventListener = el.addEventListener;
|
|
60
|
+
if (addEventListener) {
|
|
61
|
+
addEventListener.call(el, type, fn, H.supportsPassiveEvents ? {
|
|
62
|
+
passive: options.passive === void 0 ?
|
|
63
|
+
type.indexOf('touch') !== -1 : options.passive,
|
|
64
|
+
capture: false
|
|
65
|
+
} : false);
|
|
66
|
+
}
|
|
67
|
+
if (!events[type]) {
|
|
68
|
+
events[type] = [];
|
|
69
|
+
}
|
|
70
|
+
const eventObject = {
|
|
71
|
+
fn,
|
|
72
|
+
order: typeof options.order === 'number' ? options.order : Infinity
|
|
73
|
+
};
|
|
74
|
+
events[type].push(eventObject);
|
|
75
|
+
// Order the calls
|
|
76
|
+
events[type].sort((a, b) => a.order - b.order);
|
|
77
|
+
// Return a function that can be called to remove this event.
|
|
78
|
+
return function () {
|
|
79
|
+
removeEvent(el, type, fn);
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Non-recursive method to find the lowest member of an array. `Math.min` raises
|
|
84
|
+
* a maximum call stack size exceeded error in Chrome when trying to apply more
|
|
85
|
+
* than 150.000 points. This method is slightly slower, but safe.
|
|
86
|
+
*
|
|
87
|
+
* @function Highcharts.arrayMin
|
|
88
|
+
*
|
|
89
|
+
* @param {Array<*>} data
|
|
90
|
+
* An array of numbers.
|
|
91
|
+
*
|
|
92
|
+
* @return {number}
|
|
93
|
+
* The lowest number.
|
|
94
|
+
*/
|
|
95
|
+
export function arrayMin(data) {
|
|
96
|
+
let i = data.length, min = data[0];
|
|
97
|
+
while (i--) {
|
|
98
|
+
if (data[i] < min) {
|
|
99
|
+
min = data[i];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return min;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Non-recursive method to find the lowest member of an array. `Math.max` raises
|
|
106
|
+
* a maximum call stack size exceeded error in Chrome when trying to apply more
|
|
107
|
+
* than 150.000 points. This method is slightly slower, but safe.
|
|
108
|
+
*
|
|
109
|
+
* @function Highcharts.arrayMax
|
|
110
|
+
*
|
|
111
|
+
* @param {Array<*>} data
|
|
112
|
+
* An array of numbers.
|
|
113
|
+
*
|
|
114
|
+
* @return {number}
|
|
115
|
+
* The highest number.
|
|
116
|
+
*/
|
|
117
|
+
export function arrayMax(data) {
|
|
118
|
+
let i = data.length, max = data[0];
|
|
119
|
+
while (i--) {
|
|
120
|
+
if (data[i] > max) {
|
|
121
|
+
max = data[i];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return max;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Set or get an attribute or an object of attributes.
|
|
128
|
+
*
|
|
129
|
+
* To use as a setter, pass a key and a value, or let the second argument be a
|
|
130
|
+
* collection of keys and values. When using a collection, passing a value of
|
|
131
|
+
* `null` or `undefined` will remove the attribute.
|
|
132
|
+
*
|
|
133
|
+
* To use as a getter, pass only a string as the second argument.
|
|
134
|
+
*
|
|
135
|
+
* @function Highcharts.attr
|
|
136
|
+
*
|
|
137
|
+
* @param {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement} elem
|
|
138
|
+
* The DOM element to receive the attribute(s).
|
|
139
|
+
*
|
|
140
|
+
* @param {string|Highcharts.HTMLAttributes|Highcharts.SVGAttributes} [keyOrAttribs]
|
|
141
|
+
* The property or an object of key-value pairs.
|
|
142
|
+
*
|
|
143
|
+
* @param {number|string} [value]
|
|
144
|
+
* The value if a single property is set.
|
|
145
|
+
*
|
|
146
|
+
* @return {string|null|undefined}
|
|
147
|
+
* When used as a getter, return the value.
|
|
148
|
+
*/
|
|
149
|
+
export function attr(elem, keyOrAttribs, value) {
|
|
150
|
+
const isGetter = isString(keyOrAttribs) && !defined(value);
|
|
151
|
+
let ret;
|
|
152
|
+
const attrSingle = (value, key) => {
|
|
153
|
+
// Set the value
|
|
154
|
+
if (defined(value)) {
|
|
155
|
+
elem.setAttribute(key, value);
|
|
156
|
+
// Get the value
|
|
157
|
+
}
|
|
158
|
+
else if (isGetter) {
|
|
159
|
+
ret = elem.getAttribute(key);
|
|
160
|
+
// IE7 and below cannot get class through getAttribute (#7850)
|
|
161
|
+
if (!ret && key === 'class') {
|
|
162
|
+
ret = elem.getAttribute(key + 'Name');
|
|
163
|
+
}
|
|
164
|
+
// Remove the value
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
elem.removeAttribute(key);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
// If keyOrAttribs is a string
|
|
171
|
+
if (isString(keyOrAttribs)) {
|
|
172
|
+
attrSingle(value, keyOrAttribs);
|
|
173
|
+
// Else if keyOrAttribs is defined, it is a hash of key/value pairs
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
objectEach(keyOrAttribs, attrSingle);
|
|
177
|
+
}
|
|
178
|
+
return ret;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Constrain a value to within a lower and upper threshold.
|
|
182
|
+
*
|
|
183
|
+
* @internal
|
|
184
|
+
* @param {number} value The initial value
|
|
185
|
+
* @param {number} min The lower threshold
|
|
186
|
+
* @param {number} max The upper threshold
|
|
187
|
+
* @return {number} Returns a number value within min and max.
|
|
188
|
+
*/
|
|
189
|
+
export function clamp(value, min, max) {
|
|
190
|
+
return value > min ? value < max ? value : max : min;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Fix JS round off float errors.
|
|
194
|
+
*
|
|
195
|
+
* @function Highcharts.correctFloat
|
|
196
|
+
*
|
|
197
|
+
* @param {number} num
|
|
198
|
+
* A float number to fix.
|
|
199
|
+
*
|
|
200
|
+
* @param {number} [prec=14]
|
|
201
|
+
* The precision.
|
|
202
|
+
*
|
|
203
|
+
* @return {number}
|
|
204
|
+
* The corrected float number.
|
|
205
|
+
*/
|
|
206
|
+
export function correctFloat(num, prec) {
|
|
207
|
+
// When the number is higher than 1e14 use the number (#16275)
|
|
208
|
+
return num > 1e14 ? num : parseFloat(num.toPrecision(prec || 14));
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Utility function to create an HTML element with attributes and styles.
|
|
212
|
+
*
|
|
213
|
+
* @function Highcharts.createElement
|
|
214
|
+
*
|
|
215
|
+
* @param {string} tag
|
|
216
|
+
* The HTML tag.
|
|
217
|
+
*
|
|
218
|
+
* @param {Highcharts.HTMLAttributes} [attribs]
|
|
219
|
+
* Attributes as an object of key-value pairs.
|
|
220
|
+
*
|
|
221
|
+
* @param {Highcharts.CSSObject} [styles]
|
|
222
|
+
* Styles as an object of key-value pairs.
|
|
223
|
+
*
|
|
224
|
+
* @param {Highcharts.HTMLDOMElement} [parent]
|
|
225
|
+
* The parent HTML object.
|
|
226
|
+
*
|
|
227
|
+
* @param {boolean} [nopad=false]
|
|
228
|
+
* If true, remove all padding, border and margin.
|
|
229
|
+
*
|
|
230
|
+
* @return {Highcharts.HTMLDOMElement}
|
|
231
|
+
* The created DOM element.
|
|
232
|
+
*/
|
|
233
|
+
export function createElement(tag, attribs, styles, parent, nopad) {
|
|
234
|
+
const el = doc.createElement(tag);
|
|
235
|
+
if (attribs) {
|
|
236
|
+
extend(el, attribs);
|
|
237
|
+
}
|
|
238
|
+
if (nopad) {
|
|
239
|
+
css(el, { padding: '0', border: 'none', margin: '0' });
|
|
240
|
+
}
|
|
241
|
+
if (styles) {
|
|
242
|
+
css(el, styles);
|
|
243
|
+
}
|
|
244
|
+
if (parent) {
|
|
245
|
+
parent.appendChild(el);
|
|
246
|
+
}
|
|
247
|
+
return el;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Utility for crisping a line position to the nearest full pixel depening on
|
|
251
|
+
* the line width
|
|
252
|
+
*
|
|
253
|
+
* @internal
|
|
254
|
+
* @param {number} value The raw pixel position
|
|
255
|
+
* @param {number} lineWidth The line width
|
|
256
|
+
* @param {boolean} [inverted] Whether the containing group is inverted.
|
|
257
|
+
* Crisping round numbers on the y-scale need to go
|
|
258
|
+
* to the other side because the coordinate system
|
|
259
|
+
* is flipped (scaleY is -1)
|
|
260
|
+
* @return {number} The pixel position to use for a crisp display
|
|
261
|
+
*/
|
|
262
|
+
export function crisp(value, lineWidth = 0, inverted) {
|
|
263
|
+
const mod = lineWidth % 2 / 2, inverter = inverted ? -1 : 1;
|
|
264
|
+
return (Math.round(value * inverter - mod) + mod) * inverter;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Set CSS on a given element.
|
|
268
|
+
*
|
|
269
|
+
* @function Highcharts.css
|
|
270
|
+
*
|
|
271
|
+
* @param {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement} el
|
|
272
|
+
* An HTML DOM element.
|
|
273
|
+
*
|
|
274
|
+
* @param {Highcharts.CSSObject} styles
|
|
275
|
+
* Style object with camel case property names.
|
|
276
|
+
*
|
|
277
|
+
* @return {void}
|
|
278
|
+
*/
|
|
279
|
+
export function css(el, styles) {
|
|
280
|
+
extend(el.style, styles);
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Check if an object is null or undefined.
|
|
284
|
+
*
|
|
285
|
+
* @function Highcharts.defined
|
|
286
|
+
*
|
|
287
|
+
* @param {*} obj
|
|
288
|
+
* The object to check.
|
|
289
|
+
*
|
|
290
|
+
* @return {boolean}
|
|
291
|
+
* False if the object is null or undefined, otherwise true.
|
|
292
|
+
*/
|
|
293
|
+
export function defined(obj) {
|
|
294
|
+
return typeof obj !== 'undefined' && obj !== null;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Utility method that destroys any SVGElement instances that are properties on
|
|
298
|
+
* the given object. It loops all properties and invokes destroy if there is a
|
|
299
|
+
* destroy method. The property is then delete.
|
|
300
|
+
*
|
|
301
|
+
* @function Highcharts.destroyObjectProperties
|
|
302
|
+
*
|
|
303
|
+
* @param {*} obj
|
|
304
|
+
* The object to destroy properties on.
|
|
305
|
+
*
|
|
306
|
+
* @param {*} [except]
|
|
307
|
+
* Exception, do not destroy this property, only delete it.
|
|
308
|
+
*/
|
|
309
|
+
export function destroyObjectProperties(obj, except, destructablesOnly) {
|
|
310
|
+
objectEach(obj, function (val, n) {
|
|
311
|
+
// If the object is non-null and destroy is defined
|
|
312
|
+
if (val !== except && val?.destroy) {
|
|
313
|
+
// Invoke the destroy
|
|
314
|
+
val.destroy();
|
|
315
|
+
}
|
|
316
|
+
// Delete the property from the object
|
|
317
|
+
if (val?.destroy || !destructablesOnly) {
|
|
318
|
+
delete obj[n];
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Discard a HTML element
|
|
324
|
+
*
|
|
325
|
+
* @function Highcharts.discardElement
|
|
326
|
+
*
|
|
327
|
+
* @param {Highcharts.HTMLDOMElement} element
|
|
328
|
+
* The HTML node to discard.
|
|
329
|
+
*/
|
|
330
|
+
export function discardElement(element) {
|
|
331
|
+
element?.parentElement?.removeChild(element);
|
|
332
|
+
}
|
|
333
|
+
// eslint-disable-next-line valid-jsdoc
|
|
334
|
+
/**
|
|
335
|
+
* Return the deep difference between two objects. It can either return the new
|
|
336
|
+
* properties, or optionally return the old values of new properties.
|
|
337
|
+
* @internal
|
|
338
|
+
*/
|
|
339
|
+
export function diffObjects(newer, older, keepOlder, collectionsWithUpdate) {
|
|
340
|
+
const ret = {};
|
|
341
|
+
/**
|
|
342
|
+
* Recurse over a set of options and its current values, and store the
|
|
343
|
+
* current values in the ret object.
|
|
344
|
+
*/
|
|
345
|
+
function diff(newer, older, ret, depth) {
|
|
346
|
+
const keeper = keepOlder ? older : newer;
|
|
347
|
+
objectEach(newer, function (newerVal, key) {
|
|
348
|
+
if (!depth &&
|
|
349
|
+
collectionsWithUpdate &&
|
|
350
|
+
collectionsWithUpdate.indexOf(key) > -1 &&
|
|
351
|
+
older[key]) {
|
|
352
|
+
newerVal = splat(newerVal);
|
|
353
|
+
ret[key] = [];
|
|
354
|
+
// Iterate over collections like series, xAxis or yAxis and map
|
|
355
|
+
// the items by index.
|
|
356
|
+
for (let i = 0; i < Math.max(newerVal.length, older[key].length); i++) {
|
|
357
|
+
// Item exists in current data (#6347)
|
|
358
|
+
if (older[key][i]) {
|
|
359
|
+
// If the item is missing from the new data, we need to
|
|
360
|
+
// save the whole config structure. Like when
|
|
361
|
+
// responsively updating from a dual axis layout to a
|
|
362
|
+
// single axis and back (#13544).
|
|
363
|
+
if (newerVal[i] === void 0) {
|
|
364
|
+
ret[key][i] = older[key][i];
|
|
365
|
+
// Otherwise, proceed
|
|
366
|
+
}
|
|
367
|
+
else {
|
|
368
|
+
ret[key][i] = {};
|
|
369
|
+
diff(newerVal[i], older[key][i], ret[key][i], depth + 1);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
else if (isObject(newerVal, true) &&
|
|
375
|
+
!newerVal.nodeType // #10044
|
|
376
|
+
) {
|
|
377
|
+
ret[key] = isArray(newerVal) ? [] : {};
|
|
378
|
+
diff(newerVal, older[key] || {}, ret[key], depth + 1);
|
|
379
|
+
// Delete empty nested objects
|
|
380
|
+
if (Object.keys(ret[key]).length === 0 &&
|
|
381
|
+
// Except colorAxis which is a special case where the empty
|
|
382
|
+
// object means it is enabled. Which is unfortunate and we
|
|
383
|
+
// should try to find a better way.
|
|
384
|
+
!(key === 'colorAxis' && depth === 0)) {
|
|
385
|
+
delete ret[key];
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
else if (newer[key] !== older[key] ||
|
|
389
|
+
// If the newer key is explicitly undefined, keep it (#10525)
|
|
390
|
+
(key in newer && !(key in older))) {
|
|
391
|
+
if (key !== '__proto__' && key !== 'constructor') {
|
|
392
|
+
ret[key] = keeper[key];
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
diff(newer, older, ret, 0);
|
|
398
|
+
return ret;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Remove the last occurence of an item from an array.
|
|
402
|
+
*
|
|
403
|
+
* @function Highcharts.erase
|
|
404
|
+
*
|
|
405
|
+
* @param {Array<*>} arr
|
|
406
|
+
* The array.
|
|
407
|
+
*
|
|
408
|
+
* @param {*} item
|
|
409
|
+
* The item to remove.
|
|
410
|
+
*
|
|
411
|
+
* @return {void}
|
|
412
|
+
*/
|
|
413
|
+
export function erase(arr, item) {
|
|
414
|
+
let i = arr.length;
|
|
415
|
+
while (i--) {
|
|
416
|
+
if (arr[i] === item) {
|
|
417
|
+
arr.splice(i, 1);
|
|
418
|
+
break;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Utility function to extend an object with the members of another.
|
|
424
|
+
*
|
|
425
|
+
* @function Highcharts.extend<T>
|
|
426
|
+
*
|
|
427
|
+
* @param {T|undefined} a
|
|
428
|
+
* The object to be extended.
|
|
429
|
+
*
|
|
430
|
+
* @param {Partial<T>} b
|
|
431
|
+
* The object to add to the first one.
|
|
432
|
+
*
|
|
433
|
+
* @return {T}
|
|
434
|
+
* Object a, the original object.
|
|
435
|
+
*/
|
|
436
|
+
export function extend(a, b) {
|
|
437
|
+
/* eslint-enable valid-jsdoc */
|
|
438
|
+
let n;
|
|
439
|
+
if (!a) {
|
|
440
|
+
a = {};
|
|
441
|
+
}
|
|
442
|
+
for (n in b) { // eslint-disable-line guard-for-in
|
|
443
|
+
a[n] = b[n];
|
|
444
|
+
}
|
|
445
|
+
return a;
|
|
446
|
+
}
|
|
447
|
+
// eslint-disable-next-line valid-jsdoc
|
|
448
|
+
/**
|
|
449
|
+
* Extend a prototyped class by new members.
|
|
450
|
+
*
|
|
451
|
+
* @deprecated
|
|
452
|
+
* @function Highcharts.extendClass<T>
|
|
453
|
+
*
|
|
454
|
+
* @param {Highcharts.Class<T>} parent
|
|
455
|
+
* The parent prototype to inherit.
|
|
456
|
+
*
|
|
457
|
+
* @param {Highcharts.Dictionary<*>} members
|
|
458
|
+
* A collection of prototype members to add or override compared to the
|
|
459
|
+
* parent prototype.
|
|
460
|
+
*
|
|
461
|
+
* @return {Highcharts.Class<T>}
|
|
462
|
+
* A new prototype.
|
|
463
|
+
*/
|
|
464
|
+
export function extendClass(parent, members) {
|
|
465
|
+
const obj = (function () { });
|
|
466
|
+
obj.prototype = new parent(); // eslint-disable-line new-cap
|
|
467
|
+
extend(obj.prototype, members);
|
|
468
|
+
return obj;
|
|
469
|
+
}
|
|
470
|
+
/* eslint-disable valid-jsdoc */
|
|
471
|
+
/**
|
|
472
|
+
* Fire an event that was registered with {@link Highcharts#addEvent}.
|
|
473
|
+
*
|
|
474
|
+
* @function Highcharts.fireEvent<T>
|
|
475
|
+
*
|
|
476
|
+
* @param {T} el
|
|
477
|
+
* The object to fire the event on. It can be a {@link HTMLDOMElement},
|
|
478
|
+
* an {@link SVGElement} or any other object.
|
|
479
|
+
*
|
|
480
|
+
* @param {string} type
|
|
481
|
+
* The type of event.
|
|
482
|
+
*
|
|
483
|
+
* @param {Highcharts.Dictionary<*>|Event} [eventArguments]
|
|
484
|
+
* Custom event arguments that are passed on as an argument to the event
|
|
485
|
+
* handler.
|
|
486
|
+
*
|
|
487
|
+
* @param {Highcharts.EventCallbackFunction<T>|Function} [defaultFunction]
|
|
488
|
+
* The default function to execute if the other listeners haven't
|
|
489
|
+
* returned false.
|
|
490
|
+
*
|
|
491
|
+
* @return {void}
|
|
492
|
+
*/
|
|
493
|
+
export function fireEvent(el, type, eventArguments, defaultFunction) {
|
|
494
|
+
/* eslint-enable valid-jsdoc */
|
|
495
|
+
eventArguments = eventArguments || {};
|
|
496
|
+
if (doc?.createEvent &&
|
|
497
|
+
(el.dispatchEvent ||
|
|
498
|
+
(el.fireEvent &&
|
|
499
|
+
// Enable firing events on Highcharts instance.
|
|
500
|
+
el !== H))) {
|
|
501
|
+
const e = doc.createEvent('Events');
|
|
502
|
+
e.initEvent(type, true, true);
|
|
503
|
+
eventArguments = extend(e, eventArguments);
|
|
504
|
+
if (el.dispatchEvent) {
|
|
505
|
+
el.dispatchEvent(eventArguments);
|
|
506
|
+
}
|
|
507
|
+
else {
|
|
508
|
+
el.fireEvent(type, eventArguments);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
else if (el.hcEvents) {
|
|
512
|
+
if (!eventArguments.target) {
|
|
513
|
+
// We're running a custom event
|
|
514
|
+
extend(eventArguments, {
|
|
515
|
+
// Attach a simple preventDefault function to skip
|
|
516
|
+
// default handler if called. The built-in
|
|
517
|
+
// defaultPrevented property is not overwritable (#5112)
|
|
518
|
+
preventDefault: function () {
|
|
519
|
+
eventArguments.defaultPrevented = true;
|
|
520
|
+
},
|
|
521
|
+
// Setting target to native events fails with clicking
|
|
522
|
+
// the zoom-out button in Chrome.
|
|
523
|
+
target: el,
|
|
524
|
+
// If the type is not set, we're running a custom event
|
|
525
|
+
// (#2297). If it is set, we're running a browser event.
|
|
526
|
+
type: type
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
const events = [];
|
|
530
|
+
let object = el;
|
|
531
|
+
let multilevel = false;
|
|
532
|
+
// Recurse up the inheritance chain and collect hcEvents set as own
|
|
533
|
+
// objects on the prototypes.
|
|
534
|
+
while (object.hcEvents) {
|
|
535
|
+
if (Object.hasOwnProperty.call(object, 'hcEvents') &&
|
|
536
|
+
object.hcEvents[type]) {
|
|
537
|
+
if (events.length) {
|
|
538
|
+
multilevel = true;
|
|
539
|
+
}
|
|
540
|
+
events.unshift.apply(events, object.hcEvents[type]);
|
|
541
|
+
}
|
|
542
|
+
object = Object.getPrototypeOf(object);
|
|
543
|
+
}
|
|
544
|
+
// For performance reasons, only sort the event handlers in case we are
|
|
545
|
+
// dealing with multiple levels in the prototype chain. Otherwise, the
|
|
546
|
+
// events are already sorted in the addEvent function.
|
|
547
|
+
if (multilevel) {
|
|
548
|
+
// Order the calls
|
|
549
|
+
events.sort((a, b) => a.order - b.order);
|
|
550
|
+
}
|
|
551
|
+
// Call the collected event handlers
|
|
552
|
+
events.forEach((obj) => {
|
|
553
|
+
// If the event handler returns false, prevent the default handler
|
|
554
|
+
// from executing
|
|
555
|
+
if (obj.fn.call(el, eventArguments, el) === false) {
|
|
556
|
+
eventArguments.preventDefault();
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
// Run the default if not prevented
|
|
561
|
+
if (defaultFunction && !eventArguments.defaultPrevented) {
|
|
562
|
+
defaultFunction.call(el, eventArguments);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Convenience function to get the align factor, used several places for
|
|
567
|
+
* computing positions
|
|
568
|
+
* @internal
|
|
569
|
+
*/
|
|
570
|
+
export const getAlignFactor = (align = '') => ({
|
|
571
|
+
center: 0.5,
|
|
572
|
+
right: 1,
|
|
573
|
+
middle: 0.5,
|
|
574
|
+
bottom: 1
|
|
575
|
+
}[align] || 0);
|
|
576
|
+
/**
|
|
577
|
+
* Find the closest distance between two values of a two-dimensional array
|
|
578
|
+
* @internal
|
|
579
|
+
* @function Highcharts.getClosestDistance
|
|
580
|
+
*
|
|
581
|
+
* @param {Array<Array<number>>} arrays
|
|
582
|
+
* An array of arrays of numbers
|
|
583
|
+
*
|
|
584
|
+
* @return {number | undefined}
|
|
585
|
+
* The closest distance between values
|
|
586
|
+
*/
|
|
587
|
+
export function getClosestDistance(arrays, onError) {
|
|
588
|
+
const allowNegative = !onError;
|
|
589
|
+
let closest, loopLength, distance, i;
|
|
590
|
+
arrays.forEach((xData) => {
|
|
591
|
+
if (xData.length > 1) {
|
|
592
|
+
loopLength = xData.length - 1;
|
|
593
|
+
for (i = loopLength; i > 0; i--) {
|
|
594
|
+
distance = xData[i] - xData[i - 1];
|
|
595
|
+
if (distance < 0 && !allowNegative) {
|
|
596
|
+
onError?.();
|
|
597
|
+
// Only one call
|
|
598
|
+
onError = void 0;
|
|
599
|
+
}
|
|
600
|
+
else if (distance && (typeof closest === 'undefined' || distance < closest)) {
|
|
601
|
+
closest = distance;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
});
|
|
606
|
+
return closest;
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Get the magnitude of a number.
|
|
610
|
+
*
|
|
611
|
+
* @function Highcharts.getMagnitude
|
|
612
|
+
*
|
|
613
|
+
* @param {number} num
|
|
614
|
+
* The number.
|
|
615
|
+
*
|
|
616
|
+
* @return {number}
|
|
617
|
+
* The magnitude, where 1-9 are magnitude 1, 10-99 magnitude 2 etc.
|
|
618
|
+
*/
|
|
619
|
+
export function getMagnitude(num) {
|
|
620
|
+
return Math.pow(10, Math.floor(Math.log(num) / Math.LN10));
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Returns the value of a property path on a given object.
|
|
624
|
+
*
|
|
625
|
+
* @internal
|
|
626
|
+
* @function getNestedProperty
|
|
627
|
+
*
|
|
628
|
+
* @param {string} path
|
|
629
|
+
* Path to the property, for example `custom.myValue`.
|
|
630
|
+
*
|
|
631
|
+
* @param {unknown} obj
|
|
632
|
+
* Instance containing the property on the specific path.
|
|
633
|
+
*
|
|
634
|
+
* @return {unknown}
|
|
635
|
+
* The unknown property value.
|
|
636
|
+
*/
|
|
637
|
+
export function getNestedProperty(path, parent) {
|
|
638
|
+
const pathElements = path.split('.');
|
|
639
|
+
while (pathElements.length && defined(parent)) {
|
|
640
|
+
const pathElement = pathElements.shift();
|
|
641
|
+
// Filter on the key
|
|
642
|
+
if (typeof pathElement === 'undefined' ||
|
|
643
|
+
pathElement === '__proto__') {
|
|
644
|
+
return; // Undefined
|
|
645
|
+
}
|
|
646
|
+
if (pathElement === 'this') {
|
|
647
|
+
let thisProp;
|
|
648
|
+
if (isObject(parent)) {
|
|
649
|
+
thisProp = parent['@this'];
|
|
650
|
+
}
|
|
651
|
+
return thisProp ?? parent;
|
|
652
|
+
}
|
|
653
|
+
const child = parent[pathElement.replace(/[\\'"]/g, '')];
|
|
654
|
+
// Filter on the child
|
|
655
|
+
if (!defined(child) ||
|
|
656
|
+
typeof child === 'function' ||
|
|
657
|
+
typeof child.nodeType === 'number' ||
|
|
658
|
+
child === win) {
|
|
659
|
+
return; // Undefined
|
|
660
|
+
}
|
|
661
|
+
// Else, proceed
|
|
662
|
+
parent = child;
|
|
663
|
+
}
|
|
664
|
+
return parent;
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* Get the computed CSS value for given element and property, only for numerical
|
|
668
|
+
* properties. For width and height, the dimension of the inner box (excluding
|
|
669
|
+
* padding) is returned. Used for fitting the chart within the container.
|
|
670
|
+
*
|
|
671
|
+
* @function Highcharts.getStyle
|
|
672
|
+
*
|
|
673
|
+
* @param {Highcharts.HTMLDOMElement} el
|
|
674
|
+
* An HTML element.
|
|
675
|
+
*
|
|
676
|
+
* @param {string} prop
|
|
677
|
+
* The property name.
|
|
678
|
+
*
|
|
679
|
+
* @param {boolean} [toInt=true]
|
|
680
|
+
* Parse to integer.
|
|
681
|
+
*
|
|
682
|
+
* @return {number|string|undefined}
|
|
683
|
+
* The style value.
|
|
684
|
+
*/
|
|
685
|
+
export function getStyle(el, prop, toInt) {
|
|
686
|
+
let style;
|
|
687
|
+
// For width and height, return the actual inner pixel size (#4913)
|
|
688
|
+
if (prop === 'width') {
|
|
689
|
+
let offsetWidth = Math.min(el.offsetWidth, el.scrollWidth);
|
|
690
|
+
// In flex boxes, we need to use getBoundingClientRect and floor it,
|
|
691
|
+
// because scrollWidth doesn't support subpixel precision (#6427) ...
|
|
692
|
+
const boundingClientRectWidth = el.getBoundingClientRect?.().width;
|
|
693
|
+
// ...unless if the containing div or its parents are transform-scaled
|
|
694
|
+
// down, in which case the boundingClientRect can't be used as it is
|
|
695
|
+
// also scaled down (#9871, #10498).
|
|
696
|
+
if (boundingClientRectWidth < offsetWidth &&
|
|
697
|
+
boundingClientRectWidth >= offsetWidth - 1) {
|
|
698
|
+
offsetWidth = Math.floor(boundingClientRectWidth);
|
|
699
|
+
}
|
|
700
|
+
return Math.max(0, // #8377
|
|
701
|
+
(offsetWidth -
|
|
702
|
+
(getStyle(el, 'padding-left', true) || 0) -
|
|
703
|
+
(getStyle(el, 'padding-right', true) || 0)));
|
|
704
|
+
}
|
|
705
|
+
if (prop === 'height') {
|
|
706
|
+
return Math.max(0, // #8377
|
|
707
|
+
(Math.min(el.offsetHeight, el.scrollHeight) -
|
|
708
|
+
(getStyle(el, 'padding-top', true) || 0) -
|
|
709
|
+
(getStyle(el, 'padding-bottom', true) || 0)));
|
|
710
|
+
}
|
|
711
|
+
// Otherwise, get the computed style
|
|
712
|
+
const css = win.getComputedStyle(el, void 0); // eslint-disable-line no-undefined
|
|
713
|
+
if (css) {
|
|
714
|
+
style = css.getPropertyValue(prop);
|
|
715
|
+
if (pick(toInt, prop !== 'opacity')) {
|
|
716
|
+
style = pInt(style);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
return style;
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Return the value of the first element in the array that satisfies the
|
|
723
|
+
* provided testing function.
|
|
724
|
+
*
|
|
725
|
+
* @function Highcharts.find<T>
|
|
726
|
+
*
|
|
727
|
+
* @param {Array<T>} arr
|
|
728
|
+
* The array to test.
|
|
729
|
+
*
|
|
730
|
+
* @param {Function} callback
|
|
731
|
+
* The callback function. The function receives the item as the first
|
|
732
|
+
* argument. Return `true` if this item satisfies the condition.
|
|
733
|
+
*
|
|
734
|
+
* @return {T|undefined}
|
|
735
|
+
* The value of the element.
|
|
736
|
+
*/
|
|
737
|
+
export const find = Array.prototype.find ?
|
|
738
|
+
function (arr, callback) {
|
|
739
|
+
return arr.find(callback);
|
|
740
|
+
} :
|
|
741
|
+
// Legacy implementation. PhantomJS, IE <= 11 etc. #7223.
|
|
742
|
+
function (arr, callback) {
|
|
743
|
+
let i;
|
|
744
|
+
const length = arr.length;
|
|
745
|
+
for (i = 0; i < length; i++) {
|
|
746
|
+
if (callback(arr[i], i)) { // eslint-disable-line node/callback-return
|
|
747
|
+
return arr[i];
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
};
|
|
751
|
+
/**
|
|
752
|
+
* Internal clear timeout. The function checks that the `id` was not removed
|
|
753
|
+
* (e.g. by `chart.destroy()`). For the details see
|
|
754
|
+
* [issue #7901](https://github.com/highcharts/highcharts/issues/7901).
|
|
755
|
+
*
|
|
756
|
+
* @internal
|
|
757
|
+
*
|
|
758
|
+
* @function Highcharts.clearTimeout
|
|
759
|
+
*
|
|
760
|
+
* @param {number|undefined} id
|
|
761
|
+
* Id of a timeout.
|
|
762
|
+
*/
|
|
763
|
+
export function internalClearTimeout(id) {
|
|
764
|
+
if (defined(id)) {
|
|
765
|
+
clearTimeout(id);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* Utility function to check if an Object is a HTML Element.
|
|
770
|
+
*
|
|
771
|
+
* @function Highcharts.isDOMElement
|
|
772
|
+
*
|
|
773
|
+
* @param {*} obj
|
|
774
|
+
* The item to check.
|
|
775
|
+
*
|
|
776
|
+
* @return {boolean}
|
|
777
|
+
* True if the argument is a HTML Element.
|
|
778
|
+
*/
|
|
779
|
+
export function isDOMElement(obj) {
|
|
780
|
+
return isObject(obj) && typeof obj.nodeType === 'number';
|
|
781
|
+
}
|
|
782
|
+
/**
|
|
783
|
+
* Utility function to check if an Object is a class.
|
|
784
|
+
*
|
|
785
|
+
* @function Highcharts.isClass
|
|
786
|
+
*
|
|
787
|
+
* @param {object|undefined} obj
|
|
788
|
+
* The item to check.
|
|
789
|
+
*
|
|
790
|
+
* @return {boolean}
|
|
791
|
+
* True if the argument is a class.
|
|
792
|
+
*/
|
|
793
|
+
export function isClass(obj) {
|
|
794
|
+
const c = obj?.constructor;
|
|
795
|
+
return !!(isObject(obj, true) &&
|
|
796
|
+
!isDOMElement(obj) &&
|
|
797
|
+
(c?.name && c.name !== 'Object'));
|
|
798
|
+
}
|
|
799
|
+
/**
|
|
800
|
+
* Utility function to check if an item is a number and it is finite (not NaN,
|
|
801
|
+
* Infinity or -Infinity).
|
|
802
|
+
*
|
|
803
|
+
* @function Highcharts.isNumber
|
|
804
|
+
*
|
|
805
|
+
* @param {*} n
|
|
806
|
+
* The item to check.
|
|
807
|
+
*
|
|
808
|
+
* @return {boolean}
|
|
809
|
+
* True if the item is a finite number
|
|
810
|
+
*/
|
|
811
|
+
export function isNumber(n) {
|
|
812
|
+
return typeof n === 'number' && !isNaN(n) && n < Infinity && n > -Infinity;
|
|
813
|
+
}
|
|
814
|
+
/**
|
|
815
|
+
* Utility function to check for string type.
|
|
816
|
+
*
|
|
817
|
+
* @function Highcharts.isString
|
|
818
|
+
*
|
|
819
|
+
* @param {*} s
|
|
820
|
+
* The item to check.
|
|
821
|
+
*
|
|
822
|
+
* @return {boolean}
|
|
823
|
+
* True if the argument is a string.
|
|
824
|
+
*/
|
|
825
|
+
export function isString(s) {
|
|
826
|
+
return typeof s === 'string';
|
|
827
|
+
}
|
|
828
|
+
/**
|
|
829
|
+
* Utility function to check if an item is an array.
|
|
830
|
+
*
|
|
831
|
+
* @function Highcharts.isArray
|
|
832
|
+
*
|
|
833
|
+
* @param {*} obj
|
|
834
|
+
* The item to check.
|
|
835
|
+
*
|
|
836
|
+
* @return {boolean}
|
|
837
|
+
* True if the argument is an array.
|
|
838
|
+
*/
|
|
839
|
+
export function isArray(obj) {
|
|
840
|
+
const str = Object.prototype.toString.call(obj);
|
|
841
|
+
return str === '[object Array]' || str === '[object Array Iterator]';
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* Utility function to check if object is a function.
|
|
845
|
+
*
|
|
846
|
+
* @function Highcharts.isFunction
|
|
847
|
+
*
|
|
848
|
+
* @param {*} obj
|
|
849
|
+
* The item to check.
|
|
850
|
+
*
|
|
851
|
+
* @return {boolean}
|
|
852
|
+
* True if the argument is a function.
|
|
853
|
+
*/
|
|
854
|
+
export function isFunction(obj) {
|
|
855
|
+
return typeof obj === 'function';
|
|
856
|
+
}
|
|
857
|
+
/**
|
|
858
|
+
* Utility function to check if an item is of type object.
|
|
859
|
+
*
|
|
860
|
+
* @function Highcharts.isObject
|
|
861
|
+
*
|
|
862
|
+
* @param {*} obj
|
|
863
|
+
* The item to check.
|
|
864
|
+
*
|
|
865
|
+
* @param {boolean} [strict=false]
|
|
866
|
+
* Also checks that the object is not an array.
|
|
867
|
+
*
|
|
868
|
+
* @return {boolean}
|
|
869
|
+
* True if the argument is an object.
|
|
870
|
+
*/
|
|
871
|
+
export function isObject(obj, strict) {
|
|
872
|
+
return (!!obj &&
|
|
873
|
+
typeof obj === 'object' &&
|
|
874
|
+
(!strict || !isArray(obj))); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
875
|
+
}
|
|
876
|
+
/**
|
|
877
|
+
* Utility function to deep merge two or more objects and return a third object.
|
|
878
|
+
* If the first argument is true, the contents of the second object is copied
|
|
879
|
+
* into the first object. The merge function can also be used with a single
|
|
880
|
+
* object argument to create a deep copy of an object.
|
|
881
|
+
*
|
|
882
|
+
* @function Highcharts.merge<T>
|
|
883
|
+
*
|
|
884
|
+
* @param {true | T} extendOrSource
|
|
885
|
+
* Whether to extend the left-side object,
|
|
886
|
+
* or the first object to merge as a deep copy.
|
|
887
|
+
*
|
|
888
|
+
* @param {...Array<object|undefined>} [sources]
|
|
889
|
+
* Object(s) to merge into the previous one.
|
|
890
|
+
*
|
|
891
|
+
* @return {T}
|
|
892
|
+
* The merged object. If the first argument is true, the return is the
|
|
893
|
+
* same as the second argument.
|
|
894
|
+
*/
|
|
895
|
+
export function merge(extendOrSource, ...sources) {
|
|
896
|
+
let i, args = [extendOrSource, ...sources], ret = {};
|
|
897
|
+
const doCopy = function (copy, original) {
|
|
898
|
+
// An object is replacing a primitive
|
|
899
|
+
if (typeof copy !== 'object') {
|
|
900
|
+
copy = {};
|
|
901
|
+
}
|
|
902
|
+
objectEach(original, function (value, key) {
|
|
903
|
+
// Prototype pollution (#14883)
|
|
904
|
+
if (key === '__proto__' || key === 'constructor') {
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
// Copy the contents of objects, but not arrays or DOM nodes
|
|
908
|
+
if (isObject(value, true) &&
|
|
909
|
+
!isClass(value) &&
|
|
910
|
+
!isDOMElement(value)) {
|
|
911
|
+
copy[key] = doCopy(copy[key] || {}, value);
|
|
912
|
+
// Primitives and arrays are copied over directly
|
|
913
|
+
}
|
|
914
|
+
else {
|
|
915
|
+
copy[key] = original[key];
|
|
916
|
+
}
|
|
917
|
+
});
|
|
918
|
+
return copy;
|
|
919
|
+
};
|
|
920
|
+
// If first argument is true, copy into the existing object. Used in
|
|
921
|
+
// setOptions.
|
|
922
|
+
if (extendOrSource === true) {
|
|
923
|
+
ret = args[1];
|
|
924
|
+
args = Array.prototype.slice.call(args, 2);
|
|
925
|
+
}
|
|
926
|
+
// For each argument, extend the return
|
|
927
|
+
const len = args.length;
|
|
928
|
+
for (i = 0; i < len; i++) {
|
|
929
|
+
ret = doCopy(ret, args[i]);
|
|
930
|
+
}
|
|
931
|
+
return ret;
|
|
932
|
+
}
|
|
933
|
+
/**
|
|
934
|
+
* Take an interval and normalize it to multiples of round numbers.
|
|
935
|
+
*
|
|
936
|
+
* @deprecated
|
|
937
|
+
* @function Highcharts.normalizeTickInterval
|
|
938
|
+
*
|
|
939
|
+
* @param {number} interval
|
|
940
|
+
* The raw, un-rounded interval.
|
|
941
|
+
*
|
|
942
|
+
* @param {Array<*>} [multiples]
|
|
943
|
+
* Allowed multiples.
|
|
944
|
+
*
|
|
945
|
+
* @param {number} [magnitude]
|
|
946
|
+
* The magnitude of the number.
|
|
947
|
+
*
|
|
948
|
+
* @param {boolean} [allowDecimals]
|
|
949
|
+
* Whether to allow decimals.
|
|
950
|
+
*
|
|
951
|
+
* @param {boolean} [hasTickAmount]
|
|
952
|
+
* If it has tickAmount, avoid landing on tick intervals lower than
|
|
953
|
+
* original.
|
|
954
|
+
*
|
|
955
|
+
* @return {number}
|
|
956
|
+
* The normalized interval.
|
|
957
|
+
*
|
|
958
|
+
* @todo
|
|
959
|
+
* Move this function to the Axis prototype. It is here only for historical
|
|
960
|
+
* reasons.
|
|
961
|
+
*/
|
|
962
|
+
export function normalizeTickInterval(interval, multiples, magnitude, allowDecimals, hasTickAmount) {
|
|
963
|
+
let i, retInterval = interval;
|
|
964
|
+
// Round to a tenfold of 1, 2, 2.5 or 5
|
|
965
|
+
magnitude = pick(magnitude, getMagnitude(interval));
|
|
966
|
+
const normalized = interval / magnitude;
|
|
967
|
+
// Multiples for a linear scale
|
|
968
|
+
if (!multiples) {
|
|
969
|
+
multiples = hasTickAmount ?
|
|
970
|
+
// Finer grained ticks when the tick amount is hard set, including
|
|
971
|
+
// when alignTicks is true on multiple axes (#4580).
|
|
972
|
+
[1, 1.2, 1.5, 2, 2.5, 3, 4, 5, 6, 8, 10] :
|
|
973
|
+
// Else, let ticks fall on rounder numbers
|
|
974
|
+
[1, 2, 2.5, 5, 10];
|
|
975
|
+
// The allowDecimals option
|
|
976
|
+
if (allowDecimals === false) {
|
|
977
|
+
if (magnitude === 1) {
|
|
978
|
+
multiples = multiples.filter(function (num) {
|
|
979
|
+
return num % 1 === 0;
|
|
980
|
+
});
|
|
981
|
+
}
|
|
982
|
+
else if (magnitude <= 0.1) {
|
|
983
|
+
multiples = [1 / magnitude];
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
// Normalize the interval to the nearest multiple
|
|
988
|
+
for (i = 0; i < multiples.length; i++) {
|
|
989
|
+
retInterval = multiples[i];
|
|
990
|
+
// Only allow tick amounts smaller than natural
|
|
991
|
+
if ((hasTickAmount &&
|
|
992
|
+
retInterval * magnitude >= interval) ||
|
|
993
|
+
(!hasTickAmount &&
|
|
994
|
+
(normalized <=
|
|
995
|
+
(multiples[i] +
|
|
996
|
+
(multiples[i + 1] || multiples[i])) / 2))) {
|
|
997
|
+
break;
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
// Multiply back to the correct magnitude. Correct floats to appropriate
|
|
1001
|
+
// precision (#6085).
|
|
1002
|
+
retInterval = correctFloat(retInterval * magnitude, -Math.round(Math.log(0.001) / Math.LN10));
|
|
1003
|
+
return retInterval;
|
|
1004
|
+
}
|
|
1005
|
+
/* eslint-disable valid-jsdoc */
|
|
1006
|
+
/**
|
|
1007
|
+
* Iterate over object key pairs in an object.
|
|
1008
|
+
*
|
|
1009
|
+
* @function Highcharts.objectEach<T>
|
|
1010
|
+
*
|
|
1011
|
+
* @param {*} obj
|
|
1012
|
+
* The object to iterate over.
|
|
1013
|
+
*
|
|
1014
|
+
* @param {Highcharts.ObjectEachCallbackFunction<T>} fn
|
|
1015
|
+
* The iterator callback. It passes three arguments:
|
|
1016
|
+
* * value - The property value.
|
|
1017
|
+
* * key - The property key.
|
|
1018
|
+
* * obj - The object that objectEach is being applied to.
|
|
1019
|
+
*
|
|
1020
|
+
* @param {T} [ctx]
|
|
1021
|
+
* The context.
|
|
1022
|
+
*/
|
|
1023
|
+
export function objectEach(obj, fn, ctx) {
|
|
1024
|
+
/* eslint-enable valid-jsdoc */
|
|
1025
|
+
for (const key in obj) {
|
|
1026
|
+
if (Object.hasOwnProperty.call(obj, key)) {
|
|
1027
|
+
fn.call(ctx || obj[key], obj[key], key, obj);
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
/**
|
|
1032
|
+
* Get the element's offset position, corrected for `overflow: auto`.
|
|
1033
|
+
*
|
|
1034
|
+
* @function Highcharts.offset
|
|
1035
|
+
*
|
|
1036
|
+
* @param {global.Element} el
|
|
1037
|
+
* The DOM element.
|
|
1038
|
+
*
|
|
1039
|
+
* @return {Highcharts.OffsetObject}
|
|
1040
|
+
* An object containing `left` and `top` properties for the position in
|
|
1041
|
+
* the page.
|
|
1042
|
+
*/
|
|
1043
|
+
export function offset(el) {
|
|
1044
|
+
const docElem = doc.documentElement, box = (el.parentElement || el.parentNode) ?
|
|
1045
|
+
el.getBoundingClientRect() :
|
|
1046
|
+
{ top: 0, left: 0, width: 0, height: 0 };
|
|
1047
|
+
return {
|
|
1048
|
+
top: box.top + (win.pageYOffset || docElem.scrollTop) -
|
|
1049
|
+
(docElem.clientTop || 0),
|
|
1050
|
+
left: box.left + (win.pageXOffset || docElem.scrollLeft) -
|
|
1051
|
+
(docElem.clientLeft || 0),
|
|
1052
|
+
width: box.width,
|
|
1053
|
+
height: box.height
|
|
1054
|
+
};
|
|
1055
|
+
}
|
|
1056
|
+
/**
|
|
1057
|
+
* Left-pad a string to a given length by adding a character repetitively.
|
|
1058
|
+
*
|
|
1059
|
+
* @function Highcharts.pad
|
|
1060
|
+
*
|
|
1061
|
+
* @param {number} number
|
|
1062
|
+
* The input string or number.
|
|
1063
|
+
*
|
|
1064
|
+
* @param {number} [length]
|
|
1065
|
+
* The desired string length.
|
|
1066
|
+
*
|
|
1067
|
+
* @param {string} [padder=0]
|
|
1068
|
+
* The character to pad with.
|
|
1069
|
+
*
|
|
1070
|
+
* @return {string}
|
|
1071
|
+
* The padded string.
|
|
1072
|
+
*/
|
|
1073
|
+
export function pad(number, length, padder) {
|
|
1074
|
+
return new Array((length || 2) +
|
|
1075
|
+
1 -
|
|
1076
|
+
String(number)
|
|
1077
|
+
.replace('-', '')
|
|
1078
|
+
.length).join(padder || '0') + number;
|
|
1079
|
+
}
|
|
1080
|
+
/* eslint-disable valid-jsdoc */
|
|
1081
|
+
/**
|
|
1082
|
+
* Return the first value that is not null or undefined.
|
|
1083
|
+
*
|
|
1084
|
+
* @function Highcharts.pick<T>
|
|
1085
|
+
*
|
|
1086
|
+
* @param {...Array<T|null|undefined>} items
|
|
1087
|
+
* Variable number of arguments to inspect.
|
|
1088
|
+
*
|
|
1089
|
+
* @return {T}
|
|
1090
|
+
* The value of the first argument that is not null or undefined.
|
|
1091
|
+
*/
|
|
1092
|
+
export function pick() {
|
|
1093
|
+
const args = arguments;
|
|
1094
|
+
const length = args.length;
|
|
1095
|
+
for (let i = 0; i < length; i++) {
|
|
1096
|
+
const arg = args[i];
|
|
1097
|
+
if (typeof arg !== 'undefined' && arg !== null) {
|
|
1098
|
+
return arg;
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
/**
|
|
1103
|
+
* Shortcut for parseInt
|
|
1104
|
+
*
|
|
1105
|
+
* @internal
|
|
1106
|
+
* @function Highcharts.pInt
|
|
1107
|
+
*
|
|
1108
|
+
* @param {*} s
|
|
1109
|
+
* any
|
|
1110
|
+
*
|
|
1111
|
+
* @param {number} [mag]
|
|
1112
|
+
* Magnitude
|
|
1113
|
+
*
|
|
1114
|
+
* @return {number}
|
|
1115
|
+
* number
|
|
1116
|
+
*/
|
|
1117
|
+
export function pInt(s, mag) {
|
|
1118
|
+
return parseInt(s, mag || 10);
|
|
1119
|
+
}
|
|
1120
|
+
/**
|
|
1121
|
+
* Adds an item to an array, if it is not present in the array.
|
|
1122
|
+
*
|
|
1123
|
+
* @internal
|
|
1124
|
+
*
|
|
1125
|
+
* @function Highcharts.pushUnique
|
|
1126
|
+
*
|
|
1127
|
+
* @param {Array<unknown>} array
|
|
1128
|
+
* The array to add the item to.
|
|
1129
|
+
*
|
|
1130
|
+
* @param {unknown} item
|
|
1131
|
+
* The item to add.
|
|
1132
|
+
*
|
|
1133
|
+
* @return {boolean}
|
|
1134
|
+
* Returns true, if the item was not present and has been added.
|
|
1135
|
+
*/
|
|
1136
|
+
export function pushUnique(array, item) {
|
|
1137
|
+
return array.indexOf(item) < 0 && !!array.push(item);
|
|
1138
|
+
}
|
|
1139
|
+
/**
|
|
1140
|
+
* Return a length based on either the integer value, or a percentage of a base.
|
|
1141
|
+
*
|
|
1142
|
+
* @function Highcharts.relativeLength
|
|
1143
|
+
*
|
|
1144
|
+
* @param {Highcharts.RelativeSize} value
|
|
1145
|
+
* A percentage string or a number.
|
|
1146
|
+
*
|
|
1147
|
+
* @param {number} base
|
|
1148
|
+
* The full length that represents 100%.
|
|
1149
|
+
*
|
|
1150
|
+
* @param {number} [offset=0]
|
|
1151
|
+
* A pixel offset to apply for percentage values. Used internally in
|
|
1152
|
+
* axis positioning.
|
|
1153
|
+
*
|
|
1154
|
+
* @return {number}
|
|
1155
|
+
* The computed length.
|
|
1156
|
+
*/
|
|
1157
|
+
export function relativeLength(value, base, offset) {
|
|
1158
|
+
return (/%$/).test(value) ?
|
|
1159
|
+
(base * parseFloat(value) / 100) + (offset || 0) :
|
|
1160
|
+
parseFloat(value);
|
|
1161
|
+
}
|
|
1162
|
+
/**
|
|
1163
|
+
* Replaces text in a string with a given replacement in a loop to catch nested
|
|
1164
|
+
* matches after previous replacements.
|
|
1165
|
+
*
|
|
1166
|
+
* @internal
|
|
1167
|
+
*
|
|
1168
|
+
* @function Highcharts.replaceNested
|
|
1169
|
+
*
|
|
1170
|
+
* @param {string} text
|
|
1171
|
+
* Text to search and modify.
|
|
1172
|
+
*
|
|
1173
|
+
* @param {...Array<(RegExp|string)>} replacements
|
|
1174
|
+
* One or multiple tuples with search pattern (`[0]: (string|RegExp)`) and
|
|
1175
|
+
* replacement (`[1]: string`) for matching text.
|
|
1176
|
+
*
|
|
1177
|
+
* @return {string}
|
|
1178
|
+
* Text with replacements.
|
|
1179
|
+
*/
|
|
1180
|
+
export function replaceNested(text, ...replacements) {
|
|
1181
|
+
let previous, replacement;
|
|
1182
|
+
do {
|
|
1183
|
+
previous = text;
|
|
1184
|
+
for (replacement of replacements) {
|
|
1185
|
+
text = text.replace(replacement[0], replacement[1]);
|
|
1186
|
+
}
|
|
1187
|
+
} while (text !== previous);
|
|
1188
|
+
return text;
|
|
1189
|
+
}
|
|
1190
|
+
/* eslint-disable valid-jsdoc */
|
|
1191
|
+
/**
|
|
1192
|
+
* Remove an event that was added with {@link Highcharts#addEvent}.
|
|
1193
|
+
*
|
|
1194
|
+
* @function Highcharts.removeEvent<T>
|
|
1195
|
+
*
|
|
1196
|
+
* @param {Highcharts.Class<T>|T} el
|
|
1197
|
+
* The element to remove events on.
|
|
1198
|
+
*
|
|
1199
|
+
* @param {string} [type]
|
|
1200
|
+
* The type of events to remove. If undefined, all events are removed
|
|
1201
|
+
* from the element.
|
|
1202
|
+
*
|
|
1203
|
+
* @param {Highcharts.EventCallbackFunction<T>} [fn]
|
|
1204
|
+
* The specific callback to remove. If undefined, all events that match
|
|
1205
|
+
* the element and optionally the type are removed.
|
|
1206
|
+
*
|
|
1207
|
+
* @return {void}
|
|
1208
|
+
*/
|
|
1209
|
+
export function removeEvent(el, type, fn) {
|
|
1210
|
+
/* eslint-enable valid-jsdoc */
|
|
1211
|
+
/** @internal */
|
|
1212
|
+
function removeOneEvent(type, fn) {
|
|
1213
|
+
const removeEventListener = el.removeEventListener;
|
|
1214
|
+
if (removeEventListener) {
|
|
1215
|
+
removeEventListener.call(el, type, fn, false);
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
/** @internal */
|
|
1219
|
+
function removeAllEvents(eventCollection) {
|
|
1220
|
+
let types, len;
|
|
1221
|
+
if (!el.nodeName) {
|
|
1222
|
+
return; // Break on non-DOM events
|
|
1223
|
+
}
|
|
1224
|
+
if (type) {
|
|
1225
|
+
types = {};
|
|
1226
|
+
types[type] = true;
|
|
1227
|
+
}
|
|
1228
|
+
else {
|
|
1229
|
+
types = eventCollection;
|
|
1230
|
+
}
|
|
1231
|
+
objectEach(types, function (_val, n) {
|
|
1232
|
+
if (eventCollection[n]) {
|
|
1233
|
+
len = eventCollection[n].length;
|
|
1234
|
+
while (len--) {
|
|
1235
|
+
removeOneEvent(n, eventCollection[n][len].fn);
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
});
|
|
1239
|
+
}
|
|
1240
|
+
const owner = typeof el === 'function' && el.prototype || el;
|
|
1241
|
+
if (Object.hasOwnProperty.call(owner, 'hcEvents')) {
|
|
1242
|
+
const events = owner.hcEvents;
|
|
1243
|
+
if (type) {
|
|
1244
|
+
const typeEvents = (events[type] || []);
|
|
1245
|
+
if (fn) {
|
|
1246
|
+
events[type] = typeEvents.filter(function (obj) {
|
|
1247
|
+
return fn !== obj.fn;
|
|
1248
|
+
});
|
|
1249
|
+
removeOneEvent(type, fn);
|
|
1250
|
+
}
|
|
1251
|
+
else {
|
|
1252
|
+
removeAllEvents(events);
|
|
1253
|
+
events[type] = [];
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
else {
|
|
1257
|
+
removeAllEvents(events);
|
|
1258
|
+
delete owner.hcEvents;
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
/**
|
|
1263
|
+
* Check if an element is an array, and if not, make it into an array.
|
|
1264
|
+
*
|
|
1265
|
+
* @function Highcharts.splat
|
|
1266
|
+
*
|
|
1267
|
+
* @param {*} obj
|
|
1268
|
+
* The object to splat.
|
|
1269
|
+
*
|
|
1270
|
+
* @return {Array}
|
|
1271
|
+
* The produced or original array.
|
|
1272
|
+
*/
|
|
1273
|
+
export function splat(obj) {
|
|
1274
|
+
return isArray(obj) ? obj : [obj];
|
|
1275
|
+
}
|
|
1276
|
+
/**
|
|
1277
|
+
* Sort an object array and keep the order of equal items. The ECMAScript
|
|
1278
|
+
* standard does not specify the behaviour when items are equal.
|
|
1279
|
+
*
|
|
1280
|
+
* @function Highcharts.stableSort
|
|
1281
|
+
*
|
|
1282
|
+
* @param {Array<*>} arr
|
|
1283
|
+
* The array to sort.
|
|
1284
|
+
*
|
|
1285
|
+
* @param {Function} sortFunction
|
|
1286
|
+
* The function to sort it with, like with regular Array.prototype.sort.
|
|
1287
|
+
*/
|
|
1288
|
+
export function stableSort(arr, sortFunction) {
|
|
1289
|
+
// @todo It seems like Chrome since v70 sorts in a stable way internally,
|
|
1290
|
+
// plus all other browsers do it, so over time we may be able to remove this
|
|
1291
|
+
// function
|
|
1292
|
+
const length = arr.length;
|
|
1293
|
+
let sortValue, i;
|
|
1294
|
+
// Add index to each item
|
|
1295
|
+
for (i = 0; i < length; i++) {
|
|
1296
|
+
arr[i].safeI = i; // Stable sort index
|
|
1297
|
+
}
|
|
1298
|
+
arr.sort(function (a, b) {
|
|
1299
|
+
sortValue = sortFunction(a, b);
|
|
1300
|
+
return sortValue === 0 ? a.safeI - b.safeI : sortValue;
|
|
1301
|
+
});
|
|
1302
|
+
// Remove index from items
|
|
1303
|
+
for (i = 0; i < length; i++) {
|
|
1304
|
+
delete arr[i].safeI; // Stable sort index
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
/**
|
|
1308
|
+
* Set a timeout if the delay is given, otherwise perform the function
|
|
1309
|
+
* synchronously.
|
|
1310
|
+
*
|
|
1311
|
+
* @function Highcharts.syncTimeout
|
|
1312
|
+
*
|
|
1313
|
+
* @param {Function} fn
|
|
1314
|
+
* The function callback.
|
|
1315
|
+
*
|
|
1316
|
+
* @param {number} delay
|
|
1317
|
+
* Delay in milliseconds.
|
|
1318
|
+
*
|
|
1319
|
+
* @param {*} [context]
|
|
1320
|
+
* An optional context to send to the function callback.
|
|
1321
|
+
*
|
|
1322
|
+
* @return {number}
|
|
1323
|
+
* An identifier for the timeout that can later be cleared with
|
|
1324
|
+
* Highcharts.clearTimeout. Returns -1 if there is no timeout.
|
|
1325
|
+
*/
|
|
1326
|
+
export function syncTimeout(fn, delay, context) {
|
|
1327
|
+
if (delay > 0) {
|
|
1328
|
+
return setTimeout(fn, delay, context);
|
|
1329
|
+
}
|
|
1330
|
+
fn.call(0, context);
|
|
1331
|
+
return -1;
|
|
1332
|
+
}
|
|
1333
|
+
/**
|
|
1334
|
+
* @internal
|
|
1335
|
+
*/
|
|
1336
|
+
export function ucfirst(s) {
|
|
1337
|
+
return ((isString(s) ?
|
|
1338
|
+
s.substring(0, 1).toUpperCase() + s.substring(1) :
|
|
1339
|
+
String(s)));
|
|
1340
|
+
}
|
|
1341
|
+
/**
|
|
1342
|
+
* Wrap a method with extended functionality, preserving the original function.
|
|
1343
|
+
*
|
|
1344
|
+
* @function Highcharts.wrap
|
|
1345
|
+
*
|
|
1346
|
+
* @param {*} obj
|
|
1347
|
+
* The context object that the method belongs to. In real cases, this is
|
|
1348
|
+
* often a prototype.
|
|
1349
|
+
*
|
|
1350
|
+
* @param {string} method
|
|
1351
|
+
* The name of the method to extend.
|
|
1352
|
+
*
|
|
1353
|
+
* @param {Highcharts.WrapProceedFunction} func
|
|
1354
|
+
* A wrapper function callback. This function is called with the same
|
|
1355
|
+
* arguments as the original function, except that the original function
|
|
1356
|
+
* is unshifted and passed as the first argument.
|
|
1357
|
+
*/
|
|
1358
|
+
export function wrap(obj, method, func) {
|
|
1359
|
+
const proceed = obj[method];
|
|
1360
|
+
obj[method] = function () {
|
|
1361
|
+
const outerArgs = arguments, scope = this;
|
|
1362
|
+
return func.apply(this, [
|
|
1363
|
+
function () {
|
|
1364
|
+
return proceed.apply(scope, arguments.length ? arguments : outerArgs);
|
|
1365
|
+
}
|
|
1366
|
+
].concat([].slice.call(arguments)));
|
|
1367
|
+
};
|
|
1368
|
+
}
|