chore: version inicial del codigo fuente del LMS Estafeta
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
/* *
|
||||
*
|
||||
* (c) 2010-2020 Torstein Honsi
|
||||
*
|
||||
* License: www.highcharts.com/license
|
||||
*
|
||||
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
|
||||
*
|
||||
* */
|
||||
'use strict';
|
||||
import H from '../Core/Globals.js';
|
||||
/**
|
||||
* @private
|
||||
* @interface Highcharts.RadianAngles
|
||||
*/ /**
|
||||
* @name Highcharts.RadianAngles#end
|
||||
* @type {number}
|
||||
*/ /**
|
||||
* @name Highcharts.RadianAngles#start
|
||||
* @type {number}
|
||||
*/
|
||||
import U from '../Core/Utilities.js';
|
||||
var isNumber = U.isNumber, pick = U.pick, relativeLength = U.relativeLength;
|
||||
var deg2rad = H.deg2rad;
|
||||
/* eslint-disable valid-jsdoc */
|
||||
/**
|
||||
* @private
|
||||
* @mixin Highcharts.CenteredSeriesMixin
|
||||
*/
|
||||
var centeredSeriesMixin = H.CenteredSeriesMixin = {
|
||||
/**
|
||||
* Get the center of the pie based on the size and center options relative
|
||||
* to the plot area. Borrowed by the polar and gauge series types.
|
||||
*
|
||||
* @private
|
||||
* @function Highcharts.CenteredSeriesMixin.getCenter
|
||||
*
|
||||
* @return {Array<number>}
|
||||
*/
|
||||
getCenter: function () {
|
||||
var options = this.options, chart = this.chart, slicingRoom = 2 * (options.slicedOffset || 0), handleSlicingRoom, plotWidth = chart.plotWidth - 2 * slicingRoom, plotHeight = chart.plotHeight - 2 * slicingRoom, centerOption = options.center, smallestSize = Math.min(plotWidth, plotHeight), size = options.size, innerSize = options.innerSize || 0, positions, i, value;
|
||||
if (typeof size === 'string') {
|
||||
size = parseFloat(size);
|
||||
}
|
||||
if (typeof innerSize === 'string') {
|
||||
innerSize = parseFloat(innerSize);
|
||||
}
|
||||
positions = [
|
||||
pick(centerOption[0], '50%'),
|
||||
pick(centerOption[1], '50%'),
|
||||
// Prevent from negative values
|
||||
pick(size && size < 0 ? void 0 : options.size, '100%'),
|
||||
pick(innerSize && innerSize < 0 ? void 0 : options.innerSize || 0, '0%')
|
||||
];
|
||||
// No need for inner size in angular (gauges) series but still required
|
||||
// for pie series
|
||||
if (chart.angular && !(this instanceof H.Series)) {
|
||||
positions[3] = 0;
|
||||
}
|
||||
for (i = 0; i < 4; ++i) {
|
||||
value = positions[i];
|
||||
handleSlicingRoom = i < 2 || (i === 2 && /%$/.test(value));
|
||||
// i == 0: centerX, relative to width
|
||||
// i == 1: centerY, relative to height
|
||||
// i == 2: size, relative to smallestSize
|
||||
// i == 3: innerSize, relative to size
|
||||
positions[i] = relativeLength(value, [plotWidth, plotHeight, smallestSize, positions[2]][i]) + (handleSlicingRoom ? slicingRoom : 0);
|
||||
}
|
||||
// innerSize cannot be larger than size (#3632)
|
||||
if (positions[3] > positions[2]) {
|
||||
positions[3] = positions[2];
|
||||
}
|
||||
return positions;
|
||||
},
|
||||
/**
|
||||
* getStartAndEndRadians - Calculates start and end angles in radians.
|
||||
* Used in series types such as pie and sunburst.
|
||||
*
|
||||
* @private
|
||||
* @function Highcharts.CenteredSeriesMixin.getStartAndEndRadians
|
||||
*
|
||||
* @param {number} [start]
|
||||
* Start angle in degrees.
|
||||
*
|
||||
* @param {number} [end]
|
||||
* Start angle in degrees.
|
||||
*
|
||||
* @return {Highcharts.RadianAngles}
|
||||
* Returns an object containing start and end angles as radians.
|
||||
*/
|
||||
getStartAndEndRadians: function (start, end) {
|
||||
var startAngle = isNumber(start) ? start : 0, // must be a number
|
||||
endAngle = ((isNumber(end) && // must be a number
|
||||
end > startAngle && // must be larger than the start angle
|
||||
// difference must be less than 360 degrees
|
||||
(end - startAngle) < 360) ?
|
||||
end :
|
||||
startAngle + 360), correction = -90;
|
||||
return {
|
||||
start: deg2rad * (startAngle + correction),
|
||||
end: deg2rad * (endAngle + correction)
|
||||
};
|
||||
}
|
||||
};
|
||||
export default centeredSeriesMixin;
|
||||
@@ -0,0 +1,81 @@
|
||||
/* *
|
||||
*
|
||||
* (c) 2010-2020 Torstein Honsi
|
||||
*
|
||||
* License: www.highcharts.com/license
|
||||
*
|
||||
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
|
||||
*
|
||||
* */
|
||||
'use strict';
|
||||
import H from '../Core/Globals.js';
|
||||
import Point from '../Core/Series/Point.js';
|
||||
import U from '../Core/Utilities.js';
|
||||
var defined = U.defined;
|
||||
var noop = H.noop, seriesTypes = H.seriesTypes;
|
||||
/**
|
||||
* Mixin for maps and heatmaps
|
||||
*
|
||||
* @private
|
||||
* @mixin Highcharts.colorMapPointMixin
|
||||
*/
|
||||
H.colorMapPointMixin = {
|
||||
dataLabelOnNull: true,
|
||||
/* eslint-disable valid-jsdoc */
|
||||
/**
|
||||
* Color points have a value option that determines whether or not it is
|
||||
* a null point
|
||||
* @private
|
||||
* @function Highcharts.colorMapPointMixin.isValid
|
||||
* @return {boolean}
|
||||
*/
|
||||
isValid: function () {
|
||||
// undefined is allowed
|
||||
return (this.value !== null &&
|
||||
this.value !== Infinity &&
|
||||
this.value !== -Infinity);
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @function Highcharts.colorMapPointMixin.setState
|
||||
* @param {string} state
|
||||
* @return {void}
|
||||
*/
|
||||
setState: function (state) {
|
||||
Point.prototype.setState.call(this, state);
|
||||
if (this.graphic) {
|
||||
this.graphic.attr({
|
||||
zIndex: state === 'hover' ? 1 : 0
|
||||
});
|
||||
}
|
||||
}
|
||||
/* eslint-enable valid-jsdoc */
|
||||
};
|
||||
/**
|
||||
* @private
|
||||
* @mixin Highcharts.colorMapSeriesMixin
|
||||
*/
|
||||
H.colorMapSeriesMixin = {
|
||||
pointArrayMap: ['value'],
|
||||
axisTypes: ['xAxis', 'yAxis', 'colorAxis'],
|
||||
trackerGroups: ['group', 'markerGroup', 'dataLabelsGroup'],
|
||||
getSymbol: noop,
|
||||
parallelArrays: ['x', 'y', 'value'],
|
||||
colorKey: 'value',
|
||||
pointAttribs: seriesTypes.column.prototype.pointAttribs,
|
||||
/* eslint-disable valid-jsdoc */
|
||||
/**
|
||||
* Get the color attibutes to apply on the graphic
|
||||
* @private
|
||||
* @function Highcharts.colorMapSeriesMixin.colorAttribs
|
||||
* @param {Highcharts.Point} point
|
||||
* @return {Highcharts.SVGAttributes}
|
||||
*/
|
||||
colorAttribs: function (point) {
|
||||
var ret = {};
|
||||
if (defined(point.color)) {
|
||||
ret[this.colorProp || 'fill'] = point.color;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,74 @@
|
||||
/* *
|
||||
*
|
||||
* (c) 2010-2020 Torstein Honsi
|
||||
*
|
||||
* License: www.highcharts.com/license
|
||||
*
|
||||
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
|
||||
*
|
||||
* */
|
||||
'use strict';
|
||||
import H from '../Core/Globals.js';
|
||||
/**
|
||||
* Mixin for maps and heatmaps
|
||||
*
|
||||
* @private
|
||||
* @mixin Highcharts.colorPointMixin
|
||||
*/
|
||||
H.colorPointMixin = {
|
||||
/* eslint-disable valid-jsdoc */
|
||||
/**
|
||||
* Set the visibility of a single point
|
||||
* @private
|
||||
* @function Highcharts.colorPointMixin.setVisible
|
||||
* @param {boolean} visible
|
||||
* @return {void}
|
||||
*/
|
||||
setVisible: function (vis) {
|
||||
var point = this, method = vis ? 'show' : 'hide';
|
||||
point.visible = point.options.visible = Boolean(vis);
|
||||
// Show and hide associated elements
|
||||
['graphic', 'dataLabel'].forEach(function (key) {
|
||||
if (point[key]) {
|
||||
point[key][method]();
|
||||
}
|
||||
});
|
||||
this.series.buildKDTree(); // rebuild kdtree #13195
|
||||
}
|
||||
/* eslint-enable valid-jsdoc */
|
||||
};
|
||||
/**
|
||||
* @private
|
||||
* @mixin Highcharts.colorSeriesMixin
|
||||
*/
|
||||
H.colorSeriesMixin = {
|
||||
optionalAxis: 'colorAxis',
|
||||
colorAxis: 0,
|
||||
/* eslint-disable valid-jsdoc */
|
||||
/**
|
||||
* In choropleth maps, the color is a result of the value, so this needs
|
||||
* translation too
|
||||
* @private
|
||||
* @function Highcharts.colorSeriesMixin.translateColors
|
||||
* @return {void}
|
||||
*/
|
||||
translateColors: function () {
|
||||
var series = this, points = this.data.length ? this.data : this.points, nullColor = this.options.nullColor, colorAxis = this.colorAxis, colorKey = this.colorKey;
|
||||
points.forEach(function (point) {
|
||||
var value = point.getNestedProperty(colorKey), color;
|
||||
color = point.options.color ||
|
||||
(point.isNull || point.value === null ?
|
||||
nullColor :
|
||||
(colorAxis && typeof value !== 'undefined') ?
|
||||
colorAxis.toColor(value, point) :
|
||||
point.color || series.color);
|
||||
if (color && point.color !== color) {
|
||||
point.color = color;
|
||||
if (series.options.legendType === 'point' && point.legendItem) {
|
||||
series.chart.legend.colorizeItem(point, point.visible);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
/* eslint-enable valid-jsdoc */
|
||||
};
|
||||
@@ -0,0 +1,118 @@
|
||||
/* *
|
||||
*
|
||||
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
|
||||
*
|
||||
* */
|
||||
'use strict';
|
||||
import H from '../Core/Globals.js';
|
||||
import U from '../Core/Utilities.js';
|
||||
var addEvent = U.addEvent, defined = U.defined;
|
||||
import '../Core/Series/Series.js';
|
||||
var Series = H.Series, noop = H.noop;
|
||||
/* ************************************************************************** *
|
||||
*
|
||||
* DERIVED SERIES MIXIN
|
||||
*
|
||||
* ************************************************************************** */
|
||||
/**
|
||||
* Provides methods for auto setting/updating series data based on the based
|
||||
* series data.
|
||||
*
|
||||
* @private
|
||||
* @mixin derivedSeriesMixin
|
||||
*/
|
||||
var derivedSeriesMixin = {
|
||||
hasDerivedData: true,
|
||||
/* eslint-disable valid-jsdoc */
|
||||
/**
|
||||
* Initialise series
|
||||
*
|
||||
* @private
|
||||
* @function derivedSeriesMixin.init
|
||||
* @return {void}
|
||||
*/
|
||||
init: function () {
|
||||
Series.prototype.init.apply(this, arguments);
|
||||
this.initialised = false;
|
||||
this.baseSeries = null;
|
||||
this.eventRemovers = [];
|
||||
this.addEvents();
|
||||
},
|
||||
/**
|
||||
* Method to be implemented - inside the method the series has already
|
||||
* access to the base series via m `this.baseSeries` and the bases data is
|
||||
* initialised. It should return data in the format accepted by
|
||||
* `Series.setData()` method
|
||||
*
|
||||
* @private
|
||||
* @function derivedSeriesMixin.setDerivedData
|
||||
* @return {Array<Highcharts.PointOptionsType>}
|
||||
* An array of data
|
||||
*/
|
||||
setDerivedData: noop,
|
||||
/**
|
||||
* Sets base series for the series
|
||||
*
|
||||
* @private
|
||||
* @function derivedSeriesMixin.setBaseSeries
|
||||
* @return {void}
|
||||
*/
|
||||
setBaseSeries: function () {
|
||||
var chart = this.chart, baseSeriesOptions = this.options.baseSeries, baseSeries = (defined(baseSeriesOptions) &&
|
||||
(chart.series[baseSeriesOptions] ||
|
||||
chart.get(baseSeriesOptions)));
|
||||
this.baseSeries = baseSeries || null;
|
||||
},
|
||||
/**
|
||||
* Adds events for the series
|
||||
*
|
||||
* @private
|
||||
* @function derivedSeriesMixin.addEvents
|
||||
* @return {void}
|
||||
*/
|
||||
addEvents: function () {
|
||||
var derivedSeries = this, chartSeriesLinked;
|
||||
chartSeriesLinked = addEvent(this.chart, 'afterLinkSeries', function () {
|
||||
derivedSeries.setBaseSeries();
|
||||
if (derivedSeries.baseSeries && !derivedSeries.initialised) {
|
||||
derivedSeries.setDerivedData();
|
||||
derivedSeries.addBaseSeriesEvents();
|
||||
derivedSeries.initialised = true;
|
||||
}
|
||||
});
|
||||
this.eventRemovers.push(chartSeriesLinked);
|
||||
},
|
||||
/**
|
||||
* Adds events to the base series - it required for recalculating the data
|
||||
* in the series if the base series is updated / removed / etc.
|
||||
*
|
||||
* @private
|
||||
* @function derivedSeriesMixin.addBaseSeriesEvents
|
||||
* @return {void}
|
||||
*/
|
||||
addBaseSeriesEvents: function () {
|
||||
var derivedSeries = this, updatedDataRemover, destroyRemover;
|
||||
updatedDataRemover = addEvent(derivedSeries.baseSeries, 'updatedData', function () {
|
||||
derivedSeries.setDerivedData();
|
||||
});
|
||||
destroyRemover = addEvent(derivedSeries.baseSeries, 'destroy', function () {
|
||||
derivedSeries.baseSeries = null;
|
||||
derivedSeries.initialised = false;
|
||||
});
|
||||
derivedSeries.eventRemovers.push(updatedDataRemover, destroyRemover);
|
||||
},
|
||||
/**
|
||||
* Destroys the series
|
||||
*
|
||||
* @private
|
||||
* @function derivedSeriesMixin.destroy
|
||||
*/
|
||||
destroy: function () {
|
||||
this.eventRemovers.forEach(function (remover) {
|
||||
remover();
|
||||
});
|
||||
Series.prototype.destroy.apply(this, arguments);
|
||||
}
|
||||
/* eslint-disable valid-jsdoc */
|
||||
};
|
||||
export default derivedSeriesMixin;
|
||||
@@ -0,0 +1,74 @@
|
||||
/* *
|
||||
*
|
||||
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
|
||||
*
|
||||
* */
|
||||
var isFn = function (x) {
|
||||
return typeof x === 'function';
|
||||
};
|
||||
/* eslint-disable no-invalid-this, valid-jsdoc */
|
||||
/**
|
||||
* Handles the drawing of a component.
|
||||
* Can be used for any type of component that reserves the graphic property, and
|
||||
* provides a shouldDraw on its context.
|
||||
*
|
||||
* @private
|
||||
* @function draw
|
||||
* @param {DrawPointParams} params
|
||||
* Parameters.
|
||||
*
|
||||
* @todo add type checking.
|
||||
* @todo export this function to enable usage
|
||||
*/
|
||||
var draw = function draw(params) {
|
||||
var _a;
|
||||
var component = this, graphic = component.graphic, animatableAttribs = params.animatableAttribs, onComplete = params.onComplete, css = params.css, renderer = params.renderer, animation = (_a = component.series) === null || _a === void 0 ? void 0 : _a.options.animation;
|
||||
if (component.shouldDraw()) {
|
||||
if (!graphic) {
|
||||
component.graphic = graphic =
|
||||
renderer[params.shapeType](params.shapeArgs)
|
||||
.add(params.group);
|
||||
}
|
||||
graphic
|
||||
.css(css)
|
||||
.attr(params.attribs)
|
||||
.animate(animatableAttribs, params.isNew ? false : animation, onComplete);
|
||||
}
|
||||
else if (graphic) {
|
||||
var destroy = function () {
|
||||
component.graphic = graphic = graphic.destroy();
|
||||
if (isFn(onComplete)) {
|
||||
onComplete();
|
||||
}
|
||||
};
|
||||
// animate only runs complete callback if something was animated.
|
||||
if (Object.keys(animatableAttribs).length) {
|
||||
graphic.animate(animatableAttribs, void 0, function () {
|
||||
destroy();
|
||||
});
|
||||
}
|
||||
else {
|
||||
destroy();
|
||||
}
|
||||
}
|
||||
};
|
||||
/**
|
||||
* An extended version of draw customized for points.
|
||||
* It calls additional methods that is expected when rendering a point.
|
||||
* @private
|
||||
* @param {Highcharts.Dictionary<any>} params Parameters
|
||||
*/
|
||||
var drawPoint = function drawPoint(params) {
|
||||
var point = this, attribs = params.attribs = params.attribs || {};
|
||||
// Assigning class in dot notation does go well in IE8
|
||||
// eslint-disable-next-line dot-notation
|
||||
attribs['class'] = point.getClassName();
|
||||
// Call draw to render component
|
||||
draw.call(point, params);
|
||||
};
|
||||
var drawPointModule = {
|
||||
draw: draw,
|
||||
drawPoint: drawPoint,
|
||||
isFn: isFn
|
||||
};
|
||||
export default drawPointModule;
|
||||
@@ -0,0 +1,55 @@
|
||||
/* *
|
||||
*
|
||||
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
|
||||
*
|
||||
* */
|
||||
/**
|
||||
* Calculates the center between a list of points.
|
||||
* @private
|
||||
* @param {Array<Highcharts.PositionObject>} points
|
||||
* A list of points to calculate the center of.
|
||||
* @return {Highcharts.PositionObject}
|
||||
* Calculated center
|
||||
*/
|
||||
var getCenterOfPoints = function getCenterOfPoints(points) {
|
||||
var sum = points.reduce(function (sum, point) {
|
||||
sum.x += point.x;
|
||||
sum.y += point.y;
|
||||
return sum;
|
||||
}, { x: 0, y: 0 });
|
||||
return {
|
||||
x: sum.x / points.length,
|
||||
y: sum.y / points.length
|
||||
};
|
||||
};
|
||||
/**
|
||||
* Calculates the distance between two points based on their x and y
|
||||
* coordinates.
|
||||
* @private
|
||||
* @param {Highcharts.PositionObject} p1
|
||||
* The x and y coordinates of the first point.
|
||||
* @param {Highcharts.PositionObject} p2
|
||||
* The x and y coordinates of the second point.
|
||||
* @return {number}
|
||||
* Returns the distance between the points.
|
||||
*/
|
||||
var getDistanceBetweenPoints = function getDistanceBetweenPoints(p1, p2) {
|
||||
return Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2));
|
||||
};
|
||||
/**
|
||||
* Calculates the angle between two points.
|
||||
* @todo add unit tests.
|
||||
* @private
|
||||
* @param {Highcharts.PositionObject} p1 The first point.
|
||||
* @param {Highcharts.PositionObject} p2 The second point.
|
||||
* @return {number} Returns the angle in radians.
|
||||
*/
|
||||
var getAngleBetweenPoints = function getAngleBetweenPoints(p1, p2) {
|
||||
return Math.atan2(p2.x - p1.x, p2.y - p1.y);
|
||||
};
|
||||
var geometry = {
|
||||
getAngleBetweenPoints: getAngleBetweenPoints,
|
||||
getCenterOfPoints: getCenterOfPoints,
|
||||
getDistanceBetweenPoints: getDistanceBetweenPoints
|
||||
};
|
||||
export default geometry;
|
||||
@@ -0,0 +1,319 @@
|
||||
/* *
|
||||
*
|
||||
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
|
||||
*
|
||||
* */
|
||||
import Geometry from './Geometry.js';
|
||||
var getAngleBetweenPoints = Geometry.getAngleBetweenPoints, getCenterOfPoints = Geometry.getCenterOfPoints, getDistanceBetweenPoints = Geometry.getDistanceBetweenPoints;
|
||||
/**
|
||||
* @private
|
||||
* @param {number} x
|
||||
* Number to round
|
||||
* @param {number} decimals
|
||||
* Number of decimals to round to
|
||||
* @return {number}
|
||||
* Rounded number
|
||||
*/
|
||||
function round(x, decimals) {
|
||||
var a = Math.pow(10, decimals);
|
||||
return Math.round(x * a) / a;
|
||||
}
|
||||
/**
|
||||
* Calculates the area of a circle based on its radius.
|
||||
* @private
|
||||
* @param {number} r
|
||||
* The radius of the circle.
|
||||
* @return {number}
|
||||
* Returns the area of the circle.
|
||||
*/
|
||||
function getAreaOfCircle(r) {
|
||||
if (r <= 0) {
|
||||
throw new Error('radius of circle must be a positive number.');
|
||||
}
|
||||
return Math.PI * r * r;
|
||||
}
|
||||
/**
|
||||
* Calculates the area of a circular segment based on the radius of the circle
|
||||
* and the height of the segment.
|
||||
* See http://mathworld.wolfram.com/CircularSegment.html
|
||||
* @private
|
||||
* @param {number} r
|
||||
* The radius of the circle.
|
||||
* @param {number} h
|
||||
* The height of the circular segment.
|
||||
* @return {number}
|
||||
* Returns the area of the circular segment.
|
||||
*/
|
||||
function getCircularSegmentArea(r, h) {
|
||||
return r * r * Math.acos(1 - h / r) - (r - h) * Math.sqrt(h * (2 * r - h));
|
||||
}
|
||||
/**
|
||||
* Calculates the area of overlap between two circles based on their radiuses
|
||||
* and the distance between them.
|
||||
* See http://mathworld.wolfram.com/Circle-CircleIntersection.html
|
||||
* @private
|
||||
* @param {number} r1
|
||||
* Radius of the first circle.
|
||||
* @param {number} r2
|
||||
* Radius of the second circle.
|
||||
* @param {number} d
|
||||
* The distance between the two circles.
|
||||
* @return {number}
|
||||
* Returns the area of overlap between the two circles.
|
||||
*/
|
||||
function getOverlapBetweenCircles(r1, r2, d) {
|
||||
var overlap = 0;
|
||||
// If the distance is larger than the sum of the radiuses then the circles
|
||||
// does not overlap.
|
||||
if (d < r1 + r2) {
|
||||
if (d <= Math.abs(r2 - r1)) {
|
||||
// If the circles are completely overlapping, then the overlap
|
||||
// equals the area of the smallest circle.
|
||||
overlap = getAreaOfCircle(r1 < r2 ? r1 : r2);
|
||||
}
|
||||
else {
|
||||
// Height of first triangle segment.
|
||||
var d1 = (r1 * r1 - r2 * r2 + d * d) / (2 * d),
|
||||
// Height of second triangle segment.
|
||||
d2 = d - d1;
|
||||
overlap = (getCircularSegmentArea(r1, r1 - d1) +
|
||||
getCircularSegmentArea(r2, r2 - d2));
|
||||
}
|
||||
// Round the result to two decimals.
|
||||
overlap = round(overlap, 14);
|
||||
}
|
||||
return overlap;
|
||||
}
|
||||
/**
|
||||
* Calculates the intersection points of two circles.
|
||||
*
|
||||
* NOTE: does not handle floating errors well.
|
||||
* @private
|
||||
* @param {Highcharts.CircleObject} c1
|
||||
* The first circle.
|
||||
* @param {Highcharts.CircleObject} c2
|
||||
* The second sircle.
|
||||
* @return {Array<Highcharts.PositionObject>}
|
||||
* Returns the resulting intersection points.
|
||||
*/
|
||||
function getCircleCircleIntersection(c1, c2) {
|
||||
var d = getDistanceBetweenPoints(c1, c2), r1 = c1.r, r2 = c2.r;
|
||||
var points = [];
|
||||
if (d < r1 + r2 && d > Math.abs(r1 - r2)) {
|
||||
// If the circles are overlapping, but not completely overlapping, then
|
||||
// it exists intersecting points.
|
||||
var r1Square = r1 * r1, r2Square = r2 * r2,
|
||||
// d^2 - r^2 + R^2 / 2d
|
||||
x = (r1Square - r2Square + d * d) / (2 * d),
|
||||
// y^2 = R^2 - x^2
|
||||
y = Math.sqrt(r1Square - x * x), x1 = c1.x, x2 = c2.x, y1 = c1.y, y2 = c2.y, x0 = x1 + x * (x2 - x1) / d, y0 = y1 + x * (y2 - y1) / d, rx = -(y2 - y1) * (y / d), ry = -(x2 - x1) * (y / d);
|
||||
points = [
|
||||
{ x: round(x0 + rx, 14), y: round(y0 - ry, 14) },
|
||||
{ x: round(x0 - rx, 14), y: round(y0 + ry, 14) }
|
||||
];
|
||||
}
|
||||
return points;
|
||||
}
|
||||
/**
|
||||
* Calculates all the intersection points for between a list of circles.
|
||||
* @private
|
||||
* @param {Array<Highcharts.CircleObject>} circles
|
||||
* The circles to calculate the points from.
|
||||
* @return {Array<Highcharts.GeometryObject>}
|
||||
* Returns a list of intersection points.
|
||||
*/
|
||||
function getCirclesIntersectionPoints(circles) {
|
||||
return circles.reduce(function (points, c1, i, arr) {
|
||||
var additional = arr.slice(i + 1)
|
||||
.reduce(function (points, c2, j) {
|
||||
var indexes = [i, j + i + 1];
|
||||
return points.concat(getCircleCircleIntersection(c1, c2)
|
||||
.map(function (p) {
|
||||
p.indexes = indexes;
|
||||
return p;
|
||||
}));
|
||||
}, []);
|
||||
return points.concat(additional);
|
||||
}, []);
|
||||
}
|
||||
/**
|
||||
* Tests wether the first circle is completely overlapping the second circle.
|
||||
*
|
||||
* @private
|
||||
* @param {Highcharts.CircleObject} circle1 The first circle.
|
||||
* @param {Highcharts.CircleObject} circle2 The The second circle.
|
||||
* @return {boolean} Returns true if circle1 is completely overlapping circle2,
|
||||
* false if not.
|
||||
*/
|
||||
function isCircle1CompletelyOverlappingCircle2(circle1, circle2) {
|
||||
return getDistanceBetweenPoints(circle1, circle2) + circle2.r <
|
||||
circle1.r + 1e-10;
|
||||
}
|
||||
/**
|
||||
* Tests wether a point lies within a given circle.
|
||||
* @private
|
||||
* @param {Highcharts.PositionObject} point
|
||||
* The point to test for.
|
||||
* @param {Highcharts.CircleObject} circle
|
||||
* The circle to test if the point is within.
|
||||
* @return {boolean}
|
||||
* Returns true if the point is inside, false if outside.
|
||||
*/
|
||||
function isPointInsideCircle(point, circle) {
|
||||
return getDistanceBetweenPoints(point, circle) <= circle.r + 1e-10;
|
||||
}
|
||||
/**
|
||||
* Tests wether a point lies within a set of circles.
|
||||
* @private
|
||||
* @param {Highcharts.PositionObject} point
|
||||
* The point to test.
|
||||
* @param {Array<Highcharts.CircleObject>} circles
|
||||
* The list of circles to test against.
|
||||
* @return {boolean}
|
||||
* Returns true if the point is inside all the circles, false if not.
|
||||
*/
|
||||
function isPointInsideAllCircles(point, circles) {
|
||||
return !circles.some(function (circle) {
|
||||
return !isPointInsideCircle(point, circle);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Tests wether a point lies outside a set of circles.
|
||||
*
|
||||
* TODO: add unit tests.
|
||||
* @private
|
||||
* @param {Highcharts.PositionObject} point
|
||||
* The point to test.
|
||||
* @param {Array<Highcharts.CircleObject>} circles
|
||||
* The list of circles to test against.
|
||||
* @return {boolean}
|
||||
* Returns true if the point is outside all the circles, false if not.
|
||||
*/
|
||||
function isPointOutsideAllCircles(point, circles) {
|
||||
return !circles.some(function (circle) {
|
||||
return isPointInsideCircle(point, circle);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Calculates the points for the polygon of the intersection area between a set
|
||||
* of circles.
|
||||
*
|
||||
* @private
|
||||
* @param {Array<Highcharts.CircleObject>} circles
|
||||
* List of circles to calculate polygon of.
|
||||
* @return {Array<Highcharts.GeometryObject>} Return list of points in the
|
||||
* intersection polygon.
|
||||
*/
|
||||
function getCirclesIntersectionPolygon(circles) {
|
||||
return getCirclesIntersectionPoints(circles)
|
||||
.filter(function (p) {
|
||||
return isPointInsideAllCircles(p, circles);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Calculate the path for the area of overlap between a set of circles.
|
||||
* @todo handle cases with only 1 or 0 arcs.
|
||||
* @private
|
||||
* @param {Array<Highcharts.CircleObject>} circles
|
||||
* List of circles to calculate area of.
|
||||
* @return {Highcharts.GeometryIntersectionObject|undefined}
|
||||
* Returns the path for the area of overlap. Returns an empty string if
|
||||
* there are no intersection between all the circles.
|
||||
*/
|
||||
function getAreaOfIntersectionBetweenCircles(circles) {
|
||||
var intersectionPoints = getCirclesIntersectionPolygon(circles), result;
|
||||
if (intersectionPoints.length > 1) {
|
||||
// Calculate the center of the intersection points.
|
||||
var center_1 = getCenterOfPoints(intersectionPoints);
|
||||
intersectionPoints = intersectionPoints
|
||||
// Calculate the angle between the center and the points.
|
||||
.map(function (p) {
|
||||
p.angle = getAngleBetweenPoints(center_1, p);
|
||||
return p;
|
||||
})
|
||||
// Sort the points by the angle to the center.
|
||||
.sort(function (a, b) {
|
||||
return b.angle - a.angle;
|
||||
});
|
||||
var startPoint = intersectionPoints[intersectionPoints.length - 1];
|
||||
var arcs = intersectionPoints
|
||||
.reduce(function (data, p1) {
|
||||
var startPoint = data.startPoint, midPoint = getCenterOfPoints([startPoint, p1]);
|
||||
// Calculate the arc from the intersection points and their
|
||||
// circles.
|
||||
var arc = p1.indexes
|
||||
// Filter out circles that are not included in both
|
||||
// intersection points.
|
||||
.filter(function (index) {
|
||||
return startPoint.indexes.indexOf(index) > -1;
|
||||
})
|
||||
// Iterate the circles of the intersection points and
|
||||
// calculate arcs.
|
||||
.reduce(function (arc, index) {
|
||||
var circle = circles[index], angle1 = getAngleBetweenPoints(circle, p1), angle2 = getAngleBetweenPoints(circle, startPoint), angleDiff = angle2 - angle1 +
|
||||
(angle2 < angle1 ? 2 * Math.PI : 0), angle = angle2 - angleDiff / 2;
|
||||
var width = getDistanceBetweenPoints(midPoint, {
|
||||
x: circle.x + circle.r * Math.sin(angle),
|
||||
y: circle.y + circle.r * Math.cos(angle)
|
||||
});
|
||||
var r = circle.r;
|
||||
// Width can sometimes become to large due to floating
|
||||
// point errors
|
||||
if (width > r * 2) {
|
||||
width = r * 2;
|
||||
}
|
||||
// Get the arc with the smallest width.
|
||||
if (!arc || arc.width > width) {
|
||||
arc = {
|
||||
r: r,
|
||||
largeArc: width > r ? 1 : 0,
|
||||
width: width,
|
||||
x: p1.x,
|
||||
y: p1.y
|
||||
};
|
||||
}
|
||||
// Return the chosen arc.
|
||||
return arc;
|
||||
}, null);
|
||||
// If we find an arc then add it to the list and update p2.
|
||||
if (arc) {
|
||||
var r = arc.r;
|
||||
data.arcs.push(['A', r, r, 0, arc.largeArc, 1, arc.x, arc.y]);
|
||||
data.startPoint = p1;
|
||||
}
|
||||
return data;
|
||||
}, {
|
||||
startPoint: startPoint,
|
||||
arcs: []
|
||||
}).arcs;
|
||||
if (arcs.length === 0) {
|
||||
// empty
|
||||
}
|
||||
else if (arcs.length === 1) {
|
||||
// empty
|
||||
}
|
||||
else {
|
||||
arcs.unshift(['M', startPoint.x, startPoint.y]);
|
||||
result = {
|
||||
center: center_1,
|
||||
d: arcs
|
||||
};
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
var geometryCircles = {
|
||||
getAreaOfCircle: getAreaOfCircle,
|
||||
getAreaOfIntersectionBetweenCircles: getAreaOfIntersectionBetweenCircles,
|
||||
getCircleCircleIntersection: getCircleCircleIntersection,
|
||||
getCirclesIntersectionPoints: getCirclesIntersectionPoints,
|
||||
getCirclesIntersectionPolygon: getCirclesIntersectionPolygon,
|
||||
getCircularSegmentArea: getCircularSegmentArea,
|
||||
getOverlapBetweenCircles: getOverlapBetweenCircles,
|
||||
isCircle1CompletelyOverlappingCircle2: isCircle1CompletelyOverlappingCircle2,
|
||||
isPointInsideCircle: isPointInsideCircle,
|
||||
isPointInsideAllCircles: isPointInsideAllCircles,
|
||||
isPointOutsideAllCircles: isPointOutsideAllCircles,
|
||||
round: round
|
||||
};
|
||||
export default geometryCircles;
|
||||
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
*
|
||||
* (c) 2010-2020 Daniel Studencki
|
||||
*
|
||||
* License: www.highcharts.com/license
|
||||
*
|
||||
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
|
||||
*
|
||||
* */
|
||||
'use strict';
|
||||
import U from '../Core/Utilities.js';
|
||||
var error = U.error;
|
||||
/* eslint-disable no-invalid-this, valid-jsdoc */
|
||||
var requiredIndicatorMixin = {
|
||||
/**
|
||||
* Check whether given indicator is loaded, else throw error.
|
||||
* @private
|
||||
* @param {Highcharts.Indicator} indicator
|
||||
* Indicator constructor function.
|
||||
* @param {string} requiredIndicator
|
||||
* Required indicator type.
|
||||
* @param {string} type
|
||||
* Type of indicator where function was called (parent).
|
||||
* @param {Highcharts.IndicatorCallbackFunction} callback
|
||||
* Callback which is triggered if the given indicator is loaded.
|
||||
* Takes indicator as an argument.
|
||||
* @param {string} errMessage
|
||||
* Error message that will be logged in console.
|
||||
* @return {boolean}
|
||||
* Returns false when there is no required indicator loaded.
|
||||
*/
|
||||
isParentLoaded: function (indicator, requiredIndicator, type, callback, errMessage) {
|
||||
if (indicator) {
|
||||
return callback ? callback(indicator) : true;
|
||||
}
|
||||
error(errMessage || this.generateMessage(type, requiredIndicator));
|
||||
return false;
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {string} indicatorType
|
||||
* Indicator type
|
||||
* @param {string} required
|
||||
* Required indicator
|
||||
* @return {string}
|
||||
* Error message
|
||||
*/
|
||||
generateMessage: function (indicatorType, required) {
|
||||
return 'Error: "' + indicatorType +
|
||||
'" indicator type requires "' + required +
|
||||
'" indicator loaded before. Please read docs: ' +
|
||||
'https://api.highcharts.com/highstock/plotOptions.' +
|
||||
indicatorType;
|
||||
}
|
||||
};
|
||||
export default requiredIndicatorMixin;
|
||||
@@ -0,0 +1,92 @@
|
||||
/* *
|
||||
*
|
||||
* (c) 2010-2020 Torstein Honsi
|
||||
*
|
||||
* License: www.highcharts.com/license
|
||||
*
|
||||
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
|
||||
*
|
||||
* */
|
||||
import H from '../Core/Globals.js';
|
||||
import U from '../Core/Utilities.js';
|
||||
var merge = U.merge, pick = U.pick;
|
||||
/* eslint-disable valid-jsdoc */
|
||||
/**
|
||||
* Legend symbol mixin.
|
||||
*
|
||||
* @private
|
||||
* @mixin Highcharts.LegendSymbolMixin
|
||||
*/
|
||||
var LegendSymbolMixin = H.LegendSymbolMixin = {
|
||||
/**
|
||||
* Get the series' symbol in the legend
|
||||
*
|
||||
* @private
|
||||
* @function Highcharts.LegendSymbolMixin.drawRectangle
|
||||
*
|
||||
* @param {Highcharts.Legend} legend
|
||||
* The legend object
|
||||
*
|
||||
* @param {Highcharts.Point|Highcharts.Series} item
|
||||
* The series (this) or point
|
||||
*/
|
||||
drawRectangle: function (legend, item) {
|
||||
var options = legend.options, symbolHeight = legend.symbolHeight, square = options.squareSymbol, symbolWidth = square ? symbolHeight : legend.symbolWidth;
|
||||
item.legendSymbol = this.chart.renderer.rect(square ? (legend.symbolWidth - symbolHeight) / 2 : 0, legend.baseline - symbolHeight + 1, // #3988
|
||||
symbolWidth, symbolHeight, pick(legend.options.symbolRadius, symbolHeight / 2))
|
||||
.addClass('highcharts-point')
|
||||
.attr({
|
||||
zIndex: 3
|
||||
}).add(item.legendGroup);
|
||||
},
|
||||
/**
|
||||
* Get the series' symbol in the legend. This method should be overridable
|
||||
* to create custom symbols through
|
||||
* Highcharts.seriesTypes[type].prototype.drawLegendSymbols.
|
||||
*
|
||||
* @private
|
||||
* @function Highcharts.LegendSymbolMixin.drawLineMarker
|
||||
*
|
||||
* @param {Highcharts.Legend} legend
|
||||
* The legend object.
|
||||
*/
|
||||
drawLineMarker: function (legend) {
|
||||
var options = this.options, markerOptions = options.marker, radius, legendSymbol, symbolWidth = legend.symbolWidth, symbolHeight = legend.symbolHeight, generalRadius = symbolHeight / 2, renderer = this.chart.renderer, legendItemGroup = this.legendGroup, verticalCenter = legend.baseline -
|
||||
Math.round(legend.fontMetrics.b * 0.3), attr = {};
|
||||
// Draw the line
|
||||
if (!this.chart.styledMode) {
|
||||
attr = {
|
||||
'stroke-width': options.lineWidth || 0
|
||||
};
|
||||
if (options.dashStyle) {
|
||||
attr.dashstyle = options.dashStyle;
|
||||
}
|
||||
}
|
||||
this.legendLine = renderer
|
||||
.path([
|
||||
['M', 0, verticalCenter],
|
||||
['L', symbolWidth, verticalCenter]
|
||||
])
|
||||
.addClass('highcharts-graph')
|
||||
.attr(attr)
|
||||
.add(legendItemGroup);
|
||||
// Draw the marker
|
||||
if (markerOptions && markerOptions.enabled !== false && symbolWidth) {
|
||||
// Do not allow the marker to be larger than the symbolHeight
|
||||
radius = Math.min(pick(markerOptions.radius, generalRadius), generalRadius);
|
||||
// Restrict symbol markers size
|
||||
if (this.symbol.indexOf('url') === 0) {
|
||||
markerOptions = merge(markerOptions, {
|
||||
width: symbolHeight,
|
||||
height: symbolHeight
|
||||
});
|
||||
radius = 0;
|
||||
}
|
||||
this.legendSymbol = legendSymbol = renderer.symbol(this.symbol, (symbolWidth / 2) - radius, verticalCenter - radius, 2 * radius, 2 * radius, markerOptions)
|
||||
.addClass('highcharts-point')
|
||||
.add(legendItemGroup);
|
||||
legendSymbol.isMarker = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
export default LegendSymbolMixin;
|
||||
@@ -0,0 +1,175 @@
|
||||
/**
|
||||
*
|
||||
* (c) 2010-2020 Wojciech Chmiel
|
||||
*
|
||||
* License: www.highcharts.com/license
|
||||
*
|
||||
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
|
||||
*
|
||||
* */
|
||||
'use strict';
|
||||
import H from '../Core/Globals.js';
|
||||
import U from '../Core/Utilities.js';
|
||||
var defined = U.defined, error = U.error, merge = U.merge;
|
||||
var SMA = H.seriesTypes.sma;
|
||||
/**
|
||||
* Mixin useful for all indicators that have more than one line.
|
||||
* Merge it with your implementation where you will provide
|
||||
* getValues method appropriate to your indicator and pointArrayMap,
|
||||
* pointValKey, linesApiNames properites. Notice that pointArrayMap
|
||||
* should be consistent with amount of lines calculated in getValues method.
|
||||
*
|
||||
* @private
|
||||
* @mixin multipleLinesMixin
|
||||
*/
|
||||
var multipleLinesMixin = {
|
||||
/* eslint-disable valid-jsdoc */
|
||||
/**
|
||||
* Lines ids. Required to plot appropriate amount of lines.
|
||||
* Notice that pointArrayMap should have more elements than
|
||||
* linesApiNames, because it contains main line and additional lines ids.
|
||||
* Also it should be consistent with amount of lines calculated in
|
||||
* getValues method from your implementation.
|
||||
*
|
||||
* @private
|
||||
* @name multipleLinesMixin.pointArrayMap
|
||||
* @type {Array<string>}
|
||||
*/
|
||||
pointArrayMap: ['top', 'bottom'],
|
||||
/**
|
||||
* Main line id.
|
||||
*
|
||||
* @private
|
||||
* @name multipleLinesMixin.pointValKey
|
||||
* @type {string}
|
||||
*/
|
||||
pointValKey: 'top',
|
||||
/**
|
||||
* Additional lines DOCS names. Elements of linesApiNames array should
|
||||
* be consistent with DOCS line names defined in your implementation.
|
||||
* Notice that linesApiNames should have decreased amount of elements
|
||||
* relative to pointArrayMap (without pointValKey).
|
||||
*
|
||||
* @private
|
||||
* @name multipleLinesMixin.linesApiNames
|
||||
* @type {Array<string>}
|
||||
*/
|
||||
linesApiNames: ['bottomLine'],
|
||||
/**
|
||||
* Create translatedLines Collection based on pointArrayMap.
|
||||
*
|
||||
* @private
|
||||
* @function multipleLinesMixin.getTranslatedLinesNames
|
||||
* @param {string} [excludedValue]
|
||||
* Main line id
|
||||
* @return {Array<string>}
|
||||
* Returns translated lines names without excluded value.
|
||||
*/
|
||||
getTranslatedLinesNames: function (excludedValue) {
|
||||
var translatedLines = [];
|
||||
(this.pointArrayMap || []).forEach(function (propertyName) {
|
||||
if (propertyName !== excludedValue) {
|
||||
translatedLines.push('plot' +
|
||||
propertyName.charAt(0).toUpperCase() +
|
||||
propertyName.slice(1));
|
||||
}
|
||||
});
|
||||
return translatedLines;
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @function multipleLinesMixin.toYData
|
||||
* @param {Highcharts.Point} point
|
||||
* Indicator point
|
||||
* @return {Array<number>}
|
||||
* Returns point Y value for all lines
|
||||
*/
|
||||
toYData: function (point) {
|
||||
var pointColl = [];
|
||||
(this.pointArrayMap || []).forEach(function (propertyName) {
|
||||
pointColl.push(point[propertyName]);
|
||||
});
|
||||
return pointColl;
|
||||
},
|
||||
/**
|
||||
* Add lines plot pixel values.
|
||||
*
|
||||
* @private
|
||||
* @function multipleLinesMixin.translate
|
||||
* @return {void}
|
||||
*/
|
||||
translate: function () {
|
||||
var indicator = this, pointArrayMap = indicator.pointArrayMap, LinesNames = [], value;
|
||||
LinesNames = indicator.getTranslatedLinesNames();
|
||||
SMA.prototype.translate.apply(indicator, arguments);
|
||||
indicator.points.forEach(function (point) {
|
||||
pointArrayMap.forEach(function (propertyName, i) {
|
||||
value = point[propertyName];
|
||||
if (value !== null) {
|
||||
point[LinesNames[i]] = indicator.yAxis.toPixels(value, true);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Draw main and additional lines.
|
||||
*
|
||||
* @private
|
||||
* @function multipleLinesMixin.drawGraph
|
||||
* @return {void}
|
||||
*/
|
||||
drawGraph: function () {
|
||||
var indicator = this, pointValKey = indicator.pointValKey, linesApiNames = indicator.linesApiNames, mainLinePoints = indicator.points, pointsLength = mainLinePoints.length, mainLineOptions = indicator.options, mainLinePath = indicator.graph, gappedExtend = {
|
||||
options: {
|
||||
gapSize: mainLineOptions.gapSize
|
||||
}
|
||||
},
|
||||
// additional lines point place holders:
|
||||
secondaryLines = [], secondaryLinesNames = indicator.getTranslatedLinesNames(pointValKey), point;
|
||||
// Generate points for additional lines:
|
||||
secondaryLinesNames.forEach(function (plotLine, index) {
|
||||
// create additional lines point place holders
|
||||
secondaryLines[index] = [];
|
||||
while (pointsLength--) {
|
||||
point = mainLinePoints[pointsLength];
|
||||
secondaryLines[index].push({
|
||||
x: point.x,
|
||||
plotX: point.plotX,
|
||||
plotY: point[plotLine],
|
||||
isNull: !defined(point[plotLine])
|
||||
});
|
||||
}
|
||||
pointsLength = mainLinePoints.length;
|
||||
});
|
||||
// Modify options and generate additional lines:
|
||||
linesApiNames.forEach(function (lineName, i) {
|
||||
if (secondaryLines[i]) {
|
||||
indicator.points = secondaryLines[i];
|
||||
if (mainLineOptions[lineName]) {
|
||||
indicator.options = merge(mainLineOptions[lineName].styles, gappedExtend);
|
||||
}
|
||||
else {
|
||||
error('Error: "There is no ' + lineName +
|
||||
' in DOCS options declared. Check if linesApiNames' +
|
||||
' are consistent with your DOCS line names."' +
|
||||
' at mixin/multiple-line.js:34');
|
||||
}
|
||||
indicator.graph = indicator['graph' + lineName];
|
||||
SMA.prototype.drawGraph.call(indicator);
|
||||
// Now save lines:
|
||||
indicator['graph' + lineName] = indicator.graph;
|
||||
}
|
||||
else {
|
||||
error('Error: "' + lineName + ' doesn\'t have equivalent ' +
|
||||
'in pointArrayMap. To many elements in linesApiNames ' +
|
||||
'relative to pointArrayMap."');
|
||||
}
|
||||
});
|
||||
// Restore options and draw a main line:
|
||||
indicator.points = mainLinePoints;
|
||||
indicator.options = mainLineOptions;
|
||||
indicator.graph = mainLinePath;
|
||||
SMA.prototype.drawGraph.call(indicator);
|
||||
}
|
||||
};
|
||||
export default multipleLinesMixin;
|
||||
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
*
|
||||
* (c) 2010-2018 Paweł Fus
|
||||
*
|
||||
* License: www.highcharts.com/license
|
||||
*
|
||||
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
|
||||
*
|
||||
* */
|
||||
'use strict';
|
||||
var chartNavigation = {
|
||||
/**
|
||||
* Initializes `chart.navigation` object which delegates `update()` methods
|
||||
* to all other common classes (used in exporting and navigationBindings).
|
||||
*
|
||||
* @private
|
||||
* @param {Highcharts.Chart} chart
|
||||
* The chart instance.
|
||||
* @return {void}
|
||||
*/
|
||||
initUpdate: function (chart) {
|
||||
if (!chart.navigation) {
|
||||
chart.navigation = {
|
||||
updates: [],
|
||||
update: function (options, redraw) {
|
||||
this.updates.forEach(function (updateConfig) {
|
||||
updateConfig.update.call(updateConfig.context, options, redraw);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Registers an `update()` method in the `chart.navigation` object.
|
||||
*
|
||||
* @private
|
||||
* @param {Highcharts.ChartNavigationUpdateFunction} update
|
||||
* The `update()` method that will be called in `chart.update()`.
|
||||
* @param {Highcharts.Chart} chart
|
||||
* The chart instance. `update()` will use that as a context
|
||||
* (`this`).
|
||||
* @return {void}
|
||||
*/
|
||||
addUpdate: function (update, chart) {
|
||||
if (!chart.navigation) {
|
||||
this.initUpdate(chart);
|
||||
}
|
||||
chart.navigation.updates.push({
|
||||
update: update,
|
||||
context: chart
|
||||
});
|
||||
}
|
||||
};
|
||||
export default chartNavigation;
|
||||
@@ -0,0 +1,132 @@
|
||||
/* *
|
||||
*
|
||||
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
|
||||
*
|
||||
* */
|
||||
/* eslint-disable valid-jsdoc */
|
||||
var getCentroid = function (simplex) {
|
||||
var arr = simplex.slice(0, -1), length = arr.length, result = [], sum = function (data, point) {
|
||||
data.sum += point[data.i];
|
||||
return data;
|
||||
};
|
||||
for (var i = 0; i < length; i++) {
|
||||
result[i] = arr.reduce(sum, { sum: 0, i: i }).sum / length;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
/**
|
||||
* Finds an optimal position for a given point.
|
||||
* @todo add unit tests.
|
||||
* @todo add constraints to optimize the algorithm.
|
||||
* @private
|
||||
* @param {Highcharts.NelderMeadTestFunction} fn
|
||||
* The function to test a point.
|
||||
* @param {Highcharts.NelderMeadPointArray} initial
|
||||
* The initial point to optimize.
|
||||
* @return {Highcharts.NelderMeadPointArray}
|
||||
* Returns the opimized position of a point.
|
||||
*/
|
||||
var nelderMead = function nelderMead(fn, initial) {
|
||||
var maxIterations = 100, sortByFx = function (a, b) {
|
||||
return a.fx - b.fx;
|
||||
}, pRef = 1, // Reflection parameter
|
||||
pExp = 2, // Expansion parameter
|
||||
pCon = -0.5, // Contraction parameter
|
||||
pOCon = pCon * pRef, // Outwards contraction parameter
|
||||
pShrink = 0.5; // Shrink parameter
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
var weightedSum = function weightedSum(weight1, v1, weight2, v2) {
|
||||
return v1.map(function (x, i) {
|
||||
return weight1 * x + weight2 * v2[i];
|
||||
});
|
||||
};
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
var getSimplex = function getSimplex(initial) {
|
||||
var n = initial.length, simplex = new Array(n + 1);
|
||||
// Initial point to the simplex.
|
||||
simplex[0] = initial;
|
||||
simplex[0].fx = fn(initial);
|
||||
// Create a set of extra points based on the initial.
|
||||
for (var i = 0; i < n; ++i) {
|
||||
var point = initial.slice();
|
||||
point[i] = point[i] ? point[i] * 1.05 : 0.001;
|
||||
point.fx = fn(point);
|
||||
simplex[i + 1] = point;
|
||||
}
|
||||
return simplex;
|
||||
};
|
||||
var updateSimplex = function (simplex, point) {
|
||||
point.fx = fn(point);
|
||||
simplex[simplex.length - 1] = point;
|
||||
return simplex;
|
||||
};
|
||||
var shrinkSimplex = function (simplex) {
|
||||
var best = simplex[0];
|
||||
return simplex.map(function (point) {
|
||||
var p = weightedSum(1 - pShrink, best, pShrink, point);
|
||||
p.fx = fn(p);
|
||||
return p;
|
||||
});
|
||||
};
|
||||
var getPoint = function (centroid, worst, a, b) {
|
||||
var point = weightedSum(a, centroid, b, worst);
|
||||
point.fx = fn(point);
|
||||
return point;
|
||||
};
|
||||
// Create a simplex
|
||||
var simplex = getSimplex(initial);
|
||||
// Iterate from 0 to max iterations
|
||||
for (var i = 0; i < maxIterations; i++) {
|
||||
// Sort the simplex
|
||||
simplex.sort(sortByFx);
|
||||
// Create a centroid from the simplex
|
||||
var worst = simplex[simplex.length - 1];
|
||||
var centroid = getCentroid(simplex);
|
||||
// Calculate the reflected point.
|
||||
var reflected = getPoint(centroid, worst, 1 + pRef, -pRef);
|
||||
if (reflected.fx < simplex[0].fx) {
|
||||
// If reflected point is the best, then possibly expand.
|
||||
var expanded = getPoint(centroid, worst, 1 + pExp, -pExp);
|
||||
simplex = updateSimplex(simplex, (expanded.fx < reflected.fx) ? expanded : reflected);
|
||||
}
|
||||
else if (reflected.fx >= simplex[simplex.length - 2].fx) {
|
||||
// If the reflected point is worse than the second worse, then
|
||||
// contract.
|
||||
var contracted;
|
||||
if (reflected.fx > worst.fx) {
|
||||
// If the reflected is worse than the worst point, do a
|
||||
// contraction
|
||||
contracted = getPoint(centroid, worst, 1 + pCon, -pCon);
|
||||
if (contracted.fx < worst.fx) {
|
||||
simplex = updateSimplex(simplex, contracted);
|
||||
}
|
||||
else {
|
||||
simplex = shrinkSimplex(simplex);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Otherwise do an outwards contraction
|
||||
contracted = getPoint(centroid, worst, 1 - pOCon, pOCon);
|
||||
if (contracted.fx < reflected.fx) {
|
||||
simplex = updateSimplex(simplex, contracted);
|
||||
}
|
||||
else {
|
||||
simplex = shrinkSimplex(simplex);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
simplex = updateSimplex(simplex, reflected);
|
||||
}
|
||||
}
|
||||
return simplex[0];
|
||||
};
|
||||
var nelderMeadMixin = {
|
||||
getCentroid: getCentroid,
|
||||
nelderMead: nelderMead
|
||||
};
|
||||
export default nelderMeadMixin;
|
||||
@@ -0,0 +1,180 @@
|
||||
/* *
|
||||
*
|
||||
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
|
||||
*
|
||||
* */
|
||||
import H from '../Core/Globals.js';
|
||||
import Point from '../Core/Series/Point.js';
|
||||
import U from '../Core/Utilities.js';
|
||||
var defined = U.defined, extend = U.extend, find = U.find, pick = U.pick;
|
||||
import '../Core/Series/Series.js';
|
||||
var NodesMixin = H.NodesMixin = {
|
||||
/* eslint-disable valid-jsdoc */
|
||||
/**
|
||||
* Create a single node that holds information on incoming and outgoing
|
||||
* links.
|
||||
* @private
|
||||
*/
|
||||
createNode: function (id) {
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
function findById(nodes, id) {
|
||||
return find(nodes, function (node) {
|
||||
return node.id === id;
|
||||
});
|
||||
}
|
||||
var node = findById(this.nodes, id), PointClass = this.pointClass, options;
|
||||
if (!node) {
|
||||
options = this.options.nodes && findById(this.options.nodes, id);
|
||||
node = (new PointClass()).init(this, extend({
|
||||
className: 'highcharts-node',
|
||||
isNode: true,
|
||||
id: id,
|
||||
y: 1 // Pass isNull test
|
||||
}, options));
|
||||
node.linksTo = [];
|
||||
node.linksFrom = [];
|
||||
node.formatPrefix = 'node';
|
||||
node.name = node.name || node.options.id || ''; // for use in formats
|
||||
// Mass is used in networkgraph:
|
||||
node.mass = pick(
|
||||
// Node:
|
||||
node.options.mass, node.options.marker && node.options.marker.radius,
|
||||
// Series:
|
||||
this.options.marker && this.options.marker.radius,
|
||||
// Default:
|
||||
4);
|
||||
/**
|
||||
* Return the largest sum of either the incoming or outgoing links.
|
||||
* @private
|
||||
*/
|
||||
node.getSum = function () {
|
||||
var sumTo = 0, sumFrom = 0;
|
||||
node.linksTo.forEach(function (link) {
|
||||
sumTo += link.weight;
|
||||
});
|
||||
node.linksFrom.forEach(function (link) {
|
||||
sumFrom += link.weight;
|
||||
});
|
||||
return Math.max(sumTo, sumFrom);
|
||||
};
|
||||
/**
|
||||
* Get the offset in weight values of a point/link.
|
||||
* @private
|
||||
*/
|
||||
node.offset = function (point, coll) {
|
||||
var offset = 0;
|
||||
for (var i = 0; i < node[coll].length; i++) {
|
||||
if (node[coll][i] === point) {
|
||||
return offset;
|
||||
}
|
||||
offset += node[coll][i].weight;
|
||||
}
|
||||
};
|
||||
// Return true if the node has a shape, otherwise all links are
|
||||
// outgoing.
|
||||
node.hasShape = function () {
|
||||
var outgoing = 0;
|
||||
node.linksTo.forEach(function (link) {
|
||||
if (link.outgoing) {
|
||||
outgoing++;
|
||||
}
|
||||
});
|
||||
return (!node.linksTo.length ||
|
||||
outgoing !== node.linksTo.length);
|
||||
};
|
||||
this.nodes.push(node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
/**
|
||||
* Extend generatePoints by adding the nodes, which are Point objects
|
||||
* but pushed to the this.nodes array.
|
||||
*/
|
||||
generatePoints: function () {
|
||||
var chart = this.chart, nodeLookup = {};
|
||||
H.Series.prototype.generatePoints.call(this);
|
||||
if (!this.nodes) {
|
||||
this.nodes = []; // List of Point-like node items
|
||||
}
|
||||
this.colorCounter = 0;
|
||||
// Reset links from previous run
|
||||
this.nodes.forEach(function (node) {
|
||||
node.linksFrom.length = 0;
|
||||
node.linksTo.length = 0;
|
||||
node.level = node.options.level;
|
||||
});
|
||||
// Create the node list and set up links
|
||||
this.points.forEach(function (point) {
|
||||
if (defined(point.from)) {
|
||||
if (!nodeLookup[point.from]) {
|
||||
nodeLookup[point.from] = this.createNode(point.from);
|
||||
}
|
||||
nodeLookup[point.from].linksFrom.push(point);
|
||||
point.fromNode = nodeLookup[point.from];
|
||||
// Point color defaults to the fromNode's color
|
||||
if (chart.styledMode) {
|
||||
point.colorIndex = pick(point.options.colorIndex, nodeLookup[point.from].colorIndex);
|
||||
}
|
||||
else {
|
||||
point.color =
|
||||
point.options.color || nodeLookup[point.from].color;
|
||||
}
|
||||
}
|
||||
if (defined(point.to)) {
|
||||
if (!nodeLookup[point.to]) {
|
||||
nodeLookup[point.to] = this.createNode(point.to);
|
||||
}
|
||||
nodeLookup[point.to].linksTo.push(point);
|
||||
point.toNode = nodeLookup[point.to];
|
||||
}
|
||||
point.name = point.name || point.id; // for use in formats
|
||||
}, this);
|
||||
// Store lookup table for later use
|
||||
this.nodeLookup = nodeLookup;
|
||||
},
|
||||
// Destroy all nodes on setting new data
|
||||
setData: function () {
|
||||
if (this.nodes) {
|
||||
this.nodes.forEach(function (node) {
|
||||
node.destroy();
|
||||
});
|
||||
this.nodes.length = 0;
|
||||
}
|
||||
H.Series.prototype.setData.apply(this, arguments);
|
||||
},
|
||||
// Destroy alll nodes and links
|
||||
destroy: function () {
|
||||
// Nodes must also be destroyed (#8682, #9300)
|
||||
this.data = []
|
||||
.concat(this.points || [], this.nodes);
|
||||
return H.Series.prototype.destroy.apply(this, arguments);
|
||||
},
|
||||
/**
|
||||
* When hovering node, highlight all connected links. When hovering a link,
|
||||
* highlight all connected nodes.
|
||||
*/
|
||||
setNodeState: function (state) {
|
||||
var args = arguments, others = this.isNode ? this.linksTo.concat(this.linksFrom) :
|
||||
[this.fromNode, this.toNode];
|
||||
if (state !== 'select') {
|
||||
others.forEach(function (linkOrNode) {
|
||||
if (linkOrNode && linkOrNode.series) {
|
||||
Point.prototype.setState.apply(linkOrNode, args);
|
||||
if (!linkOrNode.isNode) {
|
||||
if (linkOrNode.fromNode.graphic) {
|
||||
Point.prototype.setState.apply(linkOrNode.fromNode, args);
|
||||
}
|
||||
if (linkOrNode.toNode && linkOrNode.toNode.graphic) {
|
||||
Point.prototype.setState.apply(linkOrNode.toNode, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
Point.prototype.setState.apply(this, args);
|
||||
}
|
||||
/* eslint-enable valid-jsdoc */
|
||||
};
|
||||
export default NodesMixin;
|
||||
@@ -0,0 +1,135 @@
|
||||
/* *
|
||||
*
|
||||
* (c) 2010-2020 Torstein Honsi
|
||||
*
|
||||
* License: www.highcharts.com/license
|
||||
*
|
||||
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
|
||||
*
|
||||
* */
|
||||
'use strict';
|
||||
import H from '../Core/Globals.js';
|
||||
import U from '../Core/Utilities.js';
|
||||
var defined = U.defined, stableSort = U.stableSort;
|
||||
import '../Core/Series/Series.js';
|
||||
var seriesTypes = H.seriesTypes;
|
||||
/**
|
||||
* @private
|
||||
* @mixin onSeriesMixin
|
||||
*/
|
||||
var onSeriesMixin = {
|
||||
/* eslint-disable valid-jsdoc */
|
||||
/**
|
||||
* Override getPlotBox. If the onSeries option is valid, return the plot box
|
||||
* of the onSeries, otherwise proceed as usual.
|
||||
*
|
||||
* @private
|
||||
* @function onSeriesMixin.getPlotBox
|
||||
* @return {Highcharts.SeriesPlotBoxObject}
|
||||
*/
|
||||
getPlotBox: function () {
|
||||
return H.Series.prototype.getPlotBox.call((this.options.onSeries &&
|
||||
this.chart.get(this.options.onSeries)) || this);
|
||||
},
|
||||
/**
|
||||
* Extend the translate method by placing the point on the related series
|
||||
*
|
||||
* @private
|
||||
* @function onSeriesMixin.translate
|
||||
* @return {void}
|
||||
*/
|
||||
translate: function () {
|
||||
seriesTypes.column.prototype.translate.apply(this);
|
||||
var series = this, options = series.options, chart = series.chart, points = series.points, cursor = points.length - 1, point, lastPoint, optionsOnSeries = options.onSeries, onSeries = (optionsOnSeries &&
|
||||
chart.get(optionsOnSeries)), onKey = options.onKey || 'y', step = onSeries && onSeries.options.step, onData = (onSeries && onSeries.points), i = onData && onData.length, inverted = chart.inverted, xAxis = series.xAxis, yAxis = series.yAxis, xOffset = 0, leftPoint, lastX, rightPoint, currentDataGrouping, distanceRatio;
|
||||
// relate to a master series
|
||||
if (onSeries && onSeries.visible && i) {
|
||||
xOffset = (onSeries.pointXOffset || 0) + (onSeries.barW || 0) / 2;
|
||||
currentDataGrouping = onSeries.currentDataGrouping;
|
||||
lastX = (onData[i - 1].x +
|
||||
(currentDataGrouping ? currentDataGrouping.totalRange : 0)); // #2374
|
||||
// sort the data points
|
||||
stableSort(points, function (a, b) {
|
||||
return (a.x - b.x);
|
||||
});
|
||||
onKey = 'plot' + onKey[0].toUpperCase() + onKey.substr(1);
|
||||
while (i-- && points[cursor]) {
|
||||
leftPoint = onData[i];
|
||||
point = points[cursor];
|
||||
point.y = leftPoint.y;
|
||||
if (leftPoint.x <= point.x &&
|
||||
typeof leftPoint[onKey] !== 'undefined') {
|
||||
if (point.x <= lastX) { // #803
|
||||
point.plotY = leftPoint[onKey];
|
||||
// interpolate between points, #666
|
||||
if (leftPoint.x < point.x &&
|
||||
!step) {
|
||||
rightPoint = onData[i + 1];
|
||||
if (rightPoint &&
|
||||
typeof rightPoint[onKey] !== 'undefined') {
|
||||
// the distance ratio, between 0 and 1
|
||||
distanceRatio =
|
||||
(point.x - leftPoint.x) /
|
||||
(rightPoint.x - leftPoint.x);
|
||||
point.plotY +=
|
||||
distanceRatio *
|
||||
// the plotY distance
|
||||
(rightPoint[onKey] - leftPoint[onKey]);
|
||||
point.y +=
|
||||
distanceRatio *
|
||||
(rightPoint.y - leftPoint.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
cursor--;
|
||||
i++; // check again for points in the same x position
|
||||
if (cursor < 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Add plotY position and handle stacking
|
||||
points.forEach(function (point, i) {
|
||||
var stackIndex;
|
||||
point.plotX += xOffset; // #2049
|
||||
// Undefined plotY means the point is either on axis, outside series
|
||||
// range or hidden series. If the series is outside the range of the
|
||||
// x axis it should fall through with an undefined plotY, but then
|
||||
// we must remove the shapeArgs (#847). For inverted charts, we need
|
||||
// to calculate position anyway, because series.invertGroups is not
|
||||
// defined
|
||||
if (typeof point.plotY === 'undefined' || inverted) {
|
||||
if (point.plotX >= 0 &&
|
||||
point.plotX <= xAxis.len) {
|
||||
// We're inside xAxis range
|
||||
if (inverted) {
|
||||
point.plotY = xAxis.translate(point.x, 0, 1, 0, 1);
|
||||
point.plotX = defined(point.y) ?
|
||||
yAxis.translate(point.y, 0, 0, 0, 1) :
|
||||
0;
|
||||
}
|
||||
else {
|
||||
point.plotY = (xAxis.opposite ? 0 : series.yAxis.len) +
|
||||
xAxis.offset; // For the windbarb demo
|
||||
}
|
||||
}
|
||||
else {
|
||||
point.shapeArgs = {}; // 847
|
||||
}
|
||||
}
|
||||
// if multiple flags appear at the same x, order them into a stack
|
||||
lastPoint = points[i - 1];
|
||||
if (lastPoint && lastPoint.plotX === point.plotX) {
|
||||
if (typeof lastPoint.stackIndex === 'undefined') {
|
||||
lastPoint.stackIndex = 0;
|
||||
}
|
||||
stackIndex = lastPoint.stackIndex + 1;
|
||||
}
|
||||
point.stackIndex = stackIndex; // #3639
|
||||
});
|
||||
this.onSeries = onSeries;
|
||||
}
|
||||
/* eslint-enable valid-jsdoc */
|
||||
};
|
||||
export default onSeriesMixin;
|
||||
@@ -0,0 +1,259 @@
|
||||
/* *
|
||||
*
|
||||
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
|
||||
*
|
||||
* */
|
||||
import H from '../Core/Globals.js';
|
||||
/**
|
||||
* @private
|
||||
* @interface Highcharts.PolygonPointObject
|
||||
*/ /**
|
||||
* @name Highcharts.PolygonPointObject#0
|
||||
* @type {number}
|
||||
*/ /**
|
||||
* @name Highcharts.PolygonPointObject#1
|
||||
* @type {number}
|
||||
*/
|
||||
/**
|
||||
* @private
|
||||
* @interface Highcharts.PolygonObject
|
||||
* @extends Array<Highcharts.PolygonPointObject>
|
||||
*/ /**
|
||||
* @name Highcharts.PolygonObject#axes
|
||||
* @type {Array<PolygonPointObject>}
|
||||
*/
|
||||
import U from '../Core/Utilities.js';
|
||||
var find = U.find, isArray = U.isArray, isNumber = U.isNumber;
|
||||
var deg2rad = H.deg2rad;
|
||||
/* eslint-disable no-invalid-this, valid-jsdoc */
|
||||
/**
|
||||
* Alternative solution to correctFloat.
|
||||
* E.g Highcharts.correctFloat(123, 2) returns 120, when it should be 123.
|
||||
*
|
||||
* @private
|
||||
* @function correctFloat
|
||||
* @param {number} number
|
||||
* @param {number} [precision]
|
||||
* @return {number}
|
||||
*/
|
||||
var correctFloat = function (number, precision) {
|
||||
var p = isNumber(precision) ? precision : 14, magnitude = Math.pow(10, p);
|
||||
return Math.round(number * magnitude) / magnitude;
|
||||
};
|
||||
/**
|
||||
* Calculates the normals to a line between two points.
|
||||
*
|
||||
* @private
|
||||
* @function getNormals
|
||||
* @param {Highcharts.PolygonPointObject} p1
|
||||
* Start point for the line. Array of x and y value.
|
||||
* @param {Highcharts.PolygonPointObject} p2
|
||||
* End point for the line. Array of x and y value.
|
||||
* @return {Highcharts.PolygonObject}
|
||||
* Returns the two normals in an array.
|
||||
*/
|
||||
var getNormals = function getNormal(p1, p2) {
|
||||
var dx = p2[0] - p1[0], // x2 - x1
|
||||
dy = p2[1] - p1[1]; // y2 - y1
|
||||
return [
|
||||
[-dy, dx],
|
||||
[dy, -dx]
|
||||
];
|
||||
};
|
||||
/**
|
||||
* Calculates the dot product of two coordinates. The result is a scalar value.
|
||||
*
|
||||
* @private
|
||||
* @function dotProduct
|
||||
* @param {Highcharts.PolygonPointObject} a
|
||||
* The x and y coordinates of the first point.
|
||||
*
|
||||
* @param {Highcharts.PolygonPointObject} b
|
||||
* The x and y coordinates of the second point.
|
||||
*
|
||||
* @return {number}
|
||||
* Returns the dot product of a and b.
|
||||
*/
|
||||
var dotProduct = function dotProduct(a, b) {
|
||||
var ax = a[0], ay = a[1], bx = b[0], by = b[1];
|
||||
return ax * bx + ay * by;
|
||||
};
|
||||
/**
|
||||
* Projects a polygon onto a coordinate.
|
||||
*
|
||||
* @private
|
||||
* @function project
|
||||
* @param {Highcharts.PolygonObject} polygon
|
||||
* Array of points in a polygon.
|
||||
* @param {Highcharts.PolygonPointObject} target
|
||||
* The coordinate of pr
|
||||
* @return {Highcharts.RangeObject}
|
||||
*/
|
||||
var project = function project(polygon, target) {
|
||||
var products = polygon.map(function (point) {
|
||||
return dotProduct(point, target);
|
||||
});
|
||||
return {
|
||||
min: Math.min.apply(this, products),
|
||||
max: Math.max.apply(this, products)
|
||||
};
|
||||
};
|
||||
/**
|
||||
* Rotates a point clockwise around the origin.
|
||||
*
|
||||
* @private
|
||||
* @function rotate2DToOrigin
|
||||
* @param {Highcharts.PolygonPointObject} point
|
||||
* The x and y coordinates for the point.
|
||||
* @param {number} angle
|
||||
* The angle of rotation.
|
||||
* @return {Highcharts.PolygonPointObject}
|
||||
* The x and y coordinate for the rotated point.
|
||||
*/
|
||||
var rotate2DToOrigin = function (point, angle) {
|
||||
var x = point[0], y = point[1], rad = deg2rad * -angle, cosAngle = Math.cos(rad), sinAngle = Math.sin(rad);
|
||||
return [
|
||||
correctFloat(x * cosAngle - y * sinAngle),
|
||||
correctFloat(x * sinAngle + y * cosAngle)
|
||||
];
|
||||
};
|
||||
/**
|
||||
* Rotate a point clockwise around another point.
|
||||
*
|
||||
* @private
|
||||
* @function rotate2DToPoint
|
||||
* @param {Highcharts.PolygonPointObject} point
|
||||
* The x and y coordinates for the point.
|
||||
* @param {Highcharts.PolygonPointObject} origin
|
||||
* The point to rotate around.
|
||||
* @param {number} angle
|
||||
* The angle of rotation.
|
||||
* @return {Highcharts.PolygonPointObject}
|
||||
* The x and y coordinate for the rotated point.
|
||||
*/
|
||||
var rotate2DToPoint = function (point, origin, angle) {
|
||||
var x = point[0] - origin[0], y = point[1] - origin[1], rotated = rotate2DToOrigin([x, y], angle);
|
||||
return [
|
||||
rotated[0] + origin[0],
|
||||
rotated[1] + origin[1]
|
||||
];
|
||||
};
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
var isAxesEqual = function (axis1, axis2) {
|
||||
return (axis1[0] === axis2[0] &&
|
||||
axis1[1] === axis2[1]);
|
||||
};
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
var getAxesFromPolygon = function (polygon) {
|
||||
var points, axes = polygon.axes;
|
||||
if (!isArray(axes)) {
|
||||
axes = [];
|
||||
points = points = polygon.concat([polygon[0]]);
|
||||
points.reduce(function findAxis(p1, p2) {
|
||||
var normals = getNormals(p1, p2), axis = normals[0]; // Use the left normal as axis.
|
||||
// Check that the axis is unique.
|
||||
if (!find(axes, function (existing) {
|
||||
return isAxesEqual(existing, axis);
|
||||
})) {
|
||||
axes.push(axis);
|
||||
}
|
||||
// Return p2 to be used as p1 in next iteration.
|
||||
return p2;
|
||||
});
|
||||
polygon.axes = axes;
|
||||
}
|
||||
return axes;
|
||||
};
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
var getAxes = function (polygon1, polygon2) {
|
||||
// Get the axis from both polygons.
|
||||
var axes1 = getAxesFromPolygon(polygon1), axes2 = getAxesFromPolygon(polygon2);
|
||||
return axes1.concat(axes2);
|
||||
};
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
var getPolygon = function (x, y, width, height, rotation) {
|
||||
var origin = [x, y], left = x - (width / 2), right = x + (width / 2), top = y - (height / 2), bottom = y + (height / 2), polygon = [
|
||||
[left, top],
|
||||
[right, top],
|
||||
[right, bottom],
|
||||
[left, bottom]
|
||||
];
|
||||
return polygon.map(function (point) {
|
||||
return rotate2DToPoint(point, origin, -rotation);
|
||||
});
|
||||
};
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
var getBoundingBoxFromPolygon = function (points) {
|
||||
return points.reduce(function (obj, point) {
|
||||
var x = point[0], y = point[1];
|
||||
obj.left = Math.min(x, obj.left);
|
||||
obj.right = Math.max(x, obj.right);
|
||||
obj.bottom = Math.max(y, obj.bottom);
|
||||
obj.top = Math.min(y, obj.top);
|
||||
return obj;
|
||||
}, {
|
||||
left: Number.MAX_VALUE,
|
||||
right: -Number.MAX_VALUE,
|
||||
bottom: -Number.MAX_VALUE,
|
||||
top: Number.MAX_VALUE
|
||||
});
|
||||
};
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
var isPolygonsOverlappingOnAxis = function (axis, polygon1, polygon2) {
|
||||
var projection1 = project(polygon1, axis), projection2 = project(polygon2, axis), isOverlapping = !(projection2.min > projection1.max ||
|
||||
projection2.max < projection1.min);
|
||||
return !isOverlapping;
|
||||
};
|
||||
/**
|
||||
* Checks wether two convex polygons are colliding by using the Separating Axis
|
||||
* Theorem.
|
||||
*
|
||||
* @private
|
||||
* @function isPolygonsColliding
|
||||
* @param {Highcharts.PolygonObject} polygon1
|
||||
* First polygon.
|
||||
*
|
||||
* @param {Highcharts.PolygonObject} polygon2
|
||||
* Second polygon.
|
||||
*
|
||||
* @return {boolean}
|
||||
* Returns true if they are colliding, otherwise false.
|
||||
*/
|
||||
var isPolygonsColliding = function isPolygonsColliding(polygon1, polygon2) {
|
||||
var axes = getAxes(polygon1, polygon2), overlappingOnAllAxes = !find(axes, function (axis) {
|
||||
return isPolygonsOverlappingOnAxis(axis, polygon1, polygon2);
|
||||
});
|
||||
return overlappingOnAllAxes;
|
||||
};
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
var movePolygon = function (deltaX, deltaY, polygon) {
|
||||
return polygon.map(function (point) {
|
||||
return [
|
||||
point[0] + deltaX,
|
||||
point[1] + deltaY
|
||||
];
|
||||
});
|
||||
};
|
||||
var collision = {
|
||||
getBoundingBoxFromPolygon: getBoundingBoxFromPolygon,
|
||||
getPolygon: getPolygon,
|
||||
isPolygonsColliding: isPolygonsColliding,
|
||||
movePolygon: movePolygon,
|
||||
rotate2DToOrigin: rotate2DToOrigin,
|
||||
rotate2DToPoint: rotate2DToPoint
|
||||
};
|
||||
export default collision;
|
||||
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
*
|
||||
* (c) 2010-2020 Pawel Fus & Daniel Studencki
|
||||
*
|
||||
* License: www.highcharts.com/license
|
||||
*
|
||||
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
|
||||
*
|
||||
* */
|
||||
'use strict';
|
||||
import '../Core/Utilities.js';
|
||||
var reduceArrayMixin = {
|
||||
/**
|
||||
* Get min value of array filled by OHLC data.
|
||||
* @private
|
||||
* @param {Array<*>} arr Array of OHLC points (arrays).
|
||||
* @param {string} index Index of "low" value in point array.
|
||||
* @return {number} Returns min value.
|
||||
*/
|
||||
minInArray: function (arr, index) {
|
||||
return arr.reduce(function (min, target) {
|
||||
return Math.min(min, target[index]);
|
||||
}, Number.MAX_VALUE);
|
||||
},
|
||||
/**
|
||||
* Get max value of array filled by OHLC data.
|
||||
* @private
|
||||
* @param {Array<*>} arr Array of OHLC points (arrays).
|
||||
* @param {string} index Index of "high" value in point array.
|
||||
* @return {number} Returns max value.
|
||||
*/
|
||||
maxInArray: function (arr, index) {
|
||||
return arr.reduce(function (max, target) {
|
||||
return Math.max(max, target[index]);
|
||||
}, -Number.MAX_VALUE);
|
||||
},
|
||||
/**
|
||||
* Get extremes of array filled by OHLC data.
|
||||
* @private
|
||||
* @param {Array<*>} arr Array of OHLC points (arrays).
|
||||
* @param {string} minIndex Index of "low" value in point array.
|
||||
* @param {string} maxIndex Index of "high" value in point array.
|
||||
* @return {Array<number,number>} Returns array with min and max value.
|
||||
*/
|
||||
getArrayExtremes: function (arr, minIndex, maxIndex) {
|
||||
return arr.reduce(function (prev, target) {
|
||||
return [
|
||||
Math.min(prev[0], target[minIndex]),
|
||||
Math.max(prev[1], target[maxIndex])
|
||||
];
|
||||
}, [Number.MAX_VALUE, -Number.MAX_VALUE]);
|
||||
}
|
||||
};
|
||||
export default reduceArrayMixin;
|
||||
@@ -0,0 +1,185 @@
|
||||
/* *
|
||||
*
|
||||
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
|
||||
*
|
||||
* */
|
||||
import Color from '../Core/Color.js';
|
||||
import U from '../Core/Utilities.js';
|
||||
var extend = U.extend, isArray = U.isArray, isNumber = U.isNumber, isObject = U.isObject, merge = U.merge, pick = U.pick;
|
||||
var isBoolean = function (x) {
|
||||
return typeof x === 'boolean';
|
||||
}, isFn = function (x) {
|
||||
return typeof x === 'function';
|
||||
};
|
||||
/* eslint-disable valid-jsdoc */
|
||||
/**
|
||||
* @todo Combine buildTree and buildNode with setTreeValues
|
||||
* @todo Remove logic from Treemap and make it utilize this mixin.
|
||||
* @private
|
||||
*/
|
||||
var setTreeValues = function setTreeValues(tree, options) {
|
||||
var before = options.before, idRoot = options.idRoot, mapIdToNode = options.mapIdToNode, nodeRoot = mapIdToNode[idRoot], levelIsConstant = (isBoolean(options.levelIsConstant) ?
|
||||
options.levelIsConstant :
|
||||
true), points = options.points, point = points[tree.i], optionsPoint = point && point.options || {}, childrenTotal = 0, children = [], value;
|
||||
extend(tree, {
|
||||
levelDynamic: tree.level - (levelIsConstant ? 0 : nodeRoot.level),
|
||||
name: pick(point && point.name, ''),
|
||||
visible: (idRoot === tree.id ||
|
||||
(isBoolean(options.visible) ? options.visible : false))
|
||||
});
|
||||
if (isFn(before)) {
|
||||
tree = before(tree, options);
|
||||
}
|
||||
// First give the children some values
|
||||
tree.children.forEach(function (child, i) {
|
||||
var newOptions = extend({}, options);
|
||||
extend(newOptions, {
|
||||
index: i,
|
||||
siblings: tree.children.length,
|
||||
visible: tree.visible
|
||||
});
|
||||
child = setTreeValues(child, newOptions);
|
||||
children.push(child);
|
||||
if (child.visible) {
|
||||
childrenTotal += child.val;
|
||||
}
|
||||
});
|
||||
tree.visible = childrenTotal > 0 || tree.visible;
|
||||
// Set the values
|
||||
value = pick(optionsPoint.value, childrenTotal);
|
||||
extend(tree, {
|
||||
children: children,
|
||||
childrenTotal: childrenTotal,
|
||||
isLeaf: tree.visible && !childrenTotal,
|
||||
val: value
|
||||
});
|
||||
return tree;
|
||||
};
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
var getColor = function getColor(node, options) {
|
||||
var index = options.index, mapOptionsToLevel = options.mapOptionsToLevel, parentColor = options.parentColor, parentColorIndex = options.parentColorIndex, series = options.series, colors = options.colors, siblings = options.siblings, points = series.points, getColorByPoint, chartOptionsChart = series.chart.options.chart, point, level, colorByPoint, colorIndexByPoint, color, colorIndex;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
function variation(color) {
|
||||
var colorVariation = level && level.colorVariation;
|
||||
if (colorVariation) {
|
||||
if (colorVariation.key === 'brightness') {
|
||||
return Color.parse(color).brighten(colorVariation.to * (index / siblings)).get();
|
||||
}
|
||||
}
|
||||
return color;
|
||||
}
|
||||
if (node) {
|
||||
point = points[node.i];
|
||||
level = mapOptionsToLevel[node.level] || {};
|
||||
getColorByPoint = point && level.colorByPoint;
|
||||
if (getColorByPoint) {
|
||||
colorIndexByPoint = point.index % (colors ?
|
||||
colors.length :
|
||||
chartOptionsChart.colorCount);
|
||||
colorByPoint = colors && colors[colorIndexByPoint];
|
||||
}
|
||||
// Select either point color, level color or inherited color.
|
||||
if (!series.chart.styledMode) {
|
||||
color = pick(point && point.options.color, level && level.color, colorByPoint, parentColor && variation(parentColor), series.color);
|
||||
}
|
||||
colorIndex = pick(point && point.options.colorIndex, level && level.colorIndex, colorIndexByPoint, parentColorIndex, options.colorIndex);
|
||||
}
|
||||
return {
|
||||
color: color,
|
||||
colorIndex: colorIndex
|
||||
};
|
||||
};
|
||||
/**
|
||||
* Creates a map from level number to its given options.
|
||||
*
|
||||
* @private
|
||||
* @function getLevelOptions
|
||||
* @param {object} params
|
||||
* Object containing parameters.
|
||||
* - `defaults` Object containing default options. The default options
|
||||
* are merged with the userOptions to get the final options for a
|
||||
* specific level.
|
||||
* - `from` The lowest level number.
|
||||
* - `levels` User options from series.levels.
|
||||
* - `to` The highest level number.
|
||||
* @return {Highcharts.Dictionary<object>|null}
|
||||
* Returns a map from level number to its given options.
|
||||
*/
|
||||
var getLevelOptions = function getLevelOptions(params) {
|
||||
var result = null, defaults, converted, i, from, to, levels;
|
||||
if (isObject(params)) {
|
||||
result = {};
|
||||
from = isNumber(params.from) ? params.from : 1;
|
||||
levels = params.levels;
|
||||
converted = {};
|
||||
defaults = isObject(params.defaults) ? params.defaults : {};
|
||||
if (isArray(levels)) {
|
||||
converted = levels.reduce(function (obj, item) {
|
||||
var level, levelIsConstant, options;
|
||||
if (isObject(item) && isNumber(item.level)) {
|
||||
options = merge({}, item);
|
||||
levelIsConstant = (isBoolean(options.levelIsConstant) ?
|
||||
options.levelIsConstant :
|
||||
defaults.levelIsConstant);
|
||||
// Delete redundant properties.
|
||||
delete options.levelIsConstant;
|
||||
delete options.level;
|
||||
// Calculate which level these options apply to.
|
||||
level = item.level + (levelIsConstant ? 0 : from - 1);
|
||||
if (isObject(obj[level])) {
|
||||
extend(obj[level], options);
|
||||
}
|
||||
else {
|
||||
obj[level] = options;
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}, {});
|
||||
}
|
||||
to = isNumber(params.to) ? params.to : 1;
|
||||
for (i = 0; i <= to; i++) {
|
||||
result[i] = merge({}, defaults, isObject(converted[i]) ? converted[i] : {});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
/**
|
||||
* Update the rootId property on the series. Also makes sure that it is
|
||||
* accessible to exporting.
|
||||
*
|
||||
* @private
|
||||
* @function updateRootId
|
||||
*
|
||||
* @param {object} series
|
||||
* The series to operate on.
|
||||
*
|
||||
* @return {string}
|
||||
* Returns the resulting rootId after update.
|
||||
*/
|
||||
var updateRootId = function (series) {
|
||||
var rootId, options;
|
||||
if (isObject(series)) {
|
||||
// Get the series options.
|
||||
options = isObject(series.options) ? series.options : {};
|
||||
// Calculate the rootId.
|
||||
rootId = pick(series.rootNode, options.rootId, '');
|
||||
// Set rootId on series.userOptions to pick it up in exporting.
|
||||
if (isObject(series.userOptions)) {
|
||||
series.userOptions.rootId = rootId;
|
||||
}
|
||||
// Set rootId on series to pick it up on next update.
|
||||
series.rootNode = rootId;
|
||||
}
|
||||
return rootId;
|
||||
};
|
||||
var result = {
|
||||
getColor: getColor,
|
||||
getLevelOptions: getLevelOptions,
|
||||
setTreeValues: setTreeValues,
|
||||
updateRootId: updateRootId
|
||||
};
|
||||
export default result;
|
||||
Reference in New Issue
Block a user