highcharts
Version:
JavaScript charting framework
1,093 lines (1,090 loc) • 513 kB
JavaScript
/**
* @license Highcharts JS v9.0.1 (2021-02-16)
*
* (c) 2009-2021 Torstein Honsi
*
* License: www.highcharts.com/license
*/
'use strict';
(function (factory) {
if (typeof module === 'object' && module.exports) {
factory['default'] = factory;
module.exports = factory;
} else if (typeof define === 'function' && define.amd) {
define('highcharts/highcharts-more', ['highcharts'], function (Highcharts) {
factory(Highcharts);
factory.Highcharts = Highcharts;
return factory;
});
} else {
factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
}
}(function (Highcharts) {
var _modules = Highcharts ? Highcharts._modules : {};
function _registerModule(obj, path, args, fn) {
if (!obj.hasOwnProperty(path)) {
obj[path] = fn.apply(null, args);
}
}
_registerModule(_modules, 'Extensions/Pane.js', [_modules['Core/Chart/Chart.js'], _modules['Core/Globals.js'], _modules['Core/Color/Palette.js'], _modules['Core/Pointer.js'], _modules['Core/Utilities.js'], _modules['Mixins/CenteredSeries.js']], function (Chart, H, palette, Pointer, U, centeredSeriesMixin) {
/* *
*
* (c) 2010-2021 Torstein Honsi
*
* License: www.highcharts.com/license
*
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
*
* */
var addEvent = U.addEvent,
extend = U.extend,
merge = U.merge,
pick = U.pick,
splat = U.splat;
/**
* @typedef {"arc"|"circle"|"solid"} Highcharts.PaneBackgroundShapeValue
*/
/* eslint-disable no-invalid-this, valid-jsdoc */
Chart.prototype.collectionsWithUpdate.push('pane');
/**
* The Pane object allows options that are common to a set of X and Y axes.
*
* In the future, this can be extended to basic Highcharts and Highstock.
*
* @private
* @class
* @name Highcharts.Pane
* @param {Highcharts.PaneOptions} options
* @param {Highcharts.Chart} chart
*/
var Pane = /** @class */ (function () {
function Pane(options, chart) {
this.background = void 0;
this.center = void 0;
this.chart = void 0;
this.options = void 0;
this.coll = 'pane'; // Member of chart.pane
/**
* The pane serves as a container for axes and backgrounds for circular
* gauges and polar charts.
*
* @since 2.3.0
* @product highcharts
* @requires highcharts-more
* @optionparent pane
*/
this.defaultOptions = {
/**
* The end angle of the polar X axis or gauge value axis, given in
* degrees where 0 is north. Defaults to [startAngle](#pane.startAngle)
* + 360.
*
* @sample {highcharts} highcharts/demo/gauge-vu-meter/
* VU-meter with custom start and end angle
*
* @type {number}
* @since 2.3.0
* @product highcharts
* @apioption pane.endAngle
*/
/**
* The center of a polar chart or angular gauge, given as an array
* of [x, y] positions. Positions can be given as integers that
* transform to pixels, or as percentages of the plot area size.
*
* @sample {highcharts} highcharts/demo/gauge-vu-meter/
* Two gauges with different center
*
* @type {Array<string|number>}
* @default ["50%", "50%"]
* @since 2.3.0
* @product highcharts
*/
center: ['50%', '50%'],
/**
* The size of the pane, either as a number defining pixels, or a
* percentage defining a percentage of the available plot area (the
* smallest of the plot height or plot width).
*
* @sample {highcharts} highcharts/demo/gauge-vu-meter/
* Smaller size
*
* @type {number|string}
* @product highcharts
*/
size: '85%',
/**
* The inner size of the pane, either as a number defining pixels, or a
* percentage defining a percentage of the pane's size.
*
* @sample {highcharts} highcharts/series-polar/column-inverted-inner
* The inner size set to 20%
*
* @type {number|string}
* @product highcharts
*/
innerSize: '0%',
/**
* The start angle of the polar X axis or gauge axis, given in degrees
* where 0 is north. Defaults to 0.
*
* @sample {highcharts} highcharts/demo/gauge-vu-meter/
* VU-meter with custom start and end angle
*
* @since 2.3.0
* @product highcharts
*/
startAngle: 0
};
/**
* An array of background items for the pane.
*
* @sample {highcharts} highcharts/demo/gauge-speedometer/
* Speedometer gauge with multiple backgrounds
*
* @type {Array<*>}
* @optionparent pane.background
*/
this.defaultBackgroundOptions = {
/**
* The class name for this background.
*
* @sample {highcharts} highcharts/css/pane/
* Panes styled by CSS
* @sample {highstock} highcharts/css/pane/
* Panes styled by CSS
* @sample {highmaps} highcharts/css/pane/
* Panes styled by CSS
*
* @type {string}
* @default highcharts-pane
* @since 5.0.0
* @apioption pane.background.className
*/
/**
* The shape of the pane background. When `solid`, the background
* is circular. When `arc`, the background extends only from the min
* to the max of the value axis.
*
* @type {Highcharts.PaneBackgroundShapeValue}
* @since 2.3.0
* @product highcharts
*/
shape: 'circle',
/**
* The pixel border width of the pane background.
*
* @since 2.3.0
* @product highcharts
*/
borderWidth: 1,
/**
* The pane background border color.
*
* @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
* @since 2.3.0
* @product highcharts
*/
borderColor: palette.neutralColor20,
/**
* The background color or gradient for the pane.
*
* @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
* @default { linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, stops: [[0, #ffffff], [1, #e6e6e6]] }
* @since 2.3.0
* @product highcharts
*/
backgroundColor: {
/** @ignore-option */
linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
/** @ignore-option */
stops: [
[0, palette.backgroundColor],
[1, palette.neutralColor10]
]
},
/** @ignore-option */
from: -Number.MAX_VALUE,
/**
* The inner radius of the pane background. Can be either numeric
* (pixels) or a percentage string.
*
* @type {number|string}
* @since 2.3.0
* @product highcharts
*/
innerRadius: 0,
/** @ignore-option */
to: Number.MAX_VALUE,
/**
* The outer radius of the circular pane background. Can be either
* numeric (pixels) or a percentage string.
*
* @type {number|string}
* @since 2.3.0
* @product highcharts
*/
outerRadius: '105%'
};
this.init(options, chart);
}
/**
* Initialize the Pane object
*
* @private
* @function Highcharts.Pane#init
*
* @param {Highcharts.PaneOptions} options
*
* @param {Highcharts.Chart} chart
*/
Pane.prototype.init = function (options, chart) {
this.chart = chart;
this.background = [];
chart.pane.push(this);
this.setOptions(options);
};
/**
* @private
* @function Highcharts.Pane#setOptions
*
* @param {Highcharts.PaneOptions} options
*/
Pane.prototype.setOptions = function (options) {
// Set options. Angular charts have a default background (#3318)
this.options = options = merge(this.defaultOptions, this.chart.angular ? { background: {} } : void 0, options);
};
/**
* Render the pane with its backgrounds.
*
* @private
* @function Highcharts.Pane#render
*/
Pane.prototype.render = function () {
var options = this.options,
backgroundOption = this.options.background,
renderer = this.chart.renderer,
len,
i;
if (!this.group) {
this.group = renderer.g('pane-group')
.attr({ zIndex: options.zIndex || 0 })
.add();
}
this.updateCenter();
// Render the backgrounds
if (backgroundOption) {
backgroundOption = splat(backgroundOption);
len = Math.max(backgroundOption.length, this.background.length || 0);
for (i = 0; i < len; i++) {
// #6641 - if axis exists, chart is circular and apply
// background
if (backgroundOption[i] && this.axis) {
this.renderBackground(merge(this.defaultBackgroundOptions, backgroundOption[i]), i);
}
else if (this.background[i]) {
this.background[i] = this.background[i].destroy();
this.background.splice(i, 1);
}
}
}
};
/**
* Render an individual pane background.
*
* @private
* @function Highcharts.Pane#renderBackground
*
* @param {Highcharts.PaneBackgroundOptions} backgroundOptions
* Background options
*
* @param {number} i
* The index of the background in this.backgrounds
*/
Pane.prototype.renderBackground = function (backgroundOptions, i) {
var method = 'animate',
attribs = {
'class': 'highcharts-pane ' + (backgroundOptions.className || '')
};
if (!this.chart.styledMode) {
extend(attribs, {
'fill': backgroundOptions.backgroundColor,
'stroke': backgroundOptions.borderColor,
'stroke-width': backgroundOptions.borderWidth
});
}
if (!this.background[i]) {
this.background[i] = this.chart.renderer
.path()
.add(this.group);
method = 'attr';
}
this.background[i][method]({
'd': this.axis.getPlotBandPath(backgroundOptions.from, backgroundOptions.to, backgroundOptions)
}).attr(attribs);
};
/**
* Gets the center for the pane and its axis.
*
* @private
* @function Highcharts.Pane#updateCenter
* @param {Highcharts.Axis} [axis]
* @return {void}
*/
Pane.prototype.updateCenter = function (axis) {
this.center = (axis ||
this.axis ||
{}).center = centeredSeriesMixin.getCenter.call(this);
};
/**
* Destroy the pane item
*
* @ignore
* @private
* @function Highcharts.Pane#destroy
* /
destroy: function () {
erase(this.chart.pane, this);
this.background.forEach(function (background) {
background.destroy();
});
this.background.length = 0;
this.group = this.group.destroy();
},
*/
/**
* Update the pane item with new options
*
* @private
* @function Highcharts.Pane#update
* @param {Highcharts.PaneOptions} options
* New pane options
* @param {boolean} [redraw]
* @return {void}
*/
Pane.prototype.update = function (options, redraw) {
merge(true, this.options, options);
merge(true, this.chart.options.pane, options); // #9917
this.setOptions(this.options);
this.render();
this.chart.axes.forEach(function (axis) {
if (axis.pane === this) {
axis.pane = null;
axis.update({}, redraw);
}
}, this);
};
return Pane;
}());
/**
* Check whether element is inside or outside pane.
* @private
* @param {number} x Element's x coordinate
* @param {number} y Element's y coordinate
* @param {Array<number>} center Pane's center (x, y) and diameter
* @return {boolean}
*/
function isInsidePane(x, y, center) {
return Math.sqrt(Math.pow(x - center[0], 2) + Math.pow(y - center[1], 2)) <= center[2] / 2;
}
Chart.prototype.getHoverPane = function (eventArgs) {
var chart = this;
var hoverPane;
if (eventArgs) {
chart.pane.forEach(function (pane) {
var plotX = eventArgs.chartX - chart.plotLeft,
plotY = eventArgs.chartY - chart.plotTop,
x = chart.inverted ? plotY : plotX,
y = chart.inverted ? plotX : plotY;
if (isInsidePane(x, y, pane.center)) {
hoverPane = pane;
}
});
}
return hoverPane;
};
addEvent(Chart, 'afterIsInsidePlot', function (e) {
var chart = this;
if (chart.polar) {
e.isInsidePlot = chart.pane.some(function (pane) { return isInsidePane(e.x, e.y, pane.center); });
}
});
addEvent(Pointer, 'beforeGetHoverData', function (eventArgs) {
var chart = this.chart;
if (chart.polar) {
// Find pane we are currently hovering over.
chart.hoverPane = chart.getHoverPane(eventArgs);
// Edit filter method to handle polar
eventArgs.filter = function (s) {
return (s.visible &&
!(!eventArgs.shared && s.directTouch) && // #3821
pick(s.options.enableMouseTracking, true) &&
(!chart.hoverPane || s.xAxis.pane === chart.hoverPane));
};
}
else {
chart.hoverPane = void 0;
}
});
addEvent(Pointer, 'afterGetHoverData', function (eventArgs) {
var chart = this.chart;
if (eventArgs.hoverPoint &&
eventArgs.hoverPoint.plotX &&
eventArgs.hoverPoint.plotY &&
chart.hoverPane &&
!isInsidePane(eventArgs.hoverPoint.plotX, eventArgs.hoverPoint.plotY, chart.hoverPane.center)) {
eventArgs.hoverPoint = void 0;
}
});
H.Pane = Pane;
return H.Pane;
});
_registerModule(_modules, 'Core/Axis/HiddenAxis.js', [], function () {
/* *
*
* (c) 2010-2021 Torstein Honsi
*
* License: www.highcharts.com/license
*
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
*
* */
/**
* @private
* @class
*/
var HiddenAxis = /** @class */ (function () {
function HiddenAxis() {
}
/**
* Augments methods for the x axis in order to hide it completely. Used for
* the X axis in gauges
*
* @private
*
* @param {Highcharts.Axis} axis
* Radial axis to augment.
*/
HiddenAxis.init = function (axis) {
axis.getOffset = function () { };
axis.redraw = function () {
this.isDirty = false; // prevent setting Y axis dirty
};
axis.render = function () {
this.isDirty = false; // prevent setting Y axis dirty
};
axis.createLabelCollector = function () {
return function () {
return;
};
};
axis.setScale = function () { };
axis.setCategories = function () { };
axis.setTitle = function () { };
axis.isHidden = true;
};
return HiddenAxis;
}());
return HiddenAxis;
});
_registerModule(_modules, 'Core/Axis/RadialAxis.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Axis/Tick.js'], _modules['Core/Axis/HiddenAxis.js'], _modules['Core/Utilities.js']], function (Axis, Tick, HiddenAxis, U) {
/* *
*
* (c) 2010-2021 Torstein Honsi
*
* License: www.highcharts.com/license
*
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
*
* */
var addEvent = U.addEvent,
correctFloat = U.correctFloat,
defined = U.defined,
extend = U.extend,
fireEvent = U.fireEvent,
isNumber = U.isNumber,
merge = U.merge,
pick = U.pick,
pInt = U.pInt,
relativeLength = U.relativeLength,
wrap = U.wrap;
/**
* @private
* @class
*/
var RadialAxis = /** @class */ (function () {
function RadialAxis() {
}
/* *
*
* Static Functions
*
* */
RadialAxis.init = function (axis) {
var axisProto = Axis.prototype;
// Merge and set options.
axis.setOptions = function (userOptions) {
var options = this.options = merge(axis.constructor.defaultOptions,
this.defaultPolarOptions,
userOptions);
// Make sure the plotBands array is instanciated for each Axis
// (#2649)
if (!options.plotBands) {
options.plotBands = [];
}
fireEvent(this, 'afterSetOptions');
};
// Wrap the getOffset method to return zero offset for title or labels
// in a radial axis.
axis.getOffset = function () {
// Call the Axis prototype method (the method we're in now is on the
// instance)
axisProto.getOffset.call(this);
// Title or label offsets are not counted
this.chart.axisOffset[this.side] = 0;
};
/**
* Get the path for the axis line. This method is also referenced in the
* getPlotLinePath method.
*
* @private
*
* @param {number} _lineWidth
* Line width is not used.
*
* @param {number} [radius]
* Radius of radial path.
*
* @param {number} [innerRadius]
* Inner radius of radial path.
*
* @return {RadialAxisPath}
*/
axis.getLinePath = function (_lineWidth, radius, innerRadius) {
var center = this.pane.center,
end,
chart = this.chart,
r = pick(radius,
center[2] / 2 - this.offset),
left = this.left || 0,
top = this.top || 0,
path;
if (typeof innerRadius === 'undefined') {
innerRadius = this.horiz ? 0 : this.center && -this.center[3] / 2;
}
// In case when innerSize of pane is set, it must be included
if (innerRadius) {
r += innerRadius;
}
if (this.isCircular || typeof radius !== 'undefined') {
path = this.chart.renderer.symbols.arc(left + center[0], top + center[1], r, r, {
start: this.startAngleRad,
end: this.endAngleRad,
open: true,
innerR: 0
});
// Bounds used to position the plotLine label next to the line
// (#7117)
path.xBounds = [left + center[0]];
path.yBounds = [top + center[1] - r];
}
else {
end = this.postTranslate(this.angleRad, r);
path = [
['M', this.center[0] + chart.plotLeft, this.center[1] + chart.plotTop],
['L', end.x, end.y]
];
}
return path;
};
/**
* Override setAxisTranslation by setting the translation to the
* difference in rotation. This allows the translate method to return
* angle for any given value.
*
* @private
*/
axis.setAxisTranslation = function () {
// Call uber method
axisProto.setAxisTranslation.call(this);
// Set transA and minPixelPadding
if (this.center) { // it's not defined the first time
if (this.isCircular) {
this.transA = (this.endAngleRad - this.startAngleRad) /
((this.max - this.min) || 1);
}
else {
// The transA here is the length of the axis, so in case
// of inner radius, the length must be decreased by it
this.transA = ((this.center[2] - this.center[3]) / 2) /
((this.max - this.min) || 1);
}
if (this.isXAxis) {
this.minPixelPadding = this.transA * this.minPointOffset;
}
else {
// This is a workaround for regression #2593, but categories
// still don't position correctly.
this.minPixelPadding = 0;
}
}
};
/**
* In case of auto connect, add one closestPointRange to the max value
* right before tickPositions are computed, so that ticks will extend
* passed the real max.
* @private
*/
axis.beforeSetTickPositions = function () {
// If autoConnect is true, polygonal grid lines are connected, and
// one closestPointRange is added to the X axis to prevent the last
// point from overlapping the first.
this.autoConnect = (this.isCircular &&
typeof pick(this.userMax, this.options.max) === 'undefined' &&
correctFloat(this.endAngleRad - this.startAngleRad) ===
correctFloat(2 * Math.PI));
// This will lead to add an extra tick to xAxis in order to display
// a correct range on inverted polar
if (!this.isCircular && this.chart.inverted) {
this.max++;
}
if (this.autoConnect) {
this.max += ((this.categories && 1) ||
this.pointRange ||
this.closestPointRange ||
0); // #1197, #2260
}
};
/**
* Override the setAxisSize method to use the arc's circumference as
* length. This allows tickPixelInterval to apply to pixel lengths along
* the perimeter.
* @private
*/
axis.setAxisSize = function () {
var center,
start;
axisProto.setAxisSize.call(this);
if (this.isRadial) {
// Set the center array
this.pane.updateCenter(this);
// In case when the innerSize is set in a polar chart, the axis'
// center cannot be a reference to pane's center
center = this.center = extend([], this.pane.center);
// The sector is used in Axis.translate to compute the
// translation of reversed axis points (#2570)
if (this.isCircular) {
this.sector = this.endAngleRad - this.startAngleRad;
}
else {
// When the pane's startAngle or the axis' angle is set then
// new x and y values for vertical axis' center must be
// calulated
start = this.postTranslate(this.angleRad, center[3] / 2);
center[0] = start.x - this.chart.plotLeft;
center[1] = start.y - this.chart.plotTop;
}
// Axis len is used to lay out the ticks
this.len = this.width = this.height =
(center[2] - center[3]) * pick(this.sector, 1) / 2;
}
};
/**
* Returns the x, y coordinate of a point given by a value and a pixel
* distance from center.
*
* @private
*
* @param {number} value
* Point value.
*
* @param {number} [length]
* Distance from center.
*
* @return {Highcharts.PositionObject}
*/
axis.getPosition = function (value, length) {
var translatedVal = this.translate(value);
return this.postTranslate(this.isCircular ? translatedVal : this.angleRad, // #2848
// In case when translatedVal is negative, the 0 value must be
// used instead, in order to deal with lines and labels that
// fall out of the visible range near the center of a pane
pick(this.isCircular ?
length :
(translatedVal < 0 ? 0 : translatedVal), this.center[2] / 2) - this.offset);
};
/**
* Translate from intermediate plotX (angle), plotY (axis.len - radius)
* to final chart coordinates.
*
* @private
*
* @param {number} angle
* Translation angle.
*
* @param {number} radius
* Translation radius.
*
* @return {Highcharts.PositionObject}
*/
axis.postTranslate = function (angle, radius) {
var chart = this.chart,
center = this.center;
angle = this.startAngleRad + angle;
return {
x: chart.plotLeft + center[0] + Math.cos(angle) * radius,
y: chart.plotTop + center[1] + Math.sin(angle) * radius
};
};
/**
* Find the path for plot bands along the radial axis.
*
* @private
*
* @param {number} from
* From value.
*
* @param {number} to
* To value.
*
* @param {Highcharts.AxisPlotBandsOptions} options
* Band options.
*
* @return {RadialAxisPath}
*/
axis.getPlotBandPath = function (from, to, options) {
var radiusToPixels = function (radius) {
if (typeof radius === 'string') {
var r = parseInt(radius, 10);
if (percentRegex.test(radius)) {
r = (r * fullRadius) / 100;
}
return r;
}
return radius;
};
var center = this.center,
startAngleRad = this.startAngleRad,
fullRadius = center[2] / 2,
offset = Math.min(this.offset, 0),
left = this.left || 0,
top = this.top || 0,
percentRegex = /%$/,
start,
end,
angle,
xOnPerimeter,
open,
isCircular = this.isCircular, // X axis in a polar chart
path,
outerRadius = pick(radiusToPixels(options.outerRadius),
fullRadius),
innerRadius = radiusToPixels(options.innerRadius),
thickness = pick(radiusToPixels(options.thickness), 10);
// Polygonal plot bands
if (this.options.gridLineInterpolation === 'polygon') {
path = this.getPlotLinePath({ value: from }).concat(this.getPlotLinePath({ value: to, reverse: true }));
// Circular grid bands
}
else {
// Keep within bounds
from = Math.max(from, this.min);
to = Math.min(to, this.max);
var transFrom = this.translate(from);
var transTo = this.translate(to);
// Plot bands on Y axis (radial axis) - inner and outer
// radius depend on to and from
if (!isCircular) {
outerRadius = transFrom || 0;
innerRadius = transTo || 0;
}
// Handle full circle
if (options.shape === 'circle' || !isCircular) {
start = -Math.PI / 2;
end = Math.PI * 1.5;
open = true;
}
else {
start = startAngleRad + (transFrom || 0);
end = startAngleRad + (transTo || 0);
}
outerRadius -= offset; // #5283
thickness -= offset; // #5283
path = this.chart.renderer.symbols.arc(left + center[0], top + center[1], outerRadius, outerRadius, {
// Math is for reversed yAxis (#3606)
start: Math.min(start, end),
end: Math.max(start, end),
innerR: pick(innerRadius, outerRadius - thickness),
open: open
});
// Provide positioning boxes for the label (#6406)
if (isCircular) {
angle = (end + start) / 2;
xOnPerimeter = (left +
center[0] +
(center[2] / 2) * Math.cos(angle));
path.xBounds = angle > -Math.PI / 2 && angle < Math.PI / 2 ?
// Right hemisphere
[xOnPerimeter, this.chart.plotWidth] :
// Left hemisphere
[0, xOnPerimeter];
path.yBounds = [
top + center[1] + (center[2] / 2) * Math.sin(angle)
];
// Shift up or down to get the label clear of the perimeter
path.yBounds[0] += ((angle > -Math.PI && angle < 0) ||
(angle > Math.PI)) ? -10 : 10;
}
}
return path;
};
// Find the correct end values of crosshair in polar.
axis.getCrosshairPosition = function (options, x1, y1) {
var axis = this,
value = options.value,
center = axis.pane.center,
shapeArgs,
end,
x2,
y2;
if (axis.isCircular) {
if (!defined(value)) {
// When the snap is set to false
x2 = options.chartX || 0;
y2 = options.chartY || 0;
value = axis.translate(Math.atan2(y2 - y1, x2 - x1) - axis.startAngleRad, true);
}
else if (options.point) {
// When the snap is set to true
shapeArgs = options.point.shapeArgs || {};
if (shapeArgs.start) {
// Find a true value of the point based on the
// angle
value = axis.chart.inverted ?
axis.translate(options.point.rectPlotY, true) :
options.point.x;
}
}
end = axis.getPosition(value);
x2 = end.x;
y2 = end.y;
}
else {
if (!defined(value)) {
x2 = options.chartX;
y2 = options.chartY;
}
if (defined(x2) && defined(y2)) {
// Calculate radius of non-circular axis' crosshair
y1 = center[1] + axis.chart.plotTop;
value = axis.translate(Math.min(Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)), center[2] / 2) - center[3] / 2, true);
}
}
return [value, x2 || 0, y2 || 0];
};
// Find the path for plot lines perpendicular to the radial axis.
axis.getPlotLinePath = function (options) {
var axis = this, center = axis.pane.center, chart = axis.chart, inverted = chart.inverted, value = options.value, reverse = options.reverse, end = axis.getPosition(value), background = axis.pane.options.background ?
(axis.pane.options.background[0] ||
axis.pane.options.background) :
{}, innerRadius = background.innerRadius || '0%', outerRadius = background.outerRadius || '100%', x1 = center[0] + chart.plotLeft, y1 = center[1] + chart.plotTop, x2 = end.x, y2 = end.y, height = axis.height, isCrosshair = options.isCrosshair, paneInnerR = center[3] / 2, innerRatio, distance, a, b, otherAxis, xy, tickPositions, crossPos, path;
// Crosshair logic
if (isCrosshair) {
// Find crosshair's position and perform destructuring
// assignment
crossPos = this.getCrosshairPosition(options, x1, y1);
value = crossPos[0];
x2 = crossPos[1];
y2 = crossPos[2];
}
// Spokes
if (axis.isCircular) {
distance =
Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
a = (typeof innerRadius === 'string') ?
relativeLength(innerRadius, 1) : (innerRadius / distance);
b = (typeof outerRadius === 'string') ?
relativeLength(outerRadius, 1) : (outerRadius / distance);
// To ensure that gridlines won't be displayed in area
// defined by innerSize in case of custom radiuses of pane's
// background
if (center && paneInnerR) {
innerRatio = paneInnerR / distance;
if (a < innerRatio) {
a = innerRatio;
}
if (b < innerRatio) {
b = innerRatio;
}
}
path = [
['M', x1 + a * (x2 - x1), y1 - a * (y1 - y2)],
['L', x2 - (1 - b) * (x2 - x1), y2 + (1 - b) * (y1 - y2)]
];
// Concentric circles
}
else {
// Pick the right values depending if it is grid line or
// crosshair
value = axis.translate(value);
// This is required in case when xAxis is non-circular to
// prevent grid lines (or crosshairs, if enabled) from
// rendering above the center after they supposed to be
// displayed below the center point
if (value) {
if (value < 0 || value > height) {
value = 0;
}
}
if (axis.options.gridLineInterpolation === 'circle') {
// A value of 0 is in the center, so it won't be
// visible, but draw it anyway for update and animation
// (#2366)
path = axis.getLinePath(0, value, paneInnerR);
// Concentric polygons
}
else {
path = [];
// Find the other axis (a circular one) in the same pane
chart[inverted ? 'yAxis' : 'xAxis'].forEach(function (a) {
if (a.pane === axis.pane) {
otherAxis = a;
}
});
if (otherAxis) {
tickPositions = otherAxis.tickPositions;
if (otherAxis.autoConnect) {
tickPositions =
tickPositions.concat([tickPositions[0]]);
}
// Reverse the positions for concatenation of polygonal
// plot bands
if (reverse) {
tickPositions = tickPositions.slice().reverse();
}
if (value) {
value += paneInnerR;
}
for (var i = 0; i < tickPositions.length; i++) {
xy = otherAxis.getPosition(tickPositions[i], value);
path.push(i ? ['L', xy.x, xy.y] : ['M', xy.x, xy.y]);
}
}
}
}
return path;
};
// Find the position for the axis title, by default inside the gauge.
axis.getTitlePosition = function () {
var center = this.center,
chart = this.chart,
titleOptions = this.options.title;
return {
x: chart.plotLeft + center[0] + (titleOptions.x || 0),
y: (chart.plotTop +
center[1] -
({
high: 0.5,
middle: 0.25,
low: 0
}[titleOptions.align] *
center[2]) +
(titleOptions.y || 0))
};
};
/**
* Attach and return collecting function for labels in radial axis for
* anti-collision.
*
* @private
*
* @return {Highcharts.ChartLabelCollectorFunction}
*/
axis.createLabelCollector = function () {
var axis = this;
return function () {
if (axis.isRadial &&
axis.tickPositions &&
// undocumented option for now, but working
axis.options.labels.allowOverlap !== true) {
return axis.tickPositions
.map(function (pos) {
return axis.ticks[pos] && axis.ticks[pos].label;
})
.filter(function (label) {
return Boolean(label);
});
}
};
};
};
/**
* Augments methods for the value axis.
*
* @private
*
* @param {Highcharts.Axis} AxisClass
* Axis class to extend.
*
* @param {Highcharts.Tick} TickClass
* Tick class to use.
*/
RadialAxis.compose = function (AxisClass, TickClass) {
/* eslint-disable no-invalid-this */
// Actions before axis init.
addEvent(AxisClass, 'init', function (e) {
var axis = this;
var chart = axis.chart;
var inverted = chart.inverted,
angular = chart.angular,
polar = chart.polar,
isX = axis.isXAxis,
coll = axis.coll,
isHidden = angular && isX,
isCircular,
chartOptions = chart.options,
paneIndex = e.userOptions.pane || 0,
pane = this.pane =
chart.pane && chart.pane[paneIndex];
// Prevent changes for colorAxis
if (coll === 'colorAxis') {
this.isRadial = false;
return;
}
// Before prototype.init
if (angular) {
if (isHidden) {
HiddenAxis.init(axis);
}
else {
RadialAxis.init(axis);
}
isCircular = !isX;
if (isCircular) {
axis.defaultPolarOptions = RadialAxis.defaultRadialGaugeOptions;
}
}
else if (polar) {
RadialAxis.init(axis);
// Check which axis is circular
isCircular = axis.horiz;
axis.defaultPolarOptions = isCircular ?
RadialAxis.defaultCircularOptions :
merge(coll === 'xAxis' ?
AxisClass.defaultOptions :
AxisClass.defaultYAxisOptions, RadialAxis.defaultRadialOptions);
// Apply the stack labels for yAxis in case of inverted chart
if (inverted && coll === 'yAxis') {
axis.defaultPolarOptions.stackLabels = AxisClass.defaultYAxisOptions.stackLabels;
}
}
// Disable certain features on angular and polar axes
if (angular || polar) {
axis.isRadial = true;
chartOptions.chart.zoomType = null;
if (!axis.labelCollector) {
axis.labelCollector = axis.createLabelCollector();
}
if (axis.labelCollector) {
// Prevent overlapping axis labels (#9761)
chart.labelCollectors.push(axis.labelCollector);