Carga
Carga
This commit is contained in:
@@ -0,0 +1,821 @@
|
||||
/* *
|
||||
*
|
||||
* (c) 2009-2021 Highsoft, Black Label
|
||||
*
|
||||
* License: www.highcharts.com/license
|
||||
*
|
||||
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
|
||||
*
|
||||
* */
|
||||
'use strict';
|
||||
import ChartNavigationComposition from '../../Core/Chart/ChartNavigationComposition.js';
|
||||
import D from '../../Core/DefaultOptions.js';
|
||||
var setOptions = D.setOptions;
|
||||
import F from '../../Core/FormatUtilities.js';
|
||||
var format = F.format;
|
||||
import H from '../../Core/Globals.js';
|
||||
var doc = H.doc, win = H.win;
|
||||
import NavigationBindingDefaults from './NavigationBindingsDefaults.js';
|
||||
import NBU from './NavigationBindingsUtilities.js';
|
||||
var getFieldType = NBU.getFieldType;
|
||||
import U from '../../Core/Utilities.js';
|
||||
var addEvent = U.addEvent, attr = U.attr, defined = U.defined, fireEvent = U.fireEvent, isArray = U.isArray, isFunction = U.isFunction, isNumber = U.isNumber, isObject = U.isObject, merge = U.merge, objectEach = U.objectEach, pick = U.pick;
|
||||
/* *
|
||||
*
|
||||
* Constants
|
||||
*
|
||||
* */
|
||||
var composedClasses = [];
|
||||
/* *
|
||||
*
|
||||
* Functions
|
||||
*
|
||||
* */
|
||||
/**
|
||||
* IE 9-11 polyfill for Element.closest():
|
||||
* @private
|
||||
*/
|
||||
function closestPolyfill(el, s) {
|
||||
var ElementProto = win.Element.prototype, elementMatches = ElementProto.matches ||
|
||||
ElementProto.msMatchesSelector ||
|
||||
ElementProto.webkitMatchesSelector;
|
||||
var ret = null;
|
||||
if (ElementProto.closest) {
|
||||
ret = ElementProto.closest.call(el, s);
|
||||
}
|
||||
else {
|
||||
do {
|
||||
if (elementMatches.call(el, s)) {
|
||||
return el;
|
||||
}
|
||||
el = el.parentElement || el.parentNode;
|
||||
} while (el !== null && el.nodeType === 1);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
function onAnnotationRemove() {
|
||||
if (this.chart.navigationBindings) {
|
||||
this.chart.navigationBindings.deselectAnnotation();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
function onChartDestroy() {
|
||||
if (this.navigationBindings) {
|
||||
this.navigationBindings.destroy();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
function onChartLoad() {
|
||||
var options = this.options;
|
||||
if (options && options.navigation && options.navigation.bindings) {
|
||||
this.navigationBindings = new NavigationBindings(this, options.navigation);
|
||||
this.navigationBindings.initEvents();
|
||||
this.navigationBindings.initUpdate();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
function onChartRender() {
|
||||
var navigationBindings = this.navigationBindings, disabledClassName = 'highcharts-disabled-btn';
|
||||
if (this && navigationBindings) {
|
||||
// Check if the buttons should be enabled/disabled based on
|
||||
// visible series.
|
||||
var buttonsEnabled_1 = false;
|
||||
this.series.forEach(function (series) {
|
||||
if (!series.options.isInternal && series.visible) {
|
||||
buttonsEnabled_1 = true;
|
||||
}
|
||||
});
|
||||
if (this.navigationBindings &&
|
||||
this.navigationBindings.container &&
|
||||
this.navigationBindings.container[0]) {
|
||||
var container_1 = this.navigationBindings.container[0];
|
||||
objectEach(navigationBindings.boundClassNames, function (value, key) {
|
||||
// Get the HTML element coresponding to the className taken
|
||||
// from StockToolsBindings.
|
||||
var buttonNode = container_1.querySelectorAll('.' + key);
|
||||
if (buttonNode) {
|
||||
for (var i = 0; i < buttonNode.length; i++) {
|
||||
var button = buttonNode[i], cls = button.className;
|
||||
if (value.noDataState === 'normal') {
|
||||
// If button has noDataState: 'normal', and has
|
||||
// disabledClassName, remove this className.
|
||||
if (cls.indexOf(disabledClassName) !== -1) {
|
||||
button.classList.remove(disabledClassName);
|
||||
}
|
||||
}
|
||||
else if (!buttonsEnabled_1) {
|
||||
if (cls.indexOf(disabledClassName) === -1) {
|
||||
button.className += ' ' + disabledClassName;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Enable all buttons by deleting the className.
|
||||
if (cls.indexOf(disabledClassName) !== -1) {
|
||||
button.classList.remove(disabledClassName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
function onNavigationBindingsClosePopup() {
|
||||
this.deselectAnnotation();
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
function onNavigationBindingsDeselectButton() {
|
||||
this.selectedButtonElement = null;
|
||||
}
|
||||
/**
|
||||
* Show edit-annotation form:
|
||||
* @private
|
||||
*/
|
||||
function selectableAnnotation(annotationType) {
|
||||
var originalClick = annotationType.prototype.defaultOptions.events &&
|
||||
annotationType.prototype.defaultOptions.events.click;
|
||||
/**
|
||||
* Select and show popup
|
||||
* @private
|
||||
*/
|
||||
function selectAndShowPopup(eventArguments) {
|
||||
var annotation = this, navigation = annotation.chart.navigationBindings, prevAnnotation = navigation.activeAnnotation;
|
||||
if (originalClick) {
|
||||
originalClick.call(annotation, eventArguments);
|
||||
}
|
||||
if (prevAnnotation !== annotation) {
|
||||
// Select current:
|
||||
navigation.deselectAnnotation();
|
||||
navigation.activeAnnotation = annotation;
|
||||
annotation.setControlPointsVisibility(true);
|
||||
fireEvent(navigation, 'showPopup', {
|
||||
annotation: annotation,
|
||||
formType: 'annotation-toolbar',
|
||||
options: navigation.annotationToFields(annotation),
|
||||
onSubmit: function (data) {
|
||||
if (data.actionType === 'remove') {
|
||||
navigation.activeAnnotation = false;
|
||||
navigation.chart.removeAnnotation(annotation);
|
||||
}
|
||||
else {
|
||||
var config = {};
|
||||
navigation.fieldsToOptions(data.fields, config);
|
||||
navigation.deselectAnnotation();
|
||||
var typeOptions = config.typeOptions;
|
||||
if (annotation.options.type === 'measure') {
|
||||
// Manually disable crooshars according to
|
||||
// stroke width of the shape:
|
||||
typeOptions.crosshairY.enabled = (typeOptions.crosshairY
|
||||
.strokeWidth !== 0);
|
||||
typeOptions.crosshairX.enabled = (typeOptions.crosshairX
|
||||
.strokeWidth !== 0);
|
||||
}
|
||||
annotation.update(config);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
// Deselect current:
|
||||
fireEvent(navigation, 'closePopup');
|
||||
}
|
||||
// Let bubble event to chart.click:
|
||||
eventArguments.activeAnnotation = true;
|
||||
}
|
||||
merge(true, annotationType.prototype.defaultOptions.events, {
|
||||
click: selectAndShowPopup
|
||||
});
|
||||
}
|
||||
/* *
|
||||
*
|
||||
* Class
|
||||
*
|
||||
* */
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
var NavigationBindings = /** @class */ (function () {
|
||||
/* *
|
||||
*
|
||||
* Constructor
|
||||
*
|
||||
* */
|
||||
function NavigationBindings(chart, options) {
|
||||
this.boundClassNames = void 0;
|
||||
this.selectedButton = void 0;
|
||||
this.chart = chart;
|
||||
this.options = options;
|
||||
this.eventsToUnbind = [];
|
||||
this.container = this.chart.container
|
||||
.querySelectorAll('.' + this.options.bindingsClassName);
|
||||
if (!this.container.length) {
|
||||
this.container = doc
|
||||
.querySelectorAll('.' + this.options.bindingsClassName);
|
||||
}
|
||||
}
|
||||
/* *
|
||||
*
|
||||
* Static Functions
|
||||
*
|
||||
* */
|
||||
NavigationBindings.compose = function (AnnotationClass, ChartClass) {
|
||||
if (composedClasses.indexOf(AnnotationClass) === -1) {
|
||||
composedClasses.push(AnnotationClass);
|
||||
addEvent(AnnotationClass, 'remove', onAnnotationRemove);
|
||||
// Basic shapes:
|
||||
selectableAnnotation(AnnotationClass);
|
||||
// Advanced annotations:
|
||||
objectEach(AnnotationClass.types, function (annotationType) {
|
||||
selectableAnnotation(annotationType);
|
||||
});
|
||||
}
|
||||
if (composedClasses.indexOf(ChartClass) === -1) {
|
||||
composedClasses.push(ChartClass);
|
||||
addEvent(ChartClass, 'destroy', onChartDestroy);
|
||||
addEvent(ChartClass, 'load', onChartLoad);
|
||||
addEvent(ChartClass, 'render', onChartRender);
|
||||
}
|
||||
if (composedClasses.indexOf(NavigationBindings) === -1) {
|
||||
composedClasses.push(NavigationBindings);
|
||||
addEvent(NavigationBindings, 'closePopup', onNavigationBindingsClosePopup);
|
||||
addEvent(NavigationBindings, 'deselectButton', onNavigationBindingsDeselectButton);
|
||||
}
|
||||
if (composedClasses.indexOf(setOptions) === -1) {
|
||||
composedClasses.push(setOptions);
|
||||
setOptions(NavigationBindingDefaults);
|
||||
}
|
||||
};
|
||||
/* *
|
||||
*
|
||||
* Functions
|
||||
*
|
||||
* */
|
||||
/**
|
||||
* Initi all events conencted to NavigationBindings.
|
||||
*
|
||||
* @private
|
||||
* @function Highcharts.NavigationBindings#initEvents
|
||||
*/
|
||||
NavigationBindings.prototype.initEvents = function () {
|
||||
var navigation = this, chart = navigation.chart, bindingsContainer = navigation.container, options = navigation.options;
|
||||
// Shorthand object for getting events for buttons:
|
||||
navigation.boundClassNames = {};
|
||||
objectEach((options.bindings || {}), function (value) {
|
||||
navigation.boundClassNames[value.className] = value;
|
||||
});
|
||||
// Handle multiple containers with the same class names:
|
||||
[].forEach.call(bindingsContainer, function (subContainer) {
|
||||
navigation.eventsToUnbind.push(addEvent(subContainer, 'click', function (event) {
|
||||
var bindings = navigation.getButtonEvents(subContainer, event);
|
||||
if (bindings &&
|
||||
bindings.button.className
|
||||
.indexOf('highcharts-disabled-btn') === -1) {
|
||||
navigation.bindingsButtonClick(bindings.button, bindings.events, event);
|
||||
}
|
||||
}));
|
||||
});
|
||||
objectEach((options.events || {}), function (callback, eventName) {
|
||||
if (isFunction(callback)) {
|
||||
navigation.eventsToUnbind.push(addEvent(navigation, eventName, callback, { passive: false }));
|
||||
}
|
||||
});
|
||||
navigation.eventsToUnbind.push(addEvent(chart.container, 'click', function (e) {
|
||||
if (!chart.cancelClick &&
|
||||
chart.isInsidePlot(e.chartX - chart.plotLeft, e.chartY - chart.plotTop, {
|
||||
visiblePlotOnly: true
|
||||
})) {
|
||||
navigation.bindingsChartClick(this, e);
|
||||
}
|
||||
}));
|
||||
navigation.eventsToUnbind.push(addEvent(chart.container, H.isTouchDevice ? 'touchmove' : 'mousemove', function (e) {
|
||||
navigation.bindingsContainerMouseMove(this, e);
|
||||
}, H.isTouchDevice ? { passive: false } : void 0));
|
||||
};
|
||||
/**
|
||||
* Common chart.update() delegation, shared between bindings and exporting.
|
||||
*
|
||||
* @private
|
||||
* @function Highcharts.NavigationBindings#initUpdate
|
||||
*/
|
||||
NavigationBindings.prototype.initUpdate = function () {
|
||||
var navigation = this;
|
||||
ChartNavigationComposition
|
||||
.compose(this.chart).navigation
|
||||
.addUpdate(function (options) {
|
||||
navigation.update(options);
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Hook for click on a button, method selcts/unselects buttons,
|
||||
* then calls `bindings.init` callback.
|
||||
*
|
||||
* @private
|
||||
* @function Highcharts.NavigationBindings#bindingsButtonClick
|
||||
*
|
||||
* @param {Highcharts.HTMLDOMElement} [button]
|
||||
* Clicked button
|
||||
*
|
||||
* @param {Object} events
|
||||
* Events passed down from bindings (`init`, `start`, `step`, `end`)
|
||||
*
|
||||
* @param {Highcharts.PointerEventObject} clickEvent
|
||||
* Browser's click event
|
||||
*/
|
||||
NavigationBindings.prototype.bindingsButtonClick = function (button, events, clickEvent) {
|
||||
var navigation = this, chart = navigation.chart, svgContainer = chart.renderer.boxWrapper;
|
||||
var shouldEventBeFired = true;
|
||||
if (navigation.selectedButtonElement) {
|
||||
if (navigation.selectedButtonElement.classList === button.classList) {
|
||||
shouldEventBeFired = false;
|
||||
}
|
||||
fireEvent(navigation, 'deselectButton', { button: navigation.selectedButtonElement });
|
||||
if (navigation.nextEvent) {
|
||||
// Remove in-progress annotations adders:
|
||||
if (navigation.currentUserDetails &&
|
||||
navigation.currentUserDetails.coll === 'annotations') {
|
||||
chart.removeAnnotation(navigation.currentUserDetails);
|
||||
}
|
||||
navigation.mouseMoveEvent = navigation.nextEvent = false;
|
||||
}
|
||||
}
|
||||
if (shouldEventBeFired) {
|
||||
navigation.selectedButton = events;
|
||||
navigation.selectedButtonElement = button;
|
||||
fireEvent(navigation, 'selectButton', { button: button });
|
||||
// Call "init" event, for example to open modal window
|
||||
if (events.init) {
|
||||
events.init.call(navigation, button, clickEvent);
|
||||
}
|
||||
if (events.start || events.steps) {
|
||||
chart.renderer.boxWrapper.addClass('highcharts-draw-mode');
|
||||
}
|
||||
}
|
||||
else {
|
||||
chart.stockTools &&
|
||||
chart.stockTools.toggleButtonActiveClass(button);
|
||||
svgContainer.removeClass('highcharts-draw-mode');
|
||||
navigation.nextEvent = false;
|
||||
navigation.mouseMoveEvent = false;
|
||||
navigation.selectedButton = null;
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Hook for click on a chart, first click on a chart calls `start` event,
|
||||
* then on all subsequent clicks iterate over `steps` array.
|
||||
* When finished, calls `end` event.
|
||||
*
|
||||
* @private
|
||||
* @function Highcharts.NavigationBindings#bindingsChartClick
|
||||
*
|
||||
* @param {Highcharts.Chart} chart
|
||||
* Chart that click was performed on.
|
||||
*
|
||||
* @param {Highcharts.PointerEventObject} clickEvent
|
||||
* Browser's click event.
|
||||
*/
|
||||
NavigationBindings.prototype.bindingsChartClick = function (chart, clickEvent) {
|
||||
chart = this.chart;
|
||||
var navigation = this, activeAnnotation = navigation.activeAnnotation, selectedButton = navigation.selectedButton, svgContainer = chart.renderer.boxWrapper;
|
||||
if (activeAnnotation) {
|
||||
// Click outside popups, should close them and deselect the
|
||||
// annotation
|
||||
if (!activeAnnotation.cancelClick && // #15729
|
||||
!clickEvent.activeAnnotation &&
|
||||
// Element could be removed in the child action, e.g. button
|
||||
clickEvent.target.parentNode &&
|
||||
// TO DO: Polyfill for IE11?
|
||||
!closestPolyfill(clickEvent.target, '.highcharts-popup')) {
|
||||
fireEvent(navigation, 'closePopup');
|
||||
}
|
||||
else if (activeAnnotation.cancelClick) {
|
||||
// Reset cancelClick after the other event handlers have run
|
||||
setTimeout(function () {
|
||||
activeAnnotation.cancelClick = false;
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
if (!selectedButton || !selectedButton.start) {
|
||||
return;
|
||||
}
|
||||
if (!navigation.nextEvent) {
|
||||
// Call init method:
|
||||
navigation.currentUserDetails = selectedButton.start.call(navigation, clickEvent);
|
||||
// If steps exists (e.g. Annotations), bind them:
|
||||
if (navigation.currentUserDetails && selectedButton.steps) {
|
||||
navigation.stepIndex = 0;
|
||||
navigation.steps = true;
|
||||
navigation.mouseMoveEvent = navigation.nextEvent =
|
||||
selectedButton.steps[navigation.stepIndex];
|
||||
}
|
||||
else {
|
||||
fireEvent(navigation, 'deselectButton', { button: navigation.selectedButtonElement });
|
||||
svgContainer.removeClass('highcharts-draw-mode');
|
||||
navigation.steps = false;
|
||||
navigation.selectedButton = null;
|
||||
// First click is also the last one:
|
||||
if (selectedButton.end) {
|
||||
selectedButton.end.call(navigation, clickEvent, navigation.currentUserDetails);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
navigation.nextEvent(clickEvent, navigation.currentUserDetails);
|
||||
if (navigation.steps) {
|
||||
navigation.stepIndex++;
|
||||
if (selectedButton.steps[navigation.stepIndex]) {
|
||||
// If we have more steps, bind them one by one:
|
||||
navigation.mouseMoveEvent = navigation.nextEvent = selectedButton.steps[navigation.stepIndex];
|
||||
}
|
||||
else {
|
||||
fireEvent(navigation, 'deselectButton', { button: navigation.selectedButtonElement });
|
||||
svgContainer.removeClass('highcharts-draw-mode');
|
||||
// That was the last step, call end():
|
||||
if (selectedButton.end) {
|
||||
selectedButton.end.call(navigation, clickEvent, navigation.currentUserDetails);
|
||||
}
|
||||
navigation.nextEvent = false;
|
||||
navigation.mouseMoveEvent = false;
|
||||
navigation.selectedButton = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Hook for mouse move on a chart's container. It calls current step.
|
||||
*
|
||||
* @private
|
||||
* @function Highcharts.NavigationBindings#bindingsContainerMouseMove
|
||||
*
|
||||
* @param {Highcharts.HTMLDOMElement} container
|
||||
* Chart's container.
|
||||
*
|
||||
* @param {global.Event} moveEvent
|
||||
* Browser's move event.
|
||||
*/
|
||||
NavigationBindings.prototype.bindingsContainerMouseMove = function (_container, moveEvent) {
|
||||
if (this.mouseMoveEvent) {
|
||||
this.mouseMoveEvent(moveEvent, this.currentUserDetails);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Translate fields (e.g. `params.period` or `marker.styles.color`) to
|
||||
* Highcharts options object (e.g. `{ params: { period } }`).
|
||||
*
|
||||
* @private
|
||||
* @function Highcharts.NavigationBindings#fieldsToOptions<T>
|
||||
*
|
||||
* @param {Highcharts.Dictionary<string>} fields
|
||||
* Fields from popup form.
|
||||
*
|
||||
* @param {T} config
|
||||
* Default config to be modified.
|
||||
*
|
||||
* @return {T}
|
||||
* Modified config
|
||||
*/
|
||||
NavigationBindings.prototype.fieldsToOptions = function (fields, config) {
|
||||
objectEach(fields, function (value, field) {
|
||||
var parsedValue = parseFloat(value), path = field.split('.'), pathLength = path.length - 1;
|
||||
// If it's a number (not "format" options), parse it:
|
||||
if (isNumber(parsedValue) &&
|
||||
!value.match(/px/g) &&
|
||||
!field.match(/format/g)) {
|
||||
value = parsedValue;
|
||||
}
|
||||
// Remove values like 0
|
||||
if (value !== 'undefined') {
|
||||
var parent_1 = config;
|
||||
path.forEach(function (name, index) {
|
||||
var nextName = pick(path[index + 1], '');
|
||||
if (pathLength === index) {
|
||||
// Last index, put value:
|
||||
parent_1[name] = value;
|
||||
}
|
||||
else if (!parent_1[name]) {
|
||||
// Create middle property:
|
||||
parent_1[name] = nextName.match(/\d/g) ? [] : {};
|
||||
parent_1 = parent_1[name];
|
||||
}
|
||||
else {
|
||||
// Jump into next property
|
||||
parent_1 = parent_1[name];
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return config;
|
||||
};
|
||||
/**
|
||||
* Shorthand method to deselect an annotation.
|
||||
*
|
||||
* @function Highcharts.NavigationBindings#deselectAnnotation
|
||||
*/
|
||||
NavigationBindings.prototype.deselectAnnotation = function () {
|
||||
if (this.activeAnnotation) {
|
||||
this.activeAnnotation.setControlPointsVisibility(false);
|
||||
this.activeAnnotation = false;
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Generates API config for popup in the same format as options for
|
||||
* Annotation object.
|
||||
*
|
||||
* @function Highcharts.NavigationBindings#annotationToFields
|
||||
*
|
||||
* @param {Highcharts.Annotation} annotation
|
||||
* Annotations object
|
||||
*
|
||||
* @return {Highcharts.Dictionary<string>}
|
||||
* Annotation options to be displayed in popup box
|
||||
*/
|
||||
NavigationBindings.prototype.annotationToFields = function (annotation) {
|
||||
var options = annotation.options, editables = NavigationBindings.annotationsEditable, nestedEditables = editables.nestedOptions, type = pick(options.type, options.shapes && options.shapes[0] &&
|
||||
options.shapes[0].type, options.labels && options.labels[0] &&
|
||||
options.labels[0].type, 'label'), nonEditables = NavigationBindings.annotationsNonEditable[options.langKey] || [], visualOptions = {
|
||||
langKey: options.langKey,
|
||||
type: type
|
||||
};
|
||||
/**
|
||||
* Nested options traversing. Method goes down to the options and copies
|
||||
* allowed options (with values) to new object, which is last parameter:
|
||||
* "parent".
|
||||
*
|
||||
* @private
|
||||
*
|
||||
* @param {*} option
|
||||
* Atomic type or object/array
|
||||
*
|
||||
* @param {string} key
|
||||
* Option name, for example "visible" or "x", "y"
|
||||
*
|
||||
* @param {Object} parentEditables
|
||||
* Editables from NavigationBindings.annotationsEditable
|
||||
*
|
||||
* @param {Object} parent
|
||||
* Where new options will be assigned
|
||||
*/
|
||||
function traverse(option, key, parentEditables, parent, parentKey) {
|
||||
var nextParent;
|
||||
if (parentEditables &&
|
||||
option &&
|
||||
nonEditables.indexOf(key) === -1 &&
|
||||
((parentEditables.indexOf &&
|
||||
parentEditables.indexOf(key)) >= 0 ||
|
||||
parentEditables[key] || // nested array
|
||||
parentEditables === true // simple array
|
||||
)) {
|
||||
// Roots:
|
||||
if (isArray(option)) {
|
||||
parent[key] = [];
|
||||
option.forEach(function (arrayOption, i) {
|
||||
if (!isObject(arrayOption)) {
|
||||
// Simple arrays, e.g. [String, Number, Boolean]
|
||||
traverse(arrayOption, 0, nestedEditables[key], parent[key], key);
|
||||
}
|
||||
else {
|
||||
// Advanced arrays, e.g. [Object, Object]
|
||||
parent[key][i] = {};
|
||||
objectEach(arrayOption, function (nestedOption, nestedKey) {
|
||||
traverse(nestedOption, nestedKey, nestedEditables[key], parent[key][i], key);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (isObject(option)) {
|
||||
nextParent = {};
|
||||
if (isArray(parent)) {
|
||||
parent.push(nextParent);
|
||||
nextParent[key] = {};
|
||||
nextParent = nextParent[key];
|
||||
}
|
||||
else {
|
||||
parent[key] = nextParent;
|
||||
}
|
||||
objectEach(option, function (nestedOption, nestedKey) {
|
||||
traverse(nestedOption, nestedKey, key === 0 ?
|
||||
parentEditables :
|
||||
nestedEditables[key], nextParent, key);
|
||||
});
|
||||
}
|
||||
else {
|
||||
// Leaf:
|
||||
if (key === 'format') {
|
||||
parent[key] = [
|
||||
format(option, annotation.labels[0].points[0]).toString(),
|
||||
'text'
|
||||
];
|
||||
}
|
||||
else if (isArray(parent)) {
|
||||
parent.push([option, getFieldType(parentKey, option)]);
|
||||
}
|
||||
else {
|
||||
parent[key] = [option, getFieldType(key, option)];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
objectEach(options, function (option, key) {
|
||||
if (key === 'typeOptions') {
|
||||
visualOptions[key] = {};
|
||||
objectEach(options[key], function (typeOption, typeKey) {
|
||||
traverse(typeOption, typeKey, nestedEditables, visualOptions[key], typeKey);
|
||||
});
|
||||
}
|
||||
else {
|
||||
traverse(option, key, editables[type], visualOptions, key);
|
||||
}
|
||||
});
|
||||
return visualOptions;
|
||||
};
|
||||
/**
|
||||
* Get all class names for all parents in the element. Iterates until finds
|
||||
* main container.
|
||||
*
|
||||
* @private
|
||||
* @function Highcharts.NavigationBindings#getClickedClassNames
|
||||
*
|
||||
* @param {Highcharts.HTMLDOMElement} container
|
||||
* Container that event is bound to.
|
||||
*
|
||||
* @param {global.Event} event
|
||||
* Browser's event.
|
||||
*
|
||||
* @return {Array<Array<string, Highcharts.HTMLDOMElement>>}
|
||||
* Array of class names with corresponding elements
|
||||
*/
|
||||
NavigationBindings.prototype.getClickedClassNames = function (container, event) {
|
||||
var element = event.target, classNames = [], elemClassName;
|
||||
while (element) {
|
||||
elemClassName = attr(element, 'class');
|
||||
if (elemClassName) {
|
||||
classNames = classNames.concat(elemClassName
|
||||
.split(' ')
|
||||
// eslint-disable-next-line no-loop-func
|
||||
.map(function (name) { return ([name, element]); }));
|
||||
}
|
||||
element = element.parentNode;
|
||||
if (element === container) {
|
||||
return classNames;
|
||||
}
|
||||
}
|
||||
return classNames;
|
||||
};
|
||||
/**
|
||||
* Get events bound to a button. It's a custom event delegation to find all
|
||||
* events connected to the element.
|
||||
*
|
||||
* @private
|
||||
* @function Highcharts.NavigationBindings#getButtonEvents
|
||||
*
|
||||
* @param {Highcharts.HTMLDOMElement} container
|
||||
* Container that event is bound to.
|
||||
*
|
||||
* @param {global.Event} event
|
||||
* Browser's event.
|
||||
*
|
||||
* @return {Object}
|
||||
* Object with events (init, start, steps, and end)
|
||||
*/
|
||||
NavigationBindings.prototype.getButtonEvents = function (container, event) {
|
||||
var navigation = this, classNames = this.getClickedClassNames(container, event);
|
||||
var bindings;
|
||||
classNames.forEach(function (className) {
|
||||
if (navigation.boundClassNames[className[0]] && !bindings) {
|
||||
bindings = {
|
||||
events: navigation.boundClassNames[className[0]],
|
||||
button: className[1]
|
||||
};
|
||||
}
|
||||
});
|
||||
return bindings;
|
||||
};
|
||||
/**
|
||||
* Bindings are just events, so the whole update process is simply
|
||||
* removing old events and adding new ones.
|
||||
*
|
||||
* @private
|
||||
* @function Highcharts.NavigationBindings#update
|
||||
*/
|
||||
NavigationBindings.prototype.update = function (options) {
|
||||
this.options = merge(true, this.options, options);
|
||||
this.removeEvents();
|
||||
this.initEvents();
|
||||
};
|
||||
/**
|
||||
* Remove all events created in the navigation.
|
||||
*
|
||||
* @private
|
||||
* @function Highcharts.NavigationBindings#removeEvents
|
||||
*/
|
||||
NavigationBindings.prototype.removeEvents = function () {
|
||||
this.eventsToUnbind.forEach(function (unbinder) { return unbinder(); });
|
||||
};
|
||||
/**
|
||||
* @private
|
||||
* @function Highcharts.NavigationBindings#destroy
|
||||
*/
|
||||
NavigationBindings.prototype.destroy = function () {
|
||||
this.removeEvents();
|
||||
};
|
||||
/* *
|
||||
*
|
||||
* Static Properties
|
||||
*
|
||||
* */
|
||||
// Define which options from annotations should show up in edit box:
|
||||
NavigationBindings.annotationsEditable = {
|
||||
// `typeOptions` are always available
|
||||
// Nested and shared options:
|
||||
nestedOptions: {
|
||||
labelOptions: ['style', 'format', 'backgroundColor'],
|
||||
labels: ['style'],
|
||||
label: ['style'],
|
||||
style: ['fontSize', 'color'],
|
||||
background: ['fill', 'strokeWidth', 'stroke'],
|
||||
innerBackground: ['fill', 'strokeWidth', 'stroke'],
|
||||
outerBackground: ['fill', 'strokeWidth', 'stroke'],
|
||||
shapeOptions: ['fill', 'strokeWidth', 'stroke'],
|
||||
shapes: ['fill', 'strokeWidth', 'stroke'],
|
||||
line: ['strokeWidth', 'stroke'],
|
||||
backgroundColors: [true],
|
||||
connector: ['fill', 'strokeWidth', 'stroke'],
|
||||
crosshairX: ['strokeWidth', 'stroke'],
|
||||
crosshairY: ['strokeWidth', 'stroke']
|
||||
},
|
||||
// Simple shapes:
|
||||
circle: ['shapes'],
|
||||
ellipse: ['shapes'],
|
||||
verticalLine: [],
|
||||
label: ['labelOptions'],
|
||||
// Measure
|
||||
measure: ['background', 'crosshairY', 'crosshairX'],
|
||||
// Others:
|
||||
fibonacci: [],
|
||||
tunnel: ['background', 'line', 'height'],
|
||||
pitchfork: ['innerBackground', 'outerBackground'],
|
||||
rect: ['shapes'],
|
||||
// Crooked lines, elliots, arrows etc:
|
||||
crookedLine: [],
|
||||
basicAnnotation: ['shapes', 'labelOptions']
|
||||
};
|
||||
// Define non editable fields per annotation, for example Rectangle inherits
|
||||
// options from Measure, but crosshairs are not available
|
||||
NavigationBindings.annotationsNonEditable = {
|
||||
rectangle: ['crosshairX', 'crosshairY', 'labelOptions'],
|
||||
ellipse: ['labelOptions'],
|
||||
circle: ['labelOptions']
|
||||
};
|
||||
return NavigationBindings;
|
||||
}());
|
||||
/* *
|
||||
*
|
||||
* Default Export
|
||||
*
|
||||
* */
|
||||
export default NavigationBindings;
|
||||
/* *
|
||||
*
|
||||
* API Declarations
|
||||
*
|
||||
* */
|
||||
/**
|
||||
* A config object for navigation bindings in annotations.
|
||||
*
|
||||
* @interface Highcharts.NavigationBindingsOptionsObject
|
||||
*/ /**
|
||||
* ClassName of the element for a binding.
|
||||
* @name Highcharts.NavigationBindingsOptionsObject#className
|
||||
* @type {string|undefined}
|
||||
*/ /**
|
||||
* Last event to be fired after last step event.
|
||||
* @name Highcharts.NavigationBindingsOptionsObject#end
|
||||
* @type {Function|undefined}
|
||||
*/ /**
|
||||
* Initial event, fired on a button click.
|
||||
* @name Highcharts.NavigationBindingsOptionsObject#init
|
||||
* @type {Function|undefined}
|
||||
*/ /**
|
||||
* Event fired on first click on a chart.
|
||||
* @name Highcharts.NavigationBindingsOptionsObject#start
|
||||
* @type {Function|undefined}
|
||||
*/ /**
|
||||
* Last event to be fired after last step event. Array of step events to be
|
||||
* called sequentially after each user click.
|
||||
* @name Highcharts.NavigationBindingsOptionsObject#steps
|
||||
* @type {Array<Function>|undefined}
|
||||
*/
|
||||
(''); // keeps doclets above in JS file
|
||||
Reference in New Issue
Block a user