Carga
Carga
This commit is contained in:
@@ -0,0 +1,437 @@
|
||||
/* *
|
||||
*
|
||||
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
|
||||
*
|
||||
* */
|
||||
'use strict';
|
||||
import ControlPoint from '../ControlPoint.js';
|
||||
import MockPoint from '../MockPoint.js';
|
||||
import Tooltip from '../../../Core/Tooltip.js';
|
||||
import U from '../../../Core/Utilities.js';
|
||||
var isObject = U.isObject, isString = U.isString, merge = U.merge, splat = U.splat;
|
||||
/* *
|
||||
*
|
||||
* Class
|
||||
*
|
||||
* */
|
||||
/**
|
||||
* It provides methods for handling points, control points
|
||||
* and points transformations.
|
||||
* @private
|
||||
*/
|
||||
var Controllable = /** @class */ (function () {
|
||||
/* *
|
||||
*
|
||||
* Constructor
|
||||
*
|
||||
* */
|
||||
function Controllable(annotation, options, index, itemType) {
|
||||
this.graphic = void 0;
|
||||
this.annotation = annotation;
|
||||
this.chart = annotation.chart;
|
||||
this.collection = (itemType === 'label' ? 'labels' : 'shapes');
|
||||
this.options = options;
|
||||
this.points = [];
|
||||
this.controlPoints = [];
|
||||
this.index = index;
|
||||
this.itemType = itemType;
|
||||
this.init(annotation, options, index);
|
||||
}
|
||||
/* *
|
||||
*
|
||||
* Functions
|
||||
*
|
||||
* */
|
||||
/**
|
||||
* Add control points to a controllable.
|
||||
* @private
|
||||
*/
|
||||
Controllable.prototype.addControlPoints = function () {
|
||||
var _this = this;
|
||||
var controlPoints = this.controlPoints, controlPointsOptions = this.options.controlPoints || [];
|
||||
controlPointsOptions.forEach(function (controlPointOptions, i) {
|
||||
var options = merge(_this.options.controlPointOptions, controlPointOptions);
|
||||
if (!options.index) {
|
||||
options.index = i;
|
||||
}
|
||||
controlPointsOptions[i] = options;
|
||||
controlPoints.push(new ControlPoint(_this.chart, _this, options));
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Returns object which denotes anchor position - relative and absolute.
|
||||
* @private
|
||||
* @param {Highcharts.AnnotationPointType} point
|
||||
* A point like object.
|
||||
* @return {Highcharts.AnnotationAnchorObject}
|
||||
* A controllable anchor
|
||||
*/
|
||||
Controllable.prototype.anchor = function (point) {
|
||||
var plotBox = point.series.getPlotBox(), chart = point.series.chart, box = point.mock ?
|
||||
point.toAnchor() :
|
||||
Tooltip.prototype.getAnchor.call({
|
||||
chart: point.series.chart
|
||||
}, point), anchor = {
|
||||
x: box[0] + (this.options.x || 0),
|
||||
y: box[1] + (this.options.y || 0),
|
||||
height: box[2] || 0,
|
||||
width: box[3] || 0
|
||||
};
|
||||
return {
|
||||
relativePosition: anchor,
|
||||
absolutePosition: merge(anchor, {
|
||||
x: anchor.x + (point.mock ? plotBox.translateX : chart.plotLeft),
|
||||
y: anchor.y + (point.mock ? plotBox.translateY : chart.plotTop)
|
||||
})
|
||||
};
|
||||
};
|
||||
/**
|
||||
* Redirect attr usage on the controllable graphic element.
|
||||
* @private
|
||||
*/
|
||||
Controllable.prototype.attr = function () {
|
||||
var _args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
_args[_i] = arguments[_i];
|
||||
}
|
||||
this.graphic.attr.apply(this.graphic, arguments);
|
||||
};
|
||||
/**
|
||||
* Utility function for mapping item's options
|
||||
* to element's attribute
|
||||
* @private
|
||||
* @param {Highcharts.AnnotationsLabelsOptions|Highcharts.AnnotationsShapesOptions} options
|
||||
* @return {Highcharts.SVGAttributes}
|
||||
* Mapped options.
|
||||
*/
|
||||
Controllable.prototype.attrsFromOptions = function (options) {
|
||||
var map = this.constructor.attrsMap, attrs = {}, styledMode = this.chart.styledMode;
|
||||
var key, mappedKey;
|
||||
for (key in options) { // eslint-disable-line guard-for-in
|
||||
mappedKey = map[key];
|
||||
if (typeof map[key] !== 'undefined' &&
|
||||
(!styledMode ||
|
||||
['fill', 'stroke', 'stroke-width']
|
||||
.indexOf(mappedKey) === -1)) {
|
||||
attrs[mappedKey] = options[key];
|
||||
}
|
||||
}
|
||||
return attrs;
|
||||
};
|
||||
/**
|
||||
* Destroy a controllable.
|
||||
* @private
|
||||
*/
|
||||
Controllable.prototype.destroy = function () {
|
||||
if (this.graphic) {
|
||||
this.graphic = this.graphic.destroy();
|
||||
}
|
||||
if (this.tracker) {
|
||||
this.tracker = this.tracker.destroy();
|
||||
}
|
||||
this.controlPoints.forEach(function (controlPoint) { return controlPoint.destroy(); });
|
||||
this.chart = null;
|
||||
this.points = null;
|
||||
this.controlPoints = null;
|
||||
this.options = null;
|
||||
if (this.annotation) {
|
||||
this.annotation = null;
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Get the controllable's points options.
|
||||
* @private
|
||||
* @return {Array<Highcharts.PointOptionsObject>}
|
||||
* An array of points' options.
|
||||
*/
|
||||
Controllable.prototype.getPointsOptions = function () {
|
||||
var options = this.options;
|
||||
return (options.points ||
|
||||
(options.point && splat(options.point)));
|
||||
};
|
||||
/**
|
||||
* Init the controllable
|
||||
* @private
|
||||
*/
|
||||
Controllable.prototype.init = function (annotation, options, index) {
|
||||
this.annotation = annotation;
|
||||
this.chart = annotation.chart;
|
||||
this.options = options;
|
||||
this.points = [];
|
||||
this.controlPoints = [];
|
||||
this.index = index;
|
||||
this.linkPoints();
|
||||
this.addControlPoints();
|
||||
};
|
||||
/**
|
||||
* Find point-like objects based on points options.
|
||||
* @private
|
||||
* @return {Array<Annotation.PointLike>}
|
||||
* An array of point-like objects.
|
||||
*/
|
||||
Controllable.prototype.linkPoints = function () {
|
||||
var pointsOptions = this.getPointsOptions(), points = this.points, len = (pointsOptions && pointsOptions.length) || 0;
|
||||
var i, point;
|
||||
for (i = 0; i < len; i++) {
|
||||
point = this.point(pointsOptions[i], points[i]);
|
||||
if (!point) {
|
||||
points.length = 0;
|
||||
return;
|
||||
}
|
||||
if (point.mock) {
|
||||
point.refresh();
|
||||
}
|
||||
points[i] = point;
|
||||
}
|
||||
return points;
|
||||
};
|
||||
/**
|
||||
* Map point's options to a point-like object.
|
||||
* @private
|
||||
* @param {string|Function|Highcharts.AnnotationMockPointOptionsObject|Highcharts.AnnotationPointType} pointOptions
|
||||
* Point's options.
|
||||
* @param {Highcharts.AnnotationPointType} point
|
||||
* A point-like instance.
|
||||
* @return {Highcharts.AnnotationPointType|null}
|
||||
* If the point is found/set returns this point, otherwise null
|
||||
*/
|
||||
Controllable.prototype.point = function (pointOptions, point) {
|
||||
if (pointOptions && pointOptions.series) {
|
||||
return pointOptions;
|
||||
}
|
||||
if (!point || point.series === null) {
|
||||
if (isObject(pointOptions)) {
|
||||
point = new MockPoint(this.chart, this, pointOptions);
|
||||
}
|
||||
else if (isString(pointOptions)) {
|
||||
point = this.chart.get(pointOptions) || null;
|
||||
}
|
||||
else if (typeof pointOptions === 'function') {
|
||||
var pointConfig = pointOptions.call(point, this);
|
||||
point = pointConfig.series ?
|
||||
pointConfig :
|
||||
new MockPoint(this.chart, this, pointOptions);
|
||||
}
|
||||
}
|
||||
return point;
|
||||
};
|
||||
/**
|
||||
* Render a controllable.
|
||||
* @private
|
||||
*/
|
||||
Controllable.prototype.render = function (_parentGroup) {
|
||||
this.controlPoints.forEach(function (controlPoint) { return controlPoint.render(); });
|
||||
};
|
||||
/**
|
||||
* Redraw a controllable.
|
||||
* @private
|
||||
*/
|
||||
Controllable.prototype.redraw = function (animation) {
|
||||
this.controlPoints.forEach(function (controlPoint) { return controlPoint.redraw(animation); });
|
||||
};
|
||||
/**
|
||||
* Rotate a controllable.
|
||||
* @private
|
||||
* @param {number} cx
|
||||
* Origin x rotation
|
||||
* @param {number} cy
|
||||
* Origin y rotation
|
||||
* @param {number} radians
|
||||
**/
|
||||
Controllable.prototype.rotate = function (cx, cy, radians) {
|
||||
this.transform('rotate', cx, cy, radians);
|
||||
};
|
||||
/**
|
||||
* Scale a controllable.
|
||||
* @private
|
||||
* @param {number} cx
|
||||
* Origin x rotation
|
||||
* @param {number} cy
|
||||
* Origin y rotation
|
||||
* @param {number} sx
|
||||
* Scale factor x
|
||||
* @param {number} sy
|
||||
* Scale factor y
|
||||
*/
|
||||
Controllable.prototype.scale = function (cx, cy, sx, sy) {
|
||||
this.transform('scale', cx, cy, sx, sy);
|
||||
};
|
||||
/**
|
||||
* Set control points' visibility.
|
||||
* @private
|
||||
*/
|
||||
Controllable.prototype.setControlPointsVisibility = function (visible) {
|
||||
this.controlPoints.forEach(function (controlPoint) {
|
||||
controlPoint.setVisibility(visible);
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Check if a controllable should be rendered/redrawn.
|
||||
* @private
|
||||
* @return {boolean}
|
||||
* Whether a controllable should be drawn.
|
||||
*/
|
||||
Controllable.prototype.shouldBeDrawn = function () {
|
||||
return !!this.points.length;
|
||||
};
|
||||
/**
|
||||
* Transform a controllable with a specific transformation.
|
||||
* @private
|
||||
* @param {string} transformation
|
||||
* A transformation name
|
||||
* @param {number|null} cx
|
||||
* Origin x transformation
|
||||
* @param {number|null} cy
|
||||
* Origin y transformation
|
||||
* @param {number} p1
|
||||
* Param for the transformation
|
||||
* @param {number} [p2]
|
||||
* Param for the transformation
|
||||
*/
|
||||
Controllable.prototype.transform = function (transformation, cx, cy, p1, p2) {
|
||||
var _this = this;
|
||||
if (this.chart.inverted) {
|
||||
var temp = cx;
|
||||
cx = cy;
|
||||
cy = temp;
|
||||
}
|
||||
this.points.forEach(function (_point, i) { return (_this.transformPoint(transformation, cx, cy, p1, p2, i)); }, this);
|
||||
};
|
||||
/**
|
||||
* Transform a point with a specific transformation
|
||||
* If a transformed point is a real point it is replaced with
|
||||
* the mock point.
|
||||
* @private
|
||||
* @param {string} transformation
|
||||
* A transformation name
|
||||
* @param {number|null} cx
|
||||
* Origin x transformation
|
||||
* @param {number|null} cy
|
||||
* Origin y transformation
|
||||
* @param {number} p1
|
||||
* Param for the transformation
|
||||
* @param {number|undefined} p2
|
||||
* Param for the transformation
|
||||
* @param {number} i
|
||||
* Index of the point
|
||||
*/
|
||||
Controllable.prototype.transformPoint = function (transformation, cx, cy, p1, p2, i) {
|
||||
var point = this.points[i];
|
||||
if (!point.mock) {
|
||||
point = this.points[i] = MockPoint.fromPoint(point);
|
||||
}
|
||||
point[transformation](cx, cy, p1, p2);
|
||||
};
|
||||
/**
|
||||
* Translate a controllable.
|
||||
* @private
|
||||
* @param {number} dx
|
||||
* Translation for x coordinate
|
||||
* @param {number} dy
|
||||
* Translation for y coordinate
|
||||
**/
|
||||
Controllable.prototype.translate = function (dx, dy) {
|
||||
this.transform('translate', null, null, dx, dy);
|
||||
};
|
||||
/**
|
||||
* Translate a specific point within a controllable.
|
||||
* @private
|
||||
* @param {number} dx
|
||||
* Translation for x coordinate
|
||||
* @param {number} dy
|
||||
* Translation for y coordinate
|
||||
* @param {number} i
|
||||
* Index of the point
|
||||
**/
|
||||
Controllable.prototype.translatePoint = function (dx, dy, i) {
|
||||
this.transformPoint('translate', null, null, dx, dy, i);
|
||||
};
|
||||
/**
|
||||
* Translate shape within controllable item.
|
||||
* Replaces `controllable.translate` method.
|
||||
* @private
|
||||
* @param {number} dx
|
||||
* Translation for x coordinate
|
||||
* @param {number} dy
|
||||
* Translation for y coordinate
|
||||
* @param {boolean|undefined} translateSecondPoint
|
||||
* If the shape has two points attached to it, this option allows you
|
||||
* to translate also the second point.
|
||||
*/
|
||||
Controllable.prototype.translateShape = function (dx, dy, translateSecondPoint) {
|
||||
var chart = this.annotation.chart,
|
||||
// Annotation.options
|
||||
shapeOptions = this.annotation.userOptions,
|
||||
// Chart.options.annotations
|
||||
annotationIndex = chart.annotations.indexOf(this.annotation), chartOptions = chart.options.annotations[annotationIndex];
|
||||
this.translatePoint(dx, dy, 0);
|
||||
if (translateSecondPoint) {
|
||||
this.translatePoint(dx, dy, 1);
|
||||
}
|
||||
// Options stored in:
|
||||
// - chart (for exporting)
|
||||
// - current config (for redraws)
|
||||
chartOptions[this.collection][this.index]
|
||||
.point = this.options.point;
|
||||
shapeOptions[this.collection][this.index]
|
||||
.point = this.options.point;
|
||||
};
|
||||
/**
|
||||
* Update a controllable.
|
||||
* @private
|
||||
*/
|
||||
Controllable.prototype.update = function (newOptions) {
|
||||
var annotation = this.annotation, options = merge(true, this.options, newOptions), parentGroup = this.graphic.parentGroup;
|
||||
this.destroy();
|
||||
this.constructor(annotation, options, this.index, this.itemType);
|
||||
this.render(parentGroup);
|
||||
this.redraw();
|
||||
};
|
||||
return Controllable;
|
||||
}());
|
||||
/* *
|
||||
*
|
||||
* Default Export
|
||||
*
|
||||
* */
|
||||
export default Controllable;
|
||||
/* *
|
||||
*
|
||||
* API Declarations
|
||||
*
|
||||
* */
|
||||
/**
|
||||
* An object which denots a controllable's anchor positions - relative and
|
||||
* absolute.
|
||||
*
|
||||
* @private
|
||||
* @interface Highcharts.AnnotationAnchorObject
|
||||
*/ /**
|
||||
* Relative to the plot area position
|
||||
* @name Highcharts.AnnotationAnchorObject#relativePosition
|
||||
* @type {Highcharts.BBoxObject}
|
||||
*/ /**
|
||||
* Absolute position
|
||||
* @name Highcharts.AnnotationAnchorObject#absolutePosition
|
||||
* @type {Highcharts.BBoxObject}
|
||||
*/
|
||||
/**
|
||||
* @interface Highcharts.AnnotationControllable
|
||||
*/ /**
|
||||
* @name Highcharts.AnnotationControllable#annotation
|
||||
* @type {Highcharts.Annotation}
|
||||
*/ /**
|
||||
* @name Highcharts.AnnotationControllable#chart
|
||||
* @type {Highcharts.Chart}
|
||||
*/ /**
|
||||
* @name Highcharts.AnnotationControllable#collection
|
||||
* @type {string}
|
||||
*/ /**
|
||||
* @private
|
||||
* @name Highcharts.AnnotationControllable#controlPoints
|
||||
* @type {Array<Highcharts.AnnotationControlPoint>}
|
||||
*/ /**
|
||||
* @name Highcharts.AnnotationControllable#points
|
||||
* @type {Array<Highcharts.Point>}
|
||||
*/
|
||||
(''); // keeps doclets above in JS file
|
||||
@@ -0,0 +1,130 @@
|
||||
/* *
|
||||
*
|
||||
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
|
||||
*
|
||||
* */
|
||||
'use strict';
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
import Controllable from './Controllable.js';
|
||||
import ControllablePath from './ControllablePath.js';
|
||||
import U from '../../../Core/Utilities.js';
|
||||
var merge = U.merge;
|
||||
/* *
|
||||
*
|
||||
* Class
|
||||
*
|
||||
* */
|
||||
/**
|
||||
* A controllable circle class.
|
||||
*
|
||||
* @requires modules/annotations
|
||||
*
|
||||
* @private
|
||||
* @class
|
||||
* @name Highcharts.AnnotationControllableCircle
|
||||
*
|
||||
* @param {Highcharts.Annotation} annotation an annotation instance
|
||||
* @param {Highcharts.AnnotationsShapeOptions} options a shape's options
|
||||
* @param {number} index of the circle
|
||||
*/
|
||||
var ControllableCircle = /** @class */ (function (_super) {
|
||||
__extends(ControllableCircle, _super);
|
||||
/* *
|
||||
*
|
||||
* Constructors
|
||||
*
|
||||
* */
|
||||
function ControllableCircle(annotation, options, index) {
|
||||
var _this = _super.call(this, annotation, options, index, 'shape') || this;
|
||||
/* *
|
||||
*
|
||||
* Properties
|
||||
*
|
||||
* */
|
||||
_this.type = 'circle';
|
||||
_this.translate = _super.prototype.translateShape;
|
||||
return _this;
|
||||
}
|
||||
/* *
|
||||
*
|
||||
* Functions
|
||||
*
|
||||
* */
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ControllableCircle.prototype.redraw = function (animation) {
|
||||
if (this.graphic) {
|
||||
var position = this.anchor(this.points[0]).absolutePosition;
|
||||
if (position) {
|
||||
this.graphic[animation ? 'animate' : 'attr']({
|
||||
x: position.x,
|
||||
y: position.y,
|
||||
r: this.options.r
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.graphic.attr({
|
||||
x: 0,
|
||||
y: -9e9
|
||||
});
|
||||
}
|
||||
this.graphic.placed = !!position;
|
||||
}
|
||||
_super.prototype.redraw.call(this, animation);
|
||||
};
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ControllableCircle.prototype.render = function (parent) {
|
||||
var attrs = this.attrsFromOptions(this.options);
|
||||
this.graphic = this.annotation.chart.renderer
|
||||
.circle(0, -9e9, 0)
|
||||
.attr(attrs)
|
||||
.add(parent);
|
||||
_super.prototype.render.call(this);
|
||||
};
|
||||
/**
|
||||
* Set the radius.
|
||||
* @private
|
||||
* @param {number} r
|
||||
* A radius to be set
|
||||
*/
|
||||
ControllableCircle.prototype.setRadius = function (r) {
|
||||
this.options.r = r;
|
||||
};
|
||||
/* *
|
||||
*
|
||||
* Static Properties
|
||||
*
|
||||
* */
|
||||
/**
|
||||
* A map object which allows to map options attributes to element
|
||||
* attributes.
|
||||
*
|
||||
* @name Highcharts.AnnotationControllableCircle.attrsMap
|
||||
* @type {Highcharts.Dictionary<string>}
|
||||
*/
|
||||
ControllableCircle.attrsMap = merge(ControllablePath.attrsMap, { r: 'r' });
|
||||
return ControllableCircle;
|
||||
}(Controllable));
|
||||
/* *
|
||||
*
|
||||
* Default Export
|
||||
*
|
||||
* */
|
||||
export default ControllableCircle;
|
||||
@@ -0,0 +1,95 @@
|
||||
/* *
|
||||
*
|
||||
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
|
||||
*
|
||||
* */
|
||||
'use strict';
|
||||
/**
|
||||
* Options for configuring markers for annotations.
|
||||
*
|
||||
* An example of the arrow marker:
|
||||
* <pre>
|
||||
* {
|
||||
* arrow: {
|
||||
* id: 'arrow',
|
||||
* tagName: 'marker',
|
||||
* refY: 5,
|
||||
* refX: 5,
|
||||
* markerWidth: 10,
|
||||
* markerHeight: 10,
|
||||
* children: [{
|
||||
* tagName: 'path',
|
||||
* attrs: {
|
||||
* d: 'M 0 0 L 10 5 L 0 10 Z',
|
||||
* 'stroke-width': 0
|
||||
* }
|
||||
* }]
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @sample highcharts/annotations/custom-markers/
|
||||
* Define a custom marker for annotations
|
||||
*
|
||||
* @sample highcharts/css/annotations-markers/
|
||||
* Define markers in a styled mode
|
||||
*
|
||||
* @type {Highcharts.Dictionary<Highcharts.ASTNode>}
|
||||
* @since 6.0.0
|
||||
* @optionparent defs
|
||||
*/
|
||||
var defaultMarkers = {
|
||||
/**
|
||||
* @type {Highcharts.ASTNode}
|
||||
*/
|
||||
arrow: {
|
||||
tagName: 'marker',
|
||||
attributes: {
|
||||
id: 'arrow',
|
||||
refY: 5,
|
||||
refX: 9,
|
||||
markerWidth: 10,
|
||||
markerHeight: 10
|
||||
},
|
||||
/**
|
||||
* @type {Array<Highcharts.DefsOptions>}
|
||||
*/
|
||||
children: [{
|
||||
tagName: 'path',
|
||||
attributes: {
|
||||
d: 'M 0 0 L 10 5 L 0 10 Z',
|
||||
'stroke-width': 0
|
||||
}
|
||||
}]
|
||||
},
|
||||
/**
|
||||
* @type {Highcharts.ASTNode}
|
||||
*/
|
||||
'reverse-arrow': {
|
||||
tagName: 'marker',
|
||||
attributes: {
|
||||
id: 'reverse-arrow',
|
||||
refY: 5,
|
||||
refX: 1,
|
||||
markerWidth: 10,
|
||||
markerHeight: 10
|
||||
},
|
||||
children: [{
|
||||
tagName: 'path',
|
||||
attributes: {
|
||||
// reverse triangle (used as an arrow)
|
||||
d: 'M 0 5 L 10 0 L 10 10 Z',
|
||||
'stroke-width': 0
|
||||
}
|
||||
}]
|
||||
}
|
||||
};
|
||||
/* *
|
||||
*
|
||||
* Default Export
|
||||
*
|
||||
* */
|
||||
var ControllableDefaults = {
|
||||
defaultMarkers: defaultMarkers
|
||||
};
|
||||
export default ControllableDefaults;
|
||||
@@ -0,0 +1,231 @@
|
||||
/* *
|
||||
*
|
||||
* Author: Pawel Lysy
|
||||
*
|
||||
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
|
||||
*
|
||||
* */
|
||||
'use strict';
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
import Controllable from './Controllable.js';
|
||||
import ControllablePath from './ControllablePath.js';
|
||||
import U from '../../../Core/Utilities.js';
|
||||
var merge = U.merge, defined = U.defined;
|
||||
/* *
|
||||
*
|
||||
* Class
|
||||
*
|
||||
* */
|
||||
/**
|
||||
* A controllable ellipse class.
|
||||
*
|
||||
* @requires modules/annotations
|
||||
*
|
||||
* @private
|
||||
* @class
|
||||
* @name Highcharts.AnnotationControllableEllipse
|
||||
*
|
||||
* @param {Highcharts.Annotation} annotation an annotation instance
|
||||
* @param {Highcharts.AnnotationsShapeOptions} options a shape's options
|
||||
* @param {number} index of the Ellipse
|
||||
*/
|
||||
var ControllableEllipse = /** @class */ (function (_super) {
|
||||
__extends(ControllableEllipse, _super);
|
||||
/* *
|
||||
*
|
||||
* Constructor
|
||||
*
|
||||
* */
|
||||
function ControllableEllipse(annotation, options, index) {
|
||||
var _this = _super.call(this, annotation, options, index, 'shape') || this;
|
||||
/* *
|
||||
*
|
||||
* Properties
|
||||
*
|
||||
* */
|
||||
_this.type = 'ellipse';
|
||||
return _this;
|
||||
}
|
||||
/* *
|
||||
*
|
||||
* Functions
|
||||
*
|
||||
* */
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ControllableEllipse.prototype.init = function (annotation, options, index) {
|
||||
if (defined(options.yAxis)) {
|
||||
options.points.forEach(function (point) {
|
||||
point.yAxis = options.yAxis;
|
||||
});
|
||||
}
|
||||
if (defined(options.xAxis)) {
|
||||
options.points.forEach(function (point) {
|
||||
point.xAxis = options.xAxis;
|
||||
});
|
||||
}
|
||||
_super.prototype.init.call(this, annotation, options, index);
|
||||
};
|
||||
/**
|
||||
* Render the element
|
||||
* @private
|
||||
* @param parent
|
||||
* Parent SVG element.
|
||||
*/
|
||||
ControllableEllipse.prototype.render = function (parent) {
|
||||
this.graphic = this.annotation.chart.renderer.createElement('ellipse')
|
||||
.attr(this.attrsFromOptions(this.options))
|
||||
.add(parent);
|
||||
_super.prototype.render.call(this);
|
||||
};
|
||||
/**
|
||||
* Translate the points. Mostly used to handle dragging of the ellipse.
|
||||
* @private
|
||||
*/
|
||||
ControllableEllipse.prototype.translate = function (dx, dy) {
|
||||
_super.prototype.translateShape.call(this, dx, dy, true);
|
||||
};
|
||||
/**
|
||||
* Get the distance from the line to the point.
|
||||
* @private
|
||||
* @param point1
|
||||
* First point which is on the line
|
||||
* @param point2
|
||||
* Second point
|
||||
* @param x0
|
||||
* Point's x value from which you want to calculate the distance from
|
||||
* @param y0
|
||||
* Point's y value from which you want to calculate the distance from
|
||||
*/
|
||||
ControllableEllipse.prototype.getDistanceFromLine = function (point1, point2, x0, y0) {
|
||||
return Math.abs((point2.y - point1.y) * x0 - (point2.x - point1.x) * y0 +
|
||||
point2.x * point1.y - point2.y * point1.x) / Math.sqrt((point2.y - point1.y) * (point2.y - point1.y) +
|
||||
(point2.x - point1.x) * (point2.x - point1.x));
|
||||
};
|
||||
/**
|
||||
* The fuction calculates the svg attributes of the ellipse, and returns all
|
||||
* parameters neccessary to draw the ellipse.
|
||||
* @private
|
||||
* @param position
|
||||
* Absolute position of the first point in points array
|
||||
* @param position2
|
||||
* Absolute position of the second point in points array
|
||||
*/
|
||||
ControllableEllipse.prototype.getAttrs = function (position, position2) {
|
||||
var x1 = position.x, y1 = position.y, x2 = position2.x, y2 = position2.y, cx = (x1 + x2) / 2, cy = (y1 + y2) / 2, rx = Math.sqrt((x1 - x2) * (x1 - x2) / 4 + (y1 - y2) * (y1 - y2) / 4), tan = (y2 - y1) / (x2 - x1);
|
||||
var angle = Math.atan(tan) * 180 / Math.PI;
|
||||
if (cx < x1) {
|
||||
angle += 180;
|
||||
}
|
||||
var ry = this.getRY();
|
||||
return { cx: cx, cy: cy, rx: rx, ry: ry, angle: angle };
|
||||
};
|
||||
/**
|
||||
* Get the value of minor radius of the ellipse.
|
||||
* @private
|
||||
*/
|
||||
ControllableEllipse.prototype.getRY = function () {
|
||||
var yAxis = this.getYAxis();
|
||||
return defined(yAxis) ?
|
||||
Math.abs(yAxis.toPixels(this.options.ry) - yAxis.toPixels(0)) :
|
||||
this.options.ry;
|
||||
};
|
||||
/**
|
||||
* Get the yAxis object to which the ellipse is pinned.
|
||||
* @private
|
||||
*/
|
||||
ControllableEllipse.prototype.getYAxis = function () {
|
||||
var yAxisIndex = this.options.yAxis;
|
||||
return this.chart.yAxis[yAxisIndex];
|
||||
};
|
||||
/**
|
||||
* Get the absolute coordinates of the MockPoint
|
||||
* @private
|
||||
* @param point
|
||||
* MockPoint that is added through options
|
||||
*/
|
||||
ControllableEllipse.prototype.getAbsolutePosition = function (point) {
|
||||
return this.anchor(point).absolutePosition;
|
||||
};
|
||||
/**
|
||||
* Redraw the element
|
||||
* @private
|
||||
* @param animation
|
||||
* Display an annimation
|
||||
*/
|
||||
ControllableEllipse.prototype.redraw = function (animation) {
|
||||
if (this.graphic) {
|
||||
var position = this.getAbsolutePosition(this.points[0]), position2 = this.getAbsolutePosition(this.points[1]), attrs = this.getAttrs(position, position2);
|
||||
if (position) {
|
||||
this.graphic[animation ? 'animate' : 'attr']({
|
||||
cx: attrs.cx,
|
||||
cy: attrs.cy,
|
||||
rx: attrs.rx,
|
||||
ry: attrs.ry,
|
||||
rotation: attrs.angle,
|
||||
rotationOriginX: attrs.cx,
|
||||
rotationOriginY: attrs.cy
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.graphic.attr({
|
||||
x: 0,
|
||||
y: -9e9
|
||||
});
|
||||
}
|
||||
this.graphic.placed = Boolean(position);
|
||||
}
|
||||
_super.prototype.redraw.call(this, animation);
|
||||
};
|
||||
/**
|
||||
* Set the radius Y.
|
||||
* @private
|
||||
* @param {number} ry
|
||||
* A radius in y direction to be set
|
||||
*/
|
||||
ControllableEllipse.prototype.setYRadius = function (ry) {
|
||||
var shapes = this.annotation.userOptions.shapes;
|
||||
this.options.ry = ry;
|
||||
if (shapes && shapes[0]) {
|
||||
shapes[0].ry = ry;
|
||||
shapes[0].ry = ry;
|
||||
}
|
||||
};
|
||||
/* *
|
||||
*
|
||||
* Static Properties
|
||||
*
|
||||
* */
|
||||
/**
|
||||
* A map object which allows to map options attributes to element
|
||||
* attributes.
|
||||
*
|
||||
* @name Highcharts.AnnotationControllableEllipse.attrsMap
|
||||
* @type {Highcharts.Dictionary<string>}
|
||||
*/
|
||||
ControllableEllipse.attrsMap = merge(ControllablePath.attrsMap, {
|
||||
ry: 'ry'
|
||||
});
|
||||
return ControllableEllipse;
|
||||
}(Controllable));
|
||||
/* *
|
||||
*
|
||||
* Default Export
|
||||
*
|
||||
* */
|
||||
export default ControllableEllipse;
|
||||
@@ -0,0 +1,117 @@
|
||||
/* *
|
||||
*
|
||||
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
|
||||
*
|
||||
* */
|
||||
'use strict';
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
import Controllable from './Controllable.js';
|
||||
import ControllableLabel from './ControllableLabel.js';
|
||||
/* *
|
||||
*
|
||||
* Class
|
||||
*
|
||||
* */
|
||||
/**
|
||||
* A controllable image class.
|
||||
*
|
||||
* @requires modules/annotations
|
||||
*
|
||||
* @private
|
||||
* @class
|
||||
* @name Highcharts.AnnotationControllableImage
|
||||
*
|
||||
* @param {Highcharts.Annotation} annotation
|
||||
* An annotation instance.
|
||||
*
|
||||
* @param {Highcharts.AnnotationsShapeOptions} options
|
||||
* A controllable's options.
|
||||
*
|
||||
* @param {number} index
|
||||
* Index of the image.
|
||||
*/
|
||||
var ControllableImage = /** @class */ (function (_super) {
|
||||
__extends(ControllableImage, _super);
|
||||
/* *
|
||||
*
|
||||
* Constructors
|
||||
*
|
||||
* */
|
||||
function ControllableImage(annotation, options, index) {
|
||||
var _this = _super.call(this, annotation, options, index, 'shape') || this;
|
||||
/* *
|
||||
*
|
||||
* Properties
|
||||
*
|
||||
* */
|
||||
_this.type = 'image';
|
||||
_this.translate = _super.prototype.translateShape;
|
||||
return _this;
|
||||
}
|
||||
ControllableImage.prototype.render = function (parent) {
|
||||
var attrs = this.attrsFromOptions(this.options), options = this.options;
|
||||
this.graphic = this.annotation.chart.renderer
|
||||
.image(options.src, 0, -9e9, options.width, options.height)
|
||||
.attr(attrs)
|
||||
.add(parent);
|
||||
this.graphic.width = options.width;
|
||||
this.graphic.height = options.height;
|
||||
_super.prototype.render.call(this);
|
||||
};
|
||||
ControllableImage.prototype.redraw = function (animation) {
|
||||
if (this.graphic) {
|
||||
var anchor = this.anchor(this.points[0]), position = ControllableLabel.prototype.position.call(this, anchor);
|
||||
if (position) {
|
||||
this.graphic[animation ? 'animate' : 'attr']({
|
||||
x: position.x,
|
||||
y: position.y
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.graphic.attr({
|
||||
x: 0,
|
||||
y: -9e9
|
||||
});
|
||||
}
|
||||
this.graphic.placed = Boolean(position);
|
||||
}
|
||||
_super.prototype.redraw.call(this, animation);
|
||||
};
|
||||
/* *
|
||||
*
|
||||
* Static Properties
|
||||
*
|
||||
* */
|
||||
/**
|
||||
* A map object which allows to map options attributes to element attributes
|
||||
*
|
||||
* @name Highcharts.AnnotationControllableImage.attrsMap
|
||||
* @type {Highcharts.Dictionary<string>}
|
||||
*/
|
||||
ControllableImage.attrsMap = {
|
||||
width: 'width',
|
||||
height: 'height',
|
||||
zIndex: 'zIndex'
|
||||
};
|
||||
return ControllableImage;
|
||||
}(Controllable));
|
||||
/* *
|
||||
*
|
||||
* Default Export
|
||||
*
|
||||
* */
|
||||
export default ControllableImage;
|
||||
@@ -0,0 +1,404 @@
|
||||
/* *
|
||||
*
|
||||
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
|
||||
*
|
||||
* */
|
||||
'use strict';
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
import Controllable from './Controllable.js';
|
||||
import F from '../../../Core/FormatUtilities.js';
|
||||
var format = F.format;
|
||||
import MockPoint from '../MockPoint.js';
|
||||
import Tooltip from '../../../Core/Tooltip.js';
|
||||
import U from '../../../Core/Utilities.js';
|
||||
var extend = U.extend, isNumber = U.isNumber, pick = U.pick;
|
||||
/* *
|
||||
*
|
||||
* Constants
|
||||
*
|
||||
* */
|
||||
var composedClasses = [];
|
||||
/* *
|
||||
*
|
||||
* Functions
|
||||
*
|
||||
* */
|
||||
/**
|
||||
* General symbol definition for labels with connector
|
||||
* @private
|
||||
*/
|
||||
function symbolConnector(x, y, w, h, options) {
|
||||
var anchorX = options && options.anchorX, anchorY = options && options.anchorY;
|
||||
var path, yOffset, lateral = w / 2;
|
||||
if (isNumber(anchorX) && isNumber(anchorY)) {
|
||||
path = [['M', anchorX, anchorY]];
|
||||
// Prefer 45 deg connectors
|
||||
yOffset = y - anchorY;
|
||||
if (yOffset < 0) {
|
||||
yOffset = -h - yOffset;
|
||||
}
|
||||
if (yOffset < w) {
|
||||
lateral = anchorX < x + (w / 2) ? yOffset : w - yOffset;
|
||||
}
|
||||
// Anchor below label
|
||||
if (anchorY > y + h) {
|
||||
path.push(['L', x + lateral, y + h]);
|
||||
// Anchor above label
|
||||
}
|
||||
else if (anchorY < y) {
|
||||
path.push(['L', x + lateral, y]);
|
||||
// Anchor left of label
|
||||
}
|
||||
else if (anchorX < x) {
|
||||
path.push(['L', x, y + h / 2]);
|
||||
// Anchor right of label
|
||||
}
|
||||
else if (anchorX > x + w) {
|
||||
path.push(['L', x + w, y + h / 2]);
|
||||
}
|
||||
}
|
||||
return path || [];
|
||||
}
|
||||
/* *
|
||||
*
|
||||
* Class
|
||||
*
|
||||
* */
|
||||
/**
|
||||
* A controllable label class.
|
||||
*
|
||||
* @requires modules/annotations
|
||||
*
|
||||
* @private
|
||||
* @class
|
||||
* @name Highcharts.AnnotationControllableLabel
|
||||
*
|
||||
* @param {Highcharts.Annotation} annotation
|
||||
* An annotation instance.
|
||||
* @param {Highcharts.AnnotationsLabelOptions} options
|
||||
* A label's options.
|
||||
* @param {number} index
|
||||
* Index of the label.
|
||||
*/
|
||||
var ControllableLabel = /** @class */ (function (_super) {
|
||||
__extends(ControllableLabel, _super);
|
||||
/* *
|
||||
*
|
||||
* Constructors
|
||||
*
|
||||
* */
|
||||
function ControllableLabel(annotation, options, index) {
|
||||
return _super.call(this, annotation, options, index, 'label') || this;
|
||||
}
|
||||
/* *
|
||||
*
|
||||
* Static Functions
|
||||
*
|
||||
* */
|
||||
/**
|
||||
* Returns new aligned position based alignment options and box to align to.
|
||||
* It is almost a one-to-one copy from SVGElement.prototype.align
|
||||
* except it does not use and mutate an element
|
||||
*
|
||||
* @param {Highcharts.AnnotationAlignObject} alignOptions
|
||||
*
|
||||
* @param {Highcharts.BBoxObject} box
|
||||
*
|
||||
* @return {Highcharts.PositionObject}
|
||||
* Aligned position.
|
||||
*/
|
||||
ControllableLabel.alignedPosition = function (alignOptions, box) {
|
||||
var align = alignOptions.align, vAlign = alignOptions.verticalAlign;
|
||||
var x = (box.x || 0) + (alignOptions.x || 0), y = (box.y || 0) + (alignOptions.y || 0), alignFactor, vAlignFactor;
|
||||
if (align === 'right') {
|
||||
alignFactor = 1;
|
||||
}
|
||||
else if (align === 'center') {
|
||||
alignFactor = 2;
|
||||
}
|
||||
if (alignFactor) {
|
||||
x += (box.width - (alignOptions.width || 0)) / alignFactor;
|
||||
}
|
||||
if (vAlign === 'bottom') {
|
||||
vAlignFactor = 1;
|
||||
}
|
||||
else if (vAlign === 'middle') {
|
||||
vAlignFactor = 2;
|
||||
}
|
||||
if (vAlignFactor) {
|
||||
y += (box.height - (alignOptions.height || 0)) / vAlignFactor;
|
||||
}
|
||||
return {
|
||||
x: Math.round(x),
|
||||
y: Math.round(y)
|
||||
};
|
||||
};
|
||||
ControllableLabel.compose = function (SVGRendererClass) {
|
||||
if (composedClasses.indexOf(SVGRendererClass) === -1) {
|
||||
composedClasses.push(SVGRendererClass);
|
||||
var svgRendererProto = SVGRendererClass.prototype;
|
||||
svgRendererProto.symbols.connector = symbolConnector;
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Returns new alignment options for a label if the label is outside the
|
||||
* plot area. It is almost a one-to-one copy from
|
||||
* Series.prototype.justifyDataLabel except it does not mutate the label and
|
||||
* it works with absolute instead of relative position.
|
||||
*/
|
||||
ControllableLabel.justifiedOptions = function (chart, label, alignOptions, alignAttr) {
|
||||
var align = alignOptions.align, verticalAlign = alignOptions.verticalAlign, padding = label.box ? 0 : (label.padding || 0), bBox = label.getBBox(),
|
||||
//
|
||||
options = {
|
||||
align: align,
|
||||
verticalAlign: verticalAlign,
|
||||
x: alignOptions.x,
|
||||
y: alignOptions.y,
|
||||
width: label.width,
|
||||
height: label.height
|
||||
},
|
||||
//
|
||||
x = (alignAttr.x || 0) - chart.plotLeft, y = (alignAttr.y || 0) - chart.plotTop;
|
||||
var off;
|
||||
// Off left
|
||||
off = x + padding;
|
||||
if (off < 0) {
|
||||
if (align === 'right') {
|
||||
options.align = 'left';
|
||||
}
|
||||
else {
|
||||
options.x = (options.x || 0) - off;
|
||||
}
|
||||
}
|
||||
// Off right
|
||||
off = x + bBox.width - padding;
|
||||
if (off > chart.plotWidth) {
|
||||
if (align === 'left') {
|
||||
options.align = 'right';
|
||||
}
|
||||
else {
|
||||
options.x = (options.x || 0) + chart.plotWidth - off;
|
||||
}
|
||||
}
|
||||
// Off top
|
||||
off = y + padding;
|
||||
if (off < 0) {
|
||||
if (verticalAlign === 'bottom') {
|
||||
options.verticalAlign = 'top';
|
||||
}
|
||||
else {
|
||||
options.y = (options.y || 0) - off;
|
||||
}
|
||||
}
|
||||
// Off bottom
|
||||
off = y + bBox.height - padding;
|
||||
if (off > chart.plotHeight) {
|
||||
if (verticalAlign === 'top') {
|
||||
options.verticalAlign = 'bottom';
|
||||
}
|
||||
else {
|
||||
options.y = (options.y || 0) + chart.plotHeight - off;
|
||||
}
|
||||
}
|
||||
return options;
|
||||
};
|
||||
/* *
|
||||
*
|
||||
* Functions
|
||||
*
|
||||
* */
|
||||
/**
|
||||
* Translate the point of the label by deltaX and deltaY translations.
|
||||
* The point is the label's anchor.
|
||||
*
|
||||
* @param {number} dx translation for x coordinate
|
||||
* @param {number} dy translation for y coordinate
|
||||
*/
|
||||
ControllableLabel.prototype.translatePoint = function (dx, dy) {
|
||||
_super.prototype.translatePoint.call(this, dx, dy, 0);
|
||||
};
|
||||
/**
|
||||
* Translate x and y position relative to the label's anchor.
|
||||
*
|
||||
* @param {number} dx translation for x coordinate
|
||||
* @param {number} dy translation for y coordinate
|
||||
*/
|
||||
ControllableLabel.prototype.translate = function (dx, dy) {
|
||||
var chart = this.annotation.chart,
|
||||
// Annotation.options
|
||||
labelOptions = this.annotation.userOptions,
|
||||
// Chart.options.annotations
|
||||
annotationIndex = chart.annotations.indexOf(this.annotation), chartAnnotations = chart.options.annotations, chartOptions = chartAnnotations[annotationIndex];
|
||||
if (chart.inverted) {
|
||||
var temp = dx;
|
||||
dx = dy;
|
||||
dy = temp;
|
||||
}
|
||||
// Local options:
|
||||
this.options.x += dx;
|
||||
this.options.y += dy;
|
||||
// Options stored in chart:
|
||||
chartOptions[this.collection][this.index].x = this.options.x;
|
||||
chartOptions[this.collection][this.index].y = this.options.y;
|
||||
labelOptions[this.collection][this.index].x = this.options.x;
|
||||
labelOptions[this.collection][this.index].y = this.options.y;
|
||||
};
|
||||
ControllableLabel.prototype.render = function (parent) {
|
||||
var options = this.options, attrs = this.attrsFromOptions(options), style = options.style;
|
||||
this.graphic = this.annotation.chart.renderer
|
||||
.label('', 0, -9999, // #10055
|
||||
options.shape, null, null, options.useHTML, null, 'annotation-label')
|
||||
.attr(attrs)
|
||||
.add(parent);
|
||||
if (!this.annotation.chart.styledMode) {
|
||||
if (style.color === 'contrast') {
|
||||
style.color = this.annotation.chart.renderer.getContrast(ControllableLabel.shapesWithoutBackground.indexOf(options.shape) > -1 ? '#FFFFFF' : options.backgroundColor);
|
||||
}
|
||||
this.graphic
|
||||
.css(options.style)
|
||||
.shadow(options.shadow);
|
||||
}
|
||||
if (options.className) {
|
||||
this.graphic.addClass(options.className);
|
||||
}
|
||||
this.graphic.labelrank = options.labelrank;
|
||||
_super.prototype.render.call(this);
|
||||
};
|
||||
ControllableLabel.prototype.redraw = function (animation) {
|
||||
var options = this.options, text = this.text || options.format || options.text, label = this.graphic, point = this.points[0];
|
||||
if (!label) {
|
||||
this.redraw(animation);
|
||||
return;
|
||||
}
|
||||
label.attr({
|
||||
text: text ?
|
||||
format(String(text), point.getLabelConfig(), this.annotation.chart) :
|
||||
options.formatter.call(point, this)
|
||||
});
|
||||
var anchor = this.anchor(point);
|
||||
var attrs = this.position(anchor);
|
||||
if (attrs) {
|
||||
label.alignAttr = attrs;
|
||||
attrs.anchorX = anchor.absolutePosition.x;
|
||||
attrs.anchorY = anchor.absolutePosition.y;
|
||||
label[animation ? 'animate' : 'attr'](attrs);
|
||||
}
|
||||
else {
|
||||
label.attr({
|
||||
x: 0,
|
||||
y: -9999 // #10055
|
||||
});
|
||||
}
|
||||
label.placed = !!attrs;
|
||||
_super.prototype.redraw.call(this, animation);
|
||||
};
|
||||
/**
|
||||
* All basic shapes don't support alignTo() method except label.
|
||||
* For a controllable label, we need to subtract translation from
|
||||
* options.
|
||||
*/
|
||||
ControllableLabel.prototype.anchor = function (_point) {
|
||||
var anchor = _super.prototype.anchor.apply(this, arguments), x = this.options.x || 0, y = this.options.y || 0;
|
||||
anchor.absolutePosition.x -= x;
|
||||
anchor.absolutePosition.y -= y;
|
||||
anchor.relativePosition.x -= x;
|
||||
anchor.relativePosition.y -= y;
|
||||
return anchor;
|
||||
};
|
||||
/**
|
||||
* Returns the label position relative to its anchor.
|
||||
*/
|
||||
ControllableLabel.prototype.position = function (anchor) {
|
||||
var item = this.graphic, chart = this.annotation.chart, point = this.points[0], itemOptions = this.options, anchorAbsolutePosition = anchor.absolutePosition, anchorRelativePosition = anchor.relativePosition;
|
||||
var itemPosition, alignTo, itemPosRelativeX, itemPosRelativeY, showItem = point.series.visible &&
|
||||
MockPoint.prototype.isInsidePlot.call(point);
|
||||
if (item && showItem) {
|
||||
var _a = item.width, width = _a === void 0 ? 0 : _a, _b = item.height, height = _b === void 0 ? 0 : _b;
|
||||
if (itemOptions.distance) {
|
||||
itemPosition = Tooltip.prototype.getPosition.call({
|
||||
chart: chart,
|
||||
distance: pick(itemOptions.distance, 16)
|
||||
}, width, height, {
|
||||
plotX: anchorRelativePosition.x,
|
||||
plotY: anchorRelativePosition.y,
|
||||
negative: point.negative,
|
||||
ttBelow: point.ttBelow,
|
||||
h: (anchorRelativePosition.height ||
|
||||
anchorRelativePosition.width)
|
||||
});
|
||||
}
|
||||
else if (itemOptions.positioner) {
|
||||
itemPosition = itemOptions.positioner.call(this);
|
||||
}
|
||||
else {
|
||||
alignTo = {
|
||||
x: anchorAbsolutePosition.x,
|
||||
y: anchorAbsolutePosition.y,
|
||||
width: 0,
|
||||
height: 0
|
||||
};
|
||||
itemPosition = ControllableLabel.alignedPosition(extend(itemOptions, {
|
||||
width: width,
|
||||
height: height
|
||||
}), alignTo);
|
||||
if (this.options.overflow === 'justify') {
|
||||
itemPosition = ControllableLabel.alignedPosition(ControllableLabel.justifiedOptions(chart, item, itemOptions, itemPosition), alignTo);
|
||||
}
|
||||
}
|
||||
if (itemOptions.crop) {
|
||||
itemPosRelativeX = itemPosition.x - chart.plotLeft;
|
||||
itemPosRelativeY = itemPosition.y - chart.plotTop;
|
||||
showItem =
|
||||
chart.isInsidePlot(itemPosRelativeX, itemPosRelativeY) &&
|
||||
chart.isInsidePlot(itemPosRelativeX + width, itemPosRelativeY + height);
|
||||
}
|
||||
}
|
||||
return showItem ? itemPosition : null;
|
||||
};
|
||||
/* *
|
||||
*
|
||||
* Static Properties
|
||||
*
|
||||
* */
|
||||
/**
|
||||
* A map object which allows to map options attributes to element attributes
|
||||
*
|
||||
* @type {Highcharts.Dictionary<string>}
|
||||
*/
|
||||
ControllableLabel.attrsMap = {
|
||||
backgroundColor: 'fill',
|
||||
borderColor: 'stroke',
|
||||
borderWidth: 'stroke-width',
|
||||
zIndex: 'zIndex',
|
||||
borderRadius: 'r',
|
||||
padding: 'padding'
|
||||
};
|
||||
/**
|
||||
* Shapes which do not have background - the object is used for proper
|
||||
* setting of the contrast color.
|
||||
*
|
||||
* @type {Array<string>}
|
||||
*/
|
||||
ControllableLabel.shapesWithoutBackground = ['connector'];
|
||||
return ControllableLabel;
|
||||
}(Controllable));
|
||||
/* *
|
||||
*
|
||||
* Default Export
|
||||
*
|
||||
* */
|
||||
export default ControllableLabel;
|
||||
@@ -0,0 +1,297 @@
|
||||
/* *
|
||||
*
|
||||
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
|
||||
*
|
||||
* */
|
||||
'use strict';
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
import Controllable from './Controllable.js';
|
||||
import ControllableDefaults from './ControllableDefaults.js';
|
||||
var defaultMarkers = ControllableDefaults.defaultMarkers;
|
||||
import H from '../../../Core/Globals.js';
|
||||
import U from '../../../Core/Utilities.js';
|
||||
var addEvent = U.addEvent, defined = U.defined, extend = U.extend, merge = U.merge, uniqueKey = U.uniqueKey;
|
||||
/* *
|
||||
*
|
||||
* Constants
|
||||
*
|
||||
* */
|
||||
var composedClasses = [];
|
||||
var markerEndSetter = createMarkerSetter('marker-end');
|
||||
var markerStartSetter = createMarkerSetter('marker-start');
|
||||
// See TRACKER_FILL in highcharts.src.js
|
||||
var TRACKER_FILL = 'rgba(192,192,192,' + (H.svg ? 0.0001 : 0.002) + ')';
|
||||
/* *
|
||||
*
|
||||
* Functions
|
||||
*
|
||||
* */
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
function createMarkerSetter(markerType) {
|
||||
return function (value) {
|
||||
this.attr(markerType, 'url(#' + value + ')');
|
||||
};
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
function onChartAfterGetContainer() {
|
||||
this.options.defs = merge(defaultMarkers, this.options.defs || {});
|
||||
// objectEach(this.options.defs, function (def): void {
|
||||
// const attributes = def.attributes;
|
||||
// if (
|
||||
// def.tagName === 'marker' &&
|
||||
// attributes &&
|
||||
// attributes.id &&
|
||||
// attributes.display !== 'none'
|
||||
// ) {
|
||||
// this.renderer.addMarker(attributes.id, def);
|
||||
// }
|
||||
// }, this);
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
function svgRendererAddMarker(id, markerOptions) {
|
||||
var options = { attributes: { id: id } };
|
||||
var attrs = {
|
||||
stroke: markerOptions.color || 'none',
|
||||
fill: markerOptions.color || 'rgba(0, 0, 0, 0.75)'
|
||||
};
|
||||
options.children = (markerOptions.children &&
|
||||
markerOptions.children.map(function (child) {
|
||||
return merge(attrs, child);
|
||||
}));
|
||||
var ast = merge(true, {
|
||||
attributes: {
|
||||
markerWidth: 20,
|
||||
markerHeight: 20,
|
||||
refX: 0,
|
||||
refY: 0,
|
||||
orient: 'auto'
|
||||
}
|
||||
}, markerOptions, options);
|
||||
var marker = this.definition(ast);
|
||||
marker.id = id;
|
||||
return marker;
|
||||
}
|
||||
/* *
|
||||
*
|
||||
* Class
|
||||
*
|
||||
* */
|
||||
/**
|
||||
* A controllable path class.
|
||||
*
|
||||
* @requires modules/annotations
|
||||
*
|
||||
* @private
|
||||
* @class
|
||||
* @name Highcharts.AnnotationControllablePath
|
||||
*
|
||||
* @param {Highcharts.Annotation}
|
||||
* Related annotation.
|
||||
*
|
||||
* @param {Highcharts.AnnotationsShapeOptions} options
|
||||
* A path's options object.
|
||||
*
|
||||
* @param {number} index
|
||||
* Index of the path.
|
||||
*/
|
||||
var ControllablePath = /** @class */ (function (_super) {
|
||||
__extends(ControllablePath, _super);
|
||||
/* *
|
||||
*
|
||||
* Constructors
|
||||
*
|
||||
* */
|
||||
function ControllablePath(annotation, options, index) {
|
||||
var _this = _super.call(this, annotation, options, index, 'shape') || this;
|
||||
/* *
|
||||
*
|
||||
* Properties
|
||||
*
|
||||
* */
|
||||
_this.type = 'path';
|
||||
return _this;
|
||||
}
|
||||
/* *
|
||||
*
|
||||
* Static Functions
|
||||
*
|
||||
* */
|
||||
ControllablePath.compose = function (ChartClass, SVGRendererClass) {
|
||||
if (composedClasses.indexOf(ChartClass) === -1) {
|
||||
composedClasses.push(ChartClass);
|
||||
addEvent(ChartClass, 'afterGetContainer', onChartAfterGetContainer);
|
||||
}
|
||||
if (composedClasses.indexOf(SVGRendererClass) === -1) {
|
||||
composedClasses.push(SVGRendererClass);
|
||||
var svgRendererProto = SVGRendererClass.prototype;
|
||||
svgRendererProto.addMarker = svgRendererAddMarker;
|
||||
}
|
||||
};
|
||||
/* *
|
||||
*
|
||||
* Functions
|
||||
*
|
||||
* */
|
||||
/**
|
||||
* Map the controllable path to 'd' path attribute.
|
||||
*
|
||||
* @return {Highcharts.SVGPathArray|null}
|
||||
* A path's d attribute.
|
||||
*/
|
||||
ControllablePath.prototype.toD = function () {
|
||||
var dOption = this.options.d;
|
||||
if (dOption) {
|
||||
return typeof dOption === 'function' ?
|
||||
dOption.call(this) :
|
||||
dOption;
|
||||
}
|
||||
var points = this.points, len = points.length, d = [];
|
||||
var showPath = len, point = points[0], position = showPath && this.anchor(point).absolutePosition, pointIndex = 0, command;
|
||||
if (position) {
|
||||
d.push(['M', position.x, position.y]);
|
||||
while (++pointIndex < len && showPath) {
|
||||
point = points[pointIndex];
|
||||
command = point.command || 'L';
|
||||
position = this.anchor(point).absolutePosition;
|
||||
if (command === 'M') {
|
||||
d.push([command, position.x, position.y]);
|
||||
}
|
||||
else if (command === 'L') {
|
||||
d.push([command, position.x, position.y]);
|
||||
}
|
||||
else if (command === 'Z') {
|
||||
d.push([command]);
|
||||
}
|
||||
showPath = point.series.visible;
|
||||
}
|
||||
}
|
||||
return (showPath && this.graphic ?
|
||||
this.chart.renderer.crispLine(d, this.graphic.strokeWidth()) :
|
||||
null);
|
||||
};
|
||||
ControllablePath.prototype.shouldBeDrawn = function () {
|
||||
return _super.prototype.shouldBeDrawn.call(this) || !!this.options.d;
|
||||
};
|
||||
ControllablePath.prototype.render = function (parent) {
|
||||
var options = this.options, attrs = this.attrsFromOptions(options);
|
||||
this.graphic = this.annotation.chart.renderer
|
||||
.path([['M', 0, 0]])
|
||||
.attr(attrs)
|
||||
.add(parent);
|
||||
if (options.className) {
|
||||
this.graphic.addClass(options.className);
|
||||
}
|
||||
this.tracker = this.annotation.chart.renderer
|
||||
.path([['M', 0, 0]])
|
||||
.addClass('highcharts-tracker-line')
|
||||
.attr({
|
||||
zIndex: 2
|
||||
})
|
||||
.add(parent);
|
||||
if (!this.annotation.chart.styledMode) {
|
||||
this.tracker.attr({
|
||||
'stroke-linejoin': 'round',
|
||||
stroke: TRACKER_FILL,
|
||||
fill: TRACKER_FILL,
|
||||
'stroke-width': this.graphic.strokeWidth() +
|
||||
options.snap * 2
|
||||
});
|
||||
}
|
||||
_super.prototype.render.call(this);
|
||||
extend(this.graphic, { markerStartSetter: markerStartSetter, markerEndSetter: markerEndSetter });
|
||||
this.setMarkers(this);
|
||||
};
|
||||
ControllablePath.prototype.redraw = function (animation) {
|
||||
if (this.graphic) {
|
||||
var d = this.toD(), action = animation ? 'animate' : 'attr';
|
||||
if (d) {
|
||||
this.graphic[action]({ d: d });
|
||||
this.tracker[action]({ d: d });
|
||||
}
|
||||
else {
|
||||
this.graphic.attr({ d: 'M 0 ' + -9e9 });
|
||||
this.tracker.attr({ d: 'M 0 ' + -9e9 });
|
||||
}
|
||||
this.graphic.placed = this.tracker.placed = !!d;
|
||||
}
|
||||
_super.prototype.redraw.call(this, animation);
|
||||
};
|
||||
/**
|
||||
* Set markers.
|
||||
* @private
|
||||
* @param {Highcharts.AnnotationControllablePath} item
|
||||
*/
|
||||
ControllablePath.prototype.setMarkers = function (item) {
|
||||
var itemOptions = item.options, chart = item.chart, defs = chart.options.defs, fill = itemOptions.fill, color = defined(fill) && fill !== 'none' ?
|
||||
fill :
|
||||
itemOptions.stroke;
|
||||
var setMarker = function (markerType) {
|
||||
var markerId = itemOptions[markerType], def, predefinedMarker, key, marker;
|
||||
if (markerId) {
|
||||
for (key in defs) { // eslint-disable-line guard-for-in
|
||||
def = defs[key];
|
||||
if ((markerId === (def.attributes && def.attributes.id) ||
|
||||
// Legacy, for
|
||||
// unit-tests/annotations/annotations-shapes
|
||||
markerId === def.id) &&
|
||||
def.tagName === 'marker') {
|
||||
predefinedMarker = def;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (predefinedMarker) {
|
||||
marker = item[markerType] = chart.renderer
|
||||
.addMarker((itemOptions.id || uniqueKey()) + '-' + markerId, merge(predefinedMarker, { color: color }));
|
||||
item.attr(markerType, marker.getAttribute('id'));
|
||||
}
|
||||
}
|
||||
};
|
||||
['markerStart', 'markerEnd']
|
||||
.forEach(setMarker);
|
||||
};
|
||||
/* *
|
||||
*
|
||||
* Static Properties
|
||||
*
|
||||
* */
|
||||
/**
|
||||
* A map object which allows to map options attributes to element attributes
|
||||
*
|
||||
* @name Highcharts.AnnotationControllablePath.attrsMap
|
||||
* @type {Highcharts.Dictionary<string>}
|
||||
*/
|
||||
ControllablePath.attrsMap = {
|
||||
dashStyle: 'dashstyle',
|
||||
strokeWidth: 'stroke-width',
|
||||
stroke: 'stroke',
|
||||
fill: 'fill',
|
||||
zIndex: 'zIndex'
|
||||
};
|
||||
return ControllablePath;
|
||||
}(Controllable));
|
||||
/* *
|
||||
*
|
||||
* Default Export
|
||||
*
|
||||
* */
|
||||
export default ControllablePath;
|
||||
@@ -0,0 +1,122 @@
|
||||
/* *
|
||||
*
|
||||
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
|
||||
*
|
||||
* */
|
||||
'use strict';
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
import Controllable from './Controllable.js';
|
||||
import ControllablePath from './ControllablePath.js';
|
||||
import U from '../../../Core/Utilities.js';
|
||||
var merge = U.merge;
|
||||
/* *
|
||||
*
|
||||
* Class
|
||||
*
|
||||
* */
|
||||
/**
|
||||
* A controllable rect class.
|
||||
*
|
||||
* @requires modules/annotations
|
||||
*
|
||||
* @private
|
||||
* @class
|
||||
* @name Highcharts.AnnotationControllableRect
|
||||
*
|
||||
* @param {Highcharts.Annotation} annotation
|
||||
* An annotation instance.
|
||||
*
|
||||
* @param {Highcharts.AnnotationsShapeOptions} options
|
||||
* A rect's options.
|
||||
*
|
||||
* @param {number} index
|
||||
* Index of the rectangle
|
||||
*/
|
||||
var ControllableRect = /** @class */ (function (_super) {
|
||||
__extends(ControllableRect, _super);
|
||||
/* *
|
||||
*
|
||||
* Constructors
|
||||
*
|
||||
* */
|
||||
function ControllableRect(annotation, options, index) {
|
||||
var _this = _super.call(this, annotation, options, index, 'shape') || this;
|
||||
/* *
|
||||
*
|
||||
* Properties
|
||||
*
|
||||
* */
|
||||
_this.type = 'rect';
|
||||
_this.translate = _super.prototype.translateShape;
|
||||
return _this;
|
||||
}
|
||||
/* *
|
||||
*
|
||||
* Functions
|
||||
*
|
||||
* */
|
||||
ControllableRect.prototype.render = function (parent) {
|
||||
var attrs = this.attrsFromOptions(this.options);
|
||||
this.graphic = this.annotation.chart.renderer
|
||||
.rect(0, -9e9, 0, 0)
|
||||
.attr(attrs)
|
||||
.add(parent);
|
||||
_super.prototype.render.call(this);
|
||||
};
|
||||
ControllableRect.prototype.redraw = function (animation) {
|
||||
if (this.graphic) {
|
||||
var position = this.anchor(this.points[0]).absolutePosition;
|
||||
if (position) {
|
||||
this.graphic[animation ? 'animate' : 'attr']({
|
||||
x: position.x,
|
||||
y: position.y,
|
||||
width: this.options.width,
|
||||
height: this.options.height
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.attr({
|
||||
x: 0,
|
||||
y: -9e9
|
||||
});
|
||||
}
|
||||
this.graphic.placed = Boolean(position);
|
||||
}
|
||||
_super.prototype.redraw.call(this, animation);
|
||||
};
|
||||
/* *
|
||||
*
|
||||
* Static Properties
|
||||
*
|
||||
* */
|
||||
/**
|
||||
* A map object which allows to map options attributes to element attributes
|
||||
*
|
||||
* @type {Annotation.ControllableRect.AttrsMap}
|
||||
*/
|
||||
ControllableRect.attrsMap = merge(ControllablePath.attrsMap, {
|
||||
width: 'width',
|
||||
height: 'height'
|
||||
});
|
||||
return ControllableRect;
|
||||
}(Controllable));
|
||||
/* *
|
||||
*
|
||||
* Default Export
|
||||
*
|
||||
* */
|
||||
export default ControllableRect;
|
||||
Reference in New Issue
Block a user