Files
Sensores/static/lib/Highcharts-10.2.1/es-modules/Extensions/Annotations/NavigationBindingsUtilities.js
2025-04-17 00:35:33 -06:00

99 lines
2.6 KiB
JavaScript

/* *
*
* (c) 2009-2021 Highsoft, Black Label
*
* License: www.highcharts.com/license
*
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
*
* */
'use strict';
import U from '../../Core/Utilities.js';
var defined = U.defined, isNumber = U.isNumber, pick = U.pick;
/* *
*
* Constants
*
* */
/**
* Define types for editable fields per annotation. There is no need to define
* numbers, because they won't change their type to string.
* @private
*/
var annotationsFieldsTypes = {
backgroundColor: 'string',
borderColor: 'string',
borderRadius: 'string',
color: 'string',
fill: 'string',
fontSize: 'string',
labels: 'string',
name: 'string',
stroke: 'string',
title: 'string'
};
/* *
*
* Functions
*
* */
/**
* Returns the first xAxis or yAxis that was clicked with its value.
*
* @private
*
* @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(function (coord) {
var 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.
}
/**
* Get field type according to value
*
* @private
*
* @param {'boolean'|'number'|'string'} value
* Atomic type (one of: string, number, boolean)
*
* @return {'checkbox'|'number'|'text'}
* Field type (one of: text, number, checkbox)
*/
function getFieldType(key, value) {
var predefinedType = annotationsFieldsTypes[key];
var fieldType = typeof value;
if (defined(predefinedType)) {
fieldType = predefinedType;
}
return {
'string': 'text',
'number': 'number',
'boolean': 'checkbox'
}[fieldType];
}
/* *
*
* Default Export
*
* */
var NavigationBindingUtilities = {
annotationsFieldsTypes: annotationsFieldsTypes,
getAssignedAxis: getAssignedAxis,
getFieldType: getFieldType
};
export default NavigationBindingUtilities;