highcharts
Version:
JavaScript charting framework
128 lines (127 loc) • 3.4 kB
JavaScript
/* *
*
* (c) 2009-2026 Highsoft AS
* Author: Highsoft, Black Label
*
* Integration of this software requires a license.
* - For commercial use, see www.highcharts.com/license
* - For non-commercial, see www.highcharts.com/license-eula
*
*
* */
;
import { defined, find, isNumber, pick } from '../../Shared/Utilities.js';
/* *
*
* Constants
*
* */
/**
* Define types for editable fields per annotation. There is no need to define
* numbers, because they won't change their type to string.
* @internal
*/
const annotationsFieldsTypes = {
backgroundColor: 'color',
backgroundColors: 'color',
borderColor: 'color',
borderRadius: 'string',
color: 'color',
fill: 'color',
fontSize: 'string',
labels: 'string',
name: 'string',
stroke: 'color',
title: 'string'
};
/* *
*
* Functions
*
* */
/**
* Returns the first xAxis or yAxis that was clicked with its value.
*
* @internal
*
* @param {Array<Highcharts.PointerAxisCoordinateObject>} coords
* All the chart's x or y axes with a current pointer's axis value.
*
* @return {Highcharts.PointerAxisCoordinateObject}
* Object with a first found axis and its value that pointer
* is currently pointing.
*/
function getAssignedAxis(coords) {
return coords.filter((coord) => {
const extremes = coord.axis.getExtremes(), axisMin = extremes.min, axisMax = extremes.max,
// Correct axis edges when axis has series
// with pointRange (like column)
minPointOffset = pick(coord.axis.minPointOffset, 0);
return isNumber(axisMin) && isNumber(axisMax) &&
coord.value >= (axisMin - minPointOffset) &&
coord.value <= (axisMax + minPointOffset) &&
// Don't count navigator axis
!coord.axis.options.isInternal;
})[0]; // If the axes overlap, return the first axis that was found.
}
/**
* Resolve an axis from an annotation option that can reference it either by its
* index (number) or by its id (string).
*
* @internal
*
* @param {Highcharts.Chart} chart
* The chart instance.
*
* @param {'xAxis'|'yAxis'} coll
* The axis collection to look in.
*
* @param {number|string|undefined} idOrIndex
* The axis index or id.
*
* @return {Highcharts.Axis|undefined}
* The matching axis, or `undefined` if none was found.
*/
function getAxisFromOptions(chart, coll, idOrIndex) {
if (isNumber(idOrIndex)) {
return chart[coll][idOrIndex];
}
return defined(idOrIndex) ?
find(chart[coll], (axis) => axis.options.id === idOrIndex) :
void 0;
}
/**
* Get field type according to value
*
* @internal
*
* @return {'checkbox'|'color'|'number'|'text'}
* Field type (one of: text, number, checkbox, color)
*/
function getFieldType(key, value) {
const predefinedType = annotationsFieldsTypes[key];
let fieldType = typeof value;
if (defined(predefinedType)) {
fieldType = predefinedType;
}
return {
'string': 'text',
'number': 'number',
'boolean': 'checkbox',
'color': 'color'
}[fieldType];
}
/* *
*
* Default Export
*
* */
/** @internal */
const NavigationBindingsUtilities = {
annotationsFieldsTypes,
getAssignedAxis,
getAxisFromOptions,
getFieldType
};
/** @internal */
export default NavigationBindingsUtilities;