ControlPoint.js
3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import H from './../parts/Globals.js';
import './../parts/Utilities.js';
import eventEmitterMixin from './eventEmitterMixin.js';
/**
* A control point class which is a connection between controllable
* transform methods and a user actions.
*
* @constructor
* @mixes eventEmitterMixin
* @memberOf Annotation
*
* @param {Highcharts.Chart} chart a chart instance
* @param {Object} target a controllable instance which is a target for
* a control point
* @param {Annotation.ControlPoint.Options} options an options object
* @param {number} [index]
*/
function ControlPoint(chart, target, options, index) {
this.chart = chart;
this.target = target;
this.options = options;
this.index = H.pick(options.index, index);
}
/**
* @typedef {Object} Annotation.ControlPoint.Position
* @property {number} x
* @property {number} y
*/
/**
* @callback Annotation.ControlPoint.Positioner
* @param {Object} e event
* @param {Controllable} target
* @return {Annotation.ControlPoint.Position} position
*/
/**
* @typedef {Object} Annotation.ControlPoint.Options
* @property {string} symbol
* @property {number} width
* @property {number} height
* @property {Object} style
* @property {boolean} visible
* @property {Annotation.ControlPoint.Positioner} positioner
* @property {Object} events
*/
H.extend(
ControlPoint.prototype,
eventEmitterMixin
);
/**
* List of events for `anntation.options.events` that should not be
* added to `annotation.graphic` but to the `annotation`.
*
* @type {Array<string>}
*/
ControlPoint.prototype.nonDOMEvents = ['drag'];
/**
* Set the visibility.
*
* @param {boolean} [visible]
**/
ControlPoint.prototype.setVisibility = function (visible) {
this.graphic.attr('visibility', visible ? 'visible' : 'hidden');
this.options.visible = visible;
};
/**
* Render the control point.
*/
ControlPoint.prototype.render = function () {
var chart = this.chart,
options = this.options;
this.graphic = chart.renderer
.symbol(
options.symbol,
0,
0,
options.width,
options.height
)
.add(chart.controlPointsGroup)
.css(options.style);
this.setVisibility(options.visible);
this.addEvents();
};
/**
* Redraw the control point.
*
* @param {boolean} [animation]
*/
ControlPoint.prototype.redraw = function (animation) {
this.graphic[animation ? 'animate' : 'attr'](
this.options.positioner.call(this, this.target)
);
};
/**
* Destroy the control point.
*/
ControlPoint.prototype.destroy = function () {
eventEmitterMixin.destroy.call(this);
if (this.graphic) {
this.graphic = this.graphic.destroy();
}
this.chart = null;
this.target = null;
this.options = null;
};
/**
* Update the control point.
*/
ControlPoint.prototype.update = function (userOptions) {
var chart = this.chart,
target = this.target,
index = this.index,
options = H.merge(true, this.options, userOptions);
this.destroy();
this.constructor(chart, target, options, index);
this.render(chart.controlPointsGroup);
this.redraw();
};
export default ControlPoint;