ControllableImage.js
2.44 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
'use strict';
import H from './../../parts/Globals.js';
import './../../parts/Utilities.js';
import controllableMixin from './controllableMixin.js';
import ControllableLabel from './ControllableLabel.js';
/**
 * A controllable image class.
 *
 * @class
 * @mixes Annotation.controllableMixin
 * @memberOf Annotation
 *
 * @param {Highcharts.Annotation} annotation - an annotation instance
 * @param {Object} options a controllable's options
 * @param {number} index of the image
 **/
function ControllableImage(annotation, options, index) {
    this.init(annotation, options, index);
    this.collection = 'shapes';
}
/**
 * @typedef {Object} Annotation.ControllableImage.AttrsMap
 * @property {string} width=width
 * @property {string} height=height
 * @property {string} zIndex=zIndex
 */
/**
 * A map object which allows to map options attributes to element attributes
 *
 * @type {Annotation.ControllableImage.AttrsMap}
 */
ControllableImage.attrsMap = {
    width: 'width',
    height: 'height',
    zIndex: 'zIndex'
};
H.merge(
    true,
    ControllableImage.prototype,
    controllableMixin, /** @lends Annotation.ControllableImage# */ {
        /**
         * @type 'image'
         */
        type: 'image',
        translate: controllableMixin.translateShape,
        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;
            controllableMixin.render.call(this);
        },
        redraw: function (animation) {
            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);
            controllableMixin.redraw.call(this, animation);
        }
    }
);
export default ControllableImage;