1 | import { __extends } from "tslib";
|
2 | import Displayable, { DEFAULT_COMMON_STYLE, DEFAULT_COMMON_ANIMATION_PROPS } from './Displayable.js';
|
3 | import BoundingRect from '../core/BoundingRect.js';
|
4 | import { defaults, createObject } from '../core/util.js';
|
5 | export var DEFAULT_IMAGE_STYLE = defaults({
|
6 | x: 0,
|
7 | y: 0
|
8 | }, DEFAULT_COMMON_STYLE);
|
9 | export var DEFAULT_IMAGE_ANIMATION_PROPS = {
|
10 | style: defaults({
|
11 | x: true,
|
12 | y: true,
|
13 | width: true,
|
14 | height: true,
|
15 | sx: true,
|
16 | sy: true,
|
17 | sWidth: true,
|
18 | sHeight: true
|
19 | }, DEFAULT_COMMON_ANIMATION_PROPS.style)
|
20 | };
|
21 | function isImageLike(source) {
|
22 | return !!(source
|
23 | && typeof source !== 'string'
|
24 | && source.width && source.height);
|
25 | }
|
26 | var ZRImage = (function (_super) {
|
27 | __extends(ZRImage, _super);
|
28 | function ZRImage() {
|
29 | return _super !== null && _super.apply(this, arguments) || this;
|
30 | }
|
31 | ZRImage.prototype.createStyle = function (obj) {
|
32 | return createObject(DEFAULT_IMAGE_STYLE, obj);
|
33 | };
|
34 | ZRImage.prototype._getSize = function (dim) {
|
35 | var style = this.style;
|
36 | var size = style[dim];
|
37 | if (size != null) {
|
38 | return size;
|
39 | }
|
40 | var imageSource = isImageLike(style.image)
|
41 | ? style.image : this.__image;
|
42 | if (!imageSource) {
|
43 | return 0;
|
44 | }
|
45 | var otherDim = dim === 'width' ? 'height' : 'width';
|
46 | var otherDimSize = style[otherDim];
|
47 | if (otherDimSize == null) {
|
48 | return imageSource[dim];
|
49 | }
|
50 | else {
|
51 | return imageSource[dim] / imageSource[otherDim] * otherDimSize;
|
52 | }
|
53 | };
|
54 | ZRImage.prototype.getWidth = function () {
|
55 | return this._getSize('width');
|
56 | };
|
57 | ZRImage.prototype.getHeight = function () {
|
58 | return this._getSize('height');
|
59 | };
|
60 | ZRImage.prototype.getAnimationStyleProps = function () {
|
61 | return DEFAULT_IMAGE_ANIMATION_PROPS;
|
62 | };
|
63 | ZRImage.prototype.getBoundingRect = function () {
|
64 | var style = this.style;
|
65 | if (!this._rect) {
|
66 | this._rect = new BoundingRect(style.x || 0, style.y || 0, this.getWidth(), this.getHeight());
|
67 | }
|
68 | return this._rect;
|
69 | };
|
70 | return ZRImage;
|
71 | }(Displayable));
|
72 | ZRImage.prototype.type = 'image';
|
73 | export default ZRImage;
|