UNPKG

520 kBJavaScriptView Raw
1(function webpackUniversalModuleDefinition(root, factory) {
2 if(typeof exports === 'object' && typeof module === 'object')
3 module.exports = factory();
4 else if(typeof define === 'function' && define.amd)
5 define([], factory);
6 else if(typeof exports === 'object')
7 exports["myF2"] = factory();
8 else
9 root["myF2"] = factory();
10})(typeof self !== 'undefined' ? self : this, function() {
11return /******/ (function(modules) { // webpackBootstrap
12/******/ // The module cache
13/******/ var installedModules = {};
14/******/
15/******/ // The require function
16/******/ function __webpack_require__(moduleId) {
17/******/
18/******/ // Check if module is in cache
19/******/ if(installedModules[moduleId]) {
20/******/ return installedModules[moduleId].exports;
21/******/ }
22/******/ // Create a new module (and put it into the cache)
23/******/ var module = installedModules[moduleId] = {
24/******/ i: moduleId,
25/******/ l: false,
26/******/ exports: {}
27/******/ };
28/******/
29/******/ // Execute the module function
30/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
31/******/
32/******/ // Flag the module as loaded
33/******/ module.l = true;
34/******/
35/******/ // Return the exports of the module
36/******/ return module.exports;
37/******/ }
38/******/
39/******/
40/******/ // expose the modules object (__webpack_modules__)
41/******/ __webpack_require__.m = modules;
42/******/
43/******/ // expose the module cache
44/******/ __webpack_require__.c = installedModules;
45/******/
46/******/ // define getter function for harmony exports
47/******/ __webpack_require__.d = function(exports, name, getter) {
48/******/ if(!__webpack_require__.o(exports, name)) {
49/******/ Object.defineProperty(exports, name, {
50/******/ configurable: false,
51/******/ enumerable: true,
52/******/ get: getter
53/******/ });
54/******/ }
55/******/ };
56/******/
57/******/ // getDefaultExport function for compatibility with non-harmony modules
58/******/ __webpack_require__.n = function(module) {
59/******/ var getter = module && module.__esModule ?
60/******/ function getDefault() { return module['default']; } :
61/******/ function getModuleExports() { return module; };
62/******/ __webpack_require__.d(getter, 'a', getter);
63/******/ return getter;
64/******/ };
65/******/
66/******/ // Object.prototype.hasOwnProperty.call
67/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
68/******/
69/******/ // __webpack_public_path__
70/******/ __webpack_require__.p = "";
71/******/
72/******/ // Load entry module and return exports
73/******/ return __webpack_require__(__webpack_require__.s = 48);
74/******/ })
75/************************************************************************/
76/******/ ([
77/* 0 */
78/***/ (function(module, exports, __webpack_require__) {
79
80/**
81 * @fileOverview Utility for F2
82 * @author dxq613 @gmail.com
83 * @author sima.zhang1990@gmail.com
84 */
85var DomUtil = __webpack_require__(54);
86
87var Util = {
88 upperFirst: __webpack_require__(55),
89 lowerFirst: __webpack_require__(56),
90 isString: __webpack_require__(13),
91 isNumber: __webpack_require__(14),
92 isBoolean: __webpack_require__(57),
93 isFunction: __webpack_require__(58),
94 isDate: __webpack_require__(31),
95 isArray: __webpack_require__(15),
96 isNil: __webpack_require__(10),
97 isObject: __webpack_require__(17),
98 isPlainObject: __webpack_require__(32),
99 deepMix: __webpack_require__(60),
100 mix: __webpack_require__(22),
101 each: __webpack_require__(5),
102 isObjectValueEqual: function isObjectValueEqual(a, b) {
103 // for vue.js
104 a = Object.assign({}, a);
105 b = Object.assign({}, b);
106 var aProps = Object.getOwnPropertyNames(a);
107 var bProps = Object.getOwnPropertyNames(b);
108
109 if (aProps.length !== bProps.length) {
110 return false;
111 }
112
113 for (var i = 0, len = aProps.length; i < len; i++) {
114 var propName = aProps[i];
115
116 if (a[propName] !== b[propName]) {
117 return false;
118 }
119 }
120
121 return true;
122 },
123 wrapBehavior: function wrapBehavior(obj, action) {
124 if (obj['_wrap_' + action]) {
125 return obj['_wrap_' + action];
126 }
127
128 var method = function method(e) {
129 obj[action](e);
130 };
131
132 obj['_wrap_' + action] = method;
133 return method;
134 },
135 getWrapBehavior: function getWrapBehavior(obj, action) {
136 return obj['_wrap_' + action];
137 },
138 parsePadding: function parsePadding(padding) {
139 var top;
140 var right;
141 var bottom;
142 var left;
143
144 if (Util.isNumber(padding) || Util.isString(padding)) {
145 top = bottom = left = right = padding;
146 } else if (Util.isArray(padding)) {
147 top = padding[0];
148 right = !Util.isNil(padding[1]) ? padding[1] : padding[0];
149 bottom = !Util.isNil(padding[2]) ? padding[2] : padding[0];
150 left = !Util.isNil(padding[3]) ? padding[3] : right;
151 }
152
153 return [top, right, bottom, left];
154 },
155 directionEnabled: function directionEnabled(mode, dir) {
156 if (mode === undefined) {
157 return true;
158 } else if (typeof mode === 'string') {
159 return mode.indexOf(dir) !== -1;
160 }
161
162 return false;
163 }
164};
165Util.Array = {
166 merge: function merge(dataArray) {
167 var rst = [];
168
169 for (var i = 0, len = dataArray.length; i < len; i++) {
170 rst = rst.concat(dataArray[i]);
171 }
172
173 return rst;
174 },
175 values: function values(data, name) {
176 var rst = [];
177 var tmpMap = {};
178
179 for (var i = 0, len = data.length; i < len; i++) {
180 var obj = data[i];
181 var value = obj[name];
182
183 if (!Util.isNil(value)) {
184 if (!Util.isArray(value)) {
185 if (!tmpMap[value]) {
186 rst.push(value);
187 tmpMap[value] = true;
188 }
189 } else {
190 Util.each(value, function (val) {
191 if (!tmpMap[val]) {
192 rst.push(val);
193 tmpMap[val] = true;
194 }
195 });
196 }
197 }
198 }
199
200 return rst;
201 },
202 firstValue: function firstValue(data, name) {
203 var rst = null;
204
205 for (var i = 0, len = data.length; i < len; i++) {
206 var obj = data[i];
207 var value = obj[name];
208
209 if (!Util.isNil(value)) {
210 if (Util.isArray(value)) {
211 rst = value[0];
212 } else {
213 rst = value;
214 }
215
216 break;
217 }
218 }
219
220 return rst;
221 },
222 group: function group(data, fields, appendConditions) {
223 if (appendConditions === void 0) {
224 appendConditions = {};
225 }
226
227 if (!fields) {
228 return [data];
229 }
230
231 var groups = Util.Array.groupToMap(data, fields);
232 var array = [];
233
234 if (fields.length === 1 && appendConditions[fields[0]]) {
235 var values = appendConditions[fields[0]];
236 Util.each(values, function (value) {
237 value = '_' + value;
238 array.push(groups[value]);
239 });
240 } else {
241 for (var i in groups) {
242 array.push(groups[i]);
243 }
244 }
245
246 return array;
247 },
248 groupToMap: function groupToMap(data, fields) {
249 if (!fields) {
250 return {
251 0: data
252 };
253 }
254
255 var callback = function callback(row) {
256 var unique = '_';
257
258 for (var i = 0, l = fields.length; i < l; i++) {
259 unique += row[fields[i]] && row[fields[i]].toString();
260 }
261
262 return unique;
263 };
264
265 var groups = {};
266
267 for (var i = 0, len = data.length; i < len; i++) {
268 var row = data[i];
269 var key = callback(row);
270
271 if (groups[key]) {
272 groups[key].push(row);
273 } else {
274 groups[key] = [row];
275 }
276 }
277
278 return groups;
279 },
280 remove: function remove(arr, obj) {
281 if (!arr) {
282 return;
283 }
284
285 var index = arr.indexOf(obj);
286
287 if (index !== -1) {
288 arr.splice(index, 1);
289 }
290 },
291 getRange: function getRange(values) {
292 if (!values.length) {
293 return {
294 min: 0,
295 max: 0
296 };
297 }
298
299 var max = Math.max.apply(null, values);
300 var min = Math.min.apply(null, values);
301 return {
302 min: min,
303 max: max
304 };
305 }
306};
307Util.mix(Util, DomUtil);
308module.exports = Util;
309
310/***/ }),
311/* 1 */
312/***/ (function(module, exports, __webpack_require__) {
313
314var Theme = __webpack_require__(53);
315
316var Util = __webpack_require__(0);
317
318var Global = {
319 version: '3.3.5',
320 scales: {},
321 widthRatio: {
322 column: 1 / 2,
323 rose: 0.999999,
324 multiplePie: 3 / 4
325 },
326 lineDash: [4, 4]
327};
328
329Global.setTheme = function (theme) {
330 Util.deepMix(this, theme);
331};
332
333Global.setTheme(Theme);
334module.exports = Global;
335
336/***/ }),
337/* 2 */
338/***/ (function(module, exports, __webpack_require__) {
339
340function _inheritsLoose(subClass, superClass) {
341 subClass.prototype = Object.create(superClass.prototype);
342 subClass.prototype.constructor = subClass;
343 subClass.__proto__ = superClass;
344}
345
346var Util = __webpack_require__(0);
347
348var Element = __webpack_require__(26);
349
350var Shape =
351/*#__PURE__*/
352function (_Element) {
353 _inheritsLoose(Shape, _Element);
354
355 function Shape() {
356 return _Element.apply(this, arguments) || this;
357 }
358
359 var _proto = Shape.prototype;
360
361 _proto._initProperties = function _initProperties() {
362 this._attrs = {
363 zIndex: 0,
364 visible: true,
365 destroyed: false,
366 isShape: true,
367 attrs: {}
368 };
369 };
370
371 _proto.getType = function getType() {
372 return this._attrs.type;
373 };
374
375 _proto.drawInner = function drawInner(context) {
376 var self = this;
377 var attrs = self.get('attrs');
378 self.createPath(context);
379 var originOpacity = context.globalAlpha;
380
381 if (self.hasFill()) {
382 var fillOpacity = attrs.fillOpacity;
383
384 if (!Util.isNil(fillOpacity) && fillOpacity !== 1) {
385 context.globalAlpha = fillOpacity;
386 context.fill();
387 context.globalAlpha = originOpacity;
388 } else {
389 context.fill();
390 }
391 }
392
393 if (self.hasStroke()) {
394 var lineWidth = attrs.lineWidth;
395
396 if (lineWidth > 0) {
397 var strokeOpacity = attrs.strokeOpacity;
398
399 if (!Util.isNil(strokeOpacity) && strokeOpacity !== 1) {
400 context.globalAlpha = strokeOpacity;
401 }
402
403 context.stroke();
404 }
405 }
406 };
407
408 _proto.getBBox = function getBBox() {
409 var bbox = this._attrs.bbox;
410
411 if (!bbox) {
412 bbox = this.calculateBox();
413
414 if (bbox) {
415 bbox.x = bbox.minX;
416 bbox.y = bbox.minY;
417 bbox.width = bbox.maxX - bbox.minX;
418 bbox.height = bbox.maxY - bbox.minY;
419 }
420
421 this._attrs.bbox = bbox;
422 }
423
424 return bbox;
425 };
426
427 _proto.calculateBox = function calculateBox() {
428 return null;
429 };
430
431 _proto.createPath = function createPath() {};
432
433 return Shape;
434}(Element);
435
436module.exports = Shape;
437
438/***/ }),
439/* 3 */
440/***/ (function(module, exports, __webpack_require__) {
441
442var G = {
443 Canvas: __webpack_require__(80),
444 Group: __webpack_require__(37),
445 Shape: __webpack_require__(2),
446 Matrix: __webpack_require__(27),
447 Vector2: __webpack_require__(7)
448};
449
450__webpack_require__(82);
451
452__webpack_require__(83);
453
454__webpack_require__(84);
455
456__webpack_require__(85);
457
458__webpack_require__(86);
459
460__webpack_require__(87);
461
462__webpack_require__(88);
463
464__webpack_require__(89);
465
466__webpack_require__(90);
467
468module.exports = G;
469
470/***/ }),
471/* 4 */
472/***/ (function(module, exports, __webpack_require__) {
473
474function _inheritsLoose(subClass, superClass) {
475 subClass.prototype = Object.create(superClass.prototype);
476 subClass.prototype.constructor = subClass;
477 subClass.__proto__ = superClass;
478}
479
480var Util = __webpack_require__(0);
481
482var Base = __webpack_require__(33);
483
484var GROUP_ATTRS = ['color', 'size', 'shape'];
485var FIELD_ORIGIN = '_origin';
486var FIELD_ORIGIN_Y = '_originY';
487
488var Global = __webpack_require__(1);
489
490var Attr = __webpack_require__(64);
491
492var GeometryShape = __webpack_require__(6);
493
494var Adjust = __webpack_require__(24);
495
496function parseFields(field) {
497 if (Util.isArray(field)) {
498 return field;
499 }
500
501 if (Util.isString(field)) {
502 return field.split('*');
503 }
504
505 return [field];
506}
507/**
508 * The parent class for Geometry
509 * @class Geom
510 */
511
512
513var Geom =
514/*#__PURE__*/
515function (_Base) {
516 _inheritsLoose(Geom, _Base);
517
518 function Geom() {
519 return _Base.apply(this, arguments) || this;
520 }
521
522 var _proto = Geom.prototype;
523
524 _proto.getDefaultCfg = function getDefaultCfg() {
525 return {
526 /**
527 * geometry type
528 * @type {String}
529 */
530 type: null,
531
532 /**
533 * the data of geometry
534 * @type {Array}
535 */
536 data: null,
537
538 /**
539 * the attrs of geo,etry
540 * @type {Object}
541 */
542 attrs: {},
543 scales: {},
544
545 /**
546 * group for storing the shapes
547 * @type {Canvas}
548 */
549 container: null,
550
551 /**
552 * style options
553 * @type {Object}
554 */
555 styleOptions: null,
556 chart: null,
557 shapeType: '',
558
559 /**
560 * wether to generate key points for each shape
561 * @protected
562 * @type {Boolean}
563 */
564 generatePoints: false,
565 attrOptions: {},
566 sortable: false,
567 startOnZero: true,
568 visible: true,
569 connectNulls: false
570 };
571 };
572
573 _proto.init = function init() {
574 var self = this;
575
576 self._initAttrs();
577
578 var dataArray = self._processData();
579
580 if (self.get('adjust')) {
581 self._adjustData(dataArray);
582 }
583
584 self.set('dataArray', dataArray);
585 };
586
587 _proto._getGroupScales = function _getGroupScales() {
588 var self = this;
589 var scales = [];
590 Util.each(GROUP_ATTRS, function (attrName) {
591 var attr = self.getAttr(attrName);
592
593 if (attr) {
594 var attrScales = attr.scales;
595 Util.each(attrScales, function (scale) {
596 if (scale && scale.isCategory && scales.indexOf(scale) === -1) {
597 scales.push(scale);
598 }
599 });
600 }
601 });
602 return scales;
603 };
604
605 _proto._groupData = function _groupData(data) {
606 var self = this;
607 var colDefs = self.get('colDefs');
608
609 var groupScales = self._getGroupScales();
610
611 if (groupScales.length) {
612 var appendConditions = {};
613 var names = [];
614 Util.each(groupScales, function (scale) {
615 var field = scale.field;
616 names.push(field);
617
618 if (colDefs && colDefs[field] && colDefs[field].values) {
619 // users have defined
620 appendConditions[scale.field] = colDefs[field].values;
621 }
622 });
623 return Util.Array.group(data, names, appendConditions);
624 }
625
626 return [data];
627 };
628
629 _proto._setAttrOptions = function _setAttrOptions(attrName, attrCfg) {
630 var options = this.get('attrOptions');
631 options[attrName] = attrCfg;
632 };
633
634 _proto._createAttrOption = function _createAttrOption(attrName, field, cfg, defaultValues) {
635 var attrCfg = {};
636 attrCfg.field = field;
637
638 if (cfg) {
639 if (Util.isFunction(cfg)) {
640 attrCfg.callback = cfg;
641 } else {
642 attrCfg.values = cfg;
643 }
644 } else {
645 attrCfg.values = defaultValues;
646 }
647
648 this._setAttrOptions(attrName, attrCfg);
649 };
650
651 _proto._initAttrs = function _initAttrs() {
652 var self = this;
653 var attrs = self.get('attrs');
654 var attrOptions = self.get('attrOptions');
655 var coord = self.get('coord');
656
657 for (var type in attrOptions) {
658 if (attrOptions.hasOwnProperty(type)) {
659 var option = attrOptions[type];
660 var className = Util.upperFirst(type);
661 var fields = parseFields(option.field);
662
663 if (type === 'position') {
664 option.coord = coord;
665 }
666
667 var scales = [];
668
669 for (var i = 0, len = fields.length; i < len; i++) {
670 var field = fields[i];
671
672 var scale = self._createScale(field);
673
674 scales.push(scale);
675 }
676
677 if (type === 'position') {
678 var yScale = scales[1];
679
680 if (coord.type === 'polar' && coord.transposed && self.hasAdjust('stack')) {
681 if (yScale.values.length) {
682 yScale.change({
683 nice: false,
684 min: 0,
685 max: Math.max.apply(null, yScale.values)
686 });
687 }
688 }
689 }
690
691 option.scales = scales;
692 var attr = new Attr[className](option);
693 attrs[type] = attr;
694 }
695 }
696 };
697
698 _proto._createScale = function _createScale(field) {
699 var scales = this.get('scales');
700 var scale = scales[field];
701
702 if (!scale) {
703 scale = this.get('chart').createScale(field);
704 scales[field] = scale;
705 }
706
707 return scale;
708 };
709
710 _proto._processData = function _processData() {
711 var self = this;
712 var data = this.get('data');
713 var dataArray = [];
714
715 var groupedArray = this._groupData(data);
716
717 for (var i = 0, len = groupedArray.length; i < len; i++) {
718 var subData = groupedArray[i];
719
720 var tempData = self._saveOrigin(subData);
721
722 if (this.hasAdjust('dodge')) {
723 self._numberic(tempData);
724 }
725
726 dataArray.push(tempData);
727 }
728
729 return dataArray;
730 };
731
732 _proto._saveOrigin = function _saveOrigin(data) {
733 var rst = [];
734
735 for (var i = 0, len = data.length; i < len; i++) {
736 var origin = data[i];
737 var obj = {};
738
739 for (var k in origin) {
740 obj[k] = origin[k];
741 }
742
743 obj[FIELD_ORIGIN] = origin;
744 rst.push(obj);
745 }
746
747 return rst;
748 };
749
750 _proto._numberic = function _numberic(data) {
751 var positionAttr = this.getAttr('position');
752 var scales = positionAttr.scales;
753
754 for (var j = 0, len = data.length; j < len; j++) {
755 var obj = data[j];
756 var count = Math.min(2, scales.length);
757
758 for (var i = 0; i < count; i++) {
759 var scale = scales[i];
760
761 if (scale.isCategory) {
762 var field = scale.field;
763 obj[field] = scale.translate(obj[field]);
764 }
765 }
766 }
767 };
768
769 _proto._adjustData = function _adjustData(dataArray) {
770 var self = this;
771 var adjust = self.get('adjust');
772
773 if (adjust) {
774 var adjustType = Util.upperFirst(adjust.type);
775
776 if (!Adjust[adjustType]) {
777 throw new Error('not support such adjust : ' + adjust);
778 }
779
780 var xScale = self.getXScale();
781 var yScale = self.getYScale();
782 var cfg = Util.mix({
783 xField: xScale.field,
784 yField: yScale.field
785 }, adjust);
786 var adjustObject = new Adjust[adjustType](cfg);
787 adjustObject.processAdjust(dataArray);
788
789 if (adjustType === 'Stack') {
790 self._updateStackRange(yScale.field, yScale, dataArray);
791 }
792 }
793 };
794
795 _proto._updateStackRange = function _updateStackRange(field, scale, dataArray) {
796 var mergeArray = Util.Array.merge(dataArray);
797 var min = scale.min;
798 var max = scale.max;
799
800 for (var i = 0, len = mergeArray.length; i < len; i++) {
801 var obj = mergeArray[i];
802 var tmpMin = Math.min.apply(null, obj[field]);
803 var tmpMax = Math.max.apply(null, obj[field]);
804
805 if (tmpMin < min) {
806 min = tmpMin;
807 }
808
809 if (tmpMax > max) {
810 max = tmpMax;
811 }
812 }
813
814 if (min < scale.min || max > scale.max) {
815 scale.change({
816 min: min,
817 max: max
818 });
819 }
820 };
821
822 _proto._sort = function _sort(mappedArray) {
823 var self = this;
824 var xScale = self.getXScale();
825 var field = xScale.field,
826 type = xScale.type;
827
828 if (type !== 'identity' && xScale.values.length > 1) {
829 Util.each(mappedArray, function (itemArr) {
830 itemArr.sort(function (obj1, obj2) {
831 if (type === 'timeCat') {
832 return xScale._toTimeStamp(obj1[FIELD_ORIGIN][field]) - xScale._toTimeStamp(obj2[FIELD_ORIGIN][field]);
833 }
834
835 return xScale.translate(obj1[FIELD_ORIGIN][field]) - xScale.translate(obj2[FIELD_ORIGIN][field]);
836 });
837 });
838 }
839
840 self.set('hasSorted', true);
841 self.set('dataArray', mappedArray);
842 };
843
844 _proto.paint = function paint() {
845 var self = this;
846 var dataArray = self.get('dataArray');
847 var mappedArray = [];
848 var shapeFactory = self.getShapeFactory();
849 shapeFactory.setCoord(self.get('coord'));
850
851 self._beforeMapping(dataArray);
852
853 for (var i = 0, len = dataArray.length; i < len; i++) {
854 var data = dataArray[i];
855
856 if (data.length) {
857 data = self._mapping(data);
858 mappedArray.push(data);
859 self.draw(data, shapeFactory);
860 }
861 }
862
863 self.set('dataArray', mappedArray);
864 };
865
866 _proto.getShapeFactory = function getShapeFactory() {
867 var shapeFactory = this.get('shapeFactory');
868
869 if (!shapeFactory) {
870 var shapeType = this.get('shapeType');
871 shapeFactory = GeometryShape.getShapeFactory(shapeType);
872 this.set('shapeFactory', shapeFactory);
873 }
874
875 return shapeFactory;
876 };
877
878 _proto._mapping = function _mapping(data) {
879 var self = this;
880 var attrs = self.get('attrs');
881 var yField = self.getYScale().field;
882 var mappedData = [];
883
884 for (var i = 0, len = data.length; i < len; i++) {
885 var record = data[i];
886 var newRecord = {};
887 newRecord[FIELD_ORIGIN] = record[FIELD_ORIGIN];
888 newRecord.points = record.points; // 避免
889
890 newRecord[FIELD_ORIGIN_Y] = record[yField];
891
892 for (var k in attrs) {
893 if (attrs.hasOwnProperty(k)) {
894 var attr = attrs[k];
895 var names = attr.names;
896
897 var values = self._getAttrValues(attr, record);
898
899 if (names.length > 1) {
900 for (var j = 0, _len = values.length; j < _len; j++) {
901 var val = values[j];
902 var name = names[j];
903 newRecord[name] = Util.isArray(val) && val.length === 1 ? val[0] : val;
904 }
905 } else {
906 newRecord[names[0]] = values.length === 1 ? values[0] : values;
907 }
908 }
909 }
910
911 mappedData.push(newRecord);
912 }
913
914 return mappedData;
915 };
916
917 _proto._getAttrValues = function _getAttrValues(attr, record) {
918 var scales = attr.scales;
919 var params = [];
920
921 for (var i = 0, len = scales.length; i < len; i++) {
922 var scale = scales[i];
923 var field = scale.field;
924
925 if (scale.type === 'identity') {
926 params.push(scale.value);
927 } else {
928 params.push(record[field]);
929 }
930 }
931
932 var values = attr.mapping.apply(attr, params);
933 return values;
934 };
935
936 _proto.getAttrValue = function getAttrValue(attrName, record) {
937 var attr = this.getAttr(attrName);
938 var rst = null;
939
940 if (attr) {
941 var values = this._getAttrValues(attr, record);
942
943 rst = values[0];
944 }
945
946 return rst;
947 };
948
949 _proto._beforeMapping = function _beforeMapping(dataArray) {
950 var self = this;
951
952 if (self.get('sortable')) {
953 self._sort(dataArray);
954 }
955
956 if (self.get('generatePoints')) {
957 Util.each(dataArray, function (data) {
958 self._generatePoints(data);
959 });
960 }
961 };
962
963 _proto.isInCircle = function isInCircle() {
964 var coord = this.get('coord');
965 return coord && coord.isPolar;
966 };
967
968 _proto.getCallbackCfg = function getCallbackCfg(fields, cfg, origin) {
969 if (!fields) {
970 return cfg;
971 }
972
973 var tmpCfg = {};
974 var params = fields.map(function (field) {
975 return origin[field];
976 });
977 Util.each(cfg, function (v, k) {
978 if (Util.isFunction(v)) {
979 tmpCfg[k] = v.apply(null, params);
980 } else {
981 tmpCfg[k] = v;
982 }
983 });
984 return tmpCfg;
985 };
986
987 _proto.getDrawCfg = function getDrawCfg(obj) {
988 var self = this;
989 var isInCircle = self.isInCircle();
990 var cfg = {
991 origin: obj,
992 x: obj.x,
993 y: obj.y,
994 color: obj.color,
995 size: obj.size,
996 shape: obj.shape,
997 isInCircle: isInCircle,
998 opacity: obj.opacity
999 };
1000 var styleOptions = self.get('styleOptions');
1001
1002 if (styleOptions && styleOptions.style) {
1003 cfg.style = self.getCallbackCfg(styleOptions.fields, styleOptions.style, obj[FIELD_ORIGIN]);
1004 }
1005
1006 if (self.get('generatePoints')) {
1007 cfg.points = obj.points;
1008 }
1009
1010 if (isInCircle) {
1011 cfg.center = self.get('coord').center;
1012 }
1013
1014 return cfg;
1015 };
1016
1017 _proto.draw = function draw(data, shapeFactory) {
1018 var self = this;
1019 var container = self.get('container');
1020 var yScale = self.getYScale();
1021 Util.each(data, function (obj, index) {
1022 if (yScale && Util.isNil(obj._origin[yScale.field])) {
1023 return;
1024 }
1025
1026 obj.index = index;
1027 var cfg = self.getDrawCfg(obj);
1028 var shape = obj.shape;
1029 self.drawShape(shape, obj, cfg, container, shapeFactory);
1030 });
1031 };
1032
1033 _proto.drawShape = function drawShape(shape, shapeData, cfg, container, shapeFactory) {
1034 var gShape = shapeFactory.drawShape(shape, cfg, container);
1035
1036 if (gShape) {
1037 Util.each([].concat(gShape), function (s) {
1038 s.set('origin', shapeData);
1039 });
1040 }
1041 };
1042
1043 _proto._generatePoints = function _generatePoints(data) {
1044 var self = this;
1045 var shapeFactory = self.getShapeFactory();
1046 var shapeAttr = self.getAttr('shape');
1047
1048 for (var i = 0, len = data.length; i < len; i++) {
1049 var obj = data[i];
1050 var cfg = self.createShapePointsCfg(obj);
1051 var shape = shapeAttr ? self._getAttrValues(shapeAttr, obj) : null;
1052 var points = shapeFactory.getShapePoints(shape, cfg);
1053 obj.points = points;
1054 }
1055 }
1056 /**
1057 * get the info of each shape
1058 * @protected
1059 * @param {Object} obj the data item
1060 * @return {Object} cfg return the result
1061 */
1062 ;
1063
1064 _proto.createShapePointsCfg = function createShapePointsCfg(obj) {
1065 var xScale = this.getXScale();
1066 var yScale = this.getYScale();
1067
1068 var x = this._normalizeValues(obj[xScale.field], xScale);
1069
1070 var y;
1071
1072 if (yScale) {
1073 y = this._normalizeValues(obj[yScale.field], yScale);
1074 } else {
1075 y = obj.y ? obj.y : 0.1;
1076 }
1077
1078 return {
1079 x: x,
1080 y: y,
1081 y0: yScale ? yScale.scale(this.getYMinValue()) : undefined
1082 };
1083 };
1084
1085 _proto.getYMinValue = function getYMinValue() {
1086 var yScale = this.getYScale();
1087 var min = yScale.min,
1088 max = yScale.max;
1089 var value;
1090
1091 if (this.get('startOnZero')) {
1092 if (max <= 0 && min <= 0) {
1093 value = max;
1094 } else {
1095 value = min >= 0 ? min : 0;
1096 }
1097 } else {
1098 value = min;
1099 }
1100
1101 return value;
1102 };
1103
1104 _proto._normalizeValues = function _normalizeValues(values, scale) {
1105 var rst = [];
1106
1107 if (Util.isArray(values)) {
1108 for (var i = 0, len = values.length; i < len; i++) {
1109 var v = values[i];
1110 rst.push(scale.scale(v));
1111 }
1112 } else {
1113 rst = scale.scale(values);
1114 }
1115
1116 return rst;
1117 };
1118
1119 _proto.getAttr = function getAttr(name) {
1120 return this.get('attrs')[name];
1121 };
1122
1123 _proto.getXScale = function getXScale() {
1124 return this.getAttr('position').scales[0];
1125 };
1126
1127 _proto.getYScale = function getYScale() {
1128 return this.getAttr('position').scales[1];
1129 };
1130
1131 _proto.hasAdjust = function hasAdjust(adjust) {
1132 return this.get('adjust') && this.get('adjust').type === adjust;
1133 };
1134
1135 _proto._getSnap = function _getSnap(scale, item, arr) {
1136 var i = 0;
1137 var values;
1138 var yField = this.getYScale().field; // 叠加的维度
1139
1140 if (this.hasAdjust('stack') && scale.field === yField) {
1141 values = [];
1142 arr.forEach(function (obj) {
1143 values.push(obj[FIELD_ORIGIN_Y]);
1144 });
1145
1146 for (var len = values.length; i < len; i++) {
1147 if (values[0][0] > item) {
1148 break;
1149 }
1150
1151 if (values[values.length - 1][1] <= item) {
1152 i = values.length - 1;
1153 break;
1154 }
1155
1156 if (values[i][0] <= item && values[i][1] > item) {
1157 break;
1158 }
1159 }
1160 } else {
1161 values = scale.values;
1162 values.sort(function (a, b) {
1163 return a - b;
1164 });
1165
1166 for (var _len2 = values.length; i < _len2; i++) {
1167 if ((values[0] + values[1]) / 2 > item) {
1168 break;
1169 }
1170
1171 if ((values[i - 1] + values[i]) / 2 <= item && (values[i + 1] + values[i]) / 2 > item) {
1172 break;
1173 }
1174
1175 if ((values[values.length - 2] + values[values.length - 1]) / 2 <= item) {
1176 i = values.length - 1;
1177 break;
1178 }
1179 }
1180 }
1181
1182 var result = values[i];
1183 return result;
1184 };
1185
1186 _proto.getSnapRecords = function getSnapRecords(point) {
1187 var self = this;
1188 var coord = self.get('coord');
1189 var xScale = self.getXScale();
1190 var yScale = self.getYScale();
1191 var xfield = xScale.field;
1192 var dataArray = self.get('dataArray');
1193
1194 if (!this.get('hasSorted')) {
1195 this._sort(dataArray);
1196 }
1197
1198 var rst = [];
1199 var invertPoint = coord.invertPoint(point);
1200 var invertPointX = invertPoint.x;
1201
1202 if (self.isInCircle() && !coord.transposed && invertPointX > (1 + xScale.rangeMax()) / 2) {
1203 invertPointX = xScale.rangeMin();
1204 }
1205
1206 var xValue = xScale.invert(invertPointX);
1207
1208 if (!xScale.isCategory) {
1209 xValue = self._getSnap(xScale, xValue);
1210 }
1211
1212 var tmp = [];
1213 dataArray.forEach(function (data) {
1214 data.forEach(function (obj) {
1215 var originValue = Util.isNil(obj[FIELD_ORIGIN]) ? obj[xfield] : obj[FIELD_ORIGIN][xfield];
1216
1217 if (self._isEqual(originValue, xValue, xScale)) {
1218 tmp.push(obj);
1219 }
1220 });
1221 }); // special for pie chart
1222
1223 if (this.hasAdjust('stack') && coord.isPolar && coord.transposed && xScale.values.length === 1) {
1224 if (invertPointX >= 0 && invertPointX <= 1) {
1225 var yValue = yScale.invert(invertPoint.y);
1226 yValue = self._getSnap(yScale, yValue, tmp);
1227 tmp.forEach(function (obj) {
1228 if (Util.isArray(yValue) ? obj[FIELD_ORIGIN_Y].toString() === yValue.toString() : obj[FIELD_ORIGIN_Y] === yValue) {
1229 rst.push(obj);
1230 }
1231 });
1232 }
1233 } else {
1234 rst = tmp;
1235 }
1236
1237 return rst;
1238 };
1239
1240 _proto._isEqual = function _isEqual(originValue, value, scale) {
1241 if (scale.type === 'timeCat') {
1242 return scale._toTimeStamp(originValue) === value;
1243 }
1244
1245 return value === originValue;
1246 };
1247
1248 _proto.position = function position(field) {
1249 this._setAttrOptions('position', {
1250 field: field
1251 });
1252
1253 return this;
1254 };
1255
1256 _proto.color = function color(field, values) {
1257 this._createAttrOption('color', field, values, Global.colors);
1258
1259 return this;
1260 };
1261
1262 _proto.size = function size(field, values) {
1263 this._createAttrOption('size', field, values, Global.sizes);
1264
1265 return this;
1266 };
1267
1268 _proto.shape = function shape(field, values) {
1269 var type = this.get('type');
1270 var shapes = Global.shapes[type] || [];
1271
1272 this._createAttrOption('shape', field, values, shapes);
1273
1274 return this;
1275 };
1276
1277 _proto.style = function style(field, cfg) {
1278 var styleOptions = this.get('styleOptions');
1279
1280 if (!styleOptions) {
1281 styleOptions = {};
1282 this.set('styleOptions', styleOptions);
1283 }
1284
1285 if (Util.isObject(field)) {
1286 cfg = field;
1287 field = null;
1288 }
1289
1290 var fields;
1291
1292 if (field) {
1293 fields = parseFields(field);
1294 }
1295
1296 styleOptions.fields = fields;
1297 styleOptions.style = cfg;
1298 return this;
1299 };
1300
1301 _proto.adjust = function adjust(type) {
1302 if (Util.isString(type)) {
1303 type = {
1304 type: type
1305 };
1306 }
1307
1308 this.set('adjust', type);
1309 return this;
1310 };
1311
1312 _proto.animate = function animate(cfg) {
1313 this.set('animateCfg', cfg);
1314 return this;
1315 };
1316
1317 _proto.reset = function reset() {
1318 this.set('attrOptions', {});
1319 this.set('adjust', null);
1320 this.clearInner();
1321 };
1322
1323 _proto.clearInner = function clearInner() {
1324 var container = this.get('container');
1325
1326 if (container) {
1327 container.clear();
1328 container.setMatrix([1, 0, 0, 1, 0, 0]);
1329 }
1330
1331 container && container.clear();
1332 this.set('attrs', {});
1333 this.set('groupScales', null);
1334 this.set('xDistance', null);
1335 this.set('_width', null);
1336 };
1337
1338 _proto.clear = function clear() {
1339 this.clearInner();
1340 this.set('scales', {});
1341 };
1342
1343 _proto.destroy = function destroy() {
1344 this.clear();
1345
1346 _Base.prototype.destroy.call(this);
1347 };
1348
1349 _proto._display = function _display(visible) {
1350 this.set('visible', visible);
1351 var container = this.get('container');
1352 var canvas = container.get('canvas');
1353 container.set('visible', visible);
1354 canvas.draw();
1355 };
1356
1357 _proto.show = function show() {
1358 this._display(true);
1359 };
1360
1361 _proto.hide = function hide() {
1362 this._display(false);
1363 };
1364
1365 return Geom;
1366}(Base);
1367
1368module.exports = Geom;
1369
1370/***/ }),
1371/* 5 */
1372/***/ (function(module, exports, __webpack_require__) {
1373
1374var isObject = __webpack_require__(17);
1375
1376var isArray = __webpack_require__(15);
1377
1378var each = function each(elements, func) {
1379 if (!elements) {
1380 return;
1381 }
1382
1383 var rst = void 0;
1384
1385 if (isArray(elements)) {
1386 for (var i = 0, len = elements.length; i < len; i++) {
1387 rst = func(elements[i], i);
1388
1389 if (rst === false) {
1390 break;
1391 }
1392 }
1393 } else if (isObject(elements)) {
1394 for (var k in elements) {
1395 if (elements.hasOwnProperty(k)) {
1396 rst = func(elements[k], k);
1397
1398 if (rst === false) {
1399 break;
1400 }
1401 }
1402 }
1403 }
1404};
1405
1406module.exports = each;
1407
1408/***/ }),
1409/* 6 */
1410/***/ (function(module, exports, __webpack_require__) {
1411
1412var Util = __webpack_require__(0);
1413
1414var Global = __webpack_require__(1);
1415
1416var Shape = {};
1417var ShapeBase = {
1418 _coord: null,
1419
1420 /**
1421 * draw the shape
1422 * @param {Object} cfg options
1423 * @param {Object} container container to store the shapes
1424 */
1425 draw: function draw(cfg, container) {
1426 if (this.drawShape) {
1427 this.drawShape(cfg, container);
1428 }
1429 },
1430
1431 /**
1432 * set the coordinate instance
1433 * @param {Coord} coord coordinate instance
1434 */
1435 setCoord: function setCoord(coord) {
1436 this._coord = coord;
1437 },
1438
1439 /**
1440 * convert the normalized value to the canvas position
1441 * @param {point} point the point to convert
1442 * @return {point} point return the result
1443 */
1444 parsePoint: function parsePoint(point) {
1445 var coord = this._coord;
1446
1447 if (coord.isPolar) {
1448 if (point.x === 1) point.x = 0.9999999;
1449 if (point.y === 1) point.y = 0.9999999;
1450 }
1451
1452 return coord.convertPoint(point);
1453 },
1454
1455 /**
1456 * convert the normalized value to the canvas position
1457 * @param {points} points the array that store the points
1458 * @return {points} points return the result
1459 */
1460 parsePoints: function parsePoints(points) {
1461 if (!points) return false;
1462 var self = this;
1463 var rst = [];
1464 points.forEach(function (point) {
1465 rst.push(self.parsePoint(point));
1466 });
1467 return rst;
1468 }
1469};
1470var ShapeFactoryBase = {
1471 defaultShapeType: null,
1472 setCoord: function setCoord(coord) {
1473 this._coord = coord;
1474 },
1475 getShape: function getShape(type) {
1476 var self = this;
1477
1478 if (Util.isArray(type)) {
1479 type = type[0];
1480 }
1481
1482 var shape = self[type] || self[self.defaultShapeType];
1483 shape._coord = self._coord;
1484 return shape;
1485 },
1486 getShapePoints: function getShapePoints(type, cfg) {
1487 var shape = this.getShape(type);
1488 var fn = shape.getPoints || shape.getShapePoints || this.getDefaultPoints;
1489 var points = fn(cfg);
1490 return points;
1491 },
1492 getDefaultPoints: function getDefaultPoints()
1493 /* cfg */
1494 {
1495 return [];
1496 },
1497 drawShape: function drawShape(type, cfg, container) {
1498 var shape = this.getShape(type);
1499
1500 if (!cfg.color) {
1501 cfg.color = Global.colors[0];
1502 }
1503
1504 return shape.draw(cfg, container);
1505 }
1506};
1507
1508Shape.registerFactory = function (factoryName, cfg) {
1509 var className = Util.upperFirst(factoryName);
1510 var geomObj = Util.mix({}, ShapeFactoryBase, cfg);
1511 Shape[className] = geomObj;
1512 geomObj.name = factoryName;
1513 return geomObj;
1514};
1515
1516Shape.registerShape = function (factoryName, shapeType, cfg) {
1517 var className = Util.upperFirst(factoryName);
1518 var factory = Shape[className];
1519 var shapeObj = Util.mix({}, ShapeBase, cfg);
1520 factory[shapeType] = shapeObj;
1521 return shapeObj;
1522};
1523
1524Shape.registShape = Shape.registerShape;
1525
1526Shape.getShapeFactory = function (factoryName) {
1527 var self = this;
1528 factoryName = factoryName || 'point';
1529 var className = Util.upperFirst(factoryName);
1530 return self[className];
1531};
1532
1533module.exports = Shape;
1534
1535/***/ }),
1536/* 7 */
1537/***/ (function(module, exports) {
1538
1539/**
1540 * 2 Dimensional Vector
1541 * @module vector2
1542 */
1543module.exports = {
1544 /**
1545 * Creates a new, empty vector2
1546 *
1547 * @return {vector2} a new 2D vector
1548 */
1549 create: function create() {
1550 return [0, 0];
1551 },
1552
1553 /**
1554 * Calculates the length of a vector2
1555 *
1556 * @param {vector2} v vector to calculate length of
1557 * @return {Number} length of v
1558 */
1559 length: function length(v) {
1560 var x = v[0];
1561 var y = v[1];
1562 return Math.sqrt(x * x + y * y);
1563 },
1564
1565 /**
1566 * Normalize a vector2
1567 *
1568 * @param {vector2} out the receiving vector
1569 * @param {vector2} v vector to normalize
1570 * @return {vector2} out
1571 */
1572 normalize: function normalize(out, v) {
1573 var len = this.length(v);
1574
1575 if (len === 0) {
1576 out[0] = 0;
1577 out[1] = 0;
1578 } else {
1579 out[0] = v[0] / len;
1580 out[1] = v[1] / len;
1581 }
1582
1583 return out;
1584 },
1585
1586 /**
1587 * Adds two vector2's
1588 *
1589 * @param {vector2} out the receiving vector
1590 * @param {vector2} v1 the first operand
1591 * @param {vector2} v2 the second operand
1592 * @return {vector2} out
1593 */
1594 add: function add(out, v1, v2) {
1595 out[0] = v1[0] + v2[0];
1596 out[1] = v1[1] + v2[1];
1597 return out;
1598 },
1599
1600 /**
1601 * Subtracts vector v2 from vector v1
1602 *
1603 * @param {vector2} out the receiving vector
1604 * @param {vector2} v1 the first operand
1605 * @param {vector2} v2 the second operand
1606 * @return {vector2} out
1607 */
1608 sub: function sub(out, v1, v2) {
1609 out[0] = v1[0] - v2[0];
1610 out[1] = v1[1] - v2[1];
1611 return out;
1612 },
1613
1614 /**
1615 * Scales a vector2 by a scalar number
1616 *
1617 * @param {vector2} out the receiving vector
1618 * @param {vector2} v the vector to scale
1619 * @param {Number} s amount to scale the vector by
1620 * @return {vector2} out
1621 */
1622 scale: function scale(out, v, s) {
1623 out[0] = v[0] * s;
1624 out[1] = v[1] * s;
1625 return out;
1626 },
1627
1628 /**
1629 * Calculates the dot product of two vector2's
1630 *
1631 * @param {vector2} v1 the first operand
1632 * @param {vector2} v2 the second operand
1633 * @return {Number} dot product of v1 and v2
1634 */
1635 dot: function dot(v1, v2) {
1636 return v1[0] * v2[0] + v1[1] * v2[1];
1637 },
1638
1639 /**
1640 * Calculates the direction of two vector2's
1641 *
1642 * @param {vector2} v1 the first operand
1643 * @param {vector2} v2 the second operand
1644 * @return {Boolean} the direction of v1 and v2
1645 */
1646 direction: function direction(v1, v2) {
1647 return v1[0] * v2[1] - v2[0] * v1[1];
1648 },
1649
1650 /**
1651 * Calculates the angle of two vector2's
1652 *
1653 * @param {vector2} v1 the first operand
1654 * @param {vector2} v2 the second operand
1655 * @return {Number} angle of v1 and v2
1656 */
1657 angle: function angle(v1, v2) {
1658 var theta = this.dot(v1, v2) / (this.length(v1) * this.length(v2));
1659 return Math.acos(theta);
1660 },
1661
1662 /**
1663 * Calculates the angle of two vector2's with direction
1664 *
1665 * @param {vector2} v1 the first operand
1666 * @param {vector2} v2 the second operand
1667 * @param {Boolean} direction the direction of two vector2's
1668 * @return {Number} angle of v1 and v2
1669 */
1670 angleTo: function angleTo(v1, v2, direction) {
1671 var angle = this.angle(v1, v2);
1672 var angleLargeThanPI = this.direction(v1, v2) >= 0;
1673
1674 if (direction) {
1675 if (angleLargeThanPI) {
1676 return Math.PI * 2 - angle;
1677 }
1678
1679 return angle;
1680 }
1681
1682 if (angleLargeThanPI) {
1683 return angle;
1684 }
1685
1686 return Math.PI * 2 - angle;
1687 },
1688
1689 /**
1690 * whether a vector2 is zero vector
1691 *
1692 * @param {vector2} v vector to calculate
1693 * @return {Boolean} is or not a zero vector
1694 */
1695 zero: function zero(v) {
1696 return v[0] === 0 && v[1] === 0;
1697 },
1698
1699 /**
1700 * Calculates the euclidian distance between two vector2's
1701 *
1702 * @param {vector2} v1 the first operand
1703 * @param {vector2} v2 the second operand
1704 * @return {Number} distance between a and b
1705 */
1706 distance: function distance(v1, v2) {
1707 var x = v2[0] - v1[0];
1708 var y = v2[1] - v1[1];
1709 return Math.sqrt(x * x + y * y);
1710 },
1711
1712 /**
1713 * Creates a new vector2 initialized with values from an existing vector
1714 *
1715 * @param {vector2} v vector to clone
1716 * @return {Array} a new 2D vector
1717 */
1718 clone: function clone(v) {
1719 return [v[0], v[1]];
1720 },
1721
1722 /**
1723 * Return the minimum of two vector2's
1724 *
1725 * @param {vector2} out the receiving vector
1726 * @param {vector2} v1 the first operand
1727 * @param {vector2} v2 the second operand
1728 * @return {vector2} out
1729 */
1730 min: function min(out, v1, v2) {
1731 out[0] = Math.min(v1[0], v2[0]);
1732 out[1] = Math.min(v1[1], v2[1]);
1733 return out;
1734 },
1735
1736 /**
1737 * Return the maximum of two vector2's
1738 *
1739 * @param {vector2} out the receiving vector
1740 * @param {vector2} v1 the first operand
1741 * @param {vector2} v2 the second operand
1742 * @return {vector2} out
1743 */
1744 max: function max(out, v1, v2) {
1745 out[0] = Math.max(v1[0], v2[0]);
1746 out[1] = Math.max(v1[1], v2[1]);
1747 return out;
1748 },
1749
1750 /**
1751 * Transforms the vector2 with a mat2d
1752 *
1753 * @param {vector2} out the receiving vector
1754 * @param {vector2} v the vector to transform
1755 * @param {mat2d} m matrix to transform with
1756 * @return {vector2} out
1757 */
1758 transformMat2d: function transformMat2d(out, v, m) {
1759 var x = v[0];
1760 var y = v[1];
1761 out[0] = m[0] * x + m[2] * y + m[4];
1762 out[1] = m[1] * x + m[3] * y + m[5];
1763 return out;
1764 }
1765};
1766
1767/***/ }),
1768/* 8 */
1769/***/ (function(module, exports, __webpack_require__) {
1770
1771var Util = __webpack_require__(0);
1772
1773var KEYWORDS_PERCENT = {
1774 min: 0,
1775 median: 0.5,
1776 max: 1
1777};
1778
1779var GuideBase =
1780/*#__PURE__*/
1781function () {
1782 var _proto = GuideBase.prototype;
1783
1784 _proto._initDefaultCfg = function _initDefaultCfg() {};
1785
1786 function GuideBase(cfg) {
1787 this._initDefaultCfg();
1788
1789 Util.deepMix(this, cfg);
1790 }
1791
1792 _proto._getNormalizedValue = function _getNormalizedValue(val, scale) {
1793 var rst;
1794
1795 if (Util.isNil(KEYWORDS_PERCENT[val])) {
1796 rst = scale.scale(val);
1797 } else {
1798 rst = KEYWORDS_PERCENT[val];
1799 }
1800
1801 return rst;
1802 };
1803
1804 _proto.parsePercentPoint = function parsePercentPoint(coord, position) {
1805 var xPercent = parseFloat(position[0]) / 100;
1806 var yPercent = parseFloat(position[1]) / 100;
1807 var start = coord.start;
1808 var end = coord.end;
1809 var width = Math.abs(start.x - end.x);
1810 var height = Math.abs(start.y - end.y);
1811 var x = width * xPercent + Math.min(start.x, end.x);
1812 var y = height * yPercent + Math.min(start.y, end.y);
1813 return {
1814 x: x,
1815 y: y
1816 };
1817 };
1818
1819 _proto.parsePoint = function parsePoint(coord, position) {
1820 var self = this;
1821 var xScale = self.xScale;
1822 var yScales = self.yScales;
1823
1824 if (Util.isFunction(position)) {
1825 position = position(xScale, yScales); // position 必须是对象
1826 } // 如果数据格式是 ['50%', '50%'] 的格式
1827
1828
1829 if (Util.isString(position[0]) && position[0].indexOf('%') !== -1) {
1830 return this.parsePercentPoint(coord, position);
1831 }
1832
1833 var x = self._getNormalizedValue(position[0], xScale);
1834
1835 var y = self._getNormalizedValue(position[1], yScales[0]);
1836
1837 var point = coord.convertPoint({
1838 x: x,
1839 y: y
1840 });
1841
1842 if (self.limitInPlot) {
1843 // limit in chart plotRange
1844 if (x >= 0 && x <= 1 && y >= 0 && y <= 1) {
1845 return point;
1846 }
1847
1848 return null;
1849 }
1850
1851 return point;
1852 }
1853 /**
1854 * render the guide component
1855 * @param {Coord} coord coordinate instance
1856 * @param {Canvas.Group} group the container
1857 */
1858 ;
1859
1860 _proto.render = function render()
1861 /* coord,group */
1862 {};
1863
1864 _proto.repaint = function repaint() {
1865 this.remove();
1866 var coord = this.coord,
1867 container = this.container,
1868 canvas = this.canvas;
1869
1870 if (container && !container.isDestroyed()) {
1871 this.render(coord, container);
1872 canvas.draw();
1873 }
1874 };
1875
1876 _proto.remove = function remove() {
1877 var element = this.element;
1878 element && element.remove(true);
1879 };
1880
1881 _proto.changeVisible = function changeVisible(visible) {
1882 var self = this;
1883 self.visible = visible;
1884 var element = self.element;
1885 if (!element) return;
1886
1887 if (element.set) {
1888 element.set('visible', visible);
1889 } else {
1890 element.style.display = visible ? '' : 'none';
1891 }
1892 };
1893
1894 return GuideBase;
1895}();
1896
1897module.exports = GuideBase;
1898
1899/***/ }),
1900/* 9 */
1901/***/ (function(module, exports) {
1902
1903var toString = {}.toString;
1904
1905var isType = function isType(value, type) {
1906 return toString.call(value) === '[object ' + type + ']';
1907};
1908
1909module.exports = isType;
1910
1911/***/ }),
1912/* 10 */
1913/***/ (function(module, exports) {
1914
1915// isFinite,
1916var isNil = function isNil(value) {
1917 /**
1918 * isNil(null) => true
1919 * isNil() => true
1920 */
1921 return value === null || value === undefined;
1922};
1923
1924module.exports = isNil;
1925
1926/***/ }),
1927/* 11 */
1928/***/ (function(module, exports, __webpack_require__) {
1929
1930function _inheritsLoose(subClass, superClass) {
1931 subClass.prototype = Object.create(superClass.prototype);
1932 subClass.prototype.constructor = subClass;
1933 subClass.__proto__ = superClass;
1934}
1935
1936function _assertThisInitialized(self) {
1937 if (self === void 0) {
1938 throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
1939 }
1940
1941 return self;
1942}
1943
1944var Base = __webpack_require__(33);
1945
1946var Plot = __webpack_require__(61);
1947
1948var Util = __webpack_require__(0);
1949
1950var Coord = __webpack_require__(62);
1951
1952var Geom = __webpack_require__(4);
1953
1954var ScaleController = __webpack_require__(71);
1955
1956var AxisController = __webpack_require__(77);
1957
1958var Global = __webpack_require__(1);
1959
1960var _require = __webpack_require__(3),
1961 Canvas = _require.Canvas;
1962
1963var Helper = __webpack_require__(19);
1964
1965function isFullCircle(coord) {
1966 var startAngle = coord.startAngle;
1967 var endAngle = coord.endAngle;
1968
1969 if (!Util.isNil(startAngle) && !Util.isNil(endAngle) && endAngle - startAngle < Math.PI * 2) {
1970 return false;
1971 }
1972
1973 return true;
1974}
1975
1976function compare(a, b) {
1977 return a - b;
1978}
1979
1980function _isScaleExist(scales, compareScale) {
1981 var flag = false;
1982 Util.each(scales, function (scale) {
1983 var scaleValues = [].concat(scale.values);
1984 var compareScaleValues = [].concat(compareScale.values);
1985
1986 if (scale.type === compareScale.type && scale.field === compareScale.field && scaleValues.sort(compare).toString() === compareScaleValues.sort(compare).toString()) {
1987 flag = true;
1988 return;
1989 }
1990 });
1991 return flag;
1992}
1993
1994var Chart =
1995/*#__PURE__*/
1996function (_Base) {
1997 _inheritsLoose(Chart, _Base);
1998
1999 Chart.initPlugins = function initPlugins() {
2000 return {
2001 _plugins: [],
2002 _cacheId: 0,
2003 register: function register(plugins) {
2004 var p = this._plugins;
2005 [].concat(plugins).forEach(function (plugin) {
2006 if (p.indexOf(plugin) === -1) {
2007 p.push(plugin);
2008 }
2009 });
2010 this._cacheId++;
2011 },
2012 unregister: function unregister(plugins) {
2013 var p = this._plugins;
2014 [].concat(plugins).forEach(function (plugin) {
2015 var idx = p.indexOf(plugin);
2016
2017 if (idx !== -1) {
2018 p.splice(idx, 1);
2019 }
2020 });
2021 this._cacheId++;
2022 },
2023 clear: function clear() {
2024 this._plugins = [];
2025 this._cacheId++;
2026 },
2027 count: function count() {
2028 return this._plugins.length;
2029 },
2030 getAll: function getAll() {
2031 return this._plugins;
2032 },
2033 notify: function notify(chart, hook, args) {
2034 var descriptors = this.descriptors(chart);
2035 var ilen = descriptors.length;
2036 var i;
2037 var descriptor;
2038 var plugin;
2039 var params;
2040 var method;
2041
2042 for (i = 0; i < ilen; ++i) {
2043 descriptor = descriptors[i];
2044 plugin = descriptor.plugin;
2045 method = plugin[hook];
2046
2047 if (typeof method === 'function') {
2048 params = [chart].concat(args || []);
2049
2050 if (method.apply(plugin, params) === false) {
2051 return false;
2052 }
2053 }
2054 }
2055
2056 return true;
2057 },
2058 descriptors: function descriptors(chart) {
2059 var cache = chart._plugins || (chart._plugins = {});
2060
2061 if (cache.id === this._cacheId) {
2062 return cache.descriptors;
2063 }
2064
2065 var plugins = [];
2066 var descriptors = [];
2067
2068 this._plugins.concat(chart && chart.get('plugins') || []).forEach(function (plugin) {
2069 var idx = plugins.indexOf(plugin);
2070
2071 if (idx !== -1) {
2072 return;
2073 }
2074
2075 plugins.push(plugin);
2076 descriptors.push({
2077 plugin: plugin
2078 });
2079 });
2080
2081 cache.descriptors = descriptors;
2082 cache.id = this._cacheId;
2083 return descriptors;
2084 }
2085 };
2086 };
2087
2088 var _proto = Chart.prototype;
2089
2090 _proto.getDefaultCfg = function getDefaultCfg() {
2091 return {
2092 /**
2093 * the id of canvas
2094 * @type {String}
2095 */
2096 id: null,
2097
2098 /**
2099 * padding
2100 * @type {Array|Number}
2101 */
2102 padding: Global.padding,
2103
2104 /**
2105 * data
2106 * @type {Array}
2107 */
2108 data: null,
2109
2110 /**
2111 * scales of chart
2112 * @type {Object}
2113 */
2114 scales: {},
2115
2116 /**
2117 * @private
2118 * geometry instances
2119 * @type {Array}
2120 */
2121 geoms: null,
2122
2123 /**
2124 * scale configuration
2125 * @type {Object}
2126 */
2127 colDefs: null,
2128 pixelRatio: Global.pixelRatio,
2129
2130 /**
2131 * filter options
2132 * @type {Object}
2133 */
2134 filters: null,
2135 appendPadding: Global.appendPadding
2136 };
2137 };
2138
2139 _proto._syncYScales = function _syncYScales() {
2140 var geoms = this.get('geoms');
2141 var syncScales = [];
2142 var min = [];
2143 var max = [];
2144 Util.each(geoms, function (geom) {
2145 var yScale = geom.getYScale();
2146
2147 if (yScale.isLinear) {
2148 syncScales.push(yScale);
2149 min.push(yScale.min);
2150 max.push(yScale.max);
2151 }
2152 });
2153 min = Math.min.apply(null, min);
2154 max = Math.max.apply(null, max);
2155 Util.each(syncScales, function (scale) {
2156 scale.change({
2157 min: min
2158 });
2159 scale.change({
2160 max: max
2161 });
2162 });
2163 };
2164
2165 _proto._getFieldsForLegend = function _getFieldsForLegend() {
2166 var fields = [];
2167 var geoms = this.get('geoms');
2168 Util.each(geoms, function (geom) {
2169 var attrOptions = geom.get('attrOptions');
2170 var attrCfg = attrOptions.color;
2171
2172 if (attrCfg && attrCfg.field && Util.isString(attrCfg.field)) {
2173 var arr = attrCfg.field.split('*');
2174 Util.each(arr, function (item) {
2175 if (fields.indexOf(item) === -1) {
2176 fields.push(item);
2177 }
2178 });
2179 }
2180 });
2181 return fields;
2182 };
2183
2184 _proto._createScale = function _createScale(field, data) {
2185 var scaleController = this.get('scaleController');
2186 return scaleController.createScale(field, data);
2187 };
2188
2189 _proto._adjustScale = function _adjustScale() {
2190 var self = this;
2191 var coord = self.get('coord');
2192 var xScale = self.getXScale();
2193 var yScales = self.getYScales();
2194 var scales = [];
2195 xScale && scales.push(xScale);
2196 scales = scales.concat(yScales);
2197 var inFullCircle = coord.isPolar && isFullCircle(coord);
2198 var scaleController = self.get('scaleController');
2199 var colDefs = scaleController.defs;
2200 Util.each(scales, function (scale) {
2201 if ((scale.isCategory || scale.isIdentity) && scale.values && !(colDefs[scale.field] && colDefs[scale.field].range)) {
2202 var count = scale.values.length;
2203 var range;
2204
2205 if (count === 1) {
2206 range = [0.5, 1];
2207 } else {
2208 var widthRatio = 1;
2209 var offset = 0;
2210
2211 if (inFullCircle) {
2212 if (!coord.transposed) {
2213 range = [0, 1 - 1 / count];
2214 } else {
2215 widthRatio = Global.widthRatio.multiplePie;
2216 offset = 1 / count * widthRatio;
2217 range = [offset / 2, 1 - offset / 2];
2218 }
2219 } else {
2220 offset = 1 / count * 1 / 2;
2221 range = [offset, 1 - offset];
2222 }
2223 }
2224
2225 scale.range = range;
2226 }
2227 });
2228 var geoms = this.get('geoms');
2229
2230 for (var i = 0; i < geoms.length; i++) {
2231 var geom = geoms[i];
2232
2233 if (geom.get('type') === 'interval') {
2234 var yScale = geom.getYScale();
2235 var field = yScale.field,
2236 min = yScale.min,
2237 max = yScale.max,
2238 type = yScale.type;
2239
2240 if (!(colDefs[field] && colDefs[field].min) && type !== 'time') {
2241 if (min > 0) {
2242 yScale.change({
2243 min: 0
2244 });
2245 } else if (max <= 0) {
2246 yScale.change({
2247 max: 0
2248 });
2249 }
2250 }
2251 }
2252 }
2253 };
2254
2255 _proto._removeGeoms = function _removeGeoms() {
2256 var geoms = this.get('geoms');
2257
2258 while (geoms.length > 0) {
2259 var geom = geoms.shift();
2260 geom.destroy();
2261 }
2262 };
2263
2264 _proto._clearGeoms = function _clearGeoms() {
2265 var geoms = this.get('geoms');
2266
2267 for (var i = 0, length = geoms.length; i < length; i++) {
2268 var geom = geoms[i];
2269 geom.clear();
2270 }
2271 };
2272
2273 _proto._clearInner = function _clearInner() {
2274 this.set('scales', {});
2275 this.set('legendItems', null);
2276
2277 this._clearGeoms();
2278
2279 Chart.plugins.notify(this, 'clearInner');
2280 this.get('axisController') && this.get('axisController').clear();
2281 };
2282
2283 _proto._execFilter = function _execFilter(data) {
2284 var filters = this.get('filters');
2285
2286 if (filters) {
2287 data = data.filter(function (obj) {
2288 var rst = true;
2289 Util.each(filters, function (fn, k) {
2290 if (fn) {
2291 rst = fn(obj[k], obj);
2292
2293 if (!rst) {
2294 return false;
2295 }
2296 }
2297 });
2298 return rst;
2299 });
2300 }
2301
2302 return data;
2303 };
2304
2305 _proto._initGeoms = function _initGeoms(geoms) {
2306 var coord = this.get('coord');
2307 var data = this.get('filteredData');
2308 var colDefs = this.get('colDefs');
2309
2310 for (var i = 0, length = geoms.length; i < length; i++) {
2311 var geom = geoms[i];
2312 geom.set('data', data);
2313 geom.set('coord', coord);
2314 geom.set('colDefs', colDefs);
2315 geom.init();
2316 }
2317 };
2318
2319 _proto._initCoord = function _initCoord() {
2320 var plot = this.get('plotRange');
2321 var coordCfg = Util.mix({
2322 type: 'cartesian'
2323 }, this.get('coordCfg'), {
2324 plot: plot
2325 });
2326 var type = coordCfg.type;
2327 var C = Coord[Util.upperFirst(type)];
2328 var coord = new C(coordCfg);
2329 this.set('coord', coord);
2330 };
2331
2332 _proto._initLayout = function _initLayout() {
2333 var padding = this.get('_padding');
2334
2335 if (!padding) {
2336 padding = this.get('margin') || this.get('padding');
2337 padding = Util.parsePadding(padding);
2338 }
2339
2340 var top = padding[0] === 'auto' ? 0 : padding[0];
2341 var right = padding[1] === 'auto' ? 0 : padding[1];
2342 var bottom = padding[2] === 'auto' ? 0 : padding[2];
2343 var left = padding[3] === 'auto' ? 0 : padding[3];
2344 var width = this.get('width');
2345 var height = this.get('height');
2346 var plot = new Plot({
2347 start: {
2348 x: left,
2349 y: top
2350 },
2351 end: {
2352 x: width - right,
2353 y: height - bottom
2354 }
2355 });
2356 this.set('plotRange', plot);
2357 this.set('plot', plot);
2358 };
2359
2360 _proto._initCanvas = function _initCanvas() {
2361 var self = this;
2362
2363 try {
2364 var canvas = new Canvas({
2365 el: self.get('el') || self.get('id'),
2366 context: self.get('context'),
2367 pixelRatio: self.get('pixelRatio'),
2368 width: self.get('width'),
2369 height: self.get('height'),
2370 fontFamily: Global.fontFamily
2371 });
2372 self.set('canvas', canvas);
2373 self.set('width', canvas.get('width'));
2374 self.set('height', canvas.get('height'));
2375 } catch (error) {
2376 throw error;
2377 }
2378
2379 Chart.plugins.notify(self, 'afterCanvasInit');
2380
2381 self._initLayout();
2382 };
2383
2384 _proto._initLayers = function _initLayers() {
2385 var canvas = this.get('canvas');
2386 this.set('backPlot', canvas.addGroup());
2387 this.set('middlePlot', canvas.addGroup({
2388 zIndex: 10
2389 }));
2390 this.set('frontPlot', canvas.addGroup({
2391 zIndex: 20
2392 }));
2393 };
2394
2395 _proto._init = function _init() {
2396 var self = this;
2397
2398 self._initCanvas();
2399
2400 self._initLayers();
2401
2402 self.set('geoms', []);
2403 self.set('scaleController', new ScaleController());
2404 self.set('axisController', new AxisController({
2405 frontPlot: self.get('frontPlot').addGroup({
2406 className: 'axisContainer'
2407 }),
2408 backPlot: self.get('backPlot').addGroup({
2409 className: 'axisContainer'
2410 }),
2411 chart: self
2412 }));
2413 Chart.plugins.notify(self, 'init');
2414 };
2415
2416 function Chart(cfg) {
2417 var _this;
2418
2419 _this = _Base.call(this, cfg) || this;
2420
2421 var self = _assertThisInitialized(_assertThisInitialized(_this));
2422
2423 Util.each(Geom, function (geomConstructor, className) {
2424 var methodName = Util.lowerFirst(className);
2425
2426 self[methodName] = function (cfg) {
2427 var geom = new geomConstructor(cfg);
2428 self.addGeom(geom);
2429 return geom;
2430 };
2431 });
2432
2433 self._init();
2434
2435 return _this;
2436 }
2437 /**
2438 * set data and some scale configuration
2439 * @chainable
2440 * @param {Array} data the dataset to visualize
2441 * @param {Object} colDefs the configuration for scales
2442 * @return {Chart} return the chart instance
2443 */
2444
2445
2446 _proto.source = function source(data, colDefs) {
2447 this.set('data', data);
2448
2449 if (colDefs) {
2450 this.scale(colDefs);
2451 }
2452
2453 return this;
2454 };
2455
2456 _proto.scale = function scale(field, cfg) {
2457 var colDefs = this.get('colDefs') || {};
2458
2459 if (Util.isObject(field)) {
2460 Util.mix(colDefs, field);
2461 } else {
2462 colDefs[field] = cfg;
2463 }
2464
2465 this.set('colDefs', colDefs);
2466 var scaleController = this.get('scaleController');
2467 scaleController.defs = colDefs;
2468 return this;
2469 }
2470 /**
2471 * configure the axis
2472 * @chainable
2473 * @param {String|Boolean} field the field name of data
2474 * @param {Object} cfg configuration for axis
2475 * @return {Chart} return the chart instance
2476 */
2477 ;
2478
2479 _proto.axis = function axis(field, cfg) {
2480 var axisController = this.get('axisController');
2481
2482 if (!field) {
2483 axisController.axisCfg = null;
2484 } else {
2485 axisController.axisCfg = axisController.axisCfg || {};
2486 axisController.axisCfg[field] = cfg;
2487 }
2488
2489 return this;
2490 }
2491 /**
2492 * configure the coordinate
2493 * @chainable
2494 * @param {String} type set the type of coodinate
2495 * @param {Object} cfg configuration for coordinate
2496 * @return {Chart} return the chart instance
2497 */
2498 ;
2499
2500 _proto.coord = function coord(type, cfg) {
2501 var coordCfg;
2502
2503 if (Util.isObject(type)) {
2504 coordCfg = type;
2505 } else {
2506 coordCfg = cfg || {};
2507 coordCfg.type = type || 'cartesian';
2508 }
2509
2510 this.set('coordCfg', coordCfg);
2511 return this;
2512 };
2513
2514 _proto.filter = function filter(field, condition) {
2515 var filters = this.get('filters') || {};
2516 filters[field] = condition;
2517 this.set('filters', filters);
2518 }
2519 /**
2520 * render the chart
2521 * @chainable
2522 * @return {Chart} return the chart instance
2523 */
2524 ;
2525
2526 _proto.render = function render() {
2527 var canvas = this.get('canvas');
2528 var geoms = this.get('geoms');
2529 var data = this.get('data') || [];
2530
2531 var filteredData = this._execFilter(data); // filter data
2532
2533
2534 this.set('filteredData', filteredData);
2535
2536 this._initCoord(); // initialization coordinate instance
2537
2538
2539 Chart.plugins.notify(this, 'beforeGeomInit');
2540
2541 this._initGeoms(geoms); // init all geometry instances
2542
2543
2544 this.get('syncY') && this._syncYScales();
2545
2546 this._adjustScale(); // do some adjust for data
2547
2548
2549 Chart.plugins.notify(this, 'beforeGeomDraw');
2550
2551 this._renderAxis();
2552
2553 var middlePlot = this.get('middlePlot');
2554
2555 if (this.get('limitInPlot') && !middlePlot.attr('clip')) {
2556 var coord = this.get('coord');
2557 var clip = Helper.getClip(coord);
2558 clip.set('canvas', middlePlot.get('canvas'));
2559 middlePlot.attr('clip', clip);
2560 }
2561
2562 for (var i = 0, length = geoms.length; i < length; i++) {
2563 var geom = geoms[i];
2564 geom.paint();
2565 }
2566
2567 Chart.plugins.notify(this, 'afterGeomDraw');
2568 canvas.sort();
2569 this.get('frontPlot').sort();
2570 Chart.plugins.notify(this, 'beforeCanvasDraw');
2571 canvas.draw();
2572 return this;
2573 }
2574 /**
2575 * clear the chart, include geometris and all the shapes
2576 * @chainable
2577 * @return {Chart} return the chart
2578 */
2579 ;
2580
2581 _proto.clear = function clear() {
2582 Chart.plugins.notify(this, 'clear');
2583
2584 this._removeGeoms();
2585
2586 this._clearInner();
2587
2588 this.set('filters', null);
2589 this.set('isUpdate', false);
2590 this.set('_padding', null);
2591 var canvas = this.get('canvas');
2592 canvas.draw();
2593 return this;
2594 };
2595
2596 _proto.repaint = function repaint() {
2597 this.set('isUpdate', true);
2598 Chart.plugins.notify(this, 'repaint');
2599
2600 this._clearInner();
2601
2602 this.render();
2603 };
2604
2605 _proto.changeData = function changeData(data) {
2606 this.set('data', data);
2607 Chart.plugins.notify(this, 'changeData');
2608 this.set('_padding', null);
2609 this.repaint();
2610 };
2611
2612 _proto.changeSize = function changeSize(width, height) {
2613 if (width) {
2614 this.set('width', width);
2615 } else {
2616 width = this.get('width');
2617 }
2618
2619 if (height) {
2620 this.set('height', height);
2621 } else {
2622 height = this.get('height');
2623 }
2624
2625 var canvas = this.get('canvas');
2626 canvas.changeSize(width, height);
2627
2628 this._initLayout();
2629
2630 this.repaint();
2631 return this;
2632 };
2633
2634 _proto.destroy = function destroy() {
2635 this.clear();
2636 var canvas = this.get('canvas');
2637 canvas.destroy();
2638 Chart.plugins.notify(this, 'afterCanvasDestroyed');
2639
2640 if (this._interactions) {
2641 Util.each(this._interactions, function (interaction) {
2642 interaction.destroy();
2643 });
2644 }
2645
2646 _Base.prototype.destroy.call(this);
2647 }
2648 /**
2649 * calculate dataset's position on canvas
2650 * @param {Object} record the dataset
2651 * @return {Object} return the position
2652 */
2653 ;
2654
2655 _proto.getPosition = function getPosition(record) {
2656 var self = this;
2657 var coord = self.get('coord');
2658 var xScale = self.getXScale();
2659 var yScale = self.getYScales()[0];
2660 var xField = xScale.field;
2661 var x = xScale.scale(record[xField]);
2662 var yField = yScale.field;
2663 var y = yScale.scale(record[yField]);
2664 return coord.convertPoint({
2665 x: x,
2666 y: y
2667 });
2668 }
2669 /**
2670 * get the data item of the point
2671 * @param {Object} point canvas position
2672 * @return {Object} return the data item
2673 */
2674 ;
2675
2676 _proto.getRecord = function getRecord(point) {
2677 var self = this;
2678 var coord = self.get('coord');
2679 var xScale = self.getXScale();
2680 var yScale = self.getYScales()[0];
2681 var invertPoint = coord.invertPoint(point);
2682 var record = {};
2683 record[xScale.field] = xScale.invert(invertPoint.x);
2684 record[yScale.field] = yScale.invert(invertPoint.y);
2685 return record;
2686 }
2687 /**
2688 * get the dataset of the point
2689 * @param {Object} point canvas position
2690 * @return {Array} return the dataset
2691 **/
2692 ;
2693
2694 _proto.getSnapRecords = function getSnapRecords(point) {
2695 var geom = this.get('geoms')[0];
2696 var data = [];
2697
2698 if (geom) {
2699 // need to judge
2700 data = geom.getSnapRecords(point);
2701 }
2702
2703 return data;
2704 }
2705 /**
2706 * creat scale instances
2707 * @param {String} field field name of data
2708 * @return {Scale} return the scale
2709 */
2710 ;
2711
2712 _proto.createScale = function createScale(field) {
2713 var data = this.get('data');
2714 var filteredData = this.get('filteredData');
2715
2716 if (filteredData.length) {
2717 var legendFields = this._getFieldsForLegend();
2718
2719 if (legendFields.indexOf(field) === -1) {
2720 data = filteredData;
2721 }
2722 }
2723
2724 var scales = this.get('scales');
2725
2726 if (!scales[field]) {
2727 scales[field] = this._createScale(field, data);
2728 }
2729
2730 return scales[field];
2731 }
2732 /**
2733 * @protected
2734 * add geometry instance to geoms
2735 * @param {Geom} geom geometry instance
2736 */
2737 ;
2738
2739 _proto.addGeom = function addGeom(geom) {
2740 var geoms = this.get('geoms');
2741 var middlePlot = this.get('middlePlot');
2742 geoms.push(geom);
2743 geom.set('chart', this);
2744 geom.set('container', middlePlot.addGroup());
2745 }
2746 /**
2747 * get the scale of x axis
2748 * @return {Scale} return the scale
2749 */
2750 ;
2751
2752 _proto.getXScale = function getXScale() {
2753 var self = this;
2754 var geoms = self.get('geoms');
2755 var xScale = geoms[0].getXScale();
2756 return xScale;
2757 }
2758 /**
2759 * get the scale of y axis
2760 * @return {Array} return the scale
2761 */
2762 ;
2763
2764 _proto.getYScales = function getYScales() {
2765 var geoms = this.get('geoms');
2766 var rst = [];
2767 Util.each(geoms, function (geom) {
2768 var yScale = geom.getYScale();
2769
2770 if (rst.indexOf(yScale) === -1) {
2771 rst.push(yScale);
2772 }
2773 });
2774 return rst;
2775 };
2776
2777 _proto.getLegendItems = function getLegendItems() {
2778 if (this.get('legendItems')) {
2779 return this.get('legendItems');
2780 }
2781
2782 var legendItems = {};
2783 var scales = [];
2784 var geoms = this.get('geoms');
2785 Util.each(geoms, function (geom) {
2786 var colorAttr = geom.getAttr('color');
2787
2788 if (colorAttr) {
2789 var scale = colorAttr.getScale('color');
2790
2791 if (scale.type !== 'identity' && !_isScaleExist(scales, scale)) {
2792 scales.push(scale);
2793 var field = scale.field;
2794 var ticks = scale.getTicks();
2795 var items = [];
2796 Util.each(ticks, function (tick) {
2797 var text = tick.text;
2798 var name = text;
2799 var scaleValue = tick.value;
2800 var value = scale.invert(scaleValue);
2801 var color = colorAttr.mapping(value).join('') || Global.defaultColor;
2802 var marker = {
2803 fill: color,
2804 radius: 3,
2805 symbol: 'circle',
2806 stroke: '#fff'
2807 };
2808 items.push({
2809 name: name,
2810 // for display
2811 dataValue: value,
2812 // the origin value
2813 checked: true,
2814 marker: marker
2815 });
2816 });
2817 legendItems[field] = items;
2818 }
2819 }
2820 });
2821 this.set('legendItems', legendItems);
2822 return legendItems;
2823 } // register the plugins
2824 ;
2825
2826 _proto.registerPlugins = function registerPlugins(plugins) {
2827 var self = this;
2828 var chartPlugins = self.get('plugins') || [];
2829
2830 if (!Util.isArray(chartPlugins)) {
2831 chartPlugins = [chartPlugins];
2832 }
2833
2834 [].concat(plugins).forEach(function (plugin) {
2835 if (chartPlugins.indexOf(plugin) === -1) {
2836 plugin.init && plugin.init(self); // init
2837
2838 chartPlugins.push(plugin);
2839 }
2840 });
2841 Chart.plugins._cacheId++;
2842 self.set('plugins', chartPlugins);
2843 };
2844
2845 _proto._renderAxis = function _renderAxis() {
2846 var axisController = this.get('axisController');
2847 var xScale = this.getXScale();
2848 var yScales = this.getYScales();
2849 var coord = this.get('coord');
2850 Chart.plugins.notify(this, 'beforeRenderAxis');
2851 axisController.createAxis(coord, xScale, yScales);
2852 };
2853
2854 _proto._isAutoPadding = function _isAutoPadding() {
2855 if (this.get('_padding')) {
2856 return false;
2857 }
2858
2859 var padding = this.get('padding');
2860
2861 if (Util.isArray(padding)) {
2862 return padding.indexOf('auto') !== -1;
2863 }
2864
2865 return padding === 'auto';
2866 };
2867
2868 _proto._updateLayout = function _updateLayout(padding) {
2869 var width = this.get('width');
2870 var height = this.get('height');
2871 var start = {
2872 x: padding[3],
2873 y: padding[0]
2874 };
2875 var end = {
2876 x: width - padding[1],
2877 y: height - padding[2]
2878 };
2879 var plot = this.get('plot');
2880 var coord = this.get('coord');
2881 plot.reset(start, end);
2882 coord.reset(plot);
2883 };
2884
2885 return Chart;
2886}(Base);
2887
2888Chart.plugins = Chart.initPlugins();
2889module.exports = Chart;
2890
2891/***/ }),
2892/* 12 */
2893/***/ (function(module, exports, __webpack_require__) {
2894
2895var Vector2 = __webpack_require__(7);
2896
2897var start = Vector2.create();
2898var end = Vector2.create();
2899var extremity = Vector2.create();
2900
2901function getCubicBezierXYatT(startPt, controlPt1, controlPt2, endPt, T) {
2902 var x = CubicN(T, startPt.x, controlPt1.x, controlPt2.x, endPt.x);
2903 var y = CubicN(T, startPt.y, controlPt1.y, controlPt2.y, endPt.y);
2904 return {
2905 x: x,
2906 y: y
2907 };
2908} // cubic helper formula at T distance
2909
2910
2911function CubicN(T, a, b, c, d) {
2912 var t2 = T * T;
2913 var t3 = t2 * T;
2914 return a + (-a * 3 + T * (3 * a - a * T)) * T + (3 * b + T * (-6 * b + b * 3 * T)) * T + (c * 3 - c * 3 * T) * t2 + d * t3;
2915}
2916
2917function cubicBezierBounds(c) {
2918 var minX = Infinity;
2919 var maxX = -Infinity;
2920 var minY = Infinity;
2921 var maxY = -Infinity;
2922 var s = {
2923 x: c[0],
2924 y: c[1]
2925 };
2926 var c1 = {
2927 x: c[2],
2928 y: c[3]
2929 };
2930 var c2 = {
2931 x: c[4],
2932 y: c[5]
2933 };
2934 var e = {
2935 x: c[6],
2936 y: c[7]
2937 };
2938
2939 for (var t = 0; t < 100; t++) {
2940 var pt = getCubicBezierXYatT(s, c1, c2, e, t / 100);
2941
2942 if (pt.x < minX) {
2943 minX = pt.x;
2944 }
2945
2946 if (pt.x > maxX) {
2947 maxX = pt.x;
2948 }
2949
2950 if (pt.y < minY) {
2951 minY = pt.y;
2952 }
2953
2954 if (pt.y > maxY) {
2955 maxY = pt.y;
2956 }
2957 }
2958
2959 return {
2960 minX: minX,
2961 minY: minY,
2962 maxX: maxX,
2963 maxY: maxY
2964 };
2965}
2966
2967module.exports = {
2968 getBBoxFromPoints: function getBBoxFromPoints(points, lineWidth) {
2969 if (points.length === 0) {
2970 return;
2971 }
2972
2973 var p = points[0];
2974 var left = p.x;
2975 var right = p.x;
2976 var top = p.y;
2977 var bottom = p.y;
2978 var len = points.length;
2979
2980 for (var i = 1; i < len; i++) {
2981 p = points[i];
2982 left = Math.min(left, p.x);
2983 right = Math.max(right, p.x);
2984 top = Math.min(top, p.y);
2985 bottom = Math.max(bottom, p.y);
2986 }
2987
2988 lineWidth = lineWidth / 2 || 0;
2989 return {
2990 minX: left - lineWidth,
2991 minY: top - lineWidth,
2992 maxX: right + lineWidth,
2993 maxY: bottom + lineWidth
2994 };
2995 },
2996 getBBoxFromLine: function getBBoxFromLine(x0, y0, x1, y1, lineWidth) {
2997 lineWidth = lineWidth / 2 || 0;
2998 return {
2999 minX: Math.min(x0, x1) - lineWidth,
3000 minY: Math.min(y0, y1) - lineWidth,
3001 maxX: Math.max(x0, x1) + lineWidth,
3002 maxY: Math.max(y0, y1) + lineWidth
3003 };
3004 },
3005 getBBoxFromArc: function getBBoxFromArc(x, y, r, startAngle, endAngle, anticlockwise) {
3006 var diff = Math.abs(startAngle - endAngle);
3007
3008 if (diff % Math.PI * 2 < 1e-4 && diff > 1e-4) {
3009 // Is a circle
3010 return {
3011 minX: x - r,
3012 minY: y - r,
3013 maxX: x + r,
3014 maxY: y + r
3015 };
3016 }
3017
3018 start[0] = Math.cos(startAngle) * r + x;
3019 start[1] = Math.sin(startAngle) * r + y;
3020 end[0] = Math.cos(endAngle) * r + x;
3021 end[1] = Math.sin(endAngle) * r + y;
3022 var min = [0, 0];
3023 var max = [0, 0];
3024 Vector2.min(min, start, end);
3025 Vector2.max(max, start, end); // Thresh to [0, Math.PI * 2]
3026
3027 startAngle = startAngle % (Math.PI * 2);
3028
3029 if (startAngle < 0) {
3030 startAngle = startAngle + Math.PI * 2;
3031 }
3032
3033 endAngle = endAngle % (Math.PI * 2);
3034
3035 if (endAngle < 0) {
3036 endAngle = endAngle + Math.PI * 2;
3037 }
3038
3039 if (startAngle > endAngle && !anticlockwise) {
3040 endAngle += Math.PI * 2;
3041 } else if (startAngle < endAngle && anticlockwise) {
3042 startAngle += Math.PI * 2;
3043 }
3044
3045 if (anticlockwise) {
3046 var tmp = endAngle;
3047 endAngle = startAngle;
3048 startAngle = tmp;
3049 }
3050
3051 for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
3052 if (angle > startAngle) {
3053 extremity[0] = Math.cos(angle) * r + x;
3054 extremity[1] = Math.sin(angle) * r + y;
3055 Vector2.min(min, extremity, min);
3056 Vector2.max(max, extremity, max);
3057 }
3058 }
3059
3060 return {
3061 minX: min[0],
3062 minY: min[1],
3063 maxX: max[0],
3064 maxY: max[1]
3065 };
3066 },
3067 getBBoxFromBezierGroup: function getBBoxFromBezierGroup(points, lineWidth) {
3068 var minX = Infinity;
3069 var maxX = -Infinity;
3070 var minY = Infinity;
3071 var maxY = -Infinity;
3072
3073 for (var i = 0, len = points.length; i < len; i++) {
3074 var bbox = cubicBezierBounds(points[i]);
3075
3076 if (bbox.minX < minX) {
3077 minX = bbox.minX;
3078 }
3079
3080 if (bbox.maxX > maxX) {
3081 maxX = bbox.maxX;
3082 }
3083
3084 if (bbox.minY < minY) {
3085 minY = bbox.minY;
3086 }
3087
3088 if (bbox.maxY > maxY) {
3089 maxY = bbox.maxY;
3090 }
3091 }
3092
3093 lineWidth = lineWidth / 2 || 0;
3094 return {
3095 minX: minX - lineWidth,
3096 minY: minY - lineWidth,
3097 maxX: maxX + lineWidth,
3098 maxY: maxY + lineWidth
3099 };
3100 }
3101};
3102
3103/***/ }),
3104/* 13 */
3105/***/ (function(module, exports, __webpack_require__) {
3106
3107var isType = __webpack_require__(9);
3108
3109var isString = function isString(str) {
3110 return isType(str, 'String');
3111};
3112
3113module.exports = isString;
3114
3115/***/ }),
3116/* 14 */
3117/***/ (function(module, exports, __webpack_require__) {
3118
3119/**
3120 * 判断是否数字
3121 * @return {Boolean} 是否数字
3122 */
3123var isType = __webpack_require__(9);
3124
3125var isNumber = function isNumber(value) {
3126 return isType(value, 'Number');
3127};
3128
3129module.exports = isNumber;
3130
3131/***/ }),
3132/* 15 */
3133/***/ (function(module, exports, __webpack_require__) {
3134
3135var isType = __webpack_require__(9);
3136
3137var isArray = Array.isArray ? Array.isArray : function (value) {
3138 return isType(value, 'Array');
3139};
3140module.exports = isArray;
3141
3142/***/ }),
3143/* 16 */
3144/***/ (function(module, exports, __webpack_require__) {
3145
3146var mix = __webpack_require__(22);
3147
3148var each = __webpack_require__(5);
3149
3150var isObject = __webpack_require__(17);
3151
3152var isNil = __webpack_require__(10);
3153
3154var Scale =
3155/*#__PURE__*/
3156function () {
3157 var _proto = Scale.prototype;
3158
3159 _proto._initDefaultCfg = function _initDefaultCfg() {
3160 this.type = 'base';
3161 /**
3162 * 格式化函数,输出文本或者tick时的格式化函数
3163 * @type {Function}
3164 */
3165
3166 this.formatter = null;
3167 /**
3168 * 输出的值域
3169 * @type {Array}
3170 */
3171
3172 this.range = [0, 1];
3173 /**
3174 * 度量的标记
3175 * @type {Array}
3176 */
3177
3178 this.ticks = null;
3179 /**
3180 * 参与度量计算的值,可选项
3181 * @type {Array}
3182 */
3183
3184 this.values = [];
3185 };
3186
3187 function Scale(cfg) {
3188 this._initDefaultCfg();
3189
3190 mix(this, cfg);
3191 this.init();
3192 }
3193 /**
3194 * 度量初始化
3195 * @protected
3196 */
3197
3198
3199 _proto.init = function init() {};
3200 /**
3201 * 获取该度量的ticks,返回的是多个对象,
3202 * - text: tick 的文本
3203 * - value: 对应的度量转换后的值
3204 * <code>
3205 * [
3206 * {text: 0,value:0}
3207 * {text: 1,value:0.2}
3208 * {text: 2,value:0.4}
3209 * {text: 3,value:0.6}
3210 * {text: 4,value:0.8}
3211 * {text: 5,value:1}
3212 * ]
3213 * </code>
3214 * @param {Number} count 输出tick的个数的近似值,默认是 10
3215 * @return {Array} 返回 ticks 数组
3216 */
3217
3218
3219 _proto.getTicks = function getTicks() {
3220 var self = this;
3221 var ticks = self.ticks;
3222 var rst = [];
3223 each(ticks, function (tick) {
3224 var obj;
3225
3226 if (isObject(tick)) {
3227 obj = tick;
3228 } else {
3229 obj = {
3230 text: self.getText(tick),
3231 tickValue: tick,
3232 value: self.scale(tick)
3233 };
3234 }
3235
3236 rst.push(obj);
3237 });
3238 return rst;
3239 };
3240 /**
3241 * 获取格式化后的文本
3242 * @param {*} value 输入的数据
3243 * @param {*} key 字段的 key
3244 * @return {String} 格式化的文本
3245 */
3246
3247
3248 _proto.getText = function getText(value, key) {
3249 var formatter = this.formatter;
3250 value = formatter ? formatter(value, key) : value;
3251
3252 if (isNil(value) || !value.toString) {
3253 value = '';
3254 }
3255
3256 return value.toString();
3257 };
3258 /**
3259 * 输出的值域最小值
3260 * @protected
3261 * @return {Number} 返回最小的值
3262 */
3263
3264
3265 _proto.rangeMin = function rangeMin() {
3266 return this.range[0];
3267 };
3268 /**
3269 * 输出的值域最大值
3270 * @protected
3271 * @return {Number} 返回最大的值
3272 */
3273
3274
3275 _proto.rangeMax = function rangeMax() {
3276 var range = this.range;
3277 return range[range.length - 1];
3278 };
3279 /**
3280 * 度量转换后的结果,翻转回输入域
3281 * @param {Number} value 需要翻转的数值
3282 * @return {*} 度量的输入值
3283 */
3284
3285
3286 _proto.invert = function invert(value) {
3287 return value;
3288 };
3289 /**
3290 * 将传入的值从非数值转换成数值格式,如分类字符串、时间字符串等
3291 * @param {*} value 传入的值
3292 * @return {Number} 转换的值
3293 */
3294
3295
3296 _proto.translate = function translate(value) {
3297 return value;
3298 };
3299 /**
3300 * 进行度量转换
3301 * @param {*} value 输入值
3302 * @return {Number} 输出值,在设定的输出值域之间,默认[0,1]
3303 */
3304
3305
3306 _proto.scale = function scale(value) {
3307 return value;
3308 };
3309 /**
3310 * 克隆一个新的scale,拥有跟当前scale相同的输入域、输出域等
3311 * @return {Scale} 克隆的度量
3312 */
3313
3314
3315 _proto.clone = function clone() {
3316 var self = this;
3317 var constr = self.constructor;
3318 var cfg = {};
3319 each(self, function (v, k) {
3320 cfg[k] = self[k];
3321 });
3322 return new constr(cfg);
3323 };
3324 /**
3325 * 更改度量的属性信息
3326 * @param {Object} info 属性信息
3327 * @chainable
3328 * @return {Scale} 返回自身的引用
3329 */
3330
3331
3332 _proto.change = function change(info) {
3333 this.ticks = null;
3334 mix(this, info);
3335 this.init();
3336 return this;
3337 };
3338
3339 return Scale;
3340}();
3341
3342module.exports = Scale;
3343
3344/***/ }),
3345/* 17 */
3346/***/ (function(module, exports) {
3347
3348var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
3349 return typeof obj;
3350} : function (obj) {
3351 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
3352};
3353
3354var isObject = function isObject(value) {
3355 /**
3356 * isObject({}) => true
3357 * isObject([1, 2, 3]) => true
3358 * isObject(Function) => true
3359 * isObject(null) => false
3360 */
3361 var type = typeof value === 'undefined' ? 'undefined' : _typeof(value);
3362 return value !== null && type === 'object' || type === 'function';
3363};
3364
3365module.exports = isObject;
3366
3367/***/ }),
3368/* 18 */
3369/***/ (function(module, exports, __webpack_require__) {
3370
3371/**
3372 * @fileOverview the Attribute base class
3373 */
3374var isString = __webpack_require__(13);
3375
3376var isArray = __webpack_require__(15);
3377
3378var mix = __webpack_require__(22);
3379
3380var each = __webpack_require__(5);
3381
3382function toScaleString(scale, value) {
3383 if (isString(value)) {
3384 return value;
3385 }
3386
3387 return scale.invert(scale.scale(value));
3388}
3389/**
3390 * 所有视觉通道属性的基类
3391 * @class Attr
3392 */
3393
3394
3395var AttributeBase =
3396/*#__PURE__*/
3397function () {
3398 function AttributeBase(cfg) {
3399 /**
3400 * 属性的类型
3401 * @type {String}
3402 */
3403 this.type = 'base';
3404 /**
3405 * 属性的名称
3406 * @type {String}
3407 */
3408
3409 this.name = null;
3410 /**
3411 * 回调函数
3412 * @type {Function}
3413 */
3414
3415 this.method = null;
3416 /**
3417 * 备选的值数组
3418 * @type {Array}
3419 */
3420
3421 this.values = [];
3422 /**
3423 * 属性内部的度量
3424 * @type {Array}
3425 */
3426
3427 this.scales = [];
3428 /**
3429 * 是否通过线性取值, 如果未指定,则根据数值的类型判定
3430 * @type {Boolean}
3431 */
3432
3433 this.linear = null;
3434 mix(this, cfg);
3435 } // 获取属性值,将值映射到视觉通道
3436
3437
3438 var _proto = AttributeBase.prototype;
3439
3440 _proto._getAttrValue = function _getAttrValue(scale, value) {
3441 var values = this.values;
3442
3443 if (scale.isCategory && !this.linear) {
3444 var index = scale.translate(value);
3445 return values[index % values.length];
3446 }
3447
3448 var percent = scale.scale(value);
3449 return this.getLinearValue(percent);
3450 };
3451 /**
3452 * 如果进行线性映射,返回对应的映射值
3453 * @protected
3454 * @param {Number} percent 百分比
3455 * @return {*} 颜色值、形状、大小等
3456 */
3457
3458
3459 _proto.getLinearValue = function getLinearValue(percent) {
3460 var values = this.values;
3461 var steps = values.length - 1;
3462 var step = Math.floor(steps * percent);
3463 var leftPercent = steps * percent - step;
3464 var start = values[step];
3465 var end = step === steps ? start : values[step + 1];
3466 var rstValue = start + (end - start) * leftPercent;
3467 return rstValue;
3468 };
3469 /**
3470 * 默认的回调函数
3471 * @param {*} value 回调函数的值
3472 * @type {Function}
3473 * @return {Array} 返回映射后的值
3474 */
3475
3476
3477 _proto.callback = function callback(value) {
3478 var self = this;
3479 var scale = self.scales[0];
3480 var rstValue = null;
3481
3482 if (scale.type === 'identity') {
3483 rstValue = scale.value;
3484 } else {
3485 rstValue = self._getAttrValue(scale, value);
3486 }
3487
3488 return rstValue;
3489 };
3490 /**
3491 * 根据度量获取属性名
3492 * @return {Array} dims of this Attribute
3493 */
3494
3495
3496 _proto.getNames = function getNames() {
3497 var scales = this.scales;
3498 var names = this.names;
3499 var length = Math.min(scales.length, names.length);
3500 var rst = [];
3501
3502 for (var i = 0; i < length; i++) {
3503 rst.push(names[i]);
3504 }
3505
3506 return rst;
3507 };
3508 /**
3509 * 根据度量获取维度名
3510 * @return {Array} dims of this Attribute
3511 */
3512
3513
3514 _proto.getFields = function getFields() {
3515 var scales = this.scales;
3516 var rst = [];
3517 each(scales, function (scale) {
3518 rst.push(scale.field);
3519 });
3520 return rst;
3521 };
3522 /**
3523 * 根据名称获取度量
3524 * @param {String} name the name of scale
3525 * @return {Scale} scale
3526 */
3527
3528
3529 _proto.getScale = function getScale(name) {
3530 var scales = this.scales;
3531 var names = this.names;
3532 var index = names.indexOf(name);
3533 return scales[index];
3534 };
3535 /**
3536 * 映射数据
3537 * @param {*} param1...paramn 多个数值
3538 * @return {Array} 映射的值组成的数组
3539 */
3540
3541
3542 _proto.mapping = function mapping() {
3543 var scales = this.scales;
3544 var callback = this.callback;
3545
3546 for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
3547 params[_key] = arguments[_key];
3548 }
3549
3550 var values = params;
3551
3552 if (callback) {
3553 for (var i = 0, len = params.length; i < len; i++) {
3554 params[i] = this._toOriginParam(params[i], scales[i]);
3555 }
3556
3557 values = callback.apply(this, params);
3558 }
3559
3560 values = [].concat(values);
3561 return values;
3562 }; // 原始的参数
3563
3564
3565 _proto._toOriginParam = function _toOriginParam(param, scale) {
3566 var rst = param;
3567
3568 if (!scale.isLinear) {
3569 if (isArray(param)) {
3570 rst = [];
3571
3572 for (var i = 0, len = param.length; i < len; i++) {
3573 rst.push(toScaleString(scale, param[i]));
3574 }
3575 } else {
3576 rst = toScaleString(scale, param);
3577 }
3578 }
3579
3580 return rst;
3581 };
3582
3583 return AttributeBase;
3584}();
3585
3586module.exports = AttributeBase;
3587
3588/***/ }),
3589/* 19 */
3590/***/ (function(module, exports, __webpack_require__) {
3591
3592var _require = __webpack_require__(3),
3593 Shape = _require.Shape;
3594
3595module.exports = {
3596 getClip: function getClip(coord) {
3597 var start = coord.start;
3598 var end = coord.end;
3599 var width = end.x - start.x;
3600 var height = Math.abs(end.y - start.y);
3601 var margin = 10;
3602 var clip;
3603
3604 if (coord.isPolar) {
3605 var circleRadius = coord.circleRadius,
3606 center = coord.center,
3607 startAngle = coord.startAngle,
3608 endAngle = coord.endAngle;
3609 clip = new Shape.Sector({
3610 attrs: {
3611 x: center.x,
3612 y: center.y,
3613 r: circleRadius,
3614 r0: 0,
3615 startAngle: startAngle,
3616 endAngle: endAngle
3617 }
3618 });
3619 } else {
3620 clip = new Shape.Rect({
3621 attrs: {
3622 x: start.x,
3623 y: end.y - margin,
3624 width: width,
3625 height: height + 2 * margin
3626 }
3627 });
3628 }
3629
3630 clip.isClip = true;
3631 return clip;
3632 },
3633 isPointInPlot: function isPointInPlot(point, plot) {
3634 var x = point.x,
3635 y = point.y;
3636 var tl = plot.tl,
3637 tr = plot.tr,
3638 br = plot.br;
3639 return x >= tl.x && x <= tr.x && y >= tl.y && y <= br.y;
3640 }
3641};
3642
3643/***/ }),
3644/* 20 */
3645/***/ (function(module, exports, __webpack_require__) {
3646
3647/**
3648 * @fileOverview shape util
3649 * @author dxq613@gmail.com
3650 */
3651var Util = __webpack_require__(0);
3652
3653var ShapeUtil = {
3654 splitPoints: function splitPoints(obj) {
3655 var points = [];
3656 var x = obj.x;
3657 var y = obj.y;
3658 y = Util.isArray(y) ? y : [y];
3659 y.forEach(function (yItem, index) {
3660 var point = {
3661 x: Util.isArray(x) ? x[index] : x,
3662 y: yItem
3663 };
3664 points.push(point);
3665 });
3666 return points;
3667 },
3668 splitArray: function splitArray(data, yField, connectNulls) {
3669 if (!data.length) return [];
3670 var arr = [];
3671 var tmp = [];
3672 var yValue;
3673 Util.each(data, function (obj) {
3674 yValue = obj._origin ? obj._origin[yField] : obj[yField];
3675
3676 if (connectNulls) {
3677 if (!Util.isNil(yValue)) {
3678 tmp.push(obj);
3679 }
3680 } else {
3681 if (Util.isArray(yValue) && Util.isNil(yValue[0]) || Util.isNil(yValue)) {
3682 if (tmp.length) {
3683 arr.push(tmp);
3684 tmp = [];
3685 }
3686 } else {
3687 tmp.push(obj);
3688 }
3689 }
3690 });
3691
3692 if (tmp.length) {
3693 arr.push(tmp);
3694 }
3695
3696 return arr;
3697 }
3698};
3699module.exports = ShapeUtil;
3700
3701/***/ }),
3702/* 21 */
3703/***/ (function(module, exports, __webpack_require__) {
3704
3705/**
3706 * The parent class of interaction
3707 * @author sima.zhang1990@gmail.com
3708 */
3709var Util = __webpack_require__(0);
3710
3711var Chart = __webpack_require__(11);
3712
3713var Hammer;
3714
3715if (!Util.isWx && !Util.isMy) {
3716 Hammer = __webpack_require__(138);
3717}
3718
3719var TOUCH_EVENTS = ['touchstart', 'touchmove', 'touchend'];
3720
3721var Interaction =
3722/*#__PURE__*/
3723function () {
3724 var _proto = Interaction.prototype;
3725
3726 _proto.getDefaultCfg = function getDefaultCfg() {
3727 return {
3728 startEvent: TOUCH_EVENTS[0],
3729 processEvent: TOUCH_EVENTS[1],
3730 endEvent: TOUCH_EVENTS[2],
3731 resetEvent: null
3732 };
3733 };
3734
3735 _proto._start = function _start(ev) {
3736 this.preStart && this.preStart(ev);
3737 this.start(ev);
3738 this.onStart && this.onStart(ev);
3739 };
3740
3741 _proto._process = function _process(ev) {
3742 this.preProcess && this.preProcess(ev);
3743 this.process(ev);
3744 this.onProcess && this.onProcess(ev);
3745 };
3746
3747 _proto._end = function _end(ev) {
3748 this.preEnd && this.preEnd(ev);
3749 this.end(ev);
3750 this.onEnd && this.onEnd(ev);
3751 };
3752
3753 _proto._reset = function _reset(ev) {
3754 this.preReset && this.preReset(ev);
3755 this.reset(ev);
3756 this.onReset && this.onReset(ev);
3757 } // override
3758 ;
3759
3760 _proto.start = function start() {} // override
3761 ;
3762
3763 _proto.process = function process() {} // override
3764 ;
3765
3766 _proto.end = function end() {} // override
3767 ;
3768
3769 _proto.reset = function reset() {};
3770
3771 function Interaction(cfg, chart) {
3772 var defaultCfg = this.getDefaultCfg();
3773 Util.deepMix(this, defaultCfg, cfg);
3774 this.chart = chart;
3775 this.canvas = chart.get('canvas');
3776 this.el = chart.get('canvas').get('el');
3777
3778 this._bindEvents();
3779 }
3780
3781 _proto._bindEvents = function _bindEvents() {
3782 this._clearEvents(); // clear events
3783
3784
3785 var startEvent = this.startEvent,
3786 processEvent = this.processEvent,
3787 endEvent = this.endEvent,
3788 resetEvent = this.resetEvent,
3789 el = this.el;
3790
3791 if (Hammer) {
3792 this.hammer = new Hammer(el);
3793 }
3794
3795 this._bindEvent(startEvent, '_start');
3796
3797 this._bindEvent(processEvent, '_process');
3798
3799 this._bindEvent(endEvent, '_end');
3800
3801 this._bindEvent(resetEvent, '_reset');
3802 };
3803
3804 _proto._clearEvents = function _clearEvents() {
3805 var startEvent = this.startEvent,
3806 processEvent = this.processEvent,
3807 endEvent = this.endEvent,
3808 resetEvent = this.resetEvent;
3809
3810 if (this.hammer) {
3811 this.hammer.destroy();
3812 this.hammer = null;
3813 }
3814
3815 this._clearTouchEvent(startEvent, '_start');
3816
3817 this._clearTouchEvent(processEvent, '_process');
3818
3819 this._clearTouchEvent(endEvent, '_end');
3820
3821 this._clearTouchEvent(resetEvent, '_reset');
3822 };
3823
3824 _proto._bindEvent = function _bindEvent(eventName, methodName) {
3825 var el = this.el;
3826
3827 if (eventName) {
3828 if (TOUCH_EVENTS.indexOf(eventName) !== -1) {
3829 Util.addEventListener(el, eventName, Util.wrapBehavior(this, methodName));
3830 } else if (this.hammer) {
3831 this.hammer.on(eventName, Util.wrapBehavior(this, methodName));
3832 }
3833 }
3834 };
3835
3836 _proto._clearTouchEvent = function _clearTouchEvent(eventName, methodName) {
3837 var el = this.el;
3838
3839 if (eventName && TOUCH_EVENTS.indexOf(eventName) !== -1) {
3840 Util.removeEventListener(el, eventName, Util.getWrapBehavior(this, methodName));
3841 }
3842 };
3843
3844 _proto.destroy = function destroy() {
3845 this._clearEvents();
3846 };
3847
3848 return Interaction;
3849}();
3850
3851Chart._Interactions = {};
3852
3853Chart.registerInteraction = function (type, constructor) {
3854 Chart._Interactions[type] = constructor;
3855};
3856
3857Chart.getInteraction = function (type) {
3858 return Chart._Interactions[type];
3859};
3860
3861Chart.prototype.interaction = function (type, cfg) {
3862 var interactions = this._interactions || {};
3863
3864 if (interactions[type]) {
3865 // if reprated, destroy last
3866 interactions[type].destroy();
3867 }
3868
3869 var Ctor = Chart.getInteraction(type);
3870 var interact = new Ctor(cfg, this);
3871 interactions[type] = interact;
3872 this._interactions = interactions;
3873 return this;
3874};
3875
3876Chart.prototype.clearInteraction = function (type) {
3877 var interactions = this._interactions;
3878 if (!interactions) return;
3879
3880 if (type) {
3881 interactions[type] && interactions[type].destroy();
3882 delete interactions[type];
3883 } else {
3884 Util.each(interactions, function (interaction, key) {
3885 interaction.destroy();
3886 delete interactions[key];
3887 });
3888 }
3889
3890 return this;
3891};
3892
3893module.exports = Interaction;
3894
3895/***/ }),
3896/* 22 */
3897/***/ (function(module, exports) {
3898
3899function _mix(dist, obj) {
3900 for (var key in obj) {
3901 if (obj.hasOwnProperty(key) && key !== 'constructor' && obj[key] !== undefined) {
3902 dist[key] = obj[key];
3903 }
3904 }
3905}
3906
3907var mix = function mix(dist, src1, src2, src3) {
3908 if (src1) _mix(dist, src1);
3909 if (src2) _mix(dist, src2);
3910 if (src3) _mix(dist, src3);
3911 return dist;
3912};
3913
3914module.exports = mix;
3915
3916/***/ }),
3917/* 23 */
3918/***/ (function(module, exports, __webpack_require__) {
3919
3920var Util = __webpack_require__(0);
3921
3922var Base =
3923/*#__PURE__*/
3924function () {
3925 var _proto = Base.prototype;
3926
3927 _proto._initDefaultCfg = function _initDefaultCfg() {};
3928
3929 function Base(cfg) {
3930 this._initDefaultCfg();
3931
3932 Util.mix(this, cfg);
3933 var start;
3934 var end;
3935
3936 if (this.plot) {
3937 start = this.plot.bl;
3938 end = this.plot.tr;
3939 this.start = start;
3940 this.end = end;
3941 } else {
3942 start = this.start;
3943 end = this.end;
3944 }
3945
3946 this.init(start, end);
3947 }
3948
3949 _proto.init = function init() {};
3950
3951 _proto.convertPoint = function convertPoint(point) {
3952 return point;
3953 };
3954
3955 _proto.invertPoint = function invertPoint(point) {
3956 return point;
3957 };
3958
3959 _proto.reset = function reset(plot) {
3960 this.plot = plot;
3961 var bl = plot.bl,
3962 tr = plot.tr;
3963 this.start = bl;
3964 this.end = tr;
3965 this.init(bl, tr);
3966 };
3967
3968 return Base;
3969}();
3970
3971module.exports = Base;
3972
3973/***/ }),
3974/* 24 */
3975/***/ (function(module, exports, __webpack_require__) {
3976
3977var mix = __webpack_require__(70);
3978
3979var Adjust =
3980/*#__PURE__*/
3981function () {
3982 var _proto = Adjust.prototype;
3983
3984 _proto._initDefaultCfg = function _initDefaultCfg() {
3985 this.adjustNames = ['x', 'y']; // 调整的维度,默认,x,y都做调整
3986 };
3987
3988 function Adjust(cfg) {
3989 this._initDefaultCfg();
3990
3991 mix(this, cfg);
3992 }
3993 /**
3994 * @override
3995 */
3996
3997
3998 _proto.processAdjust = function processAdjust()
3999 /* dataArray */
4000 {};
4001
4002 return Adjust;
4003}();
4004
4005module.exports = Adjust;
4006
4007/***/ }),
4008/* 25 */
4009/***/ (function(module, exports, __webpack_require__) {
4010
4011var Util = __webpack_require__(0);
4012
4013var Global = __webpack_require__(1);
4014
4015var Vector2 = __webpack_require__(7);
4016
4017var Abastract =
4018/*#__PURE__*/
4019function () {
4020 var _proto = Abastract.prototype;
4021
4022 _proto._initDefaultCfg = function _initDefaultCfg() {
4023 /**
4024 * ticks
4025 * @type {Array}
4026 */
4027 this.ticks = [];
4028 /**
4029 * the configuration for tickLine
4030 * @type {Object}
4031 */
4032
4033 this.tickLine = {};
4034 /**
4035 * the direction of ticks, 1 means clockwise
4036 * @type {Number}
4037 */
4038
4039 this.offsetFactor = 1;
4040 /**
4041 * the top container
4042 * @type {container}
4043 */
4044
4045 this.frontContainer = null;
4046 /**
4047 * the back container
4048 * @type {[type]}
4049 */
4050
4051 this.backContainer = null;
4052 /**
4053 * points for draw grid line
4054 * @type {Array}
4055 */
4056
4057 this.gridPoints = [];
4058 };
4059
4060 function Abastract(cfg) {
4061 this._initDefaultCfg();
4062
4063 Util.mix(this, cfg);
4064 this.draw();
4065 }
4066
4067 _proto.draw = function draw() {
4068 var line = this.line,
4069 tickLine = this.tickLine,
4070 label = this.label,
4071 grid = this.grid;
4072 grid && this.drawGrid(grid); // draw the grid lines
4073
4074 tickLine && this.drawTicks(tickLine); // draw the tickLine
4075
4076 line && this.drawLine(line); // draw axis line
4077
4078 label && this.drawLabels(); // draw ticks
4079 };
4080
4081 _proto.drawTicks = function drawTicks(tickCfg) {
4082 var self = this;
4083 var ticks = self.ticks;
4084 var length = tickCfg.length;
4085 var container = self.getContainer(tickCfg.top);
4086 Util.each(ticks, function (tick) {
4087 var start = self.getOffsetPoint(tick.value);
4088 var end = self.getSidePoint(start, length);
4089 var shape = container.addShape('line', {
4090 className: 'axis-tick',
4091 attrs: Util.mix({
4092 x1: start.x,
4093 y1: start.y,
4094 x2: end.x,
4095 y2: end.y
4096 }, tickCfg)
4097 });
4098 shape._id = self._id + '-ticks';
4099 });
4100 };
4101
4102 _proto.drawLabels = function drawLabels() {
4103 var self = this;
4104 var labelOffset = self.labelOffset;
4105 var labels = self.labels;
4106 Util.each(labels, function (labelShape) {
4107 var container = self.getContainer(labelShape.get('top'));
4108 var start = self.getOffsetPoint(labelShape.get('value'));
4109
4110 var _self$getSidePoint = self.getSidePoint(start, labelOffset),
4111 x = _self$getSidePoint.x,
4112 y = _self$getSidePoint.y;
4113
4114 labelShape.attr(Util.mix({
4115 x: x,
4116 y: y
4117 }, self.getTextAlignInfo(start, labelOffset), labelShape.get('textStyle')));
4118 labelShape._id = self._id + '-' + labelShape.attr('text');
4119 container.add(labelShape);
4120 });
4121 };
4122
4123 _proto.drawLine = function drawLine() {};
4124
4125 _proto.drawGrid = function drawGrid(grid) {
4126 var self = this;
4127 var gridPoints = self.gridPoints,
4128 ticks = self.ticks;
4129 var gridCfg = grid;
4130 var count = gridPoints.length;
4131 Util.each(gridPoints, function (subPoints, index) {
4132 if (Util.isFunction(grid)) {
4133 var tick = ticks[index] || {};
4134 var executedGrid = grid(tick.text, index, count);
4135 gridCfg = executedGrid ? Util.mix({}, Global._defaultAxis.grid, executedGrid) : null;
4136 }
4137
4138 if (gridCfg) {
4139 var type = gridCfg.type; // has two types: 'line' and 'arc'
4140
4141 var points = subPoints.points;
4142 var container = self.getContainer(gridCfg.top);
4143 var shape;
4144
4145 if (type === 'arc') {
4146 var center = self.center,
4147 startAngle = self.startAngle,
4148 endAngle = self.endAngle;
4149 var radius = Vector2.length([points[0].x - center.x, points[0].y - center.y]);
4150 shape = container.addShape('Arc', {
4151 className: 'axis-grid',
4152 attrs: Util.mix({
4153 x: center.x,
4154 y: center.y,
4155 startAngle: startAngle,
4156 endAngle: endAngle,
4157 r: radius
4158 }, gridCfg)
4159 });
4160 } else {
4161 shape = container.addShape('Polyline', {
4162 className: 'axis-grid',
4163 attrs: Util.mix({
4164 points: points
4165 }, gridCfg)
4166 });
4167 }
4168
4169 shape._id = subPoints._id;
4170 }
4171 });
4172 };
4173
4174 _proto.getOffsetPoint = function getOffsetPoint() {};
4175
4176 _proto.getAxisVector = function getAxisVector() {};
4177
4178 _proto.getOffsetVector = function getOffsetVector(point, offset) {
4179 var self = this;
4180 var axisVector = self.getAxisVector(point);
4181 var normal = Vector2.normalize([], axisVector);
4182 var factor = self.offsetFactor;
4183 var verticalVector = [normal[1] * -1 * factor, normal[0] * factor];
4184 return Vector2.scale([], verticalVector, offset);
4185 };
4186
4187 _proto.getSidePoint = function getSidePoint(point, offset) {
4188 var self = this;
4189 var offsetVector = self.getOffsetVector(point, offset);
4190 return {
4191 x: point.x + offsetVector[0],
4192 y: point.y + offsetVector[1]
4193 };
4194 };
4195
4196 _proto.getTextAlignInfo = function getTextAlignInfo(point, offset) {
4197 var self = this;
4198 var offsetVector = self.getOffsetVector(point, offset);
4199 var align;
4200 var baseLine;
4201
4202 if (offsetVector[0] > 0) {
4203 align = 'left';
4204 } else if (offsetVector[0] < 0) {
4205 align = 'right';
4206 } else {
4207 align = 'center';
4208 }
4209
4210 if (offsetVector[1] > 0) {
4211 baseLine = 'top';
4212 } else if (offsetVector[1] < 0) {
4213 baseLine = 'bottom';
4214 } else {
4215 baseLine = 'middle';
4216 }
4217
4218 return {
4219 textAlign: align,
4220 textBaseline: baseLine
4221 };
4222 };
4223
4224 _proto.getContainer = function getContainer(isTop) {
4225 var frontContainer = this.frontContainer,
4226 backContainer = this.backContainer;
4227 return isTop ? frontContainer : backContainer;
4228 };
4229
4230 return Abastract;
4231}();
4232
4233module.exports = Abastract;
4234
4235/***/ }),
4236/* 26 */
4237/***/ (function(module, exports, __webpack_require__) {
4238
4239var Util = __webpack_require__(0);
4240
4241var MatrixUtil = __webpack_require__(27);
4242
4243var Vector2 = __webpack_require__(7);
4244
4245var StyleUtil = __webpack_require__(81);
4246
4247function isUnchanged(m) {
4248 return m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1 && m[4] === 0 && m[5] === 0;
4249}
4250
4251var ALIAS_ATTRS_MAP = {
4252 stroke: 'strokeStyle',
4253 fill: 'fillStyle',
4254 opacity: 'globalAlpha'
4255};
4256var SHAPE_ATTRS = ['fillStyle', 'font', 'globalAlpha', 'lineCap', 'lineWidth', 'lineJoin', 'miterLimit', 'shadowBlur', 'shadowColor', 'shadowOffsetX', 'shadowOffsetY', 'strokeStyle', 'textAlign', 'textBaseline', 'lineDash', 'shadow' // 兼容支付宝小程序
4257];
4258var CLIP_SHAPES = ['circle', 'sector', 'polygon', 'rect', 'polyline'];
4259
4260var Element =
4261/*#__PURE__*/
4262function () {
4263 var _proto = Element.prototype;
4264
4265 _proto._initProperties = function _initProperties() {
4266 this._attrs = {
4267 zIndex: 0,
4268 visible: true,
4269 destroyed: false
4270 };
4271 };
4272
4273 function Element(cfg) {
4274 this._initProperties();
4275
4276 Util.mix(this._attrs, cfg);
4277 var attrs = this._attrs.attrs;
4278
4279 if (attrs) {
4280 this.initAttrs(attrs);
4281 }
4282
4283 this.initTransform();
4284 }
4285
4286 _proto.get = function get(name) {
4287 return this._attrs[name];
4288 };
4289
4290 _proto.set = function set(name, value) {
4291 this._attrs[name] = value;
4292 };
4293
4294 _proto.isGroup = function isGroup() {
4295 return this.get('isGroup');
4296 };
4297
4298 _proto.isShape = function isShape() {
4299 return this.get('isShape');
4300 };
4301
4302 _proto.initAttrs = function initAttrs(attrs) {
4303 this.attr(Util.mix(this.getDefaultAttrs(), attrs));
4304 };
4305
4306 _proto.getDefaultAttrs = function getDefaultAttrs() {
4307 return {};
4308 };
4309
4310 _proto._setAttr = function _setAttr(name, value) {
4311 var attrs = this._attrs.attrs;
4312
4313 if (name === 'clip') {
4314 value = this._setAttrClip(value);
4315 } else {
4316 var alias = ALIAS_ATTRS_MAP[name];
4317
4318 if (alias) {
4319 attrs[alias] = value;
4320 }
4321 }
4322
4323 attrs[name] = value;
4324 };
4325
4326 _proto._getAttr = function _getAttr(name) {
4327 return this._attrs.attrs[name];
4328 } // _afterAttrsSet() {}
4329 ;
4330
4331 _proto._setAttrClip = function _setAttrClip(clip) {
4332 if (clip && CLIP_SHAPES.indexOf(clip._attrs.type) > -1) {
4333 if (clip.get('canvas') === null) {
4334 clip = Object.assign({}, clip);
4335 }
4336
4337 clip.set('parent', this.get('parent'));
4338 clip.set('context', this.get('context'));
4339 return clip;
4340 }
4341
4342 return null;
4343 };
4344
4345 _proto.attr = function attr(name, value) {
4346 var self = this;
4347 if (self.get('destroyed')) return null;
4348 var argumentsLen = arguments.length;
4349
4350 if (argumentsLen === 0) {
4351 return self._attrs.attrs;
4352 }
4353
4354 if (Util.isObject(name)) {
4355 this._attrs.bbox = null;
4356
4357 for (var k in name) {
4358 self._setAttr(k, name[k]);
4359 }
4360
4361 if (self._afterAttrsSet) {
4362 self._afterAttrsSet();
4363 }
4364
4365 return self;
4366 }
4367
4368 if (argumentsLen === 2) {
4369 this._attrs.bbox = null;
4370
4371 self._setAttr(name, value);
4372
4373 if (self._afterAttrsSet) {
4374 self._afterAttrsSet();
4375 }
4376
4377 return self;
4378 }
4379
4380 return self._getAttr(name);
4381 };
4382
4383 _proto.getParent = function getParent() {
4384 return this.get('parent');
4385 };
4386
4387 _proto.draw = function draw(context) {
4388 if (this.get('destroyed')) {
4389 return;
4390 }
4391
4392 if (this.get('visible')) {
4393 this.setContext(context);
4394 this.drawInner(context);
4395 this.restoreContext(context);
4396 }
4397 };
4398
4399 _proto.setContext = function setContext(context) {
4400 var clip = this._attrs.attrs.clip;
4401 context.save();
4402
4403 if (clip) {
4404 clip.resetTransform(context);
4405 clip.createPath(context);
4406 context.clip();
4407 }
4408
4409 this.resetContext(context);
4410 this.resetTransform(context);
4411 };
4412
4413 _proto.restoreContext = function restoreContext(context) {
4414 context.restore();
4415 };
4416
4417 _proto.resetContext = function resetContext(context) {
4418 var elAttrs = this._attrs.attrs;
4419
4420 if (!this._attrs.isGroup) {
4421 for (var k in elAttrs) {
4422 if (SHAPE_ATTRS.indexOf(k) > -1) {
4423 var v = elAttrs[k];
4424
4425 if (k === 'fillStyle' || k === 'strokeStyle') {
4426 v = StyleUtil.parseStyle(v, this, context);
4427 }
4428
4429 if (k === 'lineDash' && context.setLineDash && Util.isArray(v)) {
4430 context.setLineDash(v);
4431 } else {
4432 context[k] = v;
4433 }
4434 }
4435 }
4436 }
4437 };
4438
4439 _proto.hasFill = function hasFill() {
4440 return this.get('canFill') && this._attrs.attrs.fillStyle;
4441 };
4442
4443 _proto.hasStroke = function hasStroke() {
4444 return this.get('canStroke') && this._attrs.attrs.strokeStyle;
4445 };
4446
4447 _proto.drawInner = function drawInner()
4448 /* context */
4449 {};
4450
4451 _proto.show = function show() {
4452 this.set('visible', true);
4453 return this;
4454 };
4455
4456 _proto.hide = function hide() {
4457 this.set('visible', false);
4458 return this;
4459 };
4460
4461 _proto.isVisible = function isVisible() {
4462 return this.get('visible');
4463 };
4464
4465 _proto._removeFromParent = function _removeFromParent() {
4466 var parent = this.get('parent');
4467
4468 if (parent) {
4469 var children = parent.get('children');
4470 Util.Array.remove(children, this);
4471 }
4472
4473 return this;
4474 };
4475
4476 _proto.remove = function remove(destroy) {
4477 if (destroy) {
4478 this.destroy();
4479 } else {
4480 this._removeFromParent();
4481 }
4482 };
4483
4484 _proto.destroy = function destroy() {
4485 var destroyed = this.get('destroyed');
4486
4487 if (destroyed) {
4488 return null;
4489 }
4490
4491 this._removeFromParent();
4492
4493 this._attrs = {};
4494 this.set('destroyed', true);
4495 };
4496
4497 _proto.getBBox = function getBBox() {
4498 return {
4499 minX: 0,
4500 maxX: 0,
4501 minY: 0,
4502 maxY: 0,
4503 width: 0,
4504 height: 0
4505 };
4506 };
4507
4508 _proto.initTransform = function initTransform() {
4509 var attrs = this._attrs.attrs || {};
4510
4511 if (!attrs.matrix) {
4512 attrs.matrix = [1, 0, 0, 1, 0, 0];
4513 }
4514
4515 this._attrs.attrs = attrs;
4516 };
4517
4518 _proto.getMatrix = function getMatrix() {
4519 return this._attrs.attrs.matrix;
4520 };
4521
4522 _proto.setMatrix = function setMatrix(m) {
4523 this._attrs.attrs.matrix = [m[0], m[1], m[2], m[3], m[4], m[5]];
4524 };
4525
4526 _proto.transform = function transform(actions) {
4527 var matrix = this._attrs.attrs.matrix;
4528 this._attrs.attrs.matrix = MatrixUtil.transform(matrix, actions);
4529 return this;
4530 };
4531
4532 _proto.setTransform = function setTransform(actions) {
4533 this._attrs.attrs.matrix = [1, 0, 0, 1, 0, 0];
4534 return this.transform(actions);
4535 };
4536
4537 _proto.translate = function translate(x, y) {
4538 var matrix = this._attrs.attrs.matrix;
4539 MatrixUtil.translate(matrix, matrix, [x, y]);
4540 };
4541
4542 _proto.rotate = function rotate(rad) {
4543 var matrix = this._attrs.attrs.matrix;
4544 MatrixUtil.rotate(matrix, matrix, rad);
4545 };
4546
4547 _proto.scale = function scale(sx, sy) {
4548 var matrix = this._attrs.attrs.matrix;
4549 MatrixUtil.scale(matrix, matrix, [sx, sy]);
4550 };
4551
4552 _proto.moveTo = function moveTo(x, y) {
4553 var cx = this._attrs.x || 0;
4554 var cy = this._attrs.y || 0;
4555 this.translate(x - cx, y - cy);
4556 this.set('x', x);
4557 this.set('y', y);
4558 };
4559
4560 _proto.apply = function apply(v) {
4561 var m = this._attrs.attrs.matrix;
4562 Vector2.transformMat2d(v, v, m);
4563 return this;
4564 };
4565
4566 _proto.resetTransform = function resetTransform(context) {
4567 var mo = this._attrs.attrs.matrix;
4568
4569 if (!isUnchanged(mo)) {
4570 context.transform(mo[0], mo[1], mo[2], mo[3], mo[4], mo[5]);
4571 }
4572 };
4573
4574 _proto.isDestroyed = function isDestroyed() {
4575 return this.get('destroyed');
4576 };
4577
4578 return Element;
4579}();
4580
4581module.exports = Element;
4582
4583/***/ }),
4584/* 27 */
4585/***/ (function(module, exports) {
4586
4587var Matrix = {
4588 multiply: function multiply(m1, m2) {
4589 var m11 = m1[0] * m2[0] + m1[2] * m2[1];
4590 var m12 = m1[1] * m2[0] + m1[3] * m2[1];
4591 var m21 = m1[0] * m2[2] + m1[2] * m2[3];
4592 var m22 = m1[1] * m2[2] + m1[3] * m2[3];
4593 var dx = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
4594 var dy = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
4595 return [m11, m12, m21, m22, dx, dy];
4596 },
4597 scale: function scale(out, m, v) {
4598 out[0] = m[0] * v[0];
4599 out[1] = m[1] * v[0];
4600 out[2] = m[2] * v[1];
4601 out[3] = m[3] * v[1];
4602 out[4] = m[4];
4603 out[5] = m[5];
4604 return out;
4605 },
4606 rotate: function rotate(out, m, radian) {
4607 var c = Math.cos(radian);
4608 var s = Math.sin(radian);
4609 var m11 = m[0] * c + m[2] * s;
4610 var m12 = m[1] * c + m[3] * s;
4611 var m21 = m[0] * -s + m[2] * c;
4612 var m22 = m[1] * -s + m[3] * c;
4613 out[0] = m11;
4614 out[1] = m12;
4615 out[2] = m21;
4616 out[3] = m22;
4617 out[4] = m[4];
4618 out[5] = m[5];
4619 return out;
4620 },
4621 translate: function translate(out, m, v) {
4622 out[0] = m[0];
4623 out[1] = m[1];
4624 out[2] = m[2];
4625 out[3] = m[3];
4626 out[4] = m[4] + m[0] * v[0] + m[2] * v[1];
4627 out[5] = m[5] + m[1] * v[0] + m[3] * v[1];
4628 return out;
4629 },
4630 transform: function transform(m, actions) {
4631 var out = [].concat(m);
4632
4633 for (var i = 0, len = actions.length; i < len; i++) {
4634 var action = actions[i];
4635
4636 switch (action[0]) {
4637 case 't':
4638 Matrix.translate(out, out, [action[1], action[2]]);
4639 break;
4640
4641 case 's':
4642 Matrix.scale(out, out, [action[1], action[2]]);
4643 break;
4644
4645 case 'r':
4646 Matrix.rotate(out, out, action[1]);
4647 break;
4648
4649 default:
4650 break;
4651 }
4652 }
4653
4654 return out;
4655 }
4656};
4657module.exports = Matrix;
4658
4659/***/ }),
4660/* 28 */
4661/***/ (function(module, exports, __webpack_require__) {
4662
4663/**
4664 * @fileOverview 提取公共代码到util方法
4665 * @author dxq613@gmail.com
4666 */
4667var isString = __webpack_require__(13);
4668
4669var isDate = __webpack_require__(31);
4670
4671module.exports = {
4672 toTimeStamp: function toTimeStamp(value) {
4673 if (isString(value)) {
4674 if (value.indexOf('T') > 0) {
4675 value = new Date(value).getTime();
4676 } else {
4677 value = new Date(value.replace(/-/ig, '/')).getTime();
4678 }
4679 }
4680
4681 if (isDate(value)) {
4682 value = value.getTime();
4683 }
4684
4685 return value;
4686 }
4687};
4688
4689/***/ }),
4690/* 29 */
4691/***/ (function(module, exports, __webpack_require__) {
4692
4693var TimeUtil = __webpack_require__(28);
4694
4695var Util = __webpack_require__(0);
4696
4697module.exports = {
4698 getColDef: function getColDef(chart, field) {
4699 var colDef;
4700
4701 if (chart.get('colDefs') && chart.get('colDefs')[field]) {
4702 colDef = chart.get('colDefs')[field];
4703 }
4704
4705 return colDef;
4706 },
4707 getFieldRange: function getFieldRange(scale, limitRange, type) {
4708 if (!scale) return [0, 1];
4709 var minRatio = 0;
4710 var maxRatio = 0;
4711
4712 if (type === 'linear') {
4713 var min = limitRange.min,
4714 max = limitRange.max;
4715 minRatio = (scale.min - min) / (max - min);
4716 maxRatio = (scale.max - min) / (max - min);
4717 } else {
4718 var originValues = limitRange;
4719 var values = scale.values;
4720 var firstIndex = originValues.indexOf(values[0]);
4721 var lastIndex = originValues.indexOf(values[values.length - 1]);
4722 minRatio = firstIndex / (originValues.length - 1);
4723 maxRatio = lastIndex / (originValues.length - 1);
4724 }
4725
4726 return [minRatio, maxRatio];
4727 },
4728 getLimitRange: function getLimitRange(data, scale) {
4729 var result;
4730 var field = scale.field,
4731 type = scale.type;
4732 var values = Util.Array.values(data, field);
4733
4734 if (type === 'linear') {
4735 result = Util.Array.getRange(values);
4736
4737 if (scale.min < result.min) {
4738 result.min = scale.min;
4739 }
4740
4741 if (scale.max > result.max) {
4742 result.max = scale.max;
4743 }
4744 } else if (type === 'timeCat') {
4745 Util.each(values, function (v, i) {
4746 values[i] = TimeUtil.toTimeStamp(v);
4747 });
4748 values.sort(function (v1, v2) {
4749 return v1 - v2;
4750 });
4751 result = values;
4752 } else {
4753 result = values;
4754 }
4755
4756 return result;
4757 }
4758};
4759
4760/***/ }),
4761/* 30 */
4762/***/ (function(module, exports, __webpack_require__) {
4763
4764var isNil = __webpack_require__(10);
4765
4766function toString(value) {
4767 if (isNil(value)) return '';
4768 return value.toString();
4769}
4770
4771module.exports = toString;
4772
4773/***/ }),
4774/* 31 */
4775/***/ (function(module, exports, __webpack_require__) {
4776
4777var isType = __webpack_require__(9);
4778
4779var isDate = function isDate(value) {
4780 return isType(value, 'Date');
4781};
4782
4783module.exports = isDate;
4784
4785/***/ }),
4786/* 32 */
4787/***/ (function(module, exports, __webpack_require__) {
4788
4789var isObjectLike = __webpack_require__(59);
4790
4791var isType = __webpack_require__(9);
4792
4793var isPlainObject = function isPlainObject(value) {
4794 /**
4795 * isObjectLike(new Foo) => false
4796 * isObjectLike([1, 2, 3]) => false
4797 * isObjectLike({ x: 0, y: 0 }) => true
4798 * isObjectLike(Object.create(null)) => true
4799 */
4800 if (!isObjectLike(value) || !isType(value, 'Object')) {
4801 return false;
4802 }
4803
4804 if (Object.getPrototypeOf(value) === null) {
4805 return true;
4806 }
4807
4808 var proto = value;
4809
4810 while (Object.getPrototypeOf(proto) !== null) {
4811 proto = Object.getPrototypeOf(proto);
4812 }
4813
4814 return Object.getPrototypeOf(value) === proto;
4815};
4816
4817module.exports = isPlainObject;
4818
4819/***/ }),
4820/* 33 */
4821/***/ (function(module, exports, __webpack_require__) {
4822
4823/**
4824 * @fileOverview Base class of chart and geometry
4825 * @author dxq613@gmail.com
4826 */
4827var Util = __webpack_require__(0);
4828
4829var Base =
4830/*#__PURE__*/
4831function () {
4832 var _proto = Base.prototype;
4833
4834 _proto.getDefaultCfg = function getDefaultCfg() {
4835 return {};
4836 };
4837
4838 function Base(cfg) {
4839 var attrs = {};
4840 var defaultCfg = this.getDefaultCfg();
4841 this._attrs = attrs;
4842 Util.mix(attrs, defaultCfg, cfg);
4843 }
4844
4845 _proto.get = function get(name) {
4846 return this._attrs[name];
4847 };
4848
4849 _proto.set = function set(name, value) {
4850 this._attrs[name] = value;
4851 };
4852
4853 _proto.destroy = function destroy() {
4854 this._attrs = {};
4855 this.destroyed = true;
4856 };
4857
4858 return Base;
4859}();
4860
4861module.exports = Base;
4862
4863/***/ }),
4864/* 34 */
4865/***/ (function(module, exports, __webpack_require__) {
4866
4867function _inheritsLoose(subClass, superClass) {
4868 subClass.prototype = Object.create(superClass.prototype);
4869 subClass.prototype.constructor = subClass;
4870 subClass.__proto__ = superClass;
4871}
4872
4873var Base = __webpack_require__(16);
4874
4875var catAuto = __webpack_require__(35);
4876
4877var each = __webpack_require__(5);
4878
4879var isNumber = __webpack_require__(14);
4880
4881var isString = __webpack_require__(13);
4882
4883var Category =
4884/*#__PURE__*/
4885function (_Base) {
4886 _inheritsLoose(Category, _Base);
4887
4888 function Category() {
4889 return _Base.apply(this, arguments) || this;
4890 }
4891
4892 var _proto = Category.prototype;
4893
4894 _proto._initDefaultCfg = function _initDefaultCfg() {
4895 _Base.prototype._initDefaultCfg.call(this);
4896
4897 this.type = 'cat';
4898 /**
4899 * 是否分类度量
4900 * @type {Boolean}
4901 */
4902
4903 this.isCategory = true;
4904 this.isRounding = true; // 是否进行取整操作
4905 };
4906 /**
4907 * @override
4908 */
4909
4910
4911 _proto.init = function init() {
4912 var self = this;
4913 var values = self.values;
4914 var tickCount = self.tickCount;
4915 each(values, function (v, i) {
4916 values[i] = v.toString();
4917 });
4918
4919 if (!self.ticks) {
4920 var ticks = values;
4921
4922 if (tickCount) {
4923 var temp = catAuto({
4924 maxCount: tickCount,
4925 data: values,
4926 isRounding: self.isRounding
4927 });
4928 ticks = temp.ticks;
4929 }
4930
4931 this.ticks = ticks;
4932 }
4933 };
4934 /**
4935 * @override
4936 */
4937
4938
4939 _proto.getText = function getText(value) {
4940 if (this.values.indexOf(value) === -1 && isNumber(value)) {
4941 value = this.values[Math.round(value)];
4942 }
4943
4944 return _Base.prototype.getText.call(this, value);
4945 };
4946 /**
4947 * @override
4948 */
4949
4950
4951 _proto.translate = function translate(value) {
4952 var index = this.values.indexOf(value);
4953
4954 if (index === -1 && isNumber(value)) {
4955 index = value;
4956 } else if (index === -1) {
4957 index = NaN;
4958 }
4959
4960 return index;
4961 };
4962 /**
4963 * @override
4964 */
4965
4966
4967 _proto.scale = function scale(value) {
4968 var rangeMin = this.rangeMin();
4969 var rangeMax = this.rangeMax();
4970 var percent;
4971
4972 if (isString(value) || this.values.indexOf(value) !== -1) {
4973 value = this.translate(value);
4974 }
4975
4976 if (this.values.length > 1) {
4977 percent = value / (this.values.length - 1);
4978 } else {
4979 percent = value;
4980 }
4981
4982 return rangeMin + percent * (rangeMax - rangeMin);
4983 };
4984 /**
4985 * @override
4986 */
4987
4988
4989 _proto.invert = function invert(value) {
4990 if (isString(value)) {
4991 // 如果已经是字符串
4992 return value;
4993 }
4994
4995 var min = this.rangeMin();
4996 var max = this.rangeMax(); // 归一到 范围内
4997
4998 if (value < min) {
4999 value = min;
5000 }
5001
5002 if (value > max) {
5003 value = max;
5004 }
5005
5006 var percent = (value - min) / (max - min);
5007 var index = Math.round(percent * (this.values.length - 1)) % this.values.length;
5008 index = index || 0;
5009 return this.values[index];
5010 };
5011
5012 return Category;
5013}(Base);
5014
5015Base.Cat = Category;
5016module.exports = Category;
5017
5018/***/ }),
5019/* 35 */
5020/***/ (function(module, exports, __webpack_require__) {
5021
5022/**
5023 * @fileOverview 计算分类的的坐标点
5024 * @author dxq613@gmail.com
5025 */
5026var each = __webpack_require__(5);
5027
5028var MAX_COUNT = 8;
5029var SUB_COUNT = 4; // 控制个数不能过小
5030
5031function getSimpleArray(data) {
5032 var arr = [];
5033 each(data, function (sub) {
5034 arr = arr.concat(sub);
5035 });
5036 return arr;
5037}
5038
5039function getGreatestFactor(count, number) {
5040 var i;
5041
5042 for (i = number; i > 0; i--) {
5043 if (count % i === 0) {
5044 break;
5045 }
5046 } // 如果是素数,没有可以整除的数字
5047
5048
5049 if (i === 1) {
5050 for (i = number; i > 0; i--) {
5051 if ((count - 1) % i === 0) {
5052 break;
5053 }
5054 }
5055 }
5056
5057 return i;
5058}
5059
5060module.exports = function (info) {
5061 var rst = {};
5062 var ticks = [];
5063 var isRounding = info.isRounding;
5064 var categories = getSimpleArray(info.data);
5065 var length = categories.length;
5066 var maxCount = info.maxCount || MAX_COUNT;
5067 var tickCount;
5068
5069 if (isRounding) {
5070 // 取整操作
5071 tickCount = getGreatestFactor(length - 1, maxCount - 1) + 1; // 如果计算出来只有两个坐标点,则直接使用传入的 maxCount
5072
5073 if (tickCount === 2) {
5074 tickCount = maxCount;
5075 } else if (tickCount < maxCount - SUB_COUNT) {
5076 tickCount = maxCount - SUB_COUNT;
5077 }
5078 } else {
5079 tickCount = maxCount;
5080 }
5081
5082 if (!isRounding && length <= tickCount + tickCount / 2) {
5083 ticks = [].concat(categories);
5084 } else {
5085 var step = parseInt(length / (tickCount - 1), 10);
5086 var groups = categories.map(function (e, i) {
5087 return i % step === 0 ? categories.slice(i, i + step) : null;
5088 }).filter(function (e) {
5089 return e;
5090 });
5091
5092 for (var i = 1, groupLen = groups.length; i < groupLen && (isRounding ? i * step < length - step : i < tickCount - 1); i++) {
5093 ticks.push(groups[i][0]);
5094 }
5095
5096 if (categories.length) {
5097 ticks.unshift(categories[0]);
5098 var last = categories[length - 1];
5099
5100 if (ticks.indexOf(last) === -1) {
5101 ticks.push(last);
5102 }
5103 }
5104 }
5105
5106 rst.categories = categories;
5107 rst.ticks = ticks;
5108 return rst;
5109};
5110
5111/***/ }),
5112/* 36 */
5113/***/ (function(module, exports, __webpack_require__) {
5114
5115var Util = __webpack_require__(0);
5116
5117var Shape = __webpack_require__(2);
5118
5119var SHAPE_MAP = {};
5120var INDEX = '_INDEX';
5121
5122function getComparer(compare) {
5123 return function (left, right) {
5124 var result = compare(left, right);
5125 return result === 0 ? left[INDEX] - right[INDEX] : result;
5126 };
5127}
5128
5129module.exports = {
5130 getGroupClass: function getGroupClass() {},
5131 getChildren: function getChildren() {
5132 return this.get('children');
5133 },
5134 addShape: function addShape(type, cfg) {
5135 if (cfg === void 0) {
5136 cfg = {};
5137 }
5138
5139 var canvas = this.get('canvas');
5140 var shapeType = SHAPE_MAP[type];
5141
5142 if (!shapeType) {
5143 shapeType = Util.upperFirst(type);
5144 SHAPE_MAP[type] = shapeType;
5145 }
5146
5147 cfg.canvas = canvas;
5148
5149 if (shapeType === 'Text' && canvas && canvas.get('fontFamily')) {
5150 cfg.attrs.fontFamily = cfg.attrs.fontFamily || canvas.get('fontFamily');
5151 }
5152
5153 var shape = new Shape[shapeType](cfg);
5154 this.add(shape);
5155 return shape;
5156 },
5157 addGroup: function addGroup(cfg) {
5158 var canvas = this.get('canvas');
5159 var groupClass = this.getGroupClass();
5160 cfg = Util.mix({}, cfg);
5161 cfg.canvas = canvas;
5162 cfg.parent = this;
5163 var rst = new groupClass(cfg);
5164 this.add(rst);
5165 return rst;
5166 },
5167 contain: function contain(item) {
5168 var children = this.get('children');
5169 return children.indexOf(item) > -1;
5170 },
5171 sort: function sort() {
5172 var children = this.get('children');
5173
5174 for (var i = 0, len = children.length; i < len; i++) {
5175 var child = children[i];
5176 child[INDEX] = i;
5177 }
5178
5179 children.sort(getComparer(function (obj1, obj2) {
5180 return obj1.get('zIndex') - obj2.get('zIndex');
5181 }));
5182 return this;
5183 },
5184 clear: function clear() {
5185 var children = this.get('children');
5186
5187 while (children.length !== 0) {
5188 children[children.length - 1].remove(true);
5189 }
5190
5191 return this;
5192 },
5193 add: function add(items) {
5194 var self = this;
5195 var children = self.get('children');
5196
5197 if (!Util.isArray(items)) {
5198 items = [items];
5199 }
5200
5201 for (var i = 0, len = items.length; i < len; i++) {
5202 var item = items[i];
5203 var parent = item.get('parent');
5204
5205 if (parent) {
5206 var descendants = parent.get('children');
5207 Util.Array.remove(descendants, item);
5208 }
5209
5210 self._setEvn(item);
5211
5212 children.push(item);
5213 }
5214
5215 return self;
5216 },
5217 _setEvn: function _setEvn(item) {
5218 var self = this;
5219 item._attrs.parent = self;
5220 item._attrs.context = self._attrs.context;
5221 item._attrs.canvas = self._attrs.canvas;
5222 var clip = item._attrs.attrs.clip;
5223
5224 if (clip) {
5225 clip.set('parent', self);
5226 clip.set('context', self.get('context'));
5227 }
5228
5229 if (item._attrs.isGroup) {
5230 var children = item._attrs.children;
5231
5232 for (var i = 0, len = children.length; i < len; i++) {
5233 item._setEvn(children[i]);
5234 }
5235 }
5236 }
5237};
5238
5239/***/ }),
5240/* 37 */
5241/***/ (function(module, exports, __webpack_require__) {
5242
5243function _inheritsLoose(subClass, superClass) {
5244 subClass.prototype = Object.create(superClass.prototype);
5245 subClass.prototype.constructor = subClass;
5246 subClass.__proto__ = superClass;
5247}
5248
5249var Util = __webpack_require__(0);
5250
5251var Element = __webpack_require__(26);
5252
5253var Container = __webpack_require__(36);
5254
5255var Vector2 = __webpack_require__(7);
5256
5257var Group =
5258/*#__PURE__*/
5259function (_Element) {
5260 _inheritsLoose(Group, _Element);
5261
5262 function Group() {
5263 return _Element.apply(this, arguments) || this;
5264 }
5265
5266 var _proto = Group.prototype;
5267
5268 _proto._initProperties = function _initProperties() {
5269 this._attrs = {
5270 zIndex: 0,
5271 visible: true,
5272 destroyed: false,
5273 isGroup: true,
5274 children: []
5275 };
5276 };
5277
5278 _proto.drawInner = function drawInner(context) {
5279 var children = this.get('children');
5280
5281 for (var i = 0, len = children.length; i < len; i++) {
5282 var child = children[i];
5283 child.draw(context);
5284 }
5285
5286 return this;
5287 };
5288
5289 _proto.getBBox = function getBBox() {
5290 var self = this;
5291 var minX = Infinity;
5292 var maxX = -Infinity;
5293 var minY = Infinity;
5294 var maxY = -Infinity;
5295 var children = self.get('children');
5296
5297 for (var i = 0, length = children.length; i < length; i++) {
5298 var child = children[i];
5299
5300 if (child.get('visible')) {
5301 var box = child.getBBox();
5302
5303 if (!box) {
5304 continue;
5305 }
5306
5307 var leftTop = [box.minX, box.minY];
5308 var leftBottom = [box.minX, box.maxY];
5309 var rightTop = [box.maxX, box.minY];
5310 var rightBottom = [box.maxX, box.maxY];
5311 var matrix = child.attr('matrix');
5312 Vector2.transformMat2d(leftTop, leftTop, matrix);
5313 Vector2.transformMat2d(leftBottom, leftBottom, matrix);
5314 Vector2.transformMat2d(rightTop, rightTop, matrix);
5315 Vector2.transformMat2d(rightBottom, rightBottom, matrix);
5316 minX = Math.min(leftTop[0], leftBottom[0], rightTop[0], rightBottom[0], minX);
5317 maxX = Math.max(leftTop[0], leftBottom[0], rightTop[0], rightBottom[0], maxX);
5318 minY = Math.min(leftTop[1], leftBottom[1], rightTop[1], rightBottom[1], minY);
5319 maxY = Math.max(leftTop[1], leftBottom[1], rightTop[1], rightBottom[1], maxY);
5320 }
5321 }
5322
5323 return {
5324 minX: minX,
5325 minY: minY,
5326 maxX: maxX,
5327 maxY: maxY,
5328 x: minX,
5329 y: minY,
5330 width: maxX - minX,
5331 height: maxY - minY
5332 };
5333 };
5334
5335 _proto.destroy = function destroy() {
5336 if (this.get('destroyed')) {
5337 return;
5338 }
5339
5340 this.clear();
5341
5342 _Element.prototype.destroy.call(this);
5343 };
5344
5345 return Group;
5346}(Element);
5347
5348Util.mix(Group.prototype, Container, {
5349 getGroupClass: function getGroupClass() {
5350 return Group;
5351 }
5352});
5353module.exports = Group;
5354
5355/***/ }),
5356/* 38 */
5357/***/ (function(module, exports) {
5358
5359module.exports = {
5360 requestAnimationFrame: typeof window === 'object' && window.requestAnimationFrame ? window.requestAnimationFrame : function (fn) {
5361 return setTimeout(fn, 16);
5362 }
5363};
5364
5365/***/ }),
5366/* 39 */
5367/***/ (function(module, exports, __webpack_require__) {
5368
5369/**
5370 * @fileOverview convert the line to curve
5371 * @author dxq613@gmail.com
5372 */
5373var Vector2 = __webpack_require__(7);
5374
5375function getPoint(v) {
5376 return [v.x, v.y];
5377}
5378
5379function smoothBezier(points, smooth, isLoop, constraint) {
5380 var cps = [];
5381 var prevPoint;
5382 var nextPoint;
5383 var hasConstraint = !!constraint;
5384 var min;
5385 var max;
5386 var point;
5387 var len;
5388 var l;
5389 var i;
5390
5391 if (hasConstraint) {
5392 min = [Infinity, Infinity];
5393 max = [-Infinity, -Infinity];
5394
5395 for (i = 0, l = points.length; i < l; i++) {
5396 point = getPoint(points[i]);
5397 Vector2.min(min, min, point);
5398 Vector2.max(max, max, point);
5399 }
5400
5401 Vector2.min(min, min, constraint[0]);
5402 Vector2.max(max, max, constraint[1]);
5403 }
5404
5405 for (i = 0, len = points.length; i < len; i++) {
5406 point = getPoint(points[i]);
5407
5408 if (isLoop) {
5409 prevPoint = getPoint(points[i ? i - 1 : len - 1]);
5410 nextPoint = getPoint(points[(i + 1) % len]);
5411 } else {
5412 if (i === 0 || i === len - 1) {
5413 cps.push([point[0], point[1]]);
5414 continue;
5415 } else {
5416 prevPoint = getPoint(points[i - 1]);
5417 nextPoint = getPoint(points[i + 1]);
5418 }
5419 }
5420
5421 var v = Vector2.sub([], nextPoint, prevPoint);
5422 Vector2.scale(v, v, smooth);
5423 var d0 = Vector2.distance(point, prevPoint);
5424 var d1 = Vector2.distance(point, nextPoint);
5425 var sum = d0 + d1;
5426
5427 if (sum !== 0) {
5428 d0 /= sum;
5429 d1 /= sum;
5430 }
5431
5432 var v1 = Vector2.scale([], v, -d0);
5433 var v2 = Vector2.scale([], v, d1);
5434 var cp0 = Vector2.add([], point, v1);
5435 var cp1 = Vector2.add([], point, v2);
5436
5437 if (hasConstraint) {
5438 Vector2.max(cp0, cp0, min);
5439 Vector2.min(cp0, cp0, max);
5440 Vector2.max(cp1, cp1, min);
5441 Vector2.min(cp1, cp1, max);
5442 }
5443
5444 cps.push([cp0[0], cp0[1]]);
5445 cps.push([cp1[0], cp1[1]]);
5446 }
5447
5448 if (isLoop) {
5449 cps.push(cps.shift());
5450 }
5451
5452 return cps;
5453}
5454
5455function catmullRom2bezier(pointList, z, constraint) {
5456 var isLoop = !!z;
5457 var controlPointList = smoothBezier(pointList, 0.4, isLoop, constraint);
5458 var len = pointList.length;
5459 var d1 = [];
5460 var cp1;
5461 var cp2;
5462 var p;
5463
5464 for (var i = 0; i < len - 1; i++) {
5465 cp1 = controlPointList[i * 2];
5466 cp2 = controlPointList[i * 2 + 1];
5467 p = pointList[i + 1];
5468 d1.push(['C', cp1[0], cp1[1], cp2[0], cp2[1], p.x, p.y]);
5469 }
5470
5471 if (isLoop) {
5472 cp1 = controlPointList[len];
5473 cp2 = controlPointList[len + 1];
5474 p = pointList[0];
5475 d1.push(['C', cp1[0], cp1[1], cp2[0], cp2[1], p.x, p.y]);
5476 }
5477
5478 return d1;
5479}
5480
5481module.exports = {
5482 smooth: catmullRom2bezier
5483};
5484
5485/***/ }),
5486/* 40 */
5487/***/ (function(module, exports, __webpack_require__) {
5488
5489function _inheritsLoose(subClass, superClass) {
5490 subClass.prototype = Object.create(superClass.prototype);
5491 subClass.prototype.constructor = subClass;
5492 subClass.__proto__ = superClass;
5493}
5494
5495var Geom = __webpack_require__(4);
5496
5497var ShapeUtil = __webpack_require__(20);
5498
5499var Util = __webpack_require__(0);
5500
5501__webpack_require__(41);
5502
5503var Path =
5504/*#__PURE__*/
5505function (_Geom) {
5506 _inheritsLoose(Path, _Geom);
5507
5508 function Path() {
5509 return _Geom.apply(this, arguments) || this;
5510 }
5511
5512 var _proto = Path.prototype;
5513
5514 _proto.getDefaultCfg = function getDefaultCfg() {
5515 var cfg = _Geom.prototype.getDefaultCfg.call(this);
5516
5517 cfg.type = 'path';
5518 cfg.shapeType = 'line';
5519 return cfg;
5520 };
5521
5522 _proto.getDrawCfg = function getDrawCfg(obj) {
5523 var cfg = _Geom.prototype.getDrawCfg.call(this, obj);
5524
5525 cfg.isStack = this.hasAdjust('stack');
5526 return cfg;
5527 };
5528
5529 _proto.draw = function draw(data, shapeFactory) {
5530 var self = this;
5531 var container = self.get('container');
5532 var yScale = self.getYScale();
5533 var connectNulls = self.get('connectNulls');
5534 var splitArray = ShapeUtil.splitArray(data, yScale.field, connectNulls);
5535 var cfg = this.getDrawCfg(data[0]);
5536 cfg.origin = data;
5537 Util.each(splitArray, function (subData, splitedIndex) {
5538 cfg.splitedIndex = splitedIndex;
5539 cfg.points = subData;
5540 self.drawShape(cfg.shape, data[0], cfg, container, shapeFactory);
5541 });
5542 };
5543
5544 return Path;
5545}(Geom);
5546
5547Geom.Path = Path;
5548module.exports = Path;
5549
5550/***/ }),
5551/* 41 */
5552/***/ (function(module, exports, __webpack_require__) {
5553
5554var Util = __webpack_require__(0);
5555
5556var Shape = __webpack_require__(6);
5557
5558var ShapeUtil = __webpack_require__(20);
5559
5560var Global = __webpack_require__(1); // register line geom
5561
5562
5563var Line = Shape.registerFactory('line', {
5564 defaultShapeType: 'line'
5565});
5566
5567function getStyle(cfg) {
5568 var style = {
5569 strokeStyle: cfg.color
5570 };
5571
5572 if (cfg.size >= 0) {
5573 style.lineWidth = cfg.size;
5574 }
5575
5576 Util.mix(style, cfg.style);
5577 return Util.mix({}, Global.shape.line, style);
5578}
5579
5580function drawLines(cfg, container, style, smooth) {
5581 var points = cfg.points;
5582
5583 if (points.length && Util.isArray(points[0].y)) {
5584 var topPoints = [];
5585 var bottomPoints = [];
5586
5587 for (var i = 0, len = points.length; i < len; i++) {
5588 var point = points[i];
5589 var tmp = ShapeUtil.splitPoints(point);
5590 bottomPoints.push(tmp[0]);
5591 topPoints.push(tmp[1]);
5592 }
5593
5594 if (cfg.isInCircle) {
5595 topPoints.push(topPoints[0]);
5596 bottomPoints.push(bottomPoints[0]);
5597 }
5598
5599 if (cfg.isStack) {
5600 return container.addShape('Polyline', {
5601 className: 'line',
5602 attrs: Util.mix({
5603 points: topPoints,
5604 smooth: smooth
5605 }, style)
5606 });
5607 }
5608
5609 var topShape = container.addShape('Polyline', {
5610 className: 'line',
5611 attrs: Util.mix({
5612 points: topPoints,
5613 smooth: smooth
5614 }, style)
5615 });
5616 var bottomShape = container.addShape('Polyline', {
5617 className: 'line',
5618 attrs: Util.mix({
5619 points: bottomPoints,
5620 smooth: smooth
5621 }, style)
5622 });
5623 return [topShape, bottomShape];
5624 }
5625
5626 if (cfg.isInCircle) {
5627 points.push(points[0]);
5628 }
5629
5630 return container.addShape('Polyline', {
5631 className: 'line',
5632 attrs: Util.mix({
5633 points: points,
5634 smooth: smooth
5635 }, style)
5636 });
5637}
5638
5639var SHAPES = ['line', 'smooth', 'dash'];
5640Util.each(SHAPES, function (shapeType) {
5641 Shape.registerShape('line', shapeType, {
5642 draw: function draw(cfg, container) {
5643 var smooth = shapeType === 'smooth';
5644 var style = getStyle(cfg);
5645
5646 if (shapeType === 'dash') {
5647 style.lineDash = Global.lineDash;
5648 }
5649
5650 return drawLines(cfg, container, style, smooth);
5651 }
5652 });
5653});
5654module.exports = Line;
5655
5656/***/ }),
5657/* 42 */
5658/***/ (function(module, exports, __webpack_require__) {
5659
5660/**
5661 * @fileOverview Utility for calculate the with ratui in x axis
5662 * @author sima.zhang1990@gmail.com
5663 * @author dxq613@gmail.com
5664 */
5665var Global = __webpack_require__(1);
5666
5667var Util = __webpack_require__(0);
5668
5669var SizeMixin = {
5670 getDefalutSize: function getDefalutSize() {
5671 var defaultSize = this.get('defaultSize');
5672
5673 if (!defaultSize) {
5674 var coord = this.get('coord');
5675 var xScale = this.getXScale();
5676 var dataArray = this.get('dataArray');
5677 var count = xScale.values.length;
5678 var range = xScale.range;
5679 var normalizeSize = 1 / count;
5680 var widthRatio = 1;
5681
5682 if (coord && coord.isPolar) {
5683 if (coord.transposed && count > 1) {
5684 widthRatio = Global.widthRatio.multiplePie;
5685 } else {
5686 widthRatio = Global.widthRatio.rose;
5687 }
5688 } else {
5689 if (xScale.isLinear) {
5690 normalizeSize *= range[1] - range[0];
5691 }
5692
5693 widthRatio = Global.widthRatio.column;
5694 }
5695
5696 normalizeSize *= widthRatio;
5697
5698 if (this.hasAdjust('dodge')) {
5699 normalizeSize = normalizeSize / dataArray.length;
5700 }
5701
5702 defaultSize = normalizeSize;
5703 this.set('defaultSize', defaultSize);
5704 }
5705
5706 return defaultSize;
5707 },
5708 getDimWidth: function getDimWidth(dimName) {
5709 var coord = this.get('coord');
5710 var start = coord.convertPoint({
5711 x: 0,
5712 y: 0
5713 });
5714 var end = coord.convertPoint({
5715 x: dimName === 'x' ? 1 : 0,
5716 y: dimName === 'x' ? 0 : 1
5717 });
5718 var width = 0;
5719
5720 if (start && end) {
5721 width = Math.sqrt(Math.pow(end.x - start.x, 2) + Math.pow(end.y - start.y, 2));
5722 }
5723
5724 return width;
5725 },
5726 _getWidth: function _getWidth() {
5727 var width = this.get('_width');
5728
5729 if (!width) {
5730 var coord = this.get('coord');
5731
5732 if (coord && coord.isPolar && !coord.transposed) {
5733 width = (coord.endAngle - coord.startAngle) * coord.circleRadius;
5734 } else {
5735 width = this.getDimWidth('x');
5736 }
5737
5738 this.set('_width', width);
5739 }
5740
5741 return width;
5742 },
5743 _toNormalizedSize: function _toNormalizedSize(size) {
5744 var width = this._getWidth();
5745
5746 return size / width;
5747 },
5748 _toCoordSize: function _toCoordSize(normalizeSize) {
5749 var width = this._getWidth();
5750
5751 return width * normalizeSize;
5752 },
5753 getNormalizedSize: function getNormalizedSize(obj) {
5754 var size = this.getAttrValue('size', obj);
5755
5756 if (Util.isNil(size)) {
5757 size = this.getDefalutSize();
5758 } else {
5759 size = this._toNormalizedSize(size);
5760 }
5761
5762 return size;
5763 },
5764 getSize: function getSize(obj) {
5765 var size = this.getAttrValue('size', obj);
5766
5767 if (Util.isNil(size)) {
5768 var normalizeSize = this.getDefalutSize();
5769 size = this._toCoordSize(normalizeSize);
5770 }
5771
5772 return size;
5773 }
5774};
5775module.exports = SizeMixin;
5776
5777/***/ }),
5778/* 43 */
5779/***/ (function(module, exports, __webpack_require__) {
5780
5781var isType = __webpack_require__(106);
5782
5783var isArray = Array.isArray ? Array.isArray : function (value) {
5784 return isType(value, 'Array');
5785};
5786module.exports = isArray;
5787
5788/***/ }),
5789/* 44 */
5790/***/ (function(module, exports, __webpack_require__) {
5791
5792function _inheritsLoose(subClass, superClass) {
5793 subClass.prototype = Object.create(superClass.prototype);
5794 subClass.prototype.constructor = subClass;
5795 subClass.__proto__ = superClass;
5796}
5797/**
5798 * marker shapes,used for tooltip and legend
5799 */
5800
5801
5802var Util = __webpack_require__(0);
5803
5804var _require = __webpack_require__(3),
5805 Shape = _require.Shape;
5806
5807var SYMBOLS = {
5808 circle: function circle(x, y, r, ctx) {
5809 ctx.arc(x, y, r, 0, Math.PI * 2, false);
5810 },
5811 square: function square(x, y, r, ctx) {
5812 ctx.moveTo(x - r, y - r);
5813 ctx.lineTo(x + r, y - r);
5814 ctx.lineTo(x + r, y + r);
5815 ctx.lineTo(x - r, y + r);
5816 ctx.closePath();
5817 }
5818};
5819
5820var Marker =
5821/*#__PURE__*/
5822function (_Shape) {
5823 _inheritsLoose(Marker, _Shape);
5824
5825 function Marker() {
5826 return _Shape.apply(this, arguments) || this;
5827 }
5828
5829 var _proto = Marker.prototype;
5830
5831 _proto._initProperties = function _initProperties() {
5832 _Shape.prototype._initProperties.call(this);
5833
5834 this._attrs.canFill = true;
5835 this._attrs.canStroke = true;
5836 this._attrs.type = 'marker';
5837 };
5838
5839 _proto.getDefaultAttrs = function getDefaultAttrs() {
5840 return {
5841 x: 0,
5842 y: 0,
5843 lineWidth: 0
5844 };
5845 };
5846
5847 _proto.createPath = function createPath(context) {
5848 var attrs = this.get('attrs');
5849 var x = attrs.x,
5850 y = attrs.y,
5851 radius = attrs.radius;
5852 var symbol = attrs.symbol || 'circle';
5853 var method;
5854
5855 if (Util.isFunction(symbol)) {
5856 method = symbol;
5857 } else {
5858 method = SYMBOLS[symbol];
5859 }
5860
5861 context.beginPath();
5862 method(x, y, radius, context, this);
5863 };
5864
5865 _proto.calculateBox = function calculateBox() {
5866 var attrs = this.get('attrs');
5867 var x = attrs.x,
5868 y = attrs.y,
5869 radius = attrs.radius;
5870 return {
5871 minX: x - radius,
5872 minY: y - radius,
5873 maxX: x + radius,
5874 maxY: y + radius
5875 };
5876 };
5877
5878 return Marker;
5879}(Shape);
5880
5881module.exports = Marker;
5882
5883/***/ }),
5884/* 45 */
5885/***/ (function(module, exports, __webpack_require__) {
5886
5887var Util = __webpack_require__(0);
5888
5889var _require = __webpack_require__(3),
5890 Group = _require.Group;
5891
5892var Marker = __webpack_require__(44);
5893
5894var MARKER_RADIUS = 3;
5895
5896var List =
5897/*#__PURE__*/
5898function () {
5899 var _proto = List.prototype;
5900
5901 _proto.getDefaultCfg = function getDefaultCfg() {
5902 return {
5903 showTitle: false,
5904
5905 /**
5906 * title string
5907 * @type {?String}
5908 */
5909 title: null,
5910
5911 /**
5912 * items array
5913 * @type {?Array}
5914 */
5915 items: null,
5916
5917 /**
5918 * offset between title and items
5919 * @type {Number}
5920 */
5921 titleGap: 12,
5922
5923 /**
5924 * offset between each item
5925 * @type {Number}
5926 */
5927 itemGap: 10,
5928
5929 /**
5930 * the offset between each item in vertical direaction
5931 * @type {Number}
5932 */
5933 itemMarginBottom: 12,
5934
5935 /**
5936 * the formatter for item text
5937 * @type {[type]}
5938 */
5939 itemFormatter: null,
5940 itemWidth: null,
5941
5942 /**
5943 * offset between marker and text
5944 * @type {Number}
5945 */
5946 wordSpace: 6,
5947 x: 0,
5948 y: 0,
5949 layout: 'horizontal',
5950
5951 /**
5952 * the join string of `name` and `value`
5953 * @type {String}
5954 */
5955 joinString: ': '
5956 };
5957 };
5958
5959 function List(cfg) {
5960 Util.deepMix(this, this.getDefaultCfg(), cfg);
5961
5962 this._init();
5963
5964 this._renderTitle();
5965
5966 this._renderItems();
5967 }
5968
5969 _proto._init = function _init() {
5970 var container = new Group({
5971 zIndex: this.zIndex || 0
5972 });
5973 this.container = container;
5974 var wrapper = container.addGroup();
5975 this.wrapper = wrapper;
5976 var itemsGroup = wrapper.addGroup({
5977 className: 'itemsGroup'
5978 });
5979 this.itemsGroup = itemsGroup;
5980
5981 if (this.parent) {
5982 this.parent.add(container);
5983 }
5984 };
5985
5986 _proto._renderTitle = function _renderTitle(title) {
5987 title = title || this.title;
5988 var titleShape = this.titleShape;
5989 var titleHeight = 0;
5990
5991 if (this.showTitle && title) {
5992 if (titleShape && !titleShape.get('destroyed')) {
5993 titleShape.attr('text', title);
5994 } else {
5995 var wrapper = this.wrapper,
5996 titleStyle = this.titleStyle;
5997 titleShape = wrapper.addShape('text', {
5998 className: 'title',
5999 attrs: Util.mix({
6000 x: 0,
6001 y: 0,
6002 text: title
6003 }, titleStyle)
6004 });
6005 this.titleShape = titleShape;
6006 }
6007
6008 titleHeight = titleShape.getBBox().height + this.titleGap;
6009 }
6010
6011 this._titleHeight = titleHeight;
6012 };
6013
6014 _proto._renderItems = function _renderItems(items) {
6015 var self = this;
6016 items = items || self.items;
6017
6018 if (!items) {
6019 return;
6020 }
6021
6022 if (self.reversed) {
6023 items.reverse();
6024 }
6025
6026 Util.each(items, function (item, index) {
6027 self._addItem(item, index);
6028 });
6029
6030 if (items.length > 1) {
6031 this._adjustItems();
6032 }
6033
6034 this._renderBackground();
6035 };
6036
6037 _proto._renderBackground = function _renderBackground() {
6038 var background = this.background;
6039
6040 if (background) {
6041 var container = this.container;
6042 var wrapper = this.wrapper;
6043
6044 var _wrapper$getBBox = wrapper.getBBox(),
6045 minX = _wrapper$getBBox.minX,
6046 minY = _wrapper$getBBox.minY,
6047 width = _wrapper$getBBox.width,
6048 height = _wrapper$getBBox.height;
6049
6050 var padding = background.padding || [0, 0, 0, 0];
6051 padding = Util.parsePadding(padding);
6052 var attrs = Util.mix({
6053 x: minX - padding[3],
6054 y: minY - padding[0],
6055 width: width + padding[1] + padding[3],
6056 height: height + padding[0] + padding[2]
6057 }, background);
6058 var backShape = this.backShape;
6059
6060 if (backShape) {
6061 backShape.attr(attrs);
6062 } else {
6063 backShape = container.addShape('Rect', {
6064 zIndex: -1,
6065 attrs: attrs
6066 });
6067 }
6068
6069 this.backShape = backShape;
6070 container.sort();
6071 }
6072 };
6073
6074 _proto._addItem = function _addItem(item) {
6075 var itemsGroup = this.itemsGroup;
6076 var itemGroup = itemsGroup.addGroup({
6077 name: item.name,
6078 value: item.value,
6079 dataValue: item.dataValue,
6080 checked: item.checked
6081 });
6082 var unCheckStyle = this.unCheckStyle,
6083 unCheckColor = this.unCheckColor,
6084 nameStyle = this.nameStyle,
6085 valueStyle = this.valueStyle,
6086 wordSpace = this.wordSpace;
6087 var marker = item.marker,
6088 value = item.value;
6089 var startX = 0;
6090
6091 if (unCheckColor) {
6092 unCheckStyle.fill = unCheckColor;
6093 }
6094
6095 if (marker) {
6096 var radius = marker.radius || MARKER_RADIUS;
6097 var markerAttrs = Util.mix({
6098 x: radius,
6099 y: this._titleHeight
6100 }, marker);
6101
6102 if (item.checked === false) {
6103 Util.mix(markerAttrs, unCheckStyle);
6104 }
6105
6106 var markerShape = new Marker({
6107 className: 'item-marker',
6108 attrs: markerAttrs
6109 });
6110 itemGroup.add(markerShape);
6111 startX += markerShape.getBBox().width + wordSpace;
6112 }
6113
6114 var nameText;
6115 var name = item.name;
6116
6117 if (name) {
6118 var joinString = this.joinString || '';
6119 name = value ? name + joinString : name;
6120 nameText = itemGroup.addShape('text', {
6121 className: 'name',
6122 attrs: Util.mix({
6123 x: startX,
6124 y: this._titleHeight,
6125 text: this._formatItemValue(name)
6126 }, nameStyle, item.checked === false ? unCheckStyle : null)
6127 });
6128 }
6129
6130 if (value) {
6131 var valueX = startX;
6132
6133 if (nameText) {
6134 valueX += nameText.getBBox().width;
6135 }
6136
6137 itemGroup.addShape('text', {
6138 className: 'value',
6139 attrs: Util.mix({
6140 x: valueX,
6141 y: this._titleHeight,
6142 text: value
6143 }, valueStyle, item.checked === false ? unCheckStyle : null)
6144 });
6145 }
6146
6147 return itemGroup;
6148 };
6149
6150 _proto._formatItemValue = function _formatItemValue(value) {
6151 var formatter = this.itemFormatter;
6152
6153 if (formatter) {
6154 value = formatter.call(this, value);
6155 }
6156
6157 return value;
6158 };
6159
6160 _proto._getMaxItemWidth = function _getMaxItemWidth() {
6161 var width;
6162 var itemWidth = this.itemWidth;
6163
6164 if (Util.isNumber(itemWidth) || Util.isNil(itemWidth)) {
6165 return itemWidth;
6166 }
6167
6168 if (itemWidth === 'auto') {
6169 var itemsGroup = this.itemsGroup;
6170 var children = itemsGroup.get('children');
6171 var count = children.length;
6172 var maxItemWidth = 0;
6173
6174 for (var i = 0; i < count; i++) {
6175 var _children$i$getBBox = children[i].getBBox(),
6176 _width = _children$i$getBBox.width;
6177
6178 maxItemWidth = Math.max(maxItemWidth, _width);
6179 }
6180
6181 var maxLength = this.maxLength;
6182 var itemGap = this.itemGap;
6183 var twoAvgWidth = (maxLength - itemGap) / 2;
6184 var threeAvgWidth = (maxLength - itemGap * 2) / 3;
6185
6186 if (count === 2) {
6187 width = Math.max(maxItemWidth, twoAvgWidth);
6188 } else {
6189 // 1. max <= 3Avg, 3Avg
6190 // 2. 3Avg < max && max < 2avg, 2avg
6191 // 3. max > 2avg, max, one column
6192 if (maxItemWidth <= threeAvgWidth) {
6193 width = threeAvgWidth;
6194 } else if (maxItemWidth <= twoAvgWidth) {
6195 width = twoAvgWidth;
6196 } else {
6197 width = maxItemWidth;
6198 }
6199 }
6200
6201 return width;
6202 }
6203 };
6204
6205 _proto._adjustHorizontal = function _adjustHorizontal() {
6206 var maxLength = this.maxLength,
6207 itemsGroup = this.itemsGroup;
6208 var children = itemsGroup.get('children');
6209 var itemGap = this.itemGap,
6210 itemMarginBottom = this.itemMarginBottom;
6211 var titleHeight = this._titleHeight;
6212 var row = 0;
6213 var rowWidth = 0;
6214 var width;
6215 var height;
6216
6217 var itemWidth = this._getMaxItemWidth();
6218
6219 var legendHitBoxes = [];
6220
6221 for (var i = 0, len = children.length; i < len; i++) {
6222 var child = children[i];
6223 var box = child.getBBox();
6224 var childHeight = box.height;
6225 var childWidth = box.width;
6226 width = itemWidth || childWidth;
6227 height = childHeight + itemMarginBottom;
6228
6229 if (width - (maxLength - rowWidth) > 0.0001) {
6230 row++;
6231 rowWidth = 0;
6232 }
6233
6234 child.moveTo(rowWidth, row * height);
6235 legendHitBoxes.push({
6236 x: rowWidth,
6237 y: row * height + titleHeight - childHeight / 2,
6238 width: childWidth * 1.375,
6239 height: childHeight * 1.375
6240 });
6241 rowWidth += width + itemGap;
6242 }
6243
6244 this.legendHitBoxes = legendHitBoxes;
6245 return;
6246 };
6247
6248 _proto._adjustVertical = function _adjustVertical() {
6249 var maxLength = this.maxLength,
6250 itemsGroup = this.itemsGroup;
6251 var itemGap = this.itemGap,
6252 itemMarginBottom = this.itemMarginBottom,
6253 itemWidth = this.itemWidth;
6254 var titleHeight = this._titleHeight;
6255 var children = itemsGroup.get('children');
6256 var colHeight = 0;
6257 var width;
6258 var height;
6259 var maxItemWidth = 0;
6260 var totalWidth = 0;
6261 var legendHitBoxes = [];
6262
6263 for (var i = 0, length = children.length; i < length; i++) {
6264 var child = children[i];
6265 var bbox = child.getBBox();
6266 width = bbox.width;
6267 height = bbox.height;
6268
6269 if (Util.isNumber(itemWidth)) {
6270 maxItemWidth = itemWidth + itemGap;
6271 } else if (width > maxItemWidth) {
6272 maxItemWidth = width + itemGap;
6273 }
6274
6275 if (maxLength - colHeight < height) {
6276 colHeight = 0;
6277 totalWidth += maxItemWidth;
6278 child.moveTo(totalWidth, 0);
6279 legendHitBoxes.push({
6280 x: totalWidth,
6281 y: titleHeight - height / 2,
6282 width: width * 1.375,
6283 height: height * 1.375
6284 });
6285 } else {
6286 child.moveTo(totalWidth, colHeight);
6287 legendHitBoxes.push({
6288 x: totalWidth,
6289 y: colHeight - height / 2 + titleHeight,
6290 width: width * 1.375,
6291 height: height * 1.375
6292 });
6293 }
6294
6295 colHeight += height + itemMarginBottom;
6296 }
6297
6298 this.legendHitBoxes = legendHitBoxes;
6299 return;
6300 };
6301
6302 _proto._adjustItems = function _adjustItems() {
6303 var layout = this.layout;
6304
6305 if (layout === 'horizontal') {
6306 this._adjustHorizontal();
6307 } else {
6308 this._adjustVertical();
6309 }
6310 };
6311
6312 _proto.moveTo = function moveTo(x, y) {
6313 this.x = x;
6314 this.y = y;
6315 var container = this.container;
6316 container && container.moveTo(x, y);
6317 return this;
6318 };
6319
6320 _proto.setItems = function setItems(items) {
6321 this.clearItems();
6322
6323 this._renderItems(items);
6324 };
6325
6326 _proto.setTitle = function setTitle(title) {
6327 this._renderTitle(title);
6328 };
6329
6330 _proto.clearItems = function clearItems() {
6331 var itemsGroup = this.itemsGroup;
6332 itemsGroup.clear();
6333 };
6334
6335 _proto.getWidth = function getWidth() {
6336 var container = this.container;
6337 var bbox = container.getBBox();
6338 return bbox.width;
6339 };
6340
6341 _proto.getHeight = function getHeight() {
6342 var container = this.container;
6343 var bbox = container.getBBox();
6344 return bbox.height;
6345 };
6346
6347 _proto.show = function show() {
6348 var container = this.container;
6349 container.show();
6350 };
6351
6352 _proto.hide = function hide() {
6353 var container = this.container;
6354 container.hide();
6355 };
6356
6357 _proto.clear = function clear() {
6358 var container = this.container;
6359 container.clear();
6360 container.remove(true);
6361 };
6362
6363 return List;
6364}();
6365
6366module.exports = List;
6367
6368/***/ }),
6369/* 46 */
6370/***/ (function(module, exports, __webpack_require__) {
6371
6372/**
6373 * Animate configuration and register
6374 * @author sima.zhang1990@gmail.com
6375 */
6376var Util = __webpack_require__(0);
6377
6378var defaultAnimationCfg = {
6379 appear: {
6380 duration: 450,
6381 easing: 'quadraticOut'
6382 },
6383 // 'appear' animation options
6384 update: {
6385 duration: 300,
6386 easing: 'quadraticOut'
6387 },
6388 // 'update' animation options
6389 enter: {
6390 duration: 300,
6391 easing: 'quadraticOut'
6392 },
6393 // 'enter' animation options
6394 leave: {
6395 duration: 350,
6396 easing: 'quadraticIn' // 'leave' animation options
6397
6398 }
6399};
6400var Animate = {
6401 defaultCfg: {},
6402 Action: {},
6403 getAnimation: function getAnimation(geomType, coord, animationType) {
6404 var geomAnimateCfg = this.defaultCfg[geomType];
6405
6406 if (geomAnimateCfg) {
6407 var animation = geomAnimateCfg[animationType];
6408
6409 if (Util.isFunction(animation)) {
6410 return animation(coord);
6411 }
6412 }
6413
6414 return false;
6415 },
6416 getAnimateCfg: function getAnimateCfg(geomType, animationType) {
6417 var defaultCfg = defaultAnimationCfg[animationType];
6418 var geomConfig = this.defaultCfg[geomType];
6419
6420 if (geomConfig && geomConfig.cfg && geomConfig.cfg[animationType]) {
6421 return Util.deepMix({}, defaultCfg, geomConfig.cfg[animationType]);
6422 }
6423
6424 return defaultCfg;
6425 },
6426 registerAnimation: function registerAnimation(animationName, animationFun) {
6427 if (!this.Action) {
6428 this.Action = {};
6429 }
6430
6431 this.Action[animationName] = animationFun;
6432 }
6433};
6434module.exports = Animate;
6435
6436/***/ }),
6437/* 47 */
6438/***/ (function(module, exports, __webpack_require__) {
6439
6440/**
6441 * Utility
6442 * @author sima.zhang1990@gmail.com
6443 */
6444var _require = __webpack_require__(3),
6445 Matrix = _require.Matrix;
6446
6447var Util = __webpack_require__(0);
6448
6449var Helpers = {
6450 getCoordInfo: function getCoordInfo(coord) {
6451 var start = coord.start;
6452 var end = coord.end;
6453 return {
6454 start: start,
6455 end: end,
6456 width: end.x - start.x,
6457 height: Math.abs(end.y - start.y)
6458 };
6459 },
6460 getScaledMatrix: function getScaledMatrix(shape, v, direct) {
6461 var scaledMatrix;
6462 shape.apply(v);
6463 var x = v[0];
6464 var y = v[1];
6465
6466 if (direct === 'x') {
6467 shape.transform([['t', x, y], ['s', 0.01, 1], ['t', -x, -y]]);
6468 var matrix = shape.getMatrix();
6469 scaledMatrix = Matrix.transform(matrix, [['t', x, y], ['s', 100, 1], ['t', -x, -y]]);
6470 } else if (direct === 'y') {
6471 shape.transform([['t', x, y], ['s', 1, 0.01], ['t', -x, -y]]);
6472
6473 var _matrix = shape.getMatrix();
6474
6475 scaledMatrix = Matrix.transform(_matrix, [['t', x, y], ['s', 1, 100], ['t', -x, -y]]);
6476 } else if (direct === 'xy') {
6477 shape.transform([['t', x, y], ['s', 0.01, 0.01], ['t', -x, -y]]);
6478
6479 var _matrix2 = shape.getMatrix();
6480
6481 scaledMatrix = Matrix.transform(_matrix2, [['t', x, y], ['s', 100, 100], ['t', -x, -y]]);
6482 }
6483
6484 return scaledMatrix;
6485 },
6486 getAnimateParam: function getAnimateParam(animateCfg, index, id) {
6487 var result = {};
6488
6489 if (animateCfg.delay) {
6490 result.delay = Util.isFunction(animateCfg.delay) ? animateCfg.delay(index, id) : animateCfg.delay;
6491 }
6492
6493 result.easing = animateCfg.easing;
6494 result.duration = animateCfg.duration;
6495 result.delay = animateCfg.delay;
6496 return result;
6497 },
6498 doAnimation: function doAnimation(shape, endState, animateCfg, callback) {
6499 var id = shape._id;
6500 var index = shape.get('index');
6501
6502 var _Helpers$getAnimatePa = Helpers.getAnimateParam(animateCfg, index, id),
6503 easing = _Helpers$getAnimatePa.easing,
6504 delay = _Helpers$getAnimatePa.delay,
6505 duration = _Helpers$getAnimatePa.duration;
6506
6507 var anim = shape.animate().to({
6508 attrs: endState,
6509 duration: duration,
6510 delay: delay,
6511 easing: easing
6512 });
6513
6514 if (callback) {
6515 anim.onEnd(function () {
6516 callback();
6517 });
6518 }
6519 }
6520};
6521module.exports = Helpers;
6522
6523/***/ }),
6524/* 48 */
6525/***/ (function(module, exports, __webpack_require__) {
6526
6527var F2 = __webpack_require__(49);
6528
6529__webpack_require__(91);
6530
6531__webpack_require__(103);
6532
6533__webpack_require__(112); // polar coordinate
6534
6535
6536__webpack_require__(113); // the axis for polar coordinate
6537
6538
6539__webpack_require__(114); // timeCat scale
6540
6541
6542__webpack_require__(117); // guide components
6543
6544
6545__webpack_require__(118); // guide components
6546
6547
6548__webpack_require__(119); // guide components
6549
6550
6551__webpack_require__(120); // guide components
6552
6553
6554__webpack_require__(121); // guide components
6555
6556
6557__webpack_require__(122); // guide components
6558
6559
6560__webpack_require__(123); // guide components
6561
6562
6563var Tooltip = __webpack_require__(124);
6564
6565var Guide = __webpack_require__(127);
6566
6567var Legend = __webpack_require__(128);
6568
6569var Animation = __webpack_require__(129);
6570
6571var ScrollBar = __webpack_require__(135);
6572
6573var PieLabel = __webpack_require__(136);
6574
6575F2.Animate = __webpack_require__(46); // register plugins
6576
6577F2.Chart.plugins.register([Tooltip, Legend, Guide, Animation, ScrollBar, PieLabel]); // add interaction
6578
6579__webpack_require__(137);
6580
6581__webpack_require__(139);
6582
6583__webpack_require__(140);
6584
6585F2.Interaction = __webpack_require__(21);
6586module.exports = F2;
6587
6588/***/ }),
6589/* 49 */
6590/***/ (function(module, exports, __webpack_require__) {
6591
6592var Renderer = __webpack_require__(50);
6593
6594var Core = __webpack_require__(52); // 引入 F2 的核心包
6595
6596
6597function strLen(str) {
6598 var len = 0;
6599
6600 for (var i = 0; i < str.length; i++) {
6601 if (str.charCodeAt(i) > 0 && str.charCodeAt(i) < 128) {
6602 len++;
6603 } else {
6604 len += 2;
6605 }
6606 }
6607
6608 return len;
6609} // override some methods
6610// 由于目前钉钉小程序框架善不支持 measureText 方法,故用此方法 mock
6611
6612
6613Core.Util.measureText = function (text, font, ctx) {
6614 if (!ctx || !ctx.measureText) {
6615 var fontSize = 12;
6616
6617 if (font) {
6618 fontSize = parseInt(font.split(' ')[3], 10);
6619 }
6620
6621 fontSize /= 2;
6622 return {
6623 width: strLen(text) * fontSize
6624 };
6625 }
6626
6627 ctx.font = font || '12px sans-serif';
6628 return ctx.measureText(text);
6629}; // 为小程序封装事件机制
6630
6631
6632Core.Util.addEventListener = function (source, type, listener) {
6633 source.addListener(type, listener);
6634};
6635
6636Core.Util.removeEventListener = function (source, type, listener) {
6637 source.removeListener(type, listener);
6638};
6639
6640Core.Util.createEvent = function (event, chart) {
6641 var type = event.type;
6642 var x = 0;
6643 var y = 0;
6644 var touches = event.touches;
6645
6646 if (touches && touches.length > 0) {
6647 x = touches[0].x;
6648 y = touches[0].y;
6649 }
6650
6651 return {
6652 type: type,
6653 chart: chart,
6654 x: x,
6655 y: y
6656 };
6657};
6658
6659Core.Renderer = Renderer;
6660module.exports = Core;
6661
6662/***/ }),
6663/* 50 */
6664/***/ (function(module, exports, __webpack_require__) {
6665
6666function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
6667
6668function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
6669
6670/**
6671 * f2 专为适配微信小程序绘图上下文 context 而封装的伪 Canvas
6672 * @authors (sima.zhang1990@gmail.com)
6673 * @version 1.0.0
6674 */
6675var EventEmitter = __webpack_require__(51);
6676
6677var CAPITALIZED_ATTRS_MAP = {
6678 fillStyle: 'FillStyle',
6679 fontSize: 'FontSize',
6680 globalAlpha: 'GlobalAlpha',
6681 opacity: 'GlobalAlpha',
6682 lineCap: 'LineCap',
6683 lineJoin: 'LineJoin',
6684 lineWidth: 'LineWidth',
6685 miterLimit: 'MiterLimit',
6686 strokeStyle: 'StrokeStyle',
6687 textAlign: 'TextAlign',
6688 textBaseline: 'TextBaseline',
6689 shadow: 'Shadow'
6690};
6691
6692var Renderer =
6693/*#__PURE__*/
6694function (_EventEmitter) {
6695 _inheritsLoose(Renderer, _EventEmitter);
6696
6697 function Renderer(myCtx) {
6698 var _this;
6699
6700 _this = _EventEmitter.call(this) || this;
6701
6702 var self = _assertThisInitialized(_assertThisInitialized(_this));
6703
6704 self.ctx = myCtx;
6705 self.style = {}; // just mock
6706
6707 self._initContext(myCtx);
6708
6709 return _this;
6710 }
6711
6712 var _proto = Renderer.prototype;
6713
6714 _proto.getContext = function getContext(type) {
6715 if (type === '2d') {
6716 return this.ctx;
6717 }
6718 };
6719
6720 _proto._initContext = function _initContext(myCtx) {
6721 Object.keys(CAPITALIZED_ATTRS_MAP).map(function (key) {
6722 Object.defineProperty(myCtx, key, {
6723 set: function set(value) {
6724 // myCtx.setShadow(shadowOffsetX, shadowOffsetY, shadowBlur, shadowColor)
6725 if (key === 'shadow' && myCtx.setShadow && Array.isArray(value)) {
6726 myCtx.setShadow(value[0], value[1], value[2], value[3]);
6727 } else {
6728 var name = 'set' + CAPITALIZED_ATTRS_MAP[key];
6729 myCtx[name](value);
6730 }
6731 }
6732 });
6733 return key;
6734 });
6735 };
6736
6737 return Renderer;
6738}(EventEmitter);
6739
6740module.exports = Renderer;
6741
6742/***/ }),
6743/* 51 */
6744/***/ (function(module, exports, __webpack_require__) {
6745
6746var __WEBPACK_AMD_DEFINE_RESULT__;/*!
6747 * EventEmitter v5.2.5 - git.io/ee
6748 * Unlicense - http://unlicense.org/
6749 * Oliver Caldwell - http://oli.me.uk/
6750 * @preserve
6751 */
6752;
6753
6754(function (exports) {
6755 'use strict';
6756 /**
6757 * Class for managing events.
6758 * Can be extended to provide event functionality in other classes.
6759 *
6760 * @class EventEmitter Manages event registering and emitting.
6761 */
6762
6763 function EventEmitter() {} // Shortcuts to improve speed and size
6764
6765
6766 var proto = EventEmitter.prototype;
6767 var originalGlobalValue = exports.EventEmitter;
6768 /**
6769 * Finds the index of the listener for the event in its storage array.
6770 *
6771 * @param {Function[]} listeners Array of listeners to search through.
6772 * @param {Function} listener Method to look for.
6773 * @return {Number} Index of the specified listener, -1 if not found
6774 * @api private
6775 */
6776
6777 function indexOfListener(listeners, listener) {
6778 var i = listeners.length;
6779
6780 while (i--) {
6781 if (listeners[i].listener === listener) {
6782 return i;
6783 }
6784 }
6785
6786 return -1;
6787 }
6788 /**
6789 * Alias a method while keeping the context correct, to allow for overwriting of target method.
6790 *
6791 * @param {String} name The name of the target method.
6792 * @return {Function} The aliased method
6793 * @api private
6794 */
6795
6796
6797 function alias(name) {
6798 return function aliasClosure() {
6799 return this[name].apply(this, arguments);
6800 };
6801 }
6802 /**
6803 * Returns the listener array for the specified event.
6804 * Will initialise the event object and listener arrays if required.
6805 * Will return an object if you use a regex search. The object contains keys for each matched event. So /ba[rz]/ might return an object containing bar and baz. But only if you have either defined them with defineEvent or added some listeners to them.
6806 * Each property in the object response is an array of listener functions.
6807 *
6808 * @param {String|RegExp} evt Name of the event to return the listeners from.
6809 * @return {Function[]|Object} All listener functions for the event.
6810 */
6811
6812
6813 proto.getListeners = function getListeners(evt) {
6814 var events = this._getEvents();
6815
6816 var response;
6817 var key; // Return a concatenated array of all matching events if
6818 // the selector is a regular expression.
6819
6820 if (evt instanceof RegExp) {
6821 response = {};
6822
6823 for (key in events) {
6824 if (events.hasOwnProperty(key) && evt.test(key)) {
6825 response[key] = events[key];
6826 }
6827 }
6828 } else {
6829 response = events[evt] || (events[evt] = []);
6830 }
6831
6832 return response;
6833 };
6834 /**
6835 * Takes a list of listener objects and flattens it into a list of listener functions.
6836 *
6837 * @param {Object[]} listeners Raw listener objects.
6838 * @return {Function[]} Just the listener functions.
6839 */
6840
6841
6842 proto.flattenListeners = function flattenListeners(listeners) {
6843 var flatListeners = [];
6844 var i;
6845
6846 for (i = 0; i < listeners.length; i += 1) {
6847 flatListeners.push(listeners[i].listener);
6848 }
6849
6850 return flatListeners;
6851 };
6852 /**
6853 * Fetches the requested listeners via getListeners but will always return the results inside an object. This is mainly for internal use but others may find it useful.
6854 *
6855 * @param {String|RegExp} evt Name of the event to return the listeners from.
6856 * @return {Object} All listener functions for an event in an object.
6857 */
6858
6859
6860 proto.getListenersAsObject = function getListenersAsObject(evt) {
6861 var listeners = this.getListeners(evt);
6862 var response;
6863
6864 if (listeners instanceof Array) {
6865 response = {};
6866 response[evt] = listeners;
6867 }
6868
6869 return response || listeners;
6870 };
6871
6872 function isValidListener(listener) {
6873 if (typeof listener === 'function' || listener instanceof RegExp) {
6874 return true;
6875 } else if (listener && typeof listener === 'object') {
6876 return isValidListener(listener.listener);
6877 } else {
6878 return false;
6879 }
6880 }
6881 /**
6882 * Adds a listener function to the specified event.
6883 * The listener will not be added if it is a duplicate.
6884 * If the listener returns true then it will be removed after it is called.
6885 * If you pass a regular expression as the event name then the listener will be added to all events that match it.
6886 *
6887 * @param {String|RegExp} evt Name of the event to attach the listener to.
6888 * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
6889 * @return {Object} Current instance of EventEmitter for chaining.
6890 */
6891
6892
6893 proto.addListener = function addListener(evt, listener) {
6894 if (!isValidListener(listener)) {
6895 throw new TypeError('listener must be a function');
6896 }
6897
6898 var listeners = this.getListenersAsObject(evt);
6899 var listenerIsWrapped = typeof listener === 'object';
6900 var key;
6901
6902 for (key in listeners) {
6903 if (listeners.hasOwnProperty(key) && indexOfListener(listeners[key], listener) === -1) {
6904 listeners[key].push(listenerIsWrapped ? listener : {
6905 listener: listener,
6906 once: false
6907 });
6908 }
6909 }
6910
6911 return this;
6912 };
6913 /**
6914 * Alias of addListener
6915 */
6916
6917
6918 proto.on = alias('addListener');
6919 /**
6920 * Semi-alias of addListener. It will add a listener that will be
6921 * automatically removed after its first execution.
6922 *
6923 * @param {String|RegExp} evt Name of the event to attach the listener to.
6924 * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
6925 * @return {Object} Current instance of EventEmitter for chaining.
6926 */
6927
6928 proto.addOnceListener = function addOnceListener(evt, listener) {
6929 return this.addListener(evt, {
6930 listener: listener,
6931 once: true
6932 });
6933 };
6934 /**
6935 * Alias of addOnceListener.
6936 */
6937
6938
6939 proto.once = alias('addOnceListener');
6940 /**
6941 * Defines an event name. This is required if you want to use a regex to add a listener to multiple events at once. If you don't do this then how do you expect it to know what event to add to? Should it just add to every possible match for a regex? No. That is scary and bad.
6942 * You need to tell it what event names should be matched by a regex.
6943 *
6944 * @param {String} evt Name of the event to create.
6945 * @return {Object} Current instance of EventEmitter for chaining.
6946 */
6947
6948 proto.defineEvent = function defineEvent(evt) {
6949 this.getListeners(evt);
6950 return this;
6951 };
6952 /**
6953 * Uses defineEvent to define multiple events.
6954 *
6955 * @param {String[]} evts An array of event names to define.
6956 * @return {Object} Current instance of EventEmitter for chaining.
6957 */
6958
6959
6960 proto.defineEvents = function defineEvents(evts) {
6961 for (var i = 0; i < evts.length; i += 1) {
6962 this.defineEvent(evts[i]);
6963 }
6964
6965 return this;
6966 };
6967 /**
6968 * Removes a listener function from the specified event.
6969 * When passed a regular expression as the event name, it will remove the listener from all events that match it.
6970 *
6971 * @param {String|RegExp} evt Name of the event to remove the listener from.
6972 * @param {Function} listener Method to remove from the event.
6973 * @return {Object} Current instance of EventEmitter for chaining.
6974 */
6975
6976
6977 proto.removeListener = function removeListener(evt, listener) {
6978 var listeners = this.getListenersAsObject(evt);
6979 var index;
6980 var key;
6981
6982 for (key in listeners) {
6983 if (listeners.hasOwnProperty(key)) {
6984 index = indexOfListener(listeners[key], listener);
6985
6986 if (index !== -1) {
6987 listeners[key].splice(index, 1);
6988 }
6989 }
6990 }
6991
6992 return this;
6993 };
6994 /**
6995 * Alias of removeListener
6996 */
6997
6998
6999 proto.off = alias('removeListener');
7000 /**
7001 * Adds listeners in bulk using the manipulateListeners method.
7002 * If you pass an object as the first argument you can add to multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. You can also pass it an event name and an array of listeners to be added.
7003 * You can also pass it a regular expression to add the array of listeners to all events that match it.
7004 * Yeah, this function does quite a bit. That's probably a bad thing.
7005 *
7006 * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add to multiple events at once.
7007 * @param {Function[]} [listeners] An optional array of listener functions to add.
7008 * @return {Object} Current instance of EventEmitter for chaining.
7009 */
7010
7011 proto.addListeners = function addListeners(evt, listeners) {
7012 // Pass through to manipulateListeners
7013 return this.manipulateListeners(false, evt, listeners);
7014 };
7015 /**
7016 * Removes listeners in bulk using the manipulateListeners method.
7017 * If you pass an object as the first argument you can remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.
7018 * You can also pass it an event name and an array of listeners to be removed.
7019 * You can also pass it a regular expression to remove the listeners from all events that match it.
7020 *
7021 * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to remove from multiple events at once.
7022 * @param {Function[]} [listeners] An optional array of listener functions to remove.
7023 * @return {Object} Current instance of EventEmitter for chaining.
7024 */
7025
7026
7027 proto.removeListeners = function removeListeners(evt, listeners) {
7028 // Pass through to manipulateListeners
7029 return this.manipulateListeners(true, evt, listeners);
7030 };
7031 /**
7032 * Edits listeners in bulk. The addListeners and removeListeners methods both use this to do their job. You should really use those instead, this is a little lower level.
7033 * The first argument will determine if the listeners are removed (true) or added (false).
7034 * If you pass an object as the second argument you can add/remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.
7035 * You can also pass it an event name and an array of listeners to be added/removed.
7036 * You can also pass it a regular expression to manipulate the listeners of all events that match it.
7037 *
7038 * @param {Boolean} remove True if you want to remove listeners, false if you want to add.
7039 * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add/remove from multiple events at once.
7040 * @param {Function[]} [listeners] An optional array of listener functions to add/remove.
7041 * @return {Object} Current instance of EventEmitter for chaining.
7042 */
7043
7044
7045 proto.manipulateListeners = function manipulateListeners(remove, evt, listeners) {
7046 var i;
7047 var value;
7048 var single = remove ? this.removeListener : this.addListener;
7049 var multiple = remove ? this.removeListeners : this.addListeners; // If evt is an object then pass each of its properties to this method
7050
7051 if (typeof evt === 'object' && !(evt instanceof RegExp)) {
7052 for (i in evt) {
7053 if (evt.hasOwnProperty(i) && (value = evt[i])) {
7054 // Pass the single listener straight through to the singular method
7055 if (typeof value === 'function') {
7056 single.call(this, i, value);
7057 } else {
7058 // Otherwise pass back to the multiple function
7059 multiple.call(this, i, value);
7060 }
7061 }
7062 }
7063 } else {
7064 // So evt must be a string
7065 // And listeners must be an array of listeners
7066 // Loop over it and pass each one to the multiple method
7067 i = listeners.length;
7068
7069 while (i--) {
7070 single.call(this, evt, listeners[i]);
7071 }
7072 }
7073
7074 return this;
7075 };
7076 /**
7077 * Removes all listeners from a specified event.
7078 * If you do not specify an event then all listeners will be removed.
7079 * That means every event will be emptied.
7080 * You can also pass a regex to remove all events that match it.
7081 *
7082 * @param {String|RegExp} [evt] Optional name of the event to remove all listeners for. Will remove from every event if not passed.
7083 * @return {Object} Current instance of EventEmitter for chaining.
7084 */
7085
7086
7087 proto.removeEvent = function removeEvent(evt) {
7088 var type = typeof evt;
7089
7090 var events = this._getEvents();
7091
7092 var key; // Remove different things depending on the state of evt
7093
7094 if (type === 'string') {
7095 // Remove all listeners for the specified event
7096 delete events[evt];
7097 } else if (evt instanceof RegExp) {
7098 // Remove all events matching the regex.
7099 for (key in events) {
7100 if (events.hasOwnProperty(key) && evt.test(key)) {
7101 delete events[key];
7102 }
7103 }
7104 } else {
7105 // Remove all listeners in all events
7106 delete this._events;
7107 }
7108
7109 return this;
7110 };
7111 /**
7112 * Alias of removeEvent.
7113 *
7114 * Added to mirror the node API.
7115 */
7116
7117
7118 proto.removeAllListeners = alias('removeEvent');
7119 /**
7120 * Emits an event of your choice.
7121 * When emitted, every listener attached to that event will be executed.
7122 * If you pass the optional argument array then those arguments will be passed to every listener upon execution.
7123 * Because it uses `apply`, your array of arguments will be passed as if you wrote them out separately.
7124 * So they will not arrive within the array on the other side, they will be separate.
7125 * You can also pass a regular expression to emit to all events that match it.
7126 *
7127 * @param {String|RegExp} evt Name of the event to emit and execute listeners for.
7128 * @param {Array} [args] Optional array of arguments to be passed to each listener.
7129 * @return {Object} Current instance of EventEmitter for chaining.
7130 */
7131
7132 proto.emitEvent = function emitEvent(evt, args) {
7133 var listenersMap = this.getListenersAsObject(evt);
7134 var listeners;
7135 var listener;
7136 var i;
7137 var key;
7138 var response;
7139
7140 for (key in listenersMap) {
7141 if (listenersMap.hasOwnProperty(key)) {
7142 listeners = listenersMap[key].slice(0);
7143
7144 for (i = 0; i < listeners.length; i++) {
7145 // If the listener returns true then it shall be removed from the event
7146 // The function is executed either with a basic call or an apply if there is an args array
7147 listener = listeners[i];
7148
7149 if (listener.once === true) {
7150 this.removeListener(evt, listener.listener);
7151 }
7152
7153 response = listener.listener.apply(this, args || []);
7154
7155 if (response === this._getOnceReturnValue()) {
7156 this.removeListener(evt, listener.listener);
7157 }
7158 }
7159 }
7160 }
7161
7162 return this;
7163 };
7164 /**
7165 * Alias of emitEvent
7166 */
7167
7168
7169 proto.trigger = alias('emitEvent');
7170 /**
7171 * Subtly different from emitEvent in that it will pass its arguments on to the listeners, as opposed to taking a single array of arguments to pass on.
7172 * As with emitEvent, you can pass a regex in place of the event name to emit to all events that match it.
7173 *
7174 * @param {String|RegExp} evt Name of the event to emit and execute listeners for.
7175 * @param {...*} Optional additional arguments to be passed to each listener.
7176 * @return {Object} Current instance of EventEmitter for chaining.
7177 */
7178
7179 proto.emit = function emit(evt) {
7180 var args = Array.prototype.slice.call(arguments, 1);
7181 return this.emitEvent(evt, args);
7182 };
7183 /**
7184 * Sets the current value to check against when executing listeners. If a
7185 * listeners return value matches the one set here then it will be removed
7186 * after execution. This value defaults to true.
7187 *
7188 * @param {*} value The new value to check for when executing listeners.
7189 * @return {Object} Current instance of EventEmitter for chaining.
7190 */
7191
7192
7193 proto.setOnceReturnValue = function setOnceReturnValue(value) {
7194 this._onceReturnValue = value;
7195 return this;
7196 };
7197 /**
7198 * Fetches the current value to check against when executing listeners. If
7199 * the listeners return value matches this one then it should be removed
7200 * automatically. It will return true by default.
7201 *
7202 * @return {*|Boolean} The current value to check for or the default, true.
7203 * @api private
7204 */
7205
7206
7207 proto._getOnceReturnValue = function _getOnceReturnValue() {
7208 if (this.hasOwnProperty('_onceReturnValue')) {
7209 return this._onceReturnValue;
7210 } else {
7211 return true;
7212 }
7213 };
7214 /**
7215 * Fetches the events object and creates one if required.
7216 *
7217 * @return {Object} The events storage object.
7218 * @api private
7219 */
7220
7221
7222 proto._getEvents = function _getEvents() {
7223 return this._events || (this._events = {});
7224 };
7225 /**
7226 * Reverts the global {@link EventEmitter} to its previous value and returns a reference to this version.
7227 *
7228 * @return {Function} Non conflicting EventEmitter class.
7229 */
7230
7231
7232 EventEmitter.noConflict = function noConflict() {
7233 exports.EventEmitter = originalGlobalValue;
7234 return EventEmitter;
7235 }; // Expose the class either via AMD, CommonJS or the global object
7236
7237
7238 if (true) {
7239 !(__WEBPACK_AMD_DEFINE_RESULT__ = (function () {
7240 return EventEmitter;
7241 }).call(exports, __webpack_require__, exports, module),
7242 __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
7243 } else if (typeof module === 'object' && module.exports) {
7244 module.exports = EventEmitter;
7245 } else {
7246 exports.EventEmitter = EventEmitter;
7247 }
7248})(typeof window !== 'undefined' ? window : this || {});
7249
7250/***/ }),
7251/* 52 */
7252/***/ (function(module, exports, __webpack_require__) {
7253
7254var Core = {};
7255
7256var Global = __webpack_require__(1);
7257
7258Core.Global = Global;
7259Core.version = Global.version;
7260Core.Chart = __webpack_require__(11);
7261Core.Shape = __webpack_require__(6);
7262Core.G = __webpack_require__(3);
7263Core.Util = __webpack_require__(0); // Core.track = function(enable) {
7264// Global.trackable = enable;
7265// };
7266// require('./track');
7267// 2018-12-27 关闭打点
7268
7269Core.track = function () {
7270 return null;
7271};
7272
7273module.exports = Core;
7274
7275/***/ }),
7276/* 53 */
7277/***/ (function(module, exports, __webpack_require__) {
7278
7279/**
7280 * @fileOverview default theme
7281 * @author dxq613@gail.com
7282 */
7283var Util = __webpack_require__(0);
7284
7285var color1 = '#E8E8E8'; // color of axis-line and axis-grid
7286
7287var color2 = '#808080'; // color of axis label
7288
7289var defaultAxis = {
7290 label: {
7291 fill: color2,
7292 fontSize: 10
7293 },
7294 line: {
7295 stroke: color1,
7296 lineWidth: 1
7297 },
7298 grid: {
7299 type: 'line',
7300 stroke: color1,
7301 lineWidth: 1,
7302 lineDash: [2]
7303 },
7304 tickLine: null,
7305 labelOffset: 7.5
7306};
7307var Theme = {
7308 fontFamily: '"Helvetica Neue", "San Francisco", Helvetica, Tahoma, Arial, "PingFang SC", "Hiragino Sans GB", "Heiti SC", "Microsoft YaHei", sans-serif',
7309 defaultColor: '#1890FF',
7310 pixelRatio: 1,
7311 padding: 'auto',
7312 appendPadding: 15,
7313 colors: ['#1890FF', '#2FC25B', '#FACC14', '#223273', '#8543E0', '#13C2C2', '#3436C7', '#F04864'],
7314 shapes: {
7315 line: ['line', 'dash'],
7316 point: ['circle', 'hollowCircle']
7317 },
7318 sizes: [4, 10],
7319 axis: {
7320 common: defaultAxis,
7321 // common axis configuration
7322 bottom: Util.mix({}, defaultAxis, {
7323 grid: null
7324 }),
7325 left: Util.mix({}, defaultAxis, {
7326 line: null
7327 }),
7328 right: Util.mix({}, defaultAxis, {
7329 line: null
7330 }),
7331 circle: Util.mix({}, defaultAxis, {
7332 line: null
7333 }),
7334 radius: Util.mix({}, defaultAxis, {
7335 labelOffset: 4
7336 })
7337 },
7338 shape: {
7339 line: {
7340 lineWidth: 2,
7341 lineJoin: 'round',
7342 lineCap: 'round'
7343 },
7344 point: {
7345 lineWidth: 0,
7346 size: 3
7347 },
7348 area: {
7349 fillOpacity: 0.1
7350 }
7351 },
7352 _defaultAxis: defaultAxis
7353};
7354module.exports = Theme;
7355
7356/***/ }),
7357/* 54 */
7358/***/ (function(module, exports) {
7359
7360var DomUtil;
7361/**
7362 * Detects support for options object argument in addEventListener.
7363 * https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support
7364 * @private
7365 */
7366
7367var supportsEventListenerOptions = function () {
7368 var supports = false;
7369
7370 try {
7371 var options = Object.defineProperty({}, 'passive', {
7372 get: function get() {
7373 supports = true;
7374 }
7375 });
7376 window.addEventListener('e', null, options);
7377 } catch (e) {// continue regardless of error
7378 }
7379
7380 return supports;
7381}(); // Default passive to true as expected by Chrome for 'touchstart' and 'touchend' events.
7382// https://github.com/chartjs/Chart.js/issues/4287
7383
7384
7385var eventListenerOptions = supportsEventListenerOptions ? {
7386 passive: true
7387} : false;
7388
7389function createEvent(type, chart, x, y, nativeEvent) {
7390 return {
7391 type: type,
7392 chart: chart,
7393 native: nativeEvent || null,
7394 x: x !== undefined ? x : null,
7395 y: y !== undefined ? y : null
7396 };
7397}
7398
7399function fromNativeEvent(event, chart) {
7400 var type = event.type;
7401 var point = {};
7402 var touches = event.targetTouches;
7403
7404 if (touches && touches.length > 0) {
7405 point.x = touches[0].clientX;
7406 point.y = touches[0].clientY;
7407 } else {
7408 point.x = event.clientX;
7409 point.y = event.clientY;
7410 }
7411
7412 var canvas = chart.get('canvas');
7413 var pos = DomUtil.getRelativePosition(point, canvas);
7414 return createEvent(type, chart, pos.x, pos.y, event);
7415}
7416
7417DomUtil = {
7418 /* global wx, my, module */
7419 isWx: typeof wx === 'object' && typeof wx.getSystemInfoSync === 'function',
7420 // weixin miniprogram
7421 isMy: typeof my === 'object' && typeof my.getSystemInfoSync === 'function',
7422 // ant miniprogram
7423 isNode: typeof module !== 'undefined' && typeof module.exports !== 'undefined',
7424 // in node
7425 isBrowser: typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.sessionStorage !== 'undefined',
7426 // in browser
7427 getPixelRatio: function getPixelRatio() {
7428 return window && window.devicePixelRatio || 1;
7429 },
7430 getStyle: function getStyle(el, property) {
7431 return el.currentStyle ? el.currentStyle[property] : document.defaultView.getComputedStyle(el, null).getPropertyValue(property);
7432 },
7433 getWidth: function getWidth(el) {
7434 var width = this.getStyle(el, 'width');
7435
7436 if (width === 'auto') {
7437 width = el.offsetWidth;
7438 }
7439
7440 return parseFloat(width);
7441 },
7442 getHeight: function getHeight(el) {
7443 var height = this.getStyle(el, 'height');
7444
7445 if (height === 'auto') {
7446 height = el.offsetHeight;
7447 }
7448
7449 return parseFloat(height);
7450 },
7451 getDomById: function getDomById(id) {
7452 if (!id) {
7453 return null;
7454 }
7455
7456 return document.getElementById(id);
7457 },
7458 getRelativePosition: function getRelativePosition(point, canvas) {
7459 var canvasDom = canvas.get('el');
7460
7461 var _canvasDom$getBoundin = canvasDom.getBoundingClientRect(),
7462 top = _canvasDom$getBoundin.top,
7463 right = _canvasDom$getBoundin.right,
7464 bottom = _canvasDom$getBoundin.bottom,
7465 left = _canvasDom$getBoundin.left;
7466
7467 var paddingLeft = parseFloat(this.getStyle(canvasDom, 'padding-left'));
7468 var paddingTop = parseFloat(this.getStyle(canvasDom, 'padding-top'));
7469 var paddingRight = parseFloat(this.getStyle(canvasDom, 'padding-right'));
7470 var paddingBottom = parseFloat(this.getStyle(canvasDom, 'padding-bottom'));
7471 var width = right - left - paddingLeft - paddingRight;
7472 var height = bottom - top - paddingTop - paddingBottom;
7473 var pixelRatio = canvas.get('pixelRatio');
7474 var mouseX = (point.x - left - paddingLeft) / width * canvasDom.width / pixelRatio;
7475 var mouseY = (point.y - top - paddingTop) / height * canvasDom.height / pixelRatio;
7476 return {
7477 x: mouseX,
7478 y: mouseY
7479 };
7480 },
7481 addEventListener: function addEventListener(source, type, listener) {
7482 DomUtil.isBrowser && source.addEventListener(type, listener, eventListenerOptions);
7483 },
7484 removeEventListener: function removeEventListener(source, type, listener) {
7485 DomUtil.isBrowser && source.removeEventListener(type, listener, eventListenerOptions);
7486 },
7487 createEvent: function createEvent(event, chart) {
7488 return fromNativeEvent(event, chart);
7489 },
7490 measureText: function measureText(text, font, ctx) {
7491 if (!ctx) {
7492 ctx = document.createElement('canvas').getContext('2d');
7493 }
7494
7495 ctx.font = font || '12px sans-serif';
7496 return ctx.measureText(text);
7497 }
7498};
7499module.exports = DomUtil;
7500
7501/***/ }),
7502/* 55 */
7503/***/ (function(module, exports, __webpack_require__) {
7504
7505var toString = __webpack_require__(30);
7506
7507var upperFirst = function upperFirst(value) {
7508 var str = toString(value);
7509 return str.charAt(0).toUpperCase() + str.substring(1);
7510};
7511
7512module.exports = upperFirst;
7513
7514/***/ }),
7515/* 56 */
7516/***/ (function(module, exports, __webpack_require__) {
7517
7518var toString = __webpack_require__(30);
7519
7520var lowerFirst = function lowerFirst(value) {
7521 var str = toString(value);
7522 return str.charAt(0).toLowerCase() + str.substring(1);
7523};
7524
7525module.exports = lowerFirst;
7526
7527/***/ }),
7528/* 57 */
7529/***/ (function(module, exports, __webpack_require__) {
7530
7531/**
7532 * 是否是布尔类型
7533 *
7534 * @param {Object} value 测试的值
7535 * @return {Boolean}
7536 */
7537var isType = __webpack_require__(9);
7538
7539var isBoolean = function isBoolean(value) {
7540 return isType(value, 'Boolean');
7541};
7542
7543module.exports = isBoolean;
7544
7545/***/ }),
7546/* 58 */
7547/***/ (function(module, exports, __webpack_require__) {
7548
7549/**
7550 * 是否为函数
7551 * @param {*} fn 对象
7552 * @return {Boolean} 是否函数
7553 */
7554var isType = __webpack_require__(9);
7555
7556var isFunction = function isFunction(value) {
7557 return isType(value, 'Function');
7558};
7559
7560module.exports = isFunction;
7561
7562/***/ }),
7563/* 59 */
7564/***/ (function(module, exports) {
7565
7566var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
7567 return typeof obj;
7568} : function (obj) {
7569 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
7570};
7571
7572var isObjectLike = function isObjectLike(value) {
7573 /**
7574 * isObjectLike({}) => true
7575 * isObjectLike([1, 2, 3]) => true
7576 * isObjectLike(Function) => false
7577 * isObjectLike(null) => false
7578 */
7579 return (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && value !== null;
7580};
7581
7582module.exports = isObjectLike;
7583
7584/***/ }),
7585/* 60 */
7586/***/ (function(module, exports, __webpack_require__) {
7587
7588var isPlainObject = __webpack_require__(32);
7589
7590var isArray = __webpack_require__(15);
7591
7592var MAX_MIX_LEVEL = 5;
7593
7594function _deepMix(dist, src, level, maxLevel) {
7595 level = level || 0;
7596 maxLevel = maxLevel || MAX_MIX_LEVEL;
7597
7598 for (var key in src) {
7599 if (src.hasOwnProperty(key)) {
7600 var value = src[key];
7601
7602 if (value !== null && isPlainObject(value)) {
7603 if (!isPlainObject(dist[key])) {
7604 dist[key] = {};
7605 }
7606
7607 if (level < maxLevel) {
7608 _deepMix(dist[key], value, level + 1, maxLevel);
7609 } else {
7610 dist[key] = src[key];
7611 }
7612 } else if (isArray(value)) {
7613 dist[key] = [];
7614 dist[key] = dist[key].concat(value);
7615 } else if (value !== undefined) {
7616 dist[key] = value;
7617 }
7618 }
7619 }
7620}
7621
7622var deepMix = function deepMix() {
7623 var args = new Array(arguments.length);
7624 var length = args.length;
7625
7626 for (var i = 0; i < length; i++) {
7627 args[i] = arguments[i];
7628 }
7629
7630 var rst = args[0];
7631
7632 for (var _i = 1; _i < length; _i++) {
7633 _deepMix(rst, args[_i]);
7634 }
7635
7636 return rst;
7637};
7638
7639module.exports = deepMix;
7640
7641/***/ }),
7642/* 61 */
7643/***/ (function(module, exports, __webpack_require__) {
7644
7645var Util = __webpack_require__(0);
7646
7647var Plot =
7648/*#__PURE__*/
7649function () {
7650 function Plot(cfg) {
7651 Util.mix(this, cfg);
7652
7653 this._init();
7654 }
7655
7656 var _proto = Plot.prototype;
7657
7658 _proto._init = function _init() {
7659 var self = this;
7660 var start = self.start;
7661 var end = self.end;
7662 var xMin = Math.min(start.x, end.x);
7663 var xMax = Math.max(start.x, end.x);
7664 var yMin = Math.min(start.y, end.y);
7665 var yMax = Math.max(start.y, end.y);
7666 this.tl = {
7667 x: xMin,
7668 y: yMin
7669 };
7670 this.tr = {
7671 x: xMax,
7672 y: yMin
7673 };
7674 this.bl = {
7675 x: xMin,
7676 y: yMax
7677 };
7678 this.br = {
7679 x: xMax,
7680 y: yMax
7681 };
7682 this.width = xMax - xMin;
7683 this.height = yMax - yMin;
7684 }
7685 /**
7686 * reset
7687 * @param {Object} start start point
7688 * @param {Object} end end point
7689 */
7690 ;
7691
7692 _proto.reset = function reset(start, end) {
7693 this.start = start;
7694 this.end = end;
7695
7696 this._init();
7697 }
7698 /**
7699 * check the point is in the range of plot
7700 * @param {Nubmer} x x value
7701 * @param {[type]} y y value
7702 * @return {Boolean} return the result
7703 */
7704 ;
7705
7706 _proto.isInRange = function isInRange(x, y) {
7707 if (Util.isObject(x)) {
7708 y = x.y;
7709 x = x.x;
7710 }
7711
7712 var tl = this.tl;
7713 var br = this.br;
7714 return tl.x <= x && x <= br.x && tl.y <= y && y <= br.y;
7715 };
7716
7717 return Plot;
7718}();
7719
7720module.exports = Plot;
7721
7722/***/ }),
7723/* 62 */
7724/***/ (function(module, exports, __webpack_require__) {
7725
7726var Coord = __webpack_require__(23);
7727
7728__webpack_require__(63);
7729
7730module.exports = Coord;
7731
7732/***/ }),
7733/* 63 */
7734/***/ (function(module, exports, __webpack_require__) {
7735
7736function _inheritsLoose(subClass, superClass) {
7737 subClass.prototype = Object.create(superClass.prototype);
7738 subClass.prototype.constructor = subClass;
7739 subClass.__proto__ = superClass;
7740}
7741
7742var Base = __webpack_require__(23);
7743
7744var Cartesian =
7745/*#__PURE__*/
7746function (_Base) {
7747 _inheritsLoose(Cartesian, _Base);
7748
7749 function Cartesian() {
7750 return _Base.apply(this, arguments) || this;
7751 }
7752
7753 var _proto = Cartesian.prototype;
7754
7755 _proto._initDefaultCfg = function _initDefaultCfg() {
7756 this.type = 'cartesian';
7757 this.transposed = false;
7758 this.isRect = true;
7759 };
7760
7761 _proto.init = function init(start, end) {
7762 this.x = {
7763 start: start.x,
7764 end: end.x
7765 };
7766 this.y = {
7767 start: start.y,
7768 end: end.y
7769 };
7770 };
7771
7772 _proto.convertPoint = function convertPoint(point) {
7773 var self = this;
7774 var transposed = self.transposed;
7775 var xDim = transposed ? 'y' : 'x';
7776 var yDim = transposed ? 'x' : 'y';
7777 var x = self.x;
7778 var y = self.y;
7779 return {
7780 x: x.start + (x.end - x.start) * point[xDim],
7781 y: y.start + (y.end - y.start) * point[yDim]
7782 };
7783 };
7784
7785 _proto.invertPoint = function invertPoint(point) {
7786 var self = this;
7787 var transposed = self.transposed;
7788 var xDim = transposed ? 'y' : 'x';
7789 var yDim = transposed ? 'x' : 'y';
7790 var x = self.x;
7791 var y = self.y;
7792 var rst = {};
7793 rst[xDim] = (point.x - x.start) / (x.end - x.start);
7794 rst[yDim] = (point.y - y.start) / (y.end - y.start);
7795 return rst;
7796 };
7797
7798 return Cartesian;
7799}(Base);
7800
7801Base.Cartesian = Cartesian;
7802Base.Rect = Cartesian;
7803module.exports = Cartesian;
7804
7805/***/ }),
7806/* 64 */
7807/***/ (function(module, exports, __webpack_require__) {
7808
7809module.exports = {
7810 Position: __webpack_require__(65),
7811 Shape: __webpack_require__(66),
7812 Size: __webpack_require__(67),
7813 Color: __webpack_require__(68)
7814};
7815
7816/***/ }),
7817/* 65 */
7818/***/ (function(module, exports, __webpack_require__) {
7819
7820function _inheritsLoose(subClass, superClass) {
7821 subClass.prototype = Object.create(superClass.prototype);
7822 subClass.prototype.constructor = subClass;
7823 subClass.__proto__ = superClass;
7824}
7825
7826var isNil = __webpack_require__(10);
7827
7828var isArray = __webpack_require__(15);
7829
7830var each = __webpack_require__(5);
7831
7832var Base = __webpack_require__(18);
7833
7834var Position =
7835/*#__PURE__*/
7836function (_Base) {
7837 _inheritsLoose(Position, _Base);
7838
7839 function Position(cfg) {
7840 var _this;
7841
7842 _this = _Base.call(this, cfg) || this;
7843 _this.names = ['x', 'y'];
7844 _this.type = 'position';
7845 return _this;
7846 }
7847
7848 var _proto = Position.prototype;
7849
7850 _proto.mapping = function mapping(x, y) {
7851 var scales = this.scales;
7852 var coord = this.coord;
7853 var scaleX = scales[0];
7854 var scaleY = scales[1];
7855 var rstX;
7856 var rstY;
7857 var obj;
7858
7859 if (isNil(x) || isNil(y)) {
7860 return [];
7861 }
7862
7863 if (isArray(y) && isArray(x)) {
7864 rstX = [];
7865 rstY = [];
7866
7867 for (var i = 0, j = 0, xLen = x.length, yLen = y.length; i < xLen && j < yLen; i++, j++) {
7868 obj = coord.convertPoint({
7869 x: scaleX.scale(x[i]),
7870 y: scaleY.scale(y[j])
7871 });
7872 rstX.push(obj.x);
7873 rstY.push(obj.y);
7874 }
7875 } else if (isArray(y)) {
7876 x = scaleX.scale(x);
7877 rstY = [];
7878 each(y, function (yVal) {
7879 yVal = scaleY.scale(yVal);
7880 obj = coord.convertPoint({
7881 x: x,
7882 y: yVal
7883 });
7884
7885 if (rstX && rstX !== obj.x) {
7886 if (!isArray(rstX)) {
7887 rstX = [rstX];
7888 }
7889
7890 rstX.push(obj.x);
7891 } else {
7892 rstX = obj.x;
7893 }
7894
7895 rstY.push(obj.y);
7896 });
7897 } else if (isArray(x)) {
7898 y = scaleY.scale(y);
7899 rstX = [];
7900 each(x, function (xVal) {
7901 xVal = scaleX.scale(xVal);
7902 obj = coord.convertPoint({
7903 x: xVal,
7904 y: y
7905 });
7906
7907 if (rstY && rstY !== obj.y) {
7908 if (!isArray(rstY)) {
7909 rstY = [rstY];
7910 }
7911
7912 rstY.push(obj.y);
7913 } else {
7914 rstY = obj.y;
7915 }
7916
7917 rstX.push(obj.x);
7918 });
7919 } else {
7920 x = scaleX.scale(x);
7921 y = scaleY.scale(y);
7922 var point = coord.convertPoint({
7923 x: x,
7924 y: y
7925 });
7926 rstX = point.x;
7927 rstY = point.y;
7928 }
7929
7930 return [rstX, rstY];
7931 };
7932
7933 return Position;
7934}(Base);
7935
7936module.exports = Position;
7937
7938/***/ }),
7939/* 66 */
7940/***/ (function(module, exports, __webpack_require__) {
7941
7942function _inheritsLoose(subClass, superClass) {
7943 subClass.prototype = Object.create(superClass.prototype);
7944 subClass.prototype.constructor = subClass;
7945 subClass.__proto__ = superClass;
7946}
7947
7948var Base = __webpack_require__(18);
7949
7950var Shape =
7951/*#__PURE__*/
7952function (_Base) {
7953 _inheritsLoose(Shape, _Base);
7954
7955 function Shape(cfg) {
7956 var _this;
7957
7958 _this = _Base.call(this, cfg) || this;
7959 _this.names = ['shape'];
7960 _this.type = 'shape';
7961 _this.gradient = null;
7962 return _this;
7963 }
7964 /**
7965 * @override
7966 */
7967
7968
7969 var _proto = Shape.prototype;
7970
7971 _proto.getLinearValue = function getLinearValue(percent) {
7972 var values = this.values;
7973 var index = Math.round((values.length - 1) * percent);
7974 return values[index];
7975 };
7976
7977 return Shape;
7978}(Base);
7979
7980module.exports = Shape;
7981
7982/***/ }),
7983/* 67 */
7984/***/ (function(module, exports, __webpack_require__) {
7985
7986function _inheritsLoose(subClass, superClass) {
7987 subClass.prototype = Object.create(superClass.prototype);
7988 subClass.prototype.constructor = subClass;
7989 subClass.__proto__ = superClass;
7990}
7991
7992var Base = __webpack_require__(18);
7993
7994var Size =
7995/*#__PURE__*/
7996function (_Base) {
7997 _inheritsLoose(Size, _Base);
7998
7999 function Size(cfg) {
8000 var _this;
8001
8002 _this = _Base.call(this, cfg) || this;
8003 _this.names = ['size'];
8004 _this.type = 'size';
8005 _this.gradient = null;
8006 return _this;
8007 }
8008
8009 return Size;
8010}(Base);
8011
8012module.exports = Size;
8013
8014/***/ }),
8015/* 68 */
8016/***/ (function(module, exports, __webpack_require__) {
8017
8018function _inheritsLoose(subClass, superClass) {
8019 subClass.prototype = Object.create(superClass.prototype);
8020 subClass.prototype.constructor = subClass;
8021 subClass.__proto__ = superClass;
8022}
8023
8024var Util = __webpack_require__(0);
8025
8026var ColorUtil = __webpack_require__(69);
8027
8028var Base = __webpack_require__(18);
8029
8030var Color =
8031/*#__PURE__*/
8032function (_Base) {
8033 _inheritsLoose(Color, _Base);
8034
8035 function Color(cfg) {
8036 var _this;
8037
8038 _this = _Base.call(this, cfg) || this;
8039 _this.names = ['color'];
8040 _this.type = 'color';
8041 _this.gradient = null;
8042
8043 if (Util.isString(_this.values)) {
8044 _this.linear = true;
8045 }
8046
8047 return _this;
8048 }
8049 /**
8050 * @override
8051 */
8052
8053
8054 var _proto = Color.prototype;
8055
8056 _proto.getLinearValue = function getLinearValue(percent) {
8057 var gradient = this.gradient;
8058
8059 if (!gradient) {
8060 var values = this.values;
8061 gradient = ColorUtil.gradient(values);
8062 this.gradient = gradient;
8063 }
8064
8065 return gradient(percent);
8066 };
8067
8068 return Color;
8069}(Base);
8070
8071module.exports = Color;
8072
8073/***/ }),
8074/* 69 */
8075/***/ (function(module, exports, __webpack_require__) {
8076
8077var Util = __webpack_require__(0); // Get the interpolation between colors
8078
8079
8080function getValue(start, end, percent, index) {
8081 var value = start[index] + (end[index] - start[index]) * percent;
8082 return value;
8083} // convert to hex
8084
8085
8086function arr2hex(arr) {
8087 return '#' + toRGBValue(arr[0]) + toRGBValue(arr[1]) + toRGBValue(arr[2]);
8088}
8089
8090function toRGBValue(value) {
8091 value = Math.round(value);
8092 value = value.toString(16);
8093
8094 if (value.length === 1) {
8095 value = '0' + value;
8096 }
8097
8098 return value;
8099}
8100
8101function calColor(colors, percent) {
8102 var steps = colors.length - 1;
8103 var step = Math.floor(steps * percent);
8104 var left = steps * percent - step;
8105 var start = colors[step];
8106 var end = step === steps ? start : colors[step + 1];
8107 var rgb = arr2hex([getValue(start, end, left, 0), getValue(start, end, left, 1), getValue(start, end, left, 2)]);
8108 return rgb;
8109}
8110
8111function hex2arr(str) {
8112 var arr = [];
8113 arr.push(parseInt(str.substr(1, 2), 16));
8114 arr.push(parseInt(str.substr(3, 2), 16));
8115 arr.push(parseInt(str.substr(5, 2), 16));
8116 return arr;
8117}
8118
8119var colorCache = {
8120 black: '#000000',
8121 blue: '#0000ff',
8122 grey: '#808080',
8123 green: '#008000',
8124 orange: '#ffa500',
8125 pink: '#ffc0cb',
8126 purple: '#800080',
8127 red: '#ff0000',
8128 white: '#ffffff',
8129 yellow: '#ffff00'
8130};
8131var ColorUtil = {
8132 /**
8133 * Returns a hexadecimal string representing this color in RGB space, such as #f7eaba.
8134 * @param {String} color color value
8135 * @return {String} Returns a hexadecimal string
8136 */
8137 toHex: function toHex(color) {
8138 if (colorCache[color]) {
8139 return colorCache[color];
8140 }
8141
8142 if (color[0] === '#') {
8143 if (color.length === 7) {
8144 return color;
8145 }
8146
8147 var hex = color.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, function (m, r, g, b) {
8148 return '#' + r + r + g + g + b + b;
8149 }); // hex3 to hex6
8150
8151 colorCache[color] = hex;
8152 return hex;
8153 } // rgb/rgba to hex
8154
8155
8156 var rst = color.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
8157 rst.shift();
8158 rst = arr2hex(rst);
8159 colorCache[color] = rst;
8160 return rst;
8161 },
8162 hex2arr: hex2arr,
8163
8164 /**
8165 * handle the gradient color
8166 * @param {Array} colors the colors
8167 * @return {String} return the color value
8168 */
8169 gradient: function gradient(colors) {
8170 var points = [];
8171
8172 if (Util.isString(colors)) {
8173 colors = colors.split('-');
8174 }
8175
8176 Util.each(colors, function (color) {
8177 if (color.indexOf('#') === -1) {
8178 color = ColorUtil.toHex(color);
8179 }
8180
8181 points.push(hex2arr(color));
8182 });
8183 return function (percent) {
8184 return calColor(points, percent);
8185 };
8186 }
8187};
8188module.exports = ColorUtil;
8189
8190/***/ }),
8191/* 70 */
8192/***/ (function(module, exports) {
8193
8194function _mix(dist, obj) {
8195 for (var key in obj) {
8196 if (obj.hasOwnProperty(key) && key !== 'constructor' && obj[key] !== undefined) {
8197 dist[key] = obj[key];
8198 }
8199 }
8200}
8201
8202var mix = function mix(dist, src1, src2, src3) {
8203 if (src1) _mix(dist, src1);
8204 if (src2) _mix(dist, src2);
8205 if (src3) _mix(dist, src3);
8206 return dist;
8207};
8208
8209module.exports = mix;
8210
8211/***/ }),
8212/* 71 */
8213/***/ (function(module, exports, __webpack_require__) {
8214
8215var Util = __webpack_require__(0);
8216
8217var Global = __webpack_require__(1);
8218
8219var Scale = __webpack_require__(72);
8220
8221var SCALE_TYPES_MAP = {
8222 linear: 'Linear',
8223 cat: 'Cat',
8224 timeCat: 'TimeCat',
8225 identity: 'Identity'
8226};
8227
8228var ScaleController =
8229/*#__PURE__*/
8230function () {
8231 function ScaleController(cfg) {
8232 // defs 列定义
8233 this.defs = {};
8234 Util.mix(this, cfg);
8235 }
8236
8237 var _proto = ScaleController.prototype;
8238
8239 _proto._getDef = function _getDef(field) {
8240 var defs = this.defs;
8241 var def = null;
8242
8243 if (Global.scales[field] || defs[field]) {
8244 def = Util.mix({}, Global.scales[field]);
8245 Util.each(defs[field], function (v, k) {
8246 if (Util.isNil(v)) {
8247 delete def[k];
8248 } else {
8249 def[k] = v;
8250 }
8251 });
8252 }
8253
8254 return def;
8255 };
8256
8257 _proto._getDefaultType = function _getDefaultType(field, data, def) {
8258 if (def && def.type) {
8259 return def.type;
8260 }
8261
8262 var type = 'linear';
8263 var value = Util.Array.firstValue(data, field);
8264
8265 if (Util.isArray(value)) {
8266 value = value[0];
8267 }
8268
8269 if (Util.isString(value)) {
8270 type = 'cat';
8271 }
8272
8273 return type;
8274 };
8275
8276 _proto._getScaleCfg = function _getScaleCfg(type, field, data, def) {
8277 var values;
8278
8279 if (def && def.values) {
8280 values = def.values;
8281 } else {
8282 values = Util.Array.values(data, field);
8283 }
8284
8285 var cfg = {
8286 field: field,
8287 values: values
8288 };
8289
8290 if (type !== 'cat' && type !== 'timeCat') {
8291 if (!def || !(def.min && def.max)) {
8292 var _Util$Array$getRange = Util.Array.getRange(values),
8293 min = _Util$Array$getRange.min,
8294 max = _Util$Array$getRange.max;
8295
8296 cfg.min = min;
8297 cfg.max = max;
8298 cfg.nice = true;
8299 }
8300 }
8301
8302 if (type === 'cat' || type === 'timeCat') {
8303 cfg.isRounding = false; // used for tickCount calculation
8304 }
8305
8306 return cfg;
8307 };
8308
8309 _proto.createScale = function createScale(field, data) {
8310 var self = this;
8311
8312 var def = self._getDef(field);
8313
8314 var scale;
8315
8316 if (!data || !data.length) {
8317 if (def && def.type) {
8318 def.field = field;
8319 scale = new Scale[SCALE_TYPES_MAP[def.type]](def);
8320 } else {
8321 scale = new Scale.Identity({
8322 value: field,
8323 field: field.toString(),
8324 values: [field]
8325 });
8326 }
8327
8328 return scale;
8329 }
8330
8331 var firstObj = data[0];
8332 var firstValue = firstObj[field];
8333
8334 if (firstValue === null) {
8335 firstValue = Util.Array.firstValue(data, field);
8336 }
8337
8338 if (Util.isNumber(field) || Util.isNil(firstValue) && !def) {
8339 scale = new Scale.Identity({
8340 value: field,
8341 field: field.toString(),
8342 values: [field]
8343 });
8344 } else {
8345 var type = self._getDefaultType(field, data, def);
8346
8347 var cfg = self._getScaleCfg(type, field, data, def);
8348
8349 def && Util.mix(cfg, def);
8350 scale = new Scale[SCALE_TYPES_MAP[type]](cfg);
8351 }
8352
8353 return scale;
8354 };
8355
8356 return ScaleController;
8357}();
8358
8359module.exports = ScaleController;
8360
8361/***/ }),
8362/* 72 */
8363/***/ (function(module, exports, __webpack_require__) {
8364
8365var Scale = __webpack_require__(16);
8366
8367__webpack_require__(73);
8368
8369__webpack_require__(76);
8370
8371__webpack_require__(34);
8372
8373module.exports = Scale;
8374
8375/***/ }),
8376/* 73 */
8377/***/ (function(module, exports, __webpack_require__) {
8378
8379function _inheritsLoose(subClass, superClass) {
8380 subClass.prototype = Object.create(superClass.prototype);
8381 subClass.prototype.constructor = subClass;
8382 subClass.__proto__ = superClass;
8383}
8384/**
8385 * @fileOverview The measurement of linear data scale function
8386 * @author dxq613@gmail.com
8387 */
8388
8389
8390var isNil = __webpack_require__(10);
8391
8392var each = __webpack_require__(5);
8393
8394var Base = __webpack_require__(16);
8395
8396var numberAuto = __webpack_require__(74);
8397/**
8398 * 线性度量
8399 * @class Scale.Linear
8400 */
8401
8402
8403var Linear =
8404/*#__PURE__*/
8405function (_Base) {
8406 _inheritsLoose(Linear, _Base);
8407
8408 function Linear() {
8409 return _Base.apply(this, arguments) || this;
8410 }
8411
8412 var _proto = Linear.prototype;
8413
8414 _proto._initDefaultCfg = function _initDefaultCfg() {
8415 _Base.prototype._initDefaultCfg.call(this);
8416
8417 var self = this;
8418 self.type = 'linear';
8419 self.isLinear = true;
8420 /**
8421 * 是否为了用户习惯,优化min,max和ticks,如果进行优化,则会根据生成的ticks调整min,max,否则舍弃(min,max)范围之外的ticks
8422 * @type {Boolean}
8423 * @default false
8424 */
8425
8426 self.nice = false;
8427 /**
8428 * min value of the scale
8429 * @type {Number}
8430 * @default null
8431 */
8432
8433 self.min = null;
8434 /**
8435 * min value limitted of the scale
8436 * @type {Number}
8437 * @default null
8438 */
8439
8440 self.minLimit = null;
8441 /**
8442 * max value of the scale
8443 * @type {Number}
8444 * @default null
8445 */
8446
8447 self.max = null;
8448 /**
8449 * max value limitted of the scale
8450 * @type {Number}
8451 * @default null
8452 */
8453
8454 self.maxLimit = null;
8455 /**
8456 * 自动生成标记时的个数
8457 * @type {Number}
8458 * @default null
8459 */
8460
8461 self.tickCount = null;
8462 /**
8463 * 坐标轴点之间的间距,指的是真实数据的差值
8464 * @type {Number}
8465 * @default null
8466 */
8467
8468 self.tickInterval = null;
8469 /**
8470 * 坐标轴点之间的最小间距,指的是真实数据的差值
8471 * @type {Number}
8472 * @default null
8473 */
8474
8475 self.minTickInterval = null;
8476 /**
8477 * 用于计算坐标点时逼近的数组
8478 * @type {Array}
8479 */
8480
8481 self.snapArray = null;
8482 };
8483 /**
8484 * @protected
8485 * @override
8486 */
8487
8488
8489 _proto.init = function init() {
8490 var self = this;
8491
8492 if (!self.ticks) {
8493 self.min = self.translate(self.min);
8494 self.max = self.translate(self.max);
8495 self.initTicks();
8496 } else {
8497 var ticks = self.ticks;
8498 var firstValue = self.translate(ticks[0]);
8499 var lastValue = self.translate(ticks[ticks.length - 1]);
8500
8501 if (isNil(self.min) || self.min > firstValue) {
8502 self.min = firstValue;
8503 }
8504
8505 if (isNil(self.max) || self.max < lastValue) {
8506 self.max = lastValue;
8507 }
8508 }
8509 };
8510 /**
8511 * 计算坐标点
8512 * @protected
8513 * @return {Array} 计算完成的坐标点
8514 */
8515
8516
8517 _proto.calculateTicks = function calculateTicks() {
8518 var min = this.min,
8519 max = this.max,
8520 minLimit = this.minLimit,
8521 maxLimit = this.maxLimit,
8522 tickCount = this.tickCount,
8523 tickInterval = this.tickInterval,
8524 minTickInterval = this.minTickInterval,
8525 snapArray = this.snapArray;
8526
8527 if (tickCount === 1) {
8528 throw new Error('linear scale\'tickCount should not be 1');
8529 }
8530
8531 if (max < min) {
8532 throw new Error("max: " + max + " should not be less than min: " + min);
8533 }
8534
8535 var tmp = numberAuto({
8536 min: min,
8537 max: max,
8538 minLimit: minLimit,
8539 maxLimit: maxLimit,
8540 minCount: tickCount,
8541 maxCount: tickCount,
8542 interval: tickInterval,
8543 minTickInterval: minTickInterval,
8544 snapArray: snapArray
8545 });
8546 return tmp.ticks;
8547 }; // 初始化ticks
8548
8549
8550 _proto.initTicks = function initTicks() {
8551 var self = this;
8552 var calTicks = self.calculateTicks();
8553
8554 if (self.nice) {
8555 // 如果需要优化显示的tick
8556 self.ticks = calTicks;
8557 self.min = calTicks[0];
8558 self.max = calTicks[calTicks.length - 1];
8559 } else {
8560 var ticks = [];
8561 each(calTicks, function (tick) {
8562 if (tick >= self.min && tick <= self.max) {
8563 ticks.push(tick);
8564 }
8565 }); // 如果 ticks 为空,直接输入最小值、最大值
8566
8567 if (!ticks.length) {
8568 ticks.push(self.min);
8569 ticks.push(self.max);
8570 }
8571
8572 self.ticks = ticks;
8573 }
8574 };
8575 /**
8576 * @override
8577 */
8578
8579
8580 _proto.scale = function scale(value) {
8581 if (isNil(value)) {
8582 return NaN;
8583 }
8584
8585 var max = this.max;
8586 var min = this.min;
8587
8588 if (max === min) {
8589 return 0;
8590 }
8591
8592 var percent = (value - min) / (max - min);
8593 var rangeMin = this.rangeMin();
8594 var rangeMax = this.rangeMax();
8595 return rangeMin + percent * (rangeMax - rangeMin);
8596 };
8597 /**
8598 * @override
8599 */
8600
8601
8602 _proto.invert = function invert(value) {
8603 var percent = (value - this.rangeMin()) / (this.rangeMax() - this.rangeMin());
8604 return this.min + percent * (this.max - this.min);
8605 };
8606
8607 return Linear;
8608}(Base);
8609
8610Base.Linear = Linear;
8611module.exports = Linear;
8612
8613/***/ }),
8614/* 74 */
8615/***/ (function(module, exports, __webpack_require__) {
8616
8617/**
8618 * @fileOverview 自动计算数字坐标轴
8619 * @author dxq613@gmail.com
8620 */
8621var isNil = __webpack_require__(10);
8622
8623var isNumber = __webpack_require__(14);
8624
8625var AutoUtil = __webpack_require__(75);
8626
8627var MIN_COUNT = 5;
8628var MAX_COUNT = 7;
8629var SNAP_COUNT_ARRAY = [0, 1, 1.2, 1.5, 1.6, 2, 2.2, 2.4, 2.5, 3, 4, 5, 6, 7.5, 8, 10];
8630var SNAP_ARRAY = [0, 1, 2, 4, 5, 10];
8631
8632module.exports = function (info) {
8633 var min = info.min;
8634 var max = info.max;
8635 var interval = info.interval;
8636 var minTickInterval = info.minTickInterval;
8637 var ticks = [];
8638 var minCount = info.minCount || MIN_COUNT;
8639 var maxCount = info.maxCount || MAX_COUNT;
8640 var isFixedCount = minCount === maxCount; // 是否限定死了个数
8641
8642 var minLimit = isNil(info.minLimit) ? -Infinity : info.minLimit; // 限定的最小值
8643
8644 var maxLimit = isNil(info.maxLimit) ? Infinity : info.maxLimit; // 限定最大值
8645
8646 var avgCount = (minCount + maxCount) / 2;
8647 var count = avgCount; // 用户传入的逼近数组
8648
8649 var snapArray = info.snapArray ? info.snapArray : isFixedCount ? SNAP_COUNT_ARRAY : SNAP_ARRAY; // 如果限定大小范围,同时大小范围等于用户传入的范围,同时限定了个数,interval 按照个数均分
8650
8651 if (min === minLimit && max === maxLimit && isFixedCount) {
8652 interval = (max - min) / (count - 1);
8653 }
8654
8655 if (isNil(min)) {
8656 min = 0;
8657 }
8658
8659 if (isNil(max)) {
8660 max = 0;
8661 }
8662
8663 if (max === min) {
8664 if (min === 0) {
8665 max = 1;
8666 } else {
8667 if (min > 0) {
8668 min = 0;
8669 } else {
8670 max = 0;
8671 }
8672 }
8673
8674 if (max - min < 5 && !interval && max - min >= 1) {
8675 interval = 1;
8676 }
8677 }
8678
8679 if (isNil(interval)) {
8680 // 计算间距
8681 var temp = (max - min) / (avgCount - 1);
8682 interval = AutoUtil.snapFactorTo(temp, snapArray, 'ceil');
8683
8684 if (maxCount !== minCount) {
8685 count = parseInt((max - min) / interval, 10);
8686
8687 if (count > maxCount) {
8688 count = maxCount;
8689 }
8690
8691 if (count < minCount) {
8692 count = minCount;
8693 } // 不确定tick的个数时,使得tick偏小
8694
8695
8696 interval = AutoUtil.snapFactorTo((max - min) / (count - 1), snapArray, 'floor');
8697 }
8698 } // interval should not be less than minTickInterval
8699
8700
8701 if (isNumber(minTickInterval) && interval < minTickInterval) {
8702 interval = minTickInterval;
8703 }
8704
8705 if (info.interval || maxCount !== minCount) {
8706 // 校正 max 和 min
8707 max = Math.min(AutoUtil.snapMultiple(max, interval, 'ceil'), maxLimit); // 向上逼近
8708
8709 min = Math.max(AutoUtil.snapMultiple(min, interval, 'floor'), minLimit); // 向下逼近
8710
8711 count = Math.round((max - min) / interval);
8712 min = AutoUtil.fixedBase(min, interval);
8713 max = AutoUtil.fixedBase(max, interval);
8714 } else {
8715 avgCount = parseInt(avgCount, 10); // 取整
8716
8717 var avg = (max + min) / 2;
8718 var avgTick = AutoUtil.snapMultiple(avg, interval, 'ceil');
8719 var sideCount = Math.floor((avgCount - 2) / 2);
8720 var maxTick = avgTick + sideCount * interval;
8721 var minTick;
8722
8723 if (avgCount % 2 === 0) {
8724 minTick = avgTick - sideCount * interval;
8725 } else {
8726 minTick = avgTick - (sideCount + 1) * interval;
8727 }
8728
8729 if (maxTick < max) {
8730 maxTick = maxTick + interval;
8731 }
8732
8733 if (minTick > min) {
8734 minTick = minTick - interval;
8735 }
8736
8737 max = AutoUtil.fixedBase(maxTick, interval);
8738 min = AutoUtil.fixedBase(minTick, interval);
8739 }
8740
8741 max = Math.min(max, maxLimit);
8742 min = Math.max(min, minLimit);
8743 ticks.push(min);
8744
8745 for (var i = 1; i < count; i++) {
8746 var tickValue = AutoUtil.fixedBase(interval * i + min, interval);
8747
8748 if (tickValue < max) {
8749 ticks.push(tickValue);
8750 }
8751 }
8752
8753 if (ticks[ticks.length - 1] < max) {
8754 ticks.push(max);
8755 }
8756
8757 return {
8758 min: min,
8759 max: max,
8760 interval: interval,
8761 count: count,
8762 ticks: ticks
8763 };
8764};
8765
8766/***/ }),
8767/* 75 */
8768/***/ (function(module, exports) {
8769
8770/**
8771 * @fileOverview 计算方法
8772 * @author dxq613@gmail.com
8773 */
8774// 如果小数点后面超过 10 位浮点数时进行一下处理
8775var DECIMAL_LENGTH = 12; // 获取系数
8776
8777function getFactor(v) {
8778 var factor = 1;
8779
8780 if (v === Infinity || v === -Infinity) {
8781 throw new Error('Not support Infinity!');
8782 }
8783
8784 if (v < 1) {
8785 var count = 0;
8786
8787 while (v < 1) {
8788 factor = factor / 10;
8789 v = v * 10;
8790 count++;
8791 } // 浮点数计算出现问题
8792
8793
8794 if (factor.toString().length > DECIMAL_LENGTH) {
8795 factor = parseFloat(factor.toFixed(count));
8796 }
8797 } else {
8798 while (v > 10) {
8799 factor = factor * 10;
8800 v = v / 10;
8801 }
8802 }
8803
8804 return factor;
8805} // 取小于当前值的
8806
8807
8808function arrayFloor(values, value) {
8809 var length = values.length;
8810
8811 if (length === 0) {
8812 return NaN;
8813 }
8814
8815 var pre = values[0];
8816
8817 if (value < values[0]) {
8818 return NaN;
8819 }
8820
8821 if (value >= values[length - 1]) {
8822 return values[length - 1];
8823 }
8824
8825 for (var i = 1; i < values.length; i++) {
8826 if (value < values[i]) {
8827 break;
8828 }
8829
8830 pre = values[i];
8831 }
8832
8833 return pre;
8834} // 大于当前值的第一个
8835
8836
8837function arrayCeiling(values, value) {
8838 var length = values.length;
8839
8840 if (length === 0) {
8841 return NaN;
8842 } // var pre = values[0];
8843
8844
8845 var rst;
8846
8847 if (value > values[length - 1]) {
8848 return NaN;
8849 }
8850
8851 if (value < values[0]) {
8852 return values[0];
8853 }
8854
8855 for (var i = 1; i < values.length; i++) {
8856 if (value <= values[i]) {
8857 rst = values[i];
8858 break;
8859 }
8860 }
8861
8862 return rst;
8863}
8864
8865var Util = {
8866 // 获取逼近的数值
8867 snapFactorTo: function snapFactorTo(v, arr, snapType) {
8868 // 假设 v = -512,isFloor = true
8869 if (isNaN(v)) {
8870 return NaN;
8871 }
8872
8873 var factor = 1; // 计算系数
8874
8875 if (v !== 0) {
8876 if (v < 0) {
8877 factor = -1;
8878 }
8879
8880 v = v * factor; // v = 512
8881
8882 var tmpFactor = getFactor(v);
8883 factor = factor * tmpFactor; // factor = -100
8884
8885 v = v / tmpFactor; // v = 5.12
8886 }
8887
8888 if (snapType === 'floor') {
8889 v = Util.snapFloor(arr, v); // v = 5
8890 } else if (snapType === 'ceil') {
8891 v = Util.snapCeiling(arr, v); // v = 6
8892 } else {
8893 v = Util.snapTo(arr, v); // 四舍五入 5
8894 }
8895
8896 var rst = v * factor; // 如果出现浮点数计算问题,需要处理一下
8897
8898 if (Math.abs(factor) < 1 && rst.toString().length > DECIMAL_LENGTH) {
8899 var decimalVal = parseInt(1 / factor);
8900 var symbol = factor > 0 ? 1 : -1;
8901 rst = v / decimalVal * symbol;
8902 }
8903
8904 return rst;
8905 },
8906 // 获取逼近的倍数
8907 snapMultiple: function snapMultiple(v, base, snapType) {
8908 var div;
8909
8910 if (snapType === 'ceil') {
8911 div = Math.ceil(v / base);
8912 } else if (snapType === 'floor') {
8913 div = Math.floor(v / base);
8914 } else {
8915 div = Math.round(v / base);
8916 }
8917
8918 return div * base;
8919 },
8920
8921 /**
8922 * 获取逼近的值,用于对齐数据
8923 * @param {Array} values 数据集合
8924 * @param {Number} value 数值
8925 * @return {Number} 逼近的值
8926 */
8927 snapTo: function snapTo(values, value) {
8928 // 这里假定values是升序排列
8929 var floorVal = arrayFloor(values, value);
8930 var ceilingVal = arrayCeiling(values, value);
8931
8932 if (isNaN(floorVal) || isNaN(ceilingVal)) {
8933 if (values[0] >= value) {
8934 return values[0];
8935 }
8936
8937 var last = values[values.length - 1];
8938
8939 if (last <= value) {
8940 return last;
8941 }
8942 }
8943
8944 if (Math.abs(value - floorVal) < Math.abs(ceilingVal - value)) {
8945 return floorVal;
8946 }
8947
8948 return ceilingVal;
8949 },
8950
8951 /**
8952 * 获取逼近的最小值,用于对齐数据
8953 * @param {Array} values 数据集合
8954 * @param {Number} value 数值
8955 * @return {Number} 逼近的最小值
8956 */
8957 snapFloor: function snapFloor(values, value) {
8958 // 这里假定values是升序排列
8959 return arrayFloor(values, value);
8960 },
8961
8962 /**
8963 * 获取逼近的最大值,用于对齐数据
8964 * @param {Array} values 数据集合
8965 * @param {Number} value 数值
8966 * @return {Number} 逼近的最大值
8967 */
8968 snapCeiling: function snapCeiling(values, value) {
8969 // 这里假定values是升序排列
8970 return arrayCeiling(values, value);
8971 },
8972 fixedBase: function fixedBase(v, base) {
8973 var str = base.toString();
8974 var index = str.indexOf('.');
8975
8976 if (index === -1) {
8977 return Math.round(v);
8978 }
8979
8980 var length = str.substr(index + 1).length;
8981
8982 if (length > 20) {
8983 length = 20;
8984 }
8985
8986 return parseFloat(v.toFixed(length));
8987 }
8988};
8989module.exports = Util;
8990
8991/***/ }),
8992/* 76 */
8993/***/ (function(module, exports, __webpack_require__) {
8994
8995function _inheritsLoose(subClass, superClass) {
8996 subClass.prototype = Object.create(superClass.prototype);
8997 subClass.prototype.constructor = subClass;
8998 subClass.__proto__ = superClass;
8999}
9000
9001var Base = __webpack_require__(16);
9002
9003var isNumber = __webpack_require__(14);
9004
9005var Identity =
9006/*#__PURE__*/
9007function (_Base) {
9008 _inheritsLoose(Identity, _Base);
9009
9010 function Identity() {
9011 return _Base.apply(this, arguments) || this;
9012 }
9013
9014 var _proto = Identity.prototype;
9015
9016 _proto._initDefaultCfg = function _initDefaultCfg() {
9017 _Base.prototype._initDefaultCfg.call(this);
9018
9019 this.isIdentity = true;
9020 this.type = 'identity';
9021 /**
9022 * 常量值
9023 * @type {*}
9024 */
9025
9026 this.value = null;
9027 };
9028 /**
9029 * @override
9030 */
9031
9032
9033 _proto.getText = function getText() {
9034 return this.value.toString();
9035 };
9036 /**
9037 * @override
9038 */
9039
9040
9041 _proto.scale = function scale(value) {
9042 if (this.value !== value && isNumber(value)) {
9043 return value;
9044 }
9045
9046 return this.range[0];
9047 };
9048 /**
9049 * @override
9050 */
9051
9052
9053 _proto.invert = function invert() {
9054 return this.value;
9055 };
9056
9057 return Identity;
9058}(Base);
9059
9060Base.Identity = Identity;
9061module.exports = Identity;
9062
9063/***/ }),
9064/* 77 */
9065/***/ (function(module, exports, __webpack_require__) {
9066
9067var Util = __webpack_require__(0);
9068
9069var Axis = __webpack_require__(78);
9070
9071var Global = __webpack_require__(1);
9072
9073var _require = __webpack_require__(3),
9074 Shape = _require.Shape;
9075
9076function formatTicks(ticks) {
9077 var tmp = ticks.slice(0);
9078
9079 if (tmp.length > 0) {
9080 var first = tmp[0];
9081 var last = tmp[tmp.length - 1];
9082
9083 if (first.value !== 0) {
9084 tmp.unshift({
9085 value: 0
9086 });
9087 }
9088
9089 if (last.value !== 1) {
9090 tmp.push({
9091 value: 1
9092 });
9093 }
9094 }
9095
9096 return tmp;
9097}
9098
9099var AxisController =
9100/*#__PURE__*/
9101function () {
9102 function AxisController(cfg) {
9103 this.axisCfg = {};
9104 this.frontPlot = null;
9105 this.backPlot = null;
9106 this.axes = {}; // store the axes's options
9107
9108 Util.mix(this, cfg);
9109 }
9110
9111 var _proto = AxisController.prototype;
9112
9113 _proto._isHide = function _isHide(field) {
9114 var axisCfg = this.axisCfg;
9115 return !axisCfg || axisCfg[field] === false;
9116 };
9117
9118 _proto._getLinePosition = function _getLinePosition(scale, dimType, index, transposed) {
9119 var position = '';
9120 var field = scale.field;
9121 var axisCfg = this.axisCfg;
9122
9123 if (axisCfg[field] && axisCfg[field].position) {
9124 position = axisCfg[field].position;
9125 } else if (dimType === 'x') {
9126 position = transposed ? 'left' : 'bottom';
9127 } else if (dimType === 'y') {
9128 position = index ? 'right' : 'left';
9129
9130 if (transposed) {
9131 position = 'bottom';
9132 }
9133 }
9134
9135 return position;
9136 };
9137
9138 _proto._getLineCfg = function _getLineCfg(coord, dimType, position) {
9139 var start;
9140 var end;
9141 var factor = 1; // Mark clockwise or counterclockwise
9142
9143 if (dimType === 'x') {
9144 start = {
9145 x: 0,
9146 y: 0
9147 };
9148 end = {
9149 x: 1,
9150 y: 0
9151 };
9152 } else {
9153 if (position === 'right') {
9154 // there will be several y axes
9155 start = {
9156 x: 1,
9157 y: 0
9158 };
9159 end = {
9160 x: 1,
9161 y: 1
9162 };
9163 } else {
9164 start = {
9165 x: 0,
9166 y: 0
9167 };
9168 end = {
9169 x: 0,
9170 y: 1
9171 };
9172 factor = -1;
9173 }
9174 }
9175
9176 if (coord.transposed) {
9177 factor *= -1;
9178 }
9179
9180 return {
9181 offsetFactor: factor,
9182 start: coord.convertPoint(start),
9183 end: coord.convertPoint(end)
9184 };
9185 };
9186
9187 _proto._getCircleCfg = function _getCircleCfg(coord) {
9188 return {
9189 startAngle: coord.startAngle,
9190 endAngle: coord.endAngle,
9191 center: coord.center,
9192 radius: coord.circleRadius
9193 };
9194 };
9195
9196 _proto._getRadiusCfg = function _getRadiusCfg(coord) {
9197 var transposed = coord.transposed;
9198 var start;
9199 var end;
9200
9201 if (transposed) {
9202 start = {
9203 x: 0,
9204 y: 0
9205 };
9206 end = {
9207 x: 1,
9208 y: 0
9209 };
9210 } else {
9211 start = {
9212 x: 0,
9213 y: 0
9214 };
9215 end = {
9216 x: 0,
9217 y: 1
9218 };
9219 }
9220
9221 return {
9222 offsetFactor: -1,
9223 start: coord.convertPoint(start),
9224 end: coord.convertPoint(end)
9225 };
9226 };
9227
9228 _proto._getAxisCfg = function _getAxisCfg(coord, scale, verticalScale, dimType, defaultCfg) {
9229 var self = this;
9230 var axisCfg = this.axisCfg;
9231 var ticks = scale.getTicks();
9232 var cfg = Util.deepMix({
9233 ticks: ticks,
9234 frontContainer: this.frontPlot,
9235 backContainer: this.backPlot
9236 }, defaultCfg, axisCfg[scale.field]);
9237 var labels = [];
9238 var label = cfg.label;
9239 var count = ticks.length;
9240 var maxWidth = 0;
9241 var maxHeight = 0;
9242 var labelCfg = label;
9243 Util.each(ticks, function (tick, index) {
9244 if (Util.isFunction(label)) {
9245 var executedLabel = label(tick.text, index, count);
9246 labelCfg = executedLabel ? Util.mix({}, Global._defaultAxis.label, executedLabel) : null;
9247 }
9248
9249 if (labelCfg) {
9250 var textStyle = {};
9251
9252 if (labelCfg.textAlign) {
9253 textStyle.textAlign = labelCfg.textAlign;
9254 }
9255
9256 if (labelCfg.textBaseline) {
9257 textStyle.textBaseline = labelCfg.textBaseline;
9258 }
9259
9260 var axisLabel = new Shape.Text({
9261 className: 'axis-label',
9262 attrs: Util.mix({
9263 x: 0,
9264 y: 0,
9265 text: tick.text,
9266 fontFamily: self.chart.get('canvas').get('fontFamily')
9267 }, labelCfg),
9268 value: tick.value,
9269 textStyle: textStyle,
9270 top: labelCfg.top,
9271 context: self.chart.get('canvas').get('context')
9272 });
9273 labels.push(axisLabel);
9274
9275 var _axisLabel$getBBox = axisLabel.getBBox(),
9276 width = _axisLabel$getBBox.width,
9277 height = _axisLabel$getBBox.height;
9278
9279 maxWidth = Math.max(maxWidth, width);
9280 maxHeight = Math.max(maxHeight, height);
9281 }
9282 });
9283 cfg.labels = labels;
9284 cfg.maxWidth = maxWidth;
9285 cfg.maxHeight = maxHeight;
9286 return cfg;
9287 };
9288
9289 _proto._createAxis = function _createAxis(coord, scale, verticalScale, dimType, index) {
9290 if (index === void 0) {
9291 index = '';
9292 }
9293
9294 var self = this;
9295 var coordType = coord.type;
9296 var transposed = coord.transposed;
9297 var type;
9298 var key;
9299 var defaultCfg;
9300
9301 if (coordType === 'cartesian' || coordType === 'rect') {
9302 var position = self._getLinePosition(scale, dimType, index, transposed);
9303
9304 defaultCfg = Global.axis[position];
9305 defaultCfg.position = position;
9306 type = 'Line';
9307 key = position;
9308 } else {
9309 if (dimType === 'x' && !transposed || dimType === 'y' && transposed) {
9310 defaultCfg = Global.axis.circle;
9311 type = 'Circle';
9312 key = 'circle';
9313 } else {
9314 defaultCfg = Global.axis.radius;
9315 type = 'Line';
9316 key = 'radius';
9317 }
9318 }
9319
9320 var cfg = self._getAxisCfg(coord, scale, verticalScale, dimType, defaultCfg);
9321
9322 cfg.type = type;
9323 cfg.dimType = dimType;
9324 cfg.verticalScale = verticalScale;
9325 cfg.index = index;
9326 this.axes[key] = cfg;
9327 };
9328
9329 _proto.createAxis = function createAxis(coord, xScale, yScales) {
9330 var self = this;
9331
9332 if (xScale && !self._isHide(xScale.field)) {
9333 self._createAxis(coord, xScale, yScales[0], 'x');
9334 }
9335
9336 Util.each(yScales, function (yScale, index) {
9337 if (!self._isHide(yScale.field)) {
9338 self._createAxis(coord, yScale, xScale, 'y', index);
9339 }
9340 });
9341 var axes = this.axes;
9342 var chart = self.chart;
9343
9344 if (chart._isAutoPadding()) {
9345 var userPadding = Util.parsePadding(chart.get('padding'));
9346 var appendPadding = Util.parsePadding(chart.get('appendPadding'));
9347 var legendRange = chart.get('legendRange') || {
9348 top: 0,
9349 right: 0,
9350 bottom: 0,
9351 left: 0
9352 };
9353 var padding = [userPadding[0] === 'auto' ? legendRange.top + appendPadding[0] * 2 : userPadding[0], userPadding[1] === 'auto' ? legendRange.right + appendPadding[1] : userPadding[1], userPadding[2] === 'auto' ? legendRange.bottom + appendPadding[2] : userPadding[2], userPadding[3] === 'auto' ? legendRange.left + appendPadding[3] : userPadding[3]];
9354
9355 if (coord.isPolar) {
9356 var circleAxis = axes.circle;
9357
9358 if (circleAxis) {
9359 var maxHeight = circleAxis.maxHeight,
9360 maxWidth = circleAxis.maxWidth,
9361 labelOffset = circleAxis.labelOffset;
9362 padding[0] += maxHeight + labelOffset;
9363 padding[1] += maxWidth + labelOffset;
9364 padding[2] += maxHeight + labelOffset;
9365 padding[3] += maxWidth + labelOffset;
9366 }
9367 } else {
9368 if (axes.right && userPadding[1] === 'auto') {
9369 var _axes$right = axes.right,
9370 _maxWidth = _axes$right.maxWidth,
9371 _labelOffset = _axes$right.labelOffset;
9372 padding[1] += _maxWidth + _labelOffset;
9373 }
9374
9375 if (axes.left && userPadding[3] === 'auto') {
9376 var _axes$left = axes.left,
9377 _maxWidth2 = _axes$left.maxWidth,
9378 _labelOffset2 = _axes$left.labelOffset;
9379 padding[3] += _maxWidth2 + _labelOffset2;
9380 }
9381
9382 if (axes.bottom && userPadding[2] === 'auto') {
9383 var _axes$bottom = axes.bottom,
9384 _maxHeight = _axes$bottom.maxHeight,
9385 _labelOffset3 = _axes$bottom.labelOffset;
9386 padding[2] += _maxHeight + _labelOffset3;
9387 }
9388 }
9389
9390 chart.set('_padding', padding);
9391
9392 chart._updateLayout(padding);
9393 }
9394
9395 Util.each(axes, function (axis) {
9396 var type = axis.type,
9397 grid = axis.grid,
9398 verticalScale = axis.verticalScale,
9399 ticks = axis.ticks,
9400 dimType = axis.dimType,
9401 position = axis.position,
9402 index = axis.index;
9403 var appendCfg;
9404
9405 if (coord.isPolar) {
9406 if (type === 'Line') {
9407 appendCfg = self._getRadiusCfg(coord);
9408 } else if (type === 'Circle') {
9409 appendCfg = self._getCircleCfg(coord);
9410 }
9411 } else {
9412 appendCfg = self._getLineCfg(coord, dimType, position);
9413 }
9414
9415 if (grid && verticalScale) {
9416 var gridPoints = [];
9417 var verticalTicks = formatTicks(verticalScale.getTicks());
9418 Util.each(ticks, function (tick) {
9419 var subPoints = [];
9420 Util.each(verticalTicks, function (verticalTick) {
9421 var x = dimType === 'x' ? tick.value : verticalTick.value;
9422 var y = dimType === 'x' ? verticalTick.value : tick.value;
9423
9424 if (x >= 0 && x <= 1 && y >= 0 && y <= 1) {
9425 var point = coord.convertPoint({
9426 x: x,
9427 y: y
9428 });
9429 subPoints.push(point);
9430 }
9431 });
9432 gridPoints.push({
9433 points: subPoints,
9434 _id: 'axis-' + dimType + index + '-grid-' + tick.tickValue
9435 });
9436 });
9437 axis.gridPoints = gridPoints;
9438
9439 if (coord.isPolar) {
9440 axis.center = coord.center;
9441 axis.startAngle = coord.startAngle;
9442 axis.endAngle = coord.endAngle;
9443 }
9444 }
9445
9446 appendCfg._id = 'axis-' + dimType;
9447
9448 if (!Util.isNil(index)) {
9449 appendCfg._id = 'axis-' + dimType + index;
9450 }
9451
9452 new Axis[type](Util.mix(axis, appendCfg));
9453 });
9454 };
9455
9456 _proto.clear = function clear() {
9457 this.axes = {};
9458 this.frontPlot.clear();
9459 this.backPlot.clear();
9460 };
9461
9462 return AxisController;
9463}();
9464
9465module.exports = AxisController;
9466
9467/***/ }),
9468/* 78 */
9469/***/ (function(module, exports, __webpack_require__) {
9470
9471var Abstract = __webpack_require__(25);
9472
9473__webpack_require__(79);
9474
9475module.exports = Abstract;
9476
9477/***/ }),
9478/* 79 */
9479/***/ (function(module, exports, __webpack_require__) {
9480
9481function _inheritsLoose(subClass, superClass) {
9482 subClass.prototype = Object.create(superClass.prototype);
9483 subClass.prototype.constructor = subClass;
9484 subClass.__proto__ = superClass;
9485}
9486
9487var Util = __webpack_require__(0);
9488
9489var Abstract = __webpack_require__(25);
9490
9491var Line =
9492/*#__PURE__*/
9493function (_Abstract) {
9494 _inheritsLoose(Line, _Abstract);
9495
9496 function Line() {
9497 return _Abstract.apply(this, arguments) || this;
9498 }
9499
9500 var _proto = Line.prototype;
9501
9502 _proto._initDefaultCfg = function _initDefaultCfg() {
9503 _Abstract.prototype._initDefaultCfg.call(this);
9504
9505 this.start = null;
9506 this.end = null;
9507 };
9508
9509 _proto.getOffsetPoint = function getOffsetPoint(value) {
9510 var start = this.start,
9511 end = this.end;
9512 return {
9513 x: start.x + (end.x - start.x) * value,
9514 y: start.y + (end.y - start.y) * value
9515 };
9516 };
9517
9518 _proto.getAxisVector = function getAxisVector() {
9519 var start = this.start,
9520 end = this.end;
9521 return [end.x - start.x, end.y - start.y];
9522 };
9523
9524 _proto.drawLine = function drawLine(lineCfg) {
9525 var container = this.getContainer(lineCfg.top);
9526 var start = this.start,
9527 end = this.end;
9528 container.addShape('line', {
9529 className: 'axis-line',
9530 attrs: Util.mix({
9531 x1: start.x,
9532 y1: start.y,
9533 x2: end.x,
9534 y2: end.y
9535 }, lineCfg)
9536 });
9537 };
9538
9539 return Line;
9540}(Abstract);
9541
9542Abstract.Line = Line;
9543module.exports = Line;
9544
9545/***/ }),
9546/* 80 */
9547/***/ (function(module, exports, __webpack_require__) {
9548
9549var Util = __webpack_require__(0);
9550
9551var Container = __webpack_require__(36);
9552
9553var Group = __webpack_require__(37);
9554
9555var _require = __webpack_require__(38),
9556 requestAnimationFrame = _require.requestAnimationFrame;
9557
9558var Canvas =
9559/*#__PURE__*/
9560function () {
9561 var _proto = Canvas.prototype;
9562
9563 _proto.get = function get(name) {
9564 return this._attrs[name];
9565 };
9566
9567 _proto.set = function set(name, value) {
9568 this._attrs[name] = value;
9569 };
9570
9571 function Canvas(cfg) {
9572 this._attrs = Util.mix({
9573 type: 'canvas',
9574 children: []
9575 }, cfg);
9576
9577 this._initPixelRatio();
9578
9579 this._initCanvas();
9580 }
9581
9582 _proto._initPixelRatio = function _initPixelRatio() {
9583 var pixelRatio = this.get('pixelRatio');
9584
9585 if (!pixelRatio) {
9586 this.set('pixelRatio', Util.getPixelRatio());
9587 }
9588 };
9589
9590 _proto.beforeDraw = function beforeDraw() {
9591 var context = this._attrs.context;
9592 var el = this._attrs.el;
9593 !Util.isWx && !Util.isMy && context && context.clearRect(0, 0, el.width, el.height);
9594 };
9595
9596 _proto._initCanvas = function _initCanvas() {
9597 var self = this;
9598 var el = self.get('el');
9599 var context = self.get('context');
9600 var canvas;
9601
9602 if (context) {
9603 // CanvasRenderingContext2D
9604 canvas = context.canvas;
9605 } else if (Util.isString(el)) {
9606 // HTMLElement's id
9607 canvas = Util.getDomById(el);
9608 } else {
9609 // HTMLElement
9610 canvas = el;
9611 }
9612
9613 if (!canvas) {
9614 throw new Error('Please specify the id or el of the chart!');
9615 }
9616
9617 if (context && canvas && !canvas.getContext) {
9618 canvas.getContext = function () {
9619 return context;
9620 };
9621 }
9622
9623 var width = self.get('width');
9624
9625 if (!width) {
9626 width = Util.getWidth(canvas);
9627 }
9628
9629 var height = self.get('height');
9630
9631 if (!height) {
9632 height = Util.getHeight(canvas);
9633 }
9634
9635 self.set('canvas', this);
9636 self.set('el', canvas);
9637 self.set('context', context || canvas.getContext('2d'));
9638 self.changeSize(width, height);
9639 };
9640
9641 _proto.changeSize = function changeSize(width, height) {
9642 var pixelRatio = this.get('pixelRatio');
9643 var canvasDOM = this.get('el');
9644
9645 if (Util.isBrowser) {
9646 canvasDOM.style.width = width + 'px';
9647 canvasDOM.style.height = height + 'px';
9648 }
9649
9650 if (!Util.isWx && !Util.isMy) {
9651 canvasDOM.width = width * pixelRatio;
9652 canvasDOM.height = height * pixelRatio;
9653
9654 if (pixelRatio !== 1) {
9655 var ctx = this.get('context');
9656 ctx.scale(pixelRatio, pixelRatio);
9657 }
9658 }
9659
9660 this.set('width', width);
9661 this.set('height', height);
9662 };
9663
9664 _proto.getWidth = function getWidth() {
9665 var pixelRatio = this.get('pixelRatio');
9666 var width = this.get('width');
9667 return width * pixelRatio;
9668 };
9669
9670 _proto.getHeight = function getHeight() {
9671 var pixelRatio = this.get('pixelRatio');
9672 var height = this.get('height');
9673 return height * pixelRatio;
9674 };
9675
9676 _proto.getPointByClient = function getPointByClient(clientX, clientY) {
9677 var el = this.get('el');
9678 var bbox = el.getBoundingClientRect();
9679 var width = bbox.right - bbox.left;
9680 var height = bbox.bottom - bbox.top;
9681 return {
9682 x: (clientX - bbox.left) * (el.width / width),
9683 y: (clientY - bbox.top) * (el.height / height)
9684 };
9685 };
9686
9687 _proto._beginDraw = function _beginDraw() {
9688 this._attrs.toDraw = true;
9689 };
9690
9691 _proto._endDraw = function _endDraw() {
9692 this._attrs.toDraw = false;
9693 };
9694
9695 _proto.draw = function draw() {
9696 var self = this;
9697
9698 function drawInner() {
9699 self.set('animateHandler', requestAnimationFrame(function () {
9700 self.set('animateHandler', undefined);
9701
9702 if (self.get('toDraw')) {
9703 drawInner();
9704 }
9705 }));
9706 self.beforeDraw();
9707
9708 try {
9709 var context = self._attrs.context;
9710 var children = self._attrs.children;
9711
9712 for (var i = 0, len = children.length; i < len; i++) {
9713 var child = children[i];
9714 child.draw(context);
9715 }
9716
9717 if (Util.isWx || Util.isMy) {
9718 context.draw();
9719 }
9720 } catch (ev) {
9721 console.warn('error in draw canvas, detail as:');
9722 console.warn(ev);
9723
9724 self._endDraw();
9725 }
9726
9727 self._endDraw();
9728 }
9729
9730 if (self.get('destroyed')) {
9731 return;
9732 }
9733
9734 if (self.get('animateHandler')) {
9735 this._beginDraw();
9736 } else {
9737 drawInner();
9738 }
9739 };
9740
9741 _proto.destroy = function destroy() {
9742 if (this.get('destroyed')) {
9743 return;
9744 }
9745
9746 this.clear();
9747 this._attrs = {};
9748 this.set('destroyed', true);
9749 };
9750
9751 _proto.isDestroyed = function isDestroyed() {
9752 return this.get('destroyed');
9753 };
9754
9755 return Canvas;
9756}();
9757
9758Util.mix(Canvas.prototype, Container, {
9759 getGroupClass: function getGroupClass() {
9760 return Group;
9761 }
9762});
9763module.exports = Canvas;
9764
9765/***/ }),
9766/* 81 */
9767/***/ (function(module, exports, __webpack_require__) {
9768
9769var Util = __webpack_require__(0);
9770
9771function _mod(n, m) {
9772 return (n % m + m) % m;
9773}
9774
9775function _addStop(steps, gradient) {
9776 Util.each(steps, function (item) {
9777 item = item.split(':');
9778 gradient.addColorStop(Number(item[0]), item[1]);
9779 });
9780} // the string format: 'l(0) 0:#ffffff 0.5:#7ec2f3 1:#1890ff'
9781
9782
9783function _parseLineGradient(color, shape, context) {
9784 var arr = color.split(' ');
9785 var angle = arr[0].slice(2, arr[0].length - 1);
9786 angle = _mod(parseFloat(angle) * Math.PI / 180, Math.PI * 2);
9787 var steps = arr.slice(1);
9788
9789 var _shape$getBBox = shape.getBBox(),
9790 minX = _shape$getBBox.minX,
9791 minY = _shape$getBBox.minY,
9792 maxX = _shape$getBBox.maxX,
9793 maxY = _shape$getBBox.maxY;
9794
9795 var start;
9796 var end;
9797
9798 if (angle >= 0 && angle < 0.5 * Math.PI) {
9799 start = {
9800 x: minX,
9801 y: minY
9802 };
9803 end = {
9804 x: maxX,
9805 y: maxY
9806 };
9807 } else if (0.5 * Math.PI <= angle && angle < Math.PI) {
9808 start = {
9809 x: maxX,
9810 y: minY
9811 };
9812 end = {
9813 x: minX,
9814 y: maxY
9815 };
9816 } else if (Math.PI <= angle && angle < 1.5 * Math.PI) {
9817 start = {
9818 x: maxX,
9819 y: maxY
9820 };
9821 end = {
9822 x: minX,
9823 y: minY
9824 };
9825 } else {
9826 start = {
9827 x: minX,
9828 y: maxY
9829 };
9830 end = {
9831 x: maxX,
9832 y: minY
9833 };
9834 }
9835
9836 var tanTheta = Math.tan(angle);
9837 var tanTheta2 = tanTheta * tanTheta;
9838 var x = (end.x - start.x + tanTheta * (end.y - start.y)) / (tanTheta2 + 1) + start.x;
9839 var y = tanTheta * (end.x - start.x + tanTheta * (end.y - start.y)) / (tanTheta2 + 1) + start.y;
9840 var gradient = context.createLinearGradient(start.x, start.y, x, y);
9841
9842 _addStop(steps, gradient);
9843
9844 return gradient;
9845} // the string format: 'r(0.5, 0.5, 0.1) 0:#ffffff 1:#1890ff'
9846
9847
9848function _parseRadialGradient(color, shape, context) {
9849 var arr = color.split(' ');
9850 var circleCfg = arr[0].slice(2, arr[0].length - 1);
9851 circleCfg = circleCfg.split(',');
9852 var fx = parseFloat(circleCfg[0]);
9853 var fy = parseFloat(circleCfg[1]);
9854 var fr = parseFloat(circleCfg[2]);
9855 var steps = arr.slice(1); // if radius is 0, no gradient, stroke with the last color
9856
9857 if (fr === 0) {
9858 var _color = steps[steps.length - 1];
9859 return _color.split(':')[1];
9860 }
9861
9862 var _shape$getBBox2 = shape.getBBox(),
9863 width = _shape$getBBox2.width,
9864 height = _shape$getBBox2.height,
9865 minX = _shape$getBBox2.minX,
9866 minY = _shape$getBBox2.minY;
9867
9868 var r = Math.sqrt(width * width + height * height) / 2;
9869 var gradient = context.createRadialGradient(minX + width * fx, minY + height * fy, fr * r, minX + width / 2, minY + height / 2, r);
9870
9871 _addStop(steps, gradient);
9872
9873 return gradient;
9874}
9875
9876module.exports = {
9877 parseStyle: function parseStyle(color, shape, context) {
9878 if (color[1] === '(') {
9879 try {
9880 var firstCode = color[0];
9881
9882 if (firstCode === 'l') {
9883 return _parseLineGradient(color, shape, context);
9884 } else if (firstCode === 'r') {
9885 return _parseRadialGradient(color, shape, context);
9886 }
9887 } catch (ev) {
9888 console.error('error in parsing gradient string, please check if there are any extra whitespaces.');
9889 console.error(ev);
9890 }
9891 }
9892
9893 return color;
9894 }
9895};
9896
9897/***/ }),
9898/* 82 */
9899/***/ (function(module, exports, __webpack_require__) {
9900
9901function _inheritsLoose(subClass, superClass) {
9902 subClass.prototype = Object.create(superClass.prototype);
9903 subClass.prototype.constructor = subClass;
9904 subClass.__proto__ = superClass;
9905}
9906
9907var Util = __webpack_require__(0);
9908
9909var Shape = __webpack_require__(2);
9910
9911var Rect =
9912/*#__PURE__*/
9913function (_Shape) {
9914 _inheritsLoose(Rect, _Shape);
9915
9916 function Rect() {
9917 return _Shape.apply(this, arguments) || this;
9918 }
9919
9920 var _proto = Rect.prototype;
9921
9922 _proto._initProperties = function _initProperties() {
9923 _Shape.prototype._initProperties.call(this);
9924
9925 this._attrs.canFill = true;
9926 this._attrs.canStroke = true;
9927 this._attrs.type = 'rect';
9928 };
9929
9930 _proto.getDefaultAttrs = function getDefaultAttrs() {
9931 return {
9932 x: 0,
9933 y: 0,
9934 width: 0,
9935 height: 0,
9936 radius: 0,
9937 lineWidth: 0
9938 };
9939 };
9940
9941 _proto.createPath = function createPath(context) {
9942 var self = this;
9943 var attrs = self.get('attrs');
9944 var x = attrs.x,
9945 y = attrs.y,
9946 width = attrs.width,
9947 height = attrs.height;
9948 context.beginPath();
9949 var radius = attrs.radius;
9950
9951 if (!radius || !(width * height)) {
9952 context.rect(x, y, width, height);
9953 } else {
9954 radius = Util.parsePadding(radius);
9955 context.moveTo(x + radius[0], y);
9956 context.lineTo(x + width - radius[1], y);
9957 context.arc(x + width - radius[1], y + radius[1], radius[1], -Math.PI / 2, 0, false);
9958 context.lineTo(x + width, y + height - radius[2]);
9959 context.arc(x + width - radius[2], y + height - radius[2], radius[2], 0, Math.PI / 2, false);
9960 context.lineTo(x + radius[3], y + height);
9961 context.arc(x + radius[3], y + height - radius[3], radius[3], Math.PI / 2, Math.PI, false);
9962 context.lineTo(x, y + radius[0]);
9963 context.arc(x + radius[0], y + radius[0], radius[0], Math.PI, Math.PI * 3 / 2, false);
9964 context.closePath();
9965 }
9966 };
9967
9968 _proto.calculateBox = function calculateBox() {
9969 var attrs = this.get('attrs');
9970 var x = attrs.x,
9971 y = attrs.y,
9972 width = attrs.width,
9973 height = attrs.height;
9974 return {
9975 minX: x,
9976 minY: y,
9977 maxX: x + width,
9978 maxY: y + height
9979 };
9980 };
9981
9982 return Rect;
9983}(Shape);
9984
9985Shape.Rect = Rect;
9986module.exports = Rect;
9987
9988/***/ }),
9989/* 83 */
9990/***/ (function(module, exports, __webpack_require__) {
9991
9992function _inheritsLoose(subClass, superClass) {
9993 subClass.prototype = Object.create(superClass.prototype);
9994 subClass.prototype.constructor = subClass;
9995 subClass.__proto__ = superClass;
9996}
9997
9998var Shape = __webpack_require__(2);
9999
10000var Circle =
10001/*#__PURE__*/
10002function (_Shape) {
10003 _inheritsLoose(Circle, _Shape);
10004
10005 function Circle() {
10006 return _Shape.apply(this, arguments) || this;
10007 }
10008
10009 var _proto = Circle.prototype;
10010
10011 _proto._initProperties = function _initProperties() {
10012 _Shape.prototype._initProperties.call(this);
10013
10014 this._attrs.canFill = true;
10015 this._attrs.canStroke = true;
10016 this._attrs.type = 'circle';
10017 };
10018
10019 _proto.getDefaultAttrs = function getDefaultAttrs() {
10020 return {
10021 x: 0,
10022 y: 0,
10023 r: 0,
10024 lineWidth: 0
10025 };
10026 };
10027
10028 _proto.createPath = function createPath(context) {
10029 var attrs = this.get('attrs');
10030 var x = attrs.x,
10031 y = attrs.y,
10032 r = attrs.r;
10033 context.beginPath();
10034 context.arc(x, y, r, 0, Math.PI * 2, false);
10035 context.closePath();
10036 };
10037
10038 _proto.calculateBox = function calculateBox() {
10039 var attrs = this.get('attrs');
10040 var x = attrs.x,
10041 y = attrs.y,
10042 r = attrs.r;
10043 return {
10044 minX: x - r,
10045 maxX: x + r,
10046 minY: y - r,
10047 maxY: y + r
10048 };
10049 };
10050
10051 return Circle;
10052}(Shape);
10053
10054Shape.Circle = Circle;
10055module.exports = Circle;
10056
10057/***/ }),
10058/* 84 */
10059/***/ (function(module, exports, __webpack_require__) {
10060
10061function _inheritsLoose(subClass, superClass) {
10062 subClass.prototype = Object.create(superClass.prototype);
10063 subClass.prototype.constructor = subClass;
10064 subClass.__proto__ = superClass;
10065}
10066
10067var Shape = __webpack_require__(2);
10068
10069var bbox = __webpack_require__(12);
10070
10071var Line =
10072/*#__PURE__*/
10073function (_Shape) {
10074 _inheritsLoose(Line, _Shape);
10075
10076 function Line() {
10077 return _Shape.apply(this, arguments) || this;
10078 }
10079
10080 var _proto = Line.prototype;
10081
10082 _proto._initProperties = function _initProperties() {
10083 _Shape.prototype._initProperties.call(this);
10084
10085 this._attrs.canStroke = true;
10086 this._attrs.type = 'line';
10087 };
10088
10089 _proto.getDefaultAttrs = function getDefaultAttrs() {
10090 return {
10091 x1: 0,
10092 y1: 0,
10093 x2: 0,
10094 y2: 0,
10095 lineWidth: 1
10096 };
10097 };
10098
10099 _proto.createPath = function createPath(context) {
10100 var attrs = this.get('attrs');
10101 var x1 = attrs.x1,
10102 y1 = attrs.y1,
10103 x2 = attrs.x2,
10104 y2 = attrs.y2;
10105 context.beginPath();
10106 context.moveTo(x1, y1);
10107 context.lineTo(x2, y2);
10108 };
10109
10110 _proto.calculateBox = function calculateBox() {
10111 var attrs = this.get('attrs');
10112 var x1 = attrs.x1,
10113 y1 = attrs.y1,
10114 x2 = attrs.x2,
10115 y2 = attrs.y2,
10116 lineWidth = attrs.lineWidth;
10117 return bbox.getBBoxFromLine(x1, y1, x2, y2, lineWidth);
10118 };
10119
10120 return Line;
10121}(Shape);
10122
10123Shape.Line = Line;
10124module.exports = Line;
10125
10126/***/ }),
10127/* 85 */
10128/***/ (function(module, exports, __webpack_require__) {
10129
10130function _inheritsLoose(subClass, superClass) {
10131 subClass.prototype = Object.create(superClass.prototype);
10132 subClass.prototype.constructor = subClass;
10133 subClass.__proto__ = superClass;
10134}
10135
10136var Shape = __webpack_require__(2);
10137
10138var bbox = __webpack_require__(12);
10139
10140var Polygon =
10141/*#__PURE__*/
10142function (_Shape) {
10143 _inheritsLoose(Polygon, _Shape);
10144
10145 function Polygon() {
10146 return _Shape.apply(this, arguments) || this;
10147 }
10148
10149 var _proto = Polygon.prototype;
10150
10151 _proto._initProperties = function _initProperties() {
10152 _Shape.prototype._initProperties.call(this);
10153
10154 this._attrs.canFill = true;
10155 this._attrs.canStroke = true;
10156 this._attrs.type = 'polygon';
10157 };
10158
10159 _proto.getDefaultAttrs = function getDefaultAttrs() {
10160 return {
10161 points: null,
10162 lineWidth: 0
10163 };
10164 };
10165
10166 _proto.createPath = function createPath(context) {
10167 var self = this;
10168 var attrs = self.get('attrs');
10169 var points = attrs.points;
10170 context.beginPath();
10171
10172 for (var i = 0, len = points.length; i < len; i++) {
10173 var point = points[i];
10174
10175 if (i === 0) {
10176 context.moveTo(point.x, point.y);
10177 } else {
10178 context.lineTo(point.x, point.y);
10179 }
10180 }
10181
10182 context.closePath();
10183 };
10184
10185 _proto.calculateBox = function calculateBox() {
10186 var attrs = this.get('attrs');
10187 var points = attrs.points;
10188 return bbox.getBBoxFromPoints(points);
10189 };
10190
10191 return Polygon;
10192}(Shape);
10193
10194Shape.Polygon = Polygon;
10195module.exports = Polygon;
10196
10197/***/ }),
10198/* 86 */
10199/***/ (function(module, exports, __webpack_require__) {
10200
10201function _inheritsLoose(subClass, superClass) {
10202 subClass.prototype = Object.create(superClass.prototype);
10203 subClass.prototype.constructor = subClass;
10204 subClass.__proto__ = superClass;
10205}
10206
10207var Shape = __webpack_require__(2);
10208
10209var Smooth = __webpack_require__(39);
10210
10211var bbox = __webpack_require__(12); // filter the point which x or y is NaN
10212
10213
10214function _filterPoints(points) {
10215 var filteredPoints = [];
10216
10217 for (var i = 0, len = points.length; i < len; i++) {
10218 var point = points[i];
10219
10220 if (!isNaN(point.x) && !isNaN(point.y)) {
10221 filteredPoints.push(point);
10222 }
10223 }
10224
10225 return filteredPoints;
10226}
10227
10228var Polyline =
10229/*#__PURE__*/
10230function (_Shape) {
10231 _inheritsLoose(Polyline, _Shape);
10232
10233 function Polyline() {
10234 return _Shape.apply(this, arguments) || this;
10235 }
10236
10237 var _proto = Polyline.prototype;
10238
10239 _proto._initProperties = function _initProperties() {
10240 _Shape.prototype._initProperties.call(this);
10241
10242 this._attrs.canFill = true;
10243 this._attrs.canStroke = true;
10244 this._attrs.type = 'polyline';
10245 };
10246
10247 _proto.getDefaultAttrs = function getDefaultAttrs() {
10248 return {
10249 points: null,
10250 lineWidth: 1,
10251 smooth: false
10252 };
10253 };
10254
10255 _proto.createPath = function createPath(context) {
10256 var self = this;
10257 var attrs = self.get('attrs');
10258 var points = attrs.points,
10259 smooth = attrs.smooth;
10260
10261 var filteredPoints = _filterPoints(points);
10262
10263 context.beginPath();
10264
10265 if (filteredPoints.length) {
10266 context.moveTo(filteredPoints[0].x, filteredPoints[0].y);
10267
10268 if (smooth) {
10269 var constaint = [[0, 0], [1, 1]];
10270 var sps = Smooth.smooth(filteredPoints, false, constaint);
10271
10272 for (var i = 0, n = sps.length; i < n; i++) {
10273 var sp = sps[i];
10274 context.bezierCurveTo(sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]);
10275 }
10276 } else {
10277 var _i;
10278
10279 var l;
10280
10281 for (_i = 1, l = filteredPoints.length - 1; _i < l; _i++) {
10282 context.lineTo(filteredPoints[_i].x, filteredPoints[_i].y);
10283 }
10284
10285 context.lineTo(filteredPoints[l].x, filteredPoints[l].y);
10286 }
10287 }
10288 };
10289
10290 _proto.calculateBox = function calculateBox() {
10291 var attrs = this.get('attrs');
10292 var points = attrs.points,
10293 smooth = attrs.smooth,
10294 lineWidth = attrs.lineWidth;
10295
10296 var filteredPoints = _filterPoints(points);
10297
10298 if (smooth) {
10299 var newPoints = [];
10300 var constaint = [[0, 0], [1, 1]];
10301 var sps = Smooth.smooth(filteredPoints, false, constaint);
10302
10303 for (var i = 0, n = sps.length; i < n; i++) {
10304 var sp = sps[i];
10305
10306 if (i === 0) {
10307 newPoints.push([filteredPoints[0].x, filteredPoints[0].y, sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]]);
10308 } else {
10309 var lastPoint = sps[i - 1];
10310 newPoints.push([lastPoint[5], lastPoint[6], sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]]);
10311 }
10312 }
10313
10314 return bbox.getBBoxFromBezierGroup(newPoints, lineWidth);
10315 }
10316
10317 return bbox.getBBoxFromPoints(filteredPoints, lineWidth);
10318 };
10319
10320 return Polyline;
10321}(Shape);
10322
10323Shape.Polyline = Polyline;
10324module.exports = Polyline;
10325
10326/***/ }),
10327/* 87 */
10328/***/ (function(module, exports, __webpack_require__) {
10329
10330function _inheritsLoose(subClass, superClass) {
10331 subClass.prototype = Object.create(superClass.prototype);
10332 subClass.prototype.constructor = subClass;
10333 subClass.__proto__ = superClass;
10334}
10335
10336var Shape = __webpack_require__(2);
10337
10338var bbox = __webpack_require__(12);
10339
10340var Arc =
10341/*#__PURE__*/
10342function (_Shape) {
10343 _inheritsLoose(Arc, _Shape);
10344
10345 function Arc() {
10346 return _Shape.apply(this, arguments) || this;
10347 }
10348
10349 var _proto = Arc.prototype;
10350
10351 _proto._initProperties = function _initProperties() {
10352 _Shape.prototype._initProperties.call(this);
10353
10354 this._attrs.canStroke = true;
10355 this._attrs.canFill = true;
10356 this._attrs.type = 'arc';
10357 };
10358
10359 _proto.getDefaultAttrs = function getDefaultAttrs() {
10360 return {
10361 x: 0,
10362 y: 0,
10363 r: 0,
10364 startAngle: 0,
10365 endAngle: Math.PI * 2,
10366 clockwise: false,
10367 lineWidth: 1
10368 };
10369 };
10370
10371 _proto.createPath = function createPath(context) {
10372 var attrs = this.get('attrs');
10373 var x = attrs.x,
10374 y = attrs.y,
10375 r = attrs.r,
10376 startAngle = attrs.startAngle,
10377 endAngle = attrs.endAngle,
10378 clockwise = attrs.clockwise;
10379 context.beginPath();
10380 context.arc(x, y, r, startAngle, endAngle, clockwise);
10381 };
10382
10383 _proto.calculateBox = function calculateBox() {
10384 var attrs = this.get('attrs');
10385 var x = attrs.x,
10386 y = attrs.y,
10387 r = attrs.r,
10388 startAngle = attrs.startAngle,
10389 endAngle = attrs.endAngle,
10390 clockwise = attrs.clockwise;
10391 return bbox.getBBoxFromArc(x, y, r, startAngle, endAngle, clockwise);
10392 };
10393
10394 return Arc;
10395}(Shape);
10396
10397Shape.Arc = Arc;
10398module.exports = Arc;
10399
10400/***/ }),
10401/* 88 */
10402/***/ (function(module, exports, __webpack_require__) {
10403
10404function _inheritsLoose(subClass, superClass) {
10405 subClass.prototype = Object.create(superClass.prototype);
10406 subClass.prototype.constructor = subClass;
10407 subClass.__proto__ = superClass;
10408}
10409
10410var Shape = __webpack_require__(2);
10411
10412var bbox = __webpack_require__(12);
10413
10414var Sector =
10415/*#__PURE__*/
10416function (_Shape) {
10417 _inheritsLoose(Sector, _Shape);
10418
10419 function Sector() {
10420 return _Shape.apply(this, arguments) || this;
10421 }
10422
10423 var _proto = Sector.prototype;
10424
10425 _proto._initProperties = function _initProperties() {
10426 _Shape.prototype._initProperties.call(this);
10427
10428 this._attrs.canFill = true;
10429 this._attrs.canStroke = true;
10430 this._attrs.type = 'sector';
10431 };
10432
10433 _proto.getDefaultAttrs = function getDefaultAttrs() {
10434 return {
10435 x: 0,
10436 y: 0,
10437 lineWidth: 0,
10438 r: 0,
10439 r0: 0,
10440 startAngle: 0,
10441 endAngle: Math.PI * 2,
10442 clockwise: false
10443 };
10444 };
10445
10446 _proto.createPath = function createPath(context) {
10447 var attrs = this.get('attrs');
10448 var x = attrs.x,
10449 y = attrs.y,
10450 startAngle = attrs.startAngle,
10451 endAngle = attrs.endAngle,
10452 r = attrs.r,
10453 r0 = attrs.r0,
10454 clockwise = attrs.clockwise;
10455 context.beginPath();
10456 var unitX = Math.cos(startAngle);
10457 var unitY = Math.sin(startAngle);
10458 context.moveTo(unitX * r0 + x, unitY * r0 + y);
10459 context.lineTo(unitX * r + x, unitY * r + y);
10460 context.arc(x, y, r, startAngle, endAngle, clockwise);
10461 context.lineTo(Math.cos(endAngle) * r0 + x, Math.sin(endAngle) * r0 + y);
10462
10463 if (r0 !== 0) {
10464 context.arc(x, y, r0, endAngle, startAngle, !clockwise);
10465 }
10466
10467 context.closePath();
10468 };
10469
10470 _proto.calculateBox = function calculateBox() {
10471 var attrs = this.get('attrs');
10472 var x = attrs.x,
10473 y = attrs.y,
10474 r = attrs.r,
10475 r0 = attrs.r0,
10476 startAngle = attrs.startAngle,
10477 endAngle = attrs.endAngle,
10478 clockwise = attrs.clockwise;
10479 var outerBBox = bbox.getBBoxFromArc(x, y, r, startAngle, endAngle, clockwise);
10480 var innerBBox = bbox.getBBoxFromArc(x, y, r0, startAngle, endAngle, clockwise);
10481 return {
10482 minX: Math.min(outerBBox.minX, innerBBox.minX),
10483 minY: Math.min(outerBBox.minY, innerBBox.minY),
10484 maxX: Math.max(outerBBox.maxX, innerBBox.maxX),
10485 maxY: Math.max(outerBBox.maxY, innerBBox.maxY)
10486 };
10487 };
10488
10489 return Sector;
10490}(Shape);
10491
10492Shape.Sector = Sector;
10493module.exports = Sector;
10494
10495/***/ }),
10496/* 89 */
10497/***/ (function(module, exports, __webpack_require__) {
10498
10499function _inheritsLoose(subClass, superClass) {
10500 subClass.prototype = Object.create(superClass.prototype);
10501 subClass.prototype.constructor = subClass;
10502 subClass.__proto__ = superClass;
10503}
10504
10505var Util = __webpack_require__(0);
10506
10507var Shape = __webpack_require__(2);
10508
10509var textWidthCacheCounter = 0;
10510var textWidthCache = {};
10511var TEXT_CACHE_MAX = 5000;
10512
10513var Text =
10514/*#__PURE__*/
10515function (_Shape) {
10516 _inheritsLoose(Text, _Shape);
10517
10518 function Text() {
10519 return _Shape.apply(this, arguments) || this;
10520 }
10521
10522 var _proto = Text.prototype;
10523
10524 _proto._initProperties = function _initProperties() {
10525 _Shape.prototype._initProperties.call(this);
10526
10527 this._attrs.canFill = true;
10528 this._attrs.canStroke = true;
10529 this._attrs.type = 'text';
10530 };
10531
10532 _proto.getDefaultAttrs = function getDefaultAttrs() {
10533 return {
10534 lineWidth: 0,
10535 lineCount: 1,
10536 fontSize: 12,
10537 fontFamily: 'sans-serif',
10538 fontStyle: 'normal',
10539 fontWeight: 'normal',
10540 fontVariant: 'normal',
10541 textAlign: 'start',
10542 textBaseline: 'bottom',
10543 lineHeight: null,
10544 textArr: null
10545 };
10546 };
10547
10548 _proto._getFontStyle = function _getFontStyle() {
10549 var attrs = this._attrs.attrs;
10550 var fontSize = attrs.fontSize,
10551 fontFamily = attrs.fontFamily,
10552 fontWeight = attrs.fontWeight,
10553 fontStyle = attrs.fontStyle,
10554 fontVariant = attrs.fontVariant;
10555 return fontStyle + " " + fontVariant + " " + fontWeight + " " + fontSize + "px " + fontFamily;
10556 };
10557
10558 _proto._afterAttrsSet = function _afterAttrsSet() {
10559 var attrs = this._attrs.attrs;
10560 attrs.font = this._getFontStyle();
10561
10562 if (attrs.text) {
10563 var text = attrs.text;
10564 var textArr = null;
10565 var lineCount = 1;
10566
10567 if (Util.isString(text) && text.indexOf('\n') !== -1) {
10568 textArr = text.split('\n');
10569 lineCount = textArr.length;
10570 }
10571
10572 attrs.lineCount = lineCount;
10573 attrs.textArr = textArr;
10574 }
10575
10576 this.set('attrs', attrs);
10577 };
10578
10579 _proto._getTextHeight = function _getTextHeight() {
10580 var attrs = this._attrs.attrs;
10581
10582 if (attrs.height) {
10583 return attrs.height;
10584 }
10585
10586 var lineCount = attrs.lineCount;
10587 var fontSize = attrs.fontSize * 1;
10588
10589 if (lineCount > 1) {
10590 var spaceingY = this._getSpaceingY();
10591
10592 return fontSize * lineCount + spaceingY * (lineCount - 1);
10593 }
10594
10595 return fontSize;
10596 };
10597
10598 _proto._getSpaceingY = function _getSpaceingY() {
10599 var attrs = this._attrs.attrs;
10600 var lineHeight = attrs.lineHeight;
10601 var fontSize = attrs.fontSize * 1;
10602 return lineHeight ? lineHeight - fontSize : fontSize * 0.14;
10603 };
10604
10605 _proto.drawInner = function drawInner(context) {
10606 var self = this;
10607 var attrs = self._attrs.attrs;
10608 var text = attrs.text;
10609 var x = attrs.x;
10610 var y = attrs.y;
10611
10612 if (Util.isNil(text) || isNaN(x) || isNaN(y)) {
10613 // text will be 0
10614 return;
10615 }
10616
10617 var textArr = attrs.textArr;
10618 var fontSize = attrs.fontSize * 1;
10619
10620 var spaceingY = self._getSpaceingY();
10621
10622 if (attrs.rotate) {
10623 // do rotation
10624 context.translate(x, y);
10625 context.rotate(attrs.rotate);
10626 x = 0;
10627 y = 0;
10628 }
10629
10630 var textBaseline = attrs.textBaseline;
10631 var height;
10632
10633 if (textArr) {
10634 height = self._getTextHeight();
10635 }
10636
10637 var subY; // context.beginPath();
10638
10639 if (self.hasFill()) {
10640 var fillOpacity = attrs.fillOpacity;
10641
10642 if (!Util.isNil(fillOpacity) && fillOpacity !== 1) {
10643 context.globalAlpha = fillOpacity;
10644 }
10645
10646 if (textArr) {
10647 for (var i = 0, len = textArr.length; i < len; i++) {
10648 var subText = textArr[i];
10649 subY = y + i * (spaceingY + fontSize) - height + fontSize; // bottom;
10650
10651 if (textBaseline === 'middle') {
10652 subY += height - fontSize - (height - fontSize) / 2;
10653 }
10654
10655 if (textBaseline === 'top') {
10656 subY += height - fontSize;
10657 }
10658
10659 context.fillText(subText, x, subY);
10660 }
10661 } else {
10662 context.fillText(text, x, y);
10663 }
10664 }
10665
10666 if (self.hasStroke()) {
10667 if (textArr) {
10668 for (var _i = 0, _len = textArr.length; _i < _len; _i++) {
10669 var _subText = textArr[_i];
10670 subY = y + _i * (spaceingY + fontSize) - height + fontSize; // bottom;
10671
10672 if (textBaseline === 'middle') {
10673 subY += height - fontSize - (height - fontSize) / 2;
10674 }
10675
10676 if (textBaseline === 'top') {
10677 subY += height - fontSize;
10678 }
10679
10680 context.strokeText(_subText, x, subY);
10681 }
10682 } else {
10683 context.strokeText(text, x, y);
10684 }
10685 }
10686 };
10687
10688 _proto.calculateBox = function calculateBox() {
10689 var self = this;
10690 var attrs = self._attrs.attrs;
10691 var x = attrs.x,
10692 y = attrs.y,
10693 textAlign = attrs.textAlign,
10694 textBaseline = attrs.textBaseline;
10695
10696 var width = self._getTextWidth(); // attrs.width
10697
10698
10699 if (!width) {
10700 return {
10701 minX: x,
10702 minY: y,
10703 maxX: x,
10704 maxY: y
10705 };
10706 }
10707
10708 var height = self._getTextHeight(); // attrs.height
10709
10710
10711 var point = {
10712 x: x,
10713 y: y - height
10714 }; // default textAlign: start, textBaseline: bottom
10715
10716 if (textAlign) {
10717 if (textAlign === 'end' || textAlign === 'right') {
10718 point.x -= width;
10719 } else if (textAlign === 'center') {
10720 point.x -= width / 2;
10721 }
10722 }
10723
10724 if (textBaseline) {
10725 if (textBaseline === 'top') {
10726 point.y += height;
10727 } else if (textBaseline === 'middle') {
10728 point.y += height / 2;
10729 }
10730 }
10731
10732 return {
10733 minX: point.x,
10734 minY: point.y,
10735 maxX: point.x + width,
10736 maxY: point.y + height
10737 };
10738 };
10739
10740 _proto._getTextWidth = function _getTextWidth() {
10741 var attrs = this._attrs.attrs;
10742
10743 if (attrs.width) {
10744 return attrs.width;
10745 }
10746
10747 var text = attrs.text;
10748 var context = this.get('context');
10749 if (Util.isNil(text)) return undefined;
10750 var font = attrs.font;
10751 var textArr = attrs.textArr;
10752 var key = text + '' + font;
10753
10754 if (textWidthCache[key]) {
10755 return textWidthCache[key];
10756 }
10757
10758 var width = 0;
10759
10760 if (textArr) {
10761 for (var i = 0, length = textArr.length; i < length; i++) {
10762 var subText = textArr[i];
10763 width = Math.max(width, Util.measureText(subText, font, context).width);
10764 }
10765 } else {
10766 width = Util.measureText(text, font, context).width;
10767 }
10768
10769 if (textWidthCacheCounter > TEXT_CACHE_MAX) {
10770 textWidthCacheCounter = 0;
10771 textWidthCache = {};
10772 }
10773
10774 textWidthCacheCounter++;
10775 textWidthCache[key] = width;
10776 return width;
10777 };
10778
10779 return Text;
10780}(Shape);
10781
10782Shape.Text = Text;
10783module.exports = Text;
10784
10785/***/ }),
10786/* 90 */
10787/***/ (function(module, exports, __webpack_require__) {
10788
10789function _inheritsLoose(subClass, superClass) {
10790 subClass.prototype = Object.create(superClass.prototype);
10791 subClass.prototype.constructor = subClass;
10792 subClass.__proto__ = superClass;
10793}
10794
10795var Shape = __webpack_require__(2);
10796
10797var Custom =
10798/*#__PURE__*/
10799function (_Shape) {
10800 _inheritsLoose(Custom, _Shape);
10801
10802 function Custom() {
10803 return _Shape.apply(this, arguments) || this;
10804 }
10805
10806 var _proto = Custom.prototype;
10807
10808 _proto._initProperties = function _initProperties() {
10809 _Shape.prototype._initProperties.call(this);
10810
10811 this._attrs.canFill = true;
10812 this._attrs.canStroke = true;
10813 this._attrs.createPath = null;
10814 this._attrs.type = 'custom';
10815 };
10816
10817 _proto.createPath = function createPath(context) {
10818 var createPath = this.get('createPath');
10819 createPath && createPath.call(this, context);
10820 };
10821
10822 _proto.calculateBox = function calculateBox() {
10823 var calculateBox = this.get('calculateBox');
10824 return calculateBox && calculateBox.call(this);
10825 };
10826
10827 return Custom;
10828}(Shape);
10829
10830Shape.Custom = Custom;
10831module.exports = Custom;
10832
10833/***/ }),
10834/* 91 */
10835/***/ (function(module, exports, __webpack_require__) {
10836
10837var Geom = __webpack_require__(4);
10838
10839__webpack_require__(92);
10840
10841__webpack_require__(40);
10842
10843__webpack_require__(94);
10844
10845__webpack_require__(95);
10846
10847__webpack_require__(97);
10848
10849__webpack_require__(99);
10850
10851__webpack_require__(101);
10852
10853module.exports = Geom;
10854
10855/***/ }),
10856/* 92 */
10857/***/ (function(module, exports, __webpack_require__) {
10858
10859function _inheritsLoose(subClass, superClass) {
10860 subClass.prototype = Object.create(superClass.prototype);
10861 subClass.prototype.constructor = subClass;
10862 subClass.__proto__ = superClass;
10863}
10864
10865var Util = __webpack_require__(0);
10866
10867var Geom = __webpack_require__(4);
10868
10869__webpack_require__(93);
10870
10871var Point =
10872/*#__PURE__*/
10873function (_Geom) {
10874 _inheritsLoose(Point, _Geom);
10875
10876 function Point() {
10877 return _Geom.apply(this, arguments) || this;
10878 }
10879
10880 var _proto = Point.prototype;
10881
10882 _proto.getDefaultCfg = function getDefaultCfg() {
10883 var cfg = _Geom.prototype.getDefaultCfg.call(this);
10884
10885 cfg.type = 'point';
10886 cfg.shapeType = 'point';
10887 cfg.generatePoints = true;
10888 return cfg;
10889 };
10890
10891 _proto.draw = function draw(data, shapeFactory) {
10892 var self = this;
10893 var container = self.get('container');
10894 Util.each(data, function (obj) {
10895 var shape = obj.shape;
10896 var cfg = self.getDrawCfg(obj);
10897
10898 if (Util.isArray(obj.y)) {
10899 var hasStack = self.hasAdjust('stack');
10900 Util.each(obj.y, function (y, idx) {
10901 cfg.y = y;
10902
10903 if (!hasStack || idx !== 0) {
10904 self.drawShape(shape, obj, cfg, container, shapeFactory);
10905 }
10906 });
10907 } else if (!Util.isNil(obj.y)) {
10908 self.drawShape(shape, obj, cfg, container, shapeFactory);
10909 }
10910 });
10911 };
10912
10913 return Point;
10914}(Geom);
10915
10916Geom.Point = Point;
10917module.exports = Point;
10918
10919/***/ }),
10920/* 93 */
10921/***/ (function(module, exports, __webpack_require__) {
10922
10923var Util = __webpack_require__(0);
10924
10925var Global = __webpack_require__(1);
10926
10927var ShapeUtil = __webpack_require__(20);
10928
10929var Shape = __webpack_require__(6);
10930
10931var SHAPES = ['circle', 'hollowCircle', 'rect'];
10932var Point = Shape.registerFactory('point', {
10933 defaultShapeType: 'circle',
10934 getDefaultPoints: function getDefaultPoints(pointInfo) {
10935 return ShapeUtil.splitPoints(pointInfo);
10936 }
10937});
10938
10939function getPointsCfg(cfg) {
10940 var style = {
10941 lineWidth: 0,
10942 stroke: cfg.color,
10943 fill: cfg.color
10944 };
10945
10946 if (cfg.size) {
10947 style.size = cfg.size;
10948 }
10949
10950 Util.mix(style, cfg.style);
10951 return Util.mix({}, Global.shape.point, style);
10952}
10953
10954function drawShape(cfg, container, shape) {
10955 if (cfg.size === 0) return;
10956 var pointCfg = getPointsCfg(cfg);
10957 var size = pointCfg.r || pointCfg.size;
10958 var x = cfg.x;
10959 var y = !Util.isArray(cfg.y) ? [cfg.y] : cfg.y;
10960
10961 if (shape === 'hollowCircle') {
10962 pointCfg.lineWidth = 1;
10963 pointCfg.fill = null;
10964 }
10965
10966 for (var i = 0, len = y.length; i < len; i++) {
10967 if (shape === 'rect') {
10968 return container.addShape('Rect', {
10969 className: 'point',
10970 attrs: Util.mix({
10971 x: x - size,
10972 y: y[i] - size,
10973 width: size * 2,
10974 height: size * 2
10975 }, pointCfg)
10976 });
10977 }
10978
10979 return container.addShape('Circle', {
10980 className: 'point',
10981 attrs: Util.mix({
10982 x: x,
10983 y: y[i],
10984 r: size
10985 }, pointCfg)
10986 });
10987 }
10988}
10989
10990Util.each(SHAPES, function (shapeType) {
10991 Shape.registerShape('point', shapeType, {
10992 draw: function draw(cfg, container) {
10993 return drawShape(cfg, container, shapeType);
10994 }
10995 });
10996});
10997module.exports = Point;
10998
10999/***/ }),
11000/* 94 */
11001/***/ (function(module, exports, __webpack_require__) {
11002
11003function _inheritsLoose(subClass, superClass) {
11004 subClass.prototype = Object.create(superClass.prototype);
11005 subClass.prototype.constructor = subClass;
11006 subClass.__proto__ = superClass;
11007}
11008
11009var Path = __webpack_require__(40);
11010
11011var Geom = __webpack_require__(4);
11012
11013__webpack_require__(41);
11014
11015var Line =
11016/*#__PURE__*/
11017function (_Path) {
11018 _inheritsLoose(Line, _Path);
11019
11020 function Line() {
11021 return _Path.apply(this, arguments) || this;
11022 }
11023
11024 var _proto = Line.prototype;
11025
11026 _proto.getDefaultCfg = function getDefaultCfg() {
11027 var cfg = _Path.prototype.getDefaultCfg.call(this);
11028
11029 cfg.type = 'line';
11030 cfg.sortable = true;
11031 return cfg;
11032 };
11033
11034 return Line;
11035}(Path);
11036
11037Geom.Line = Line;
11038module.exports = Line;
11039
11040/***/ }),
11041/* 95 */
11042/***/ (function(module, exports, __webpack_require__) {
11043
11044function _inheritsLoose(subClass, superClass) {
11045 subClass.prototype = Object.create(superClass.prototype);
11046 subClass.prototype.constructor = subClass;
11047 subClass.__proto__ = superClass;
11048}
11049/**
11050 * @fileOverview area geometry
11051 * @author dxq613 @gmail.com
11052 * @author sima.zhang1990@gmail.com
11053 */
11054
11055
11056var Geom = __webpack_require__(4);
11057
11058var ShapeUtil = __webpack_require__(20);
11059
11060var Util = __webpack_require__(0);
11061
11062__webpack_require__(96);
11063
11064var Area =
11065/*#__PURE__*/
11066function (_Geom) {
11067 _inheritsLoose(Area, _Geom);
11068
11069 function Area() {
11070 return _Geom.apply(this, arguments) || this;
11071 }
11072
11073 var _proto = Area.prototype;
11074 /**
11075 * get the default configuration
11076 * @protected
11077 * @return {Object} return the result
11078 */
11079
11080 _proto.getDefaultCfg = function getDefaultCfg() {
11081 var cfg = _Geom.prototype.getDefaultCfg.call(this);
11082
11083 cfg.type = 'area';
11084 cfg.shapeType = 'area';
11085 cfg.generatePoints = true;
11086 cfg.sortable = true;
11087 return cfg;
11088 };
11089
11090 _proto.draw = function draw(data, shapeFactory) {
11091 var self = this;
11092 var container = self.get('container');
11093 var cfg = this.getDrawCfg(data[0]);
11094 var yScale = self.getYScale();
11095 var connectNulls = self.get('connectNulls');
11096 var splitArray = ShapeUtil.splitArray(data, yScale.field, connectNulls);
11097 cfg.origin = data;
11098 Util.each(splitArray, function (subData, splitedIndex) {
11099 cfg.splitedIndex = splitedIndex;
11100 var points = subData.map(function (obj) {
11101 return obj.points;
11102 });
11103 cfg.points = points;
11104 self.drawShape(cfg.shape, data[0], cfg, container, shapeFactory);
11105 });
11106 };
11107
11108 return Area;
11109}(Geom);
11110
11111Geom.Area = Area;
11112module.exports = Area;
11113
11114/***/ }),
11115/* 96 */
11116/***/ (function(module, exports, __webpack_require__) {
11117
11118var Util = __webpack_require__(0);
11119
11120var Shape = __webpack_require__(6);
11121
11122var Smooth = __webpack_require__(39);
11123
11124var bbox = __webpack_require__(12);
11125
11126var Global = __webpack_require__(1);
11127
11128function equals(v1, v2) {
11129 return Math.abs(v1 - v2) < 0.00001;
11130}
11131
11132function notEmpty(value) {
11133 return !isNaN(value) && !Util.isNil(value);
11134}
11135
11136function filterPoints(points) {
11137 var filteredPoints = []; // filter the point which x or y is NaN
11138
11139 for (var i = 0, len = points.length; i < len; i++) {
11140 var point = points[i];
11141
11142 if (notEmpty(point.x) && notEmpty(point.y)) {
11143 filteredPoints.push(point);
11144 }
11145 }
11146
11147 return filteredPoints;
11148}
11149
11150function equalsCenter(points, center) {
11151 var eqls = true;
11152 Util.each(points, function (point) {
11153 if (!equals(point.x, center.x) || !equals(point.y, center.y)) {
11154 eqls = false;
11155 return false;
11156 }
11157 });
11158 return eqls;
11159}
11160
11161function drawRectShape(topPoints, bottomPoints, container, style, isSmooth) {
11162 var shape;
11163 var points = topPoints.concat(bottomPoints);
11164
11165 if (isSmooth) {
11166 shape = container.addShape('Custom', {
11167 className: 'area',
11168 attrs: Util.mix({
11169 points: points
11170 }, style),
11171 createPath: function createPath(context) {
11172 var constaint = [[0, 0], [1, 1]];
11173 var points = filterPoints(this._attrs.attrs.points);
11174 var pointsLen = points.length;
11175 var topPoints = points.slice(0, pointsLen / 2);
11176 var bottomPoints = points.slice(pointsLen / 2, pointsLen);
11177 var topSps = Smooth.smooth(topPoints, false, constaint);
11178 context.beginPath();
11179 context.moveTo(topPoints[0].x, topPoints[0].y);
11180
11181 for (var i = 0, n = topSps.length; i < n; i++) {
11182 var sp = topSps[i];
11183 context.bezierCurveTo(sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]);
11184 }
11185
11186 if (bottomPoints.length) {
11187 var bottomSps = Smooth.smooth(bottomPoints, false, constaint);
11188 context.lineTo(bottomPoints[0].x, bottomPoints[0].y);
11189
11190 for (var _i = 0, _n = bottomSps.length; _i < _n; _i++) {
11191 var _sp = bottomSps[_i];
11192 context.bezierCurveTo(_sp[1], _sp[2], _sp[3], _sp[4], _sp[5], _sp[6]);
11193 }
11194 }
11195
11196 context.closePath();
11197 },
11198 calculateBox: function calculateBox() {
11199 var points = filterPoints(this._attrs.attrs.points);
11200 return bbox.getBBoxFromPoints(points);
11201 }
11202 });
11203 } else {
11204 shape = container.addShape('Polyline', {
11205 className: 'area',
11206 attrs: Util.mix({
11207 points: points
11208 }, style)
11209 });
11210 }
11211
11212 return shape;
11213}
11214
11215function drawShape(cfg, container, isSmooth) {
11216 var self = this;
11217 var points = cfg.points;
11218 var topPoints = [];
11219 var bottomPoints = [];
11220 Util.each(points, function (point) {
11221 bottomPoints.push(point[0]);
11222 topPoints.push(point[1]);
11223 });
11224 var style = Util.mix({
11225 fillStyle: cfg.color
11226 }, Global.shape.area, cfg.style);
11227 bottomPoints.reverse();
11228 topPoints = self.parsePoints(topPoints);
11229 bottomPoints = self.parsePoints(bottomPoints);
11230
11231 if (cfg.isInCircle) {
11232 topPoints.push(topPoints[0]);
11233 bottomPoints.unshift(bottomPoints[bottomPoints.length - 1]);
11234
11235 if (equalsCenter(bottomPoints, cfg.center)) {
11236 bottomPoints = [];
11237 }
11238 }
11239
11240 return drawRectShape(topPoints, bottomPoints, container, style, isSmooth);
11241}
11242
11243var Area = Shape.registerFactory('area', {
11244 defaultShapeType: 'area',
11245 getDefaultPoints: function getDefaultPoints(obj) {
11246 var x = obj.x;
11247 var y = obj.y;
11248 var y0 = obj.y0;
11249 y = Util.isArray(y) ? y : [y0, y];
11250 var points = [];
11251 points.push({
11252 x: x,
11253 y: y[0]
11254 }, {
11255 x: x,
11256 y: y[1]
11257 });
11258 return points;
11259 }
11260});
11261var SHAPES = ['area', 'smooth'];
11262Util.each(SHAPES, function (shapeType) {
11263 Shape.registerShape('area', shapeType, {
11264 draw: function draw(cfg, container) {
11265 var smooth = shapeType === 'smooth';
11266 return drawShape.call(this, cfg, container, smooth);
11267 }
11268 });
11269});
11270module.exports = Area;
11271
11272/***/ }),
11273/* 97 */
11274/***/ (function(module, exports, __webpack_require__) {
11275
11276function _inheritsLoose(subClass, superClass) {
11277 subClass.prototype = Object.create(superClass.prototype);
11278 subClass.prototype.constructor = subClass;
11279 subClass.__proto__ = superClass;
11280}
11281
11282function _assertThisInitialized(self) {
11283 if (self === void 0) {
11284 throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
11285 }
11286
11287 return self;
11288}
11289
11290var Geom = __webpack_require__(4);
11291
11292var Util = __webpack_require__(0);
11293
11294var SizeMixin = __webpack_require__(42);
11295
11296__webpack_require__(98);
11297
11298var Interval =
11299/*#__PURE__*/
11300function (_Geom) {
11301 _inheritsLoose(Interval, _Geom);
11302
11303 var _proto = Interval.prototype;
11304
11305 _proto.getDefaultCfg = function getDefaultCfg() {
11306 var cfg = _Geom.prototype.getDefaultCfg.call(this);
11307
11308 cfg.type = 'interval';
11309 cfg.shapeType = 'interval';
11310 cfg.generatePoints = true;
11311 return cfg;
11312 };
11313
11314 function Interval(cfg) {
11315 var _this;
11316
11317 _this = _Geom.call(this, cfg) || this;
11318 Util.mix(_assertThisInitialized(_assertThisInitialized(_this)), SizeMixin);
11319 return _this;
11320 }
11321
11322 _proto.createShapePointsCfg = function createShapePointsCfg(obj) {
11323 var cfg = _Geom.prototype.createShapePointsCfg.call(this, obj);
11324
11325 cfg.size = this.getNormalizedSize(obj);
11326 return cfg;
11327 };
11328
11329 _proto.clearInner = function clearInner() {
11330 _Geom.prototype.clearInner.call(this);
11331
11332 this.set('defaultSize', null);
11333 };
11334
11335 return Interval;
11336}(Geom);
11337
11338Geom.Interval = Interval;
11339module.exports = Interval;
11340
11341/***/ }),
11342/* 98 */
11343/***/ (function(module, exports, __webpack_require__) {
11344
11345var Util = __webpack_require__(0);
11346
11347var Shape = __webpack_require__(6);
11348
11349var Vector2 = __webpack_require__(7);
11350
11351var Global = __webpack_require__(1);
11352
11353function getRectPoints(cfg) {
11354 var x = cfg.x,
11355 y = cfg.y,
11356 y0 = cfg.y0,
11357 size = cfg.size;
11358 var ymin = y0;
11359 var ymax = y;
11360
11361 if (Util.isArray(y)) {
11362 ymax = y[1];
11363 ymin = y[0];
11364 }
11365
11366 var xmin;
11367 var xmax;
11368
11369 if (Util.isArray(x)) {
11370 xmin = x[0];
11371 xmax = x[1];
11372 } else {
11373 xmin = x - size / 2;
11374 xmax = x + size / 2;
11375 }
11376
11377 return [{
11378 x: xmin,
11379 y: ymin
11380 }, {
11381 x: xmin,
11382 y: ymax
11383 }, {
11384 x: xmax,
11385 y: ymax
11386 }, {
11387 x: xmax,
11388 y: ymin
11389 }];
11390}
11391
11392function getRectRange(points) {
11393 var xValues = [];
11394 var yValues = [];
11395
11396 for (var i = 0, len = points.length; i < len; i++) {
11397 var point = points[i];
11398 xValues.push(point.x);
11399 yValues.push(point.y);
11400 }
11401
11402 var xMin = Math.min.apply(null, xValues);
11403 var yMin = Math.min.apply(null, yValues);
11404 var xMax = Math.max.apply(null, xValues);
11405 var yMax = Math.max.apply(null, yValues);
11406 return {
11407 x: xMin,
11408 y: yMin,
11409 width: xMax - xMin,
11410 height: yMax - yMin
11411 };
11412}
11413
11414var Interval = Shape.registerFactory('interval', {
11415 defaultShapeType: 'rect',
11416 getDefaultPoints: function getDefaultPoints(cfg) {
11417 return getRectPoints(cfg);
11418 }
11419});
11420Shape.registerShape('interval', 'rect', {
11421 draw: function draw(cfg, container) {
11422 var points = this.parsePoints(cfg.points);
11423 var style = Util.mix({
11424 fill: cfg.color
11425 }, Global.shape.interval, cfg.style);
11426
11427 if (cfg.isInCircle) {
11428 var newPoints = points.slice(0);
11429
11430 if (this._coord.transposed) {
11431 newPoints = [points[0], points[3], points[2], points[1]];
11432 }
11433
11434 var _cfg$center = cfg.center,
11435 x = _cfg$center.x,
11436 y = _cfg$center.y;
11437 var v = [1, 0];
11438 var v0 = [newPoints[0].x - x, newPoints[0].y - y];
11439 var v1 = [newPoints[1].x - x, newPoints[1].y - y];
11440 var v2 = [newPoints[2].x - x, newPoints[2].y - y];
11441 var startAngle = Vector2.angleTo(v, v1);
11442 var endAngle = Vector2.angleTo(v, v2);
11443 var r0 = Vector2.length(v0);
11444 var r = Vector2.length(v1);
11445
11446 if (startAngle >= 1.5 * Math.PI) {
11447 startAngle = startAngle - 2 * Math.PI;
11448 }
11449
11450 if (endAngle >= 1.5 * Math.PI) {
11451 endAngle = endAngle - 2 * Math.PI;
11452 }
11453
11454 return container.addShape('Sector', {
11455 className: 'interval',
11456 attrs: Util.mix({
11457 x: x,
11458 y: y,
11459 r: r,
11460 r0: r0,
11461 startAngle: startAngle,
11462 endAngle: endAngle
11463 }, style)
11464 });
11465 }
11466
11467 var rectCfg = getRectRange(points);
11468 return container.addShape('rect', {
11469 className: 'interval',
11470 attrs: Util.mix(rectCfg, style)
11471 });
11472 }
11473});
11474module.exports = Interval;
11475
11476/***/ }),
11477/* 99 */
11478/***/ (function(module, exports, __webpack_require__) {
11479
11480function _inheritsLoose(subClass, superClass) {
11481 subClass.prototype = Object.create(superClass.prototype);
11482 subClass.prototype.constructor = subClass;
11483 subClass.__proto__ = superClass;
11484}
11485
11486var Geom = __webpack_require__(4);
11487
11488var Util = __webpack_require__(0);
11489
11490__webpack_require__(100);
11491
11492var Polygon =
11493/*#__PURE__*/
11494function (_Geom) {
11495 _inheritsLoose(Polygon, _Geom);
11496
11497 function Polygon() {
11498 return _Geom.apply(this, arguments) || this;
11499 }
11500
11501 var _proto = Polygon.prototype;
11502
11503 _proto.getDefaultCfg = function getDefaultCfg() {
11504 var cfg = _Geom.prototype.getDefaultCfg.call(this);
11505
11506 cfg.type = 'polygon';
11507 cfg.shapeType = 'polygon';
11508 cfg.generatePoints = true;
11509 return cfg;
11510 };
11511
11512 _proto.createShapePointsCfg = function createShapePointsCfg(obj) {
11513 var cfg = _Geom.prototype.createShapePointsCfg.call(this, obj);
11514
11515 var self = this;
11516 var x = cfg.x;
11517 var y = cfg.y;
11518 var temp;
11519
11520 if (!(Util.isArray(x) && Util.isArray(y))) {
11521 var xScale = self.getXScale();
11522 var yScale = self.getYScale();
11523 var xCount = xScale.values ? xScale.values.length : xScale.ticks.length;
11524 var yCount = yScale.values ? yScale.values.length : yScale.ticks.length;
11525 var xOffset = 0.5 * 1 / xCount;
11526 var yOffset = 0.5 * 1 / yCount;
11527
11528 if (xScale.isCategory && yScale.isCategory) {
11529 x = [x - xOffset, x - xOffset, x + xOffset, x + xOffset];
11530 y = [y - yOffset, y + yOffset, y + yOffset, y - yOffset];
11531 } else if (Util.isArray(x)) {
11532 temp = x;
11533 x = [temp[0], temp[0], temp[1], temp[1]];
11534 y = [y - yOffset / 2, y + yOffset / 2, y + yOffset / 2, y - yOffset / 2];
11535 } else if (Util.isArray(y)) {
11536 temp = y;
11537 y = [temp[0], temp[1], temp[1], temp[0]];
11538 x = [x - xOffset / 2, x - xOffset / 2, x + xOffset / 2, x + xOffset / 2];
11539 }
11540
11541 cfg.x = x;
11542 cfg.y = y;
11543 }
11544
11545 return cfg;
11546 };
11547
11548 return Polygon;
11549}(Geom);
11550
11551Geom.Polygon = Polygon;
11552module.exports = Polygon;
11553
11554/***/ }),
11555/* 100 */
11556/***/ (function(module, exports, __webpack_require__) {
11557
11558var Shape = __webpack_require__(6);
11559
11560var Util = __webpack_require__(0);
11561
11562var Polygon = Shape.registerFactory('polygon', {
11563 defaultShapeType: 'polygon',
11564 getDefaultPoints: function getDefaultPoints(pointInfo) {
11565 var points = [];
11566 var x = pointInfo.x,
11567 y = pointInfo.y;
11568
11569 for (var i = 0, len = x.length; i < len; i++) {
11570 points.push({
11571 x: x[i],
11572 y: y[i]
11573 });
11574 }
11575
11576 return points;
11577 }
11578});
11579Shape.registerShape('polygon', 'polygon', {
11580 draw: function draw(cfg, container) {
11581 var points = this.parsePoints(cfg.points);
11582 var style = Util.mix({
11583 fill: cfg.color,
11584 points: points
11585 }, cfg.style);
11586 return container.addShape('Polygon', {
11587 className: 'polygon',
11588 attrs: style
11589 });
11590 }
11591});
11592module.exports = Polygon;
11593
11594/***/ }),
11595/* 101 */
11596/***/ (function(module, exports, __webpack_require__) {
11597
11598function _inheritsLoose(subClass, superClass) {
11599 subClass.prototype = Object.create(superClass.prototype);
11600 subClass.prototype.constructor = subClass;
11601 subClass.__proto__ = superClass;
11602}
11603
11604function _assertThisInitialized(self) {
11605 if (self === void 0) {
11606 throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
11607 }
11608
11609 return self;
11610}
11611
11612var Geom = __webpack_require__(4);
11613
11614var Util = __webpack_require__(0);
11615
11616var SizeMixin = __webpack_require__(42);
11617
11618__webpack_require__(102);
11619
11620var Schema =
11621/*#__PURE__*/
11622function (_Geom) {
11623 _inheritsLoose(Schema, _Geom);
11624
11625 var _proto = Schema.prototype;
11626
11627 _proto.getDefaultCfg = function getDefaultCfg() {
11628 var cfg = _Geom.prototype.getDefaultCfg.call(this);
11629
11630 cfg.type = 'schema';
11631 cfg.shapeType = 'schema';
11632 cfg.generatePoints = true;
11633 return cfg;
11634 };
11635
11636 function Schema(cfg) {
11637 var _this;
11638
11639 _this = _Geom.call(this, cfg) || this;
11640 Util.mix(_assertThisInitialized(_assertThisInitialized(_this)), SizeMixin);
11641 return _this;
11642 }
11643
11644 _proto.createShapePointsCfg = function createShapePointsCfg(obj) {
11645 var cfg = _Geom.prototype.createShapePointsCfg.call(this, obj);
11646
11647 cfg.size = this.getNormalizedSize(obj);
11648 return cfg;
11649 };
11650
11651 _proto.clearInner = function clearInner() {
11652 _Geom.prototype.clearInner.call(this);
11653
11654 this.set('defaultSize', null);
11655 };
11656
11657 return Schema;
11658}(Geom);
11659
11660Geom.Schema = Schema;
11661module.exports = Schema;
11662
11663/***/ }),
11664/* 102 */
11665/***/ (function(module, exports, __webpack_require__) {
11666
11667var Shape = __webpack_require__(6);
11668
11669var Util = __webpack_require__(0);
11670
11671function _sortValue(value) {
11672 var sorted = value.sort(function (a, b) {
11673 return a < b ? 1 : -1;
11674 });
11675 var length = sorted.length;
11676
11677 if (length < 4) {
11678 var min = sorted[length - 1];
11679
11680 for (var i = 0; i < 4 - length; i++) {
11681 sorted.push(min);
11682 }
11683 }
11684
11685 return sorted;
11686} // from left bottom corner, and clockwise
11687
11688
11689function getCandlePoints(x, y, width) {
11690 var yValues = _sortValue(y);
11691
11692 var points = [{
11693 x: x,
11694 y: yValues[0]
11695 }, {
11696 x: x,
11697 y: yValues[1]
11698 }, {
11699 x: x - width / 2,
11700 y: yValues[2]
11701 }, {
11702 x: x - width / 2,
11703 y: yValues[1]
11704 }, {
11705 x: x + width / 2,
11706 y: yValues[1]
11707 }, {
11708 x: x + width / 2,
11709 y: yValues[2]
11710 }, {
11711 x: x,
11712 y: yValues[2]
11713 }, {
11714 x: x,
11715 y: yValues[3]
11716 }];
11717 return points;
11718}
11719
11720var Schema = Shape.registerFactory('schema', {});
11721Shape.registerShape('schema', 'candle', {
11722 getPoints: function getPoints(cfg) {
11723 return getCandlePoints(cfg.x, cfg.y, cfg.size);
11724 },
11725 draw: function draw(cfg, container) {
11726 var points = this.parsePoints(cfg.points);
11727 var style = Util.mix({
11728 stroke: cfg.color,
11729 fill: cfg.color,
11730 lineWidth: 1
11731 }, cfg.style);
11732 return container.addShape('Custom', {
11733 className: 'schema',
11734 attrs: style,
11735 createPath: function createPath(ctx) {
11736 ctx.beginPath();
11737 ctx.moveTo(points[0].x, points[0].y);
11738 ctx.lineTo(points[1].x, points[1].y);
11739 ctx.moveTo(points[2].x, points[2].y);
11740
11741 for (var i = 3; i < 6; i++) {
11742 ctx.lineTo(points[i].x, points[i].y);
11743 }
11744
11745 ctx.closePath();
11746 ctx.moveTo(points[6].x, points[6].y);
11747 ctx.lineTo(points[7].x, points[7].y);
11748 }
11749 });
11750 }
11751});
11752module.exports = Schema;
11753
11754/***/ }),
11755/* 103 */
11756/***/ (function(module, exports, __webpack_require__) {
11757
11758module.exports = {
11759 Stack: __webpack_require__(104),
11760 Dodge: __webpack_require__(108)
11761};
11762
11763/***/ }),
11764/* 104 */
11765/***/ (function(module, exports, __webpack_require__) {
11766
11767var Stack = __webpack_require__(105);
11768
11769module.exports = Stack;
11770
11771/***/ }),
11772/* 105 */
11773/***/ (function(module, exports, __webpack_require__) {
11774
11775function _inheritsLoose(subClass, superClass) {
11776 subClass.prototype = Object.create(superClass.prototype);
11777 subClass.prototype.constructor = subClass;
11778 subClass.__proto__ = superClass;
11779}
11780
11781var isArray = __webpack_require__(43);
11782
11783var isNil = __webpack_require__(107);
11784
11785var Adjust = __webpack_require__(24);
11786
11787var Stack =
11788/*#__PURE__*/
11789function (_Adjust) {
11790 _inheritsLoose(Stack, _Adjust);
11791
11792 function Stack() {
11793 return _Adjust.apply(this, arguments) || this;
11794 }
11795
11796 var _proto = Stack.prototype;
11797
11798 _proto._initDefaultCfg = function _initDefaultCfg() {
11799 this.xField = null; // 调整对应的 x 方向对应的字段名称
11800
11801 this.yField = null; // 调整对应的 y 方向对应的字段名称
11802 };
11803
11804 _proto.processAdjust = function processAdjust(dataArray) {
11805 this.processStack(dataArray);
11806 };
11807
11808 _proto.processStack = function processStack(dataArray) {
11809 var self = this;
11810 var xField = self.xField;
11811 var yField = self.yField;
11812 var count = dataArray.length;
11813 var stackCache = {
11814 positive: {},
11815 negative: {}
11816 }; // 层叠顺序翻转
11817
11818 if (self.reverseOrder) {
11819 dataArray = dataArray.slice(0).reverse();
11820 }
11821
11822 for (var i = 0; i < count; i++) {
11823 var data = dataArray[i];
11824
11825 for (var j = 0, len = data.length; j < len; j++) {
11826 var item = data[j];
11827 var x = item[xField] || 0;
11828 var y = item[yField];
11829 var xkey = x.toString();
11830 y = isArray(y) ? y[1] : y;
11831
11832 if (!isNil(y)) {
11833 var direction = y >= 0 ? 'positive' : 'negative';
11834
11835 if (!stackCache[direction][xkey]) {
11836 stackCache[direction][xkey] = 0;
11837 }
11838
11839 item[yField] = [stackCache[direction][xkey], y + stackCache[direction][xkey]];
11840 stackCache[direction][xkey] += y;
11841 }
11842 }
11843 }
11844 };
11845
11846 return Stack;
11847}(Adjust);
11848
11849Adjust.Stack = Stack;
11850module.exports = Stack;
11851
11852/***/ }),
11853/* 106 */
11854/***/ (function(module, exports) {
11855
11856var toString = {}.toString;
11857
11858var isType = function isType(value, type) {
11859 return toString.call(value) === '[object ' + type + ']';
11860};
11861
11862module.exports = isType;
11863
11864/***/ }),
11865/* 107 */
11866/***/ (function(module, exports) {
11867
11868// isFinite,
11869var isNil = function isNil(value) {
11870 /**
11871 * isNil(null) => true
11872 * isNil() => true
11873 */
11874 return value === null || value === undefined;
11875};
11876
11877module.exports = isNil;
11878
11879/***/ }),
11880/* 108 */
11881/***/ (function(module, exports, __webpack_require__) {
11882
11883var Dodge = __webpack_require__(109);
11884
11885module.exports = Dodge;
11886
11887/***/ }),
11888/* 109 */
11889/***/ (function(module, exports, __webpack_require__) {
11890
11891function _inheritsLoose(subClass, superClass) {
11892 subClass.prototype = Object.create(superClass.prototype);
11893 subClass.prototype.constructor = subClass;
11894 subClass.__proto__ = superClass;
11895}
11896
11897var Adjust = __webpack_require__(24);
11898
11899var each = __webpack_require__(110);
11900
11901var MARGIN_RATIO = 1 / 2;
11902var DODGE_RATIO = 1 / 2;
11903
11904var Dodge =
11905/*#__PURE__*/
11906function (_Adjust) {
11907 _inheritsLoose(Dodge, _Adjust);
11908
11909 function Dodge() {
11910 return _Adjust.apply(this, arguments) || this;
11911 }
11912
11913 var _proto = Dodge.prototype;
11914
11915 _proto._initDefaultCfg = function _initDefaultCfg() {
11916 /**
11917 * 调整过程中,2个数据的间距
11918 * @type {Number}
11919 */
11920 this.marginRatio = MARGIN_RATIO;
11921 /**
11922 * 调整占单位宽度的比例,例如:占2个分类间距的 1/2
11923 * @type {Number}
11924 */
11925
11926 this.dodgeRatio = DODGE_RATIO;
11927 this.adjustNames = ['x', 'y']; // 调整的维度,默认,x,y都做调整
11928 };
11929
11930 _proto.getDodgeOffset = function getDodgeOffset(range, index, count) {
11931 var self = this;
11932 var pre = range.pre;
11933 var next = range.next;
11934 var tickLength = next - pre;
11935 var width = tickLength * self.dodgeRatio / count;
11936 var margin = self.marginRatio * width;
11937 var offset = 1 / 2 * (tickLength - count * width - (count - 1) * margin) + ((index + 1) * width + index * margin) - 1 / 2 * width - 1 / 2 * tickLength;
11938 return (pre + next) / 2 + offset;
11939 };
11940
11941 _proto.processAdjust = function processAdjust(dataArray) {
11942 var self = this;
11943 var count = dataArray.length;
11944 var xField = self.xField;
11945 each(dataArray, function (data, index) {
11946 for (var i = 0, len = data.length; i < len; i++) {
11947 var obj = data[i];
11948 var value = obj[xField];
11949 var range = {
11950 pre: len === 1 ? value - 1 : value - 0.5,
11951 next: len === 1 ? value + 1 : value + 0.5
11952 };
11953 var dodgeValue = self.getDodgeOffset(range, index, count);
11954 obj[xField] = dodgeValue;
11955 }
11956 });
11957 };
11958
11959 return Dodge;
11960}(Adjust);
11961
11962Adjust.Dodge = Dodge;
11963module.exports = Dodge;
11964
11965/***/ }),
11966/* 110 */
11967/***/ (function(module, exports, __webpack_require__) {
11968
11969var isObject = __webpack_require__(111);
11970
11971var isArray = __webpack_require__(43);
11972
11973var each = function each(elements, func) {
11974 if (!elements) {
11975 return;
11976 }
11977
11978 var rst = void 0;
11979
11980 if (isArray(elements)) {
11981 for (var i = 0, len = elements.length; i < len; i++) {
11982 rst = func(elements[i], i);
11983
11984 if (rst === false) {
11985 break;
11986 }
11987 }
11988 } else if (isObject(elements)) {
11989 for (var k in elements) {
11990 if (elements.hasOwnProperty(k)) {
11991 rst = func(elements[k], k);
11992
11993 if (rst === false) {
11994 break;
11995 }
11996 }
11997 }
11998 }
11999};
12000
12001module.exports = each;
12002
12003/***/ }),
12004/* 111 */
12005/***/ (function(module, exports) {
12006
12007var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
12008 return typeof obj;
12009} : function (obj) {
12010 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
12011};
12012
12013var isObject = function isObject(value) {
12014 /**
12015 * isObject({}) => true
12016 * isObject([1, 2, 3]) => true
12017 * isObject(Function) => true
12018 * isObject(null) => false
12019 */
12020 var type = typeof value === 'undefined' ? 'undefined' : _typeof(value);
12021 return value !== null && type === 'object' || type === 'function';
12022};
12023
12024module.exports = isObject;
12025
12026/***/ }),
12027/* 112 */
12028/***/ (function(module, exports, __webpack_require__) {
12029
12030function _inheritsLoose(subClass, superClass) {
12031 subClass.prototype = Object.create(superClass.prototype);
12032 subClass.prototype.constructor = subClass;
12033 subClass.__proto__ = superClass;
12034}
12035
12036var Base = __webpack_require__(23);
12037
12038var Vector2 = __webpack_require__(7);
12039
12040var Matrix = __webpack_require__(27);
12041
12042var Polar =
12043/*#__PURE__*/
12044function (_Base) {
12045 _inheritsLoose(Polar, _Base);
12046
12047 function Polar() {
12048 return _Base.apply(this, arguments) || this;
12049 }
12050
12051 var _proto = Polar.prototype;
12052
12053 _proto._initDefaultCfg = function _initDefaultCfg() {
12054 this.type = 'polar';
12055 this.startAngle = -Math.PI / 2;
12056 this.endAngle = Math.PI * 3 / 2;
12057 this.inner = 0;
12058 this.innerRadius = 0; // alias
12059
12060 this.isPolar = true;
12061 this.transposed = false;
12062 this.center = null;
12063 this.radius = null; // relative, 0 ~ 1
12064 };
12065
12066 _proto.init = function init(start, end) {
12067 var self = this;
12068 var inner = self.inner || self.innerRadius;
12069 var width = Math.abs(end.x - start.x);
12070 var height = Math.abs(end.y - start.y);
12071 var maxRadius;
12072 var center;
12073
12074 if (self.startAngle === -Math.PI && self.endAngle === 0) {
12075 maxRadius = Math.min(width / 2, height);
12076 center = {
12077 x: (start.x + end.x) / 2,
12078 y: start.y
12079 };
12080 } else {
12081 maxRadius = Math.min(width, height) / 2;
12082 center = {
12083 x: (start.x + end.x) / 2,
12084 y: (start.y + end.y) / 2
12085 };
12086 }
12087
12088 var radius = self.radius;
12089
12090 if (radius > 0 && radius <= 1) {
12091 maxRadius = maxRadius * radius;
12092 }
12093
12094 this.x = {
12095 start: self.startAngle,
12096 end: self.endAngle
12097 };
12098 this.y = {
12099 start: maxRadius * inner,
12100 end: maxRadius
12101 };
12102 this.center = center;
12103 this.circleRadius = maxRadius; // the radius value in px
12104 };
12105
12106 _proto.convertPoint = function convertPoint(point) {
12107 var self = this;
12108 var center = self.center;
12109 var transposed = self.transposed;
12110 var xDim = transposed ? 'y' : 'x';
12111 var yDim = transposed ? 'x' : 'y';
12112 var x = self.x;
12113 var y = self.y;
12114 var angle = x.start + (x.end - x.start) * point[xDim];
12115 var radius = y.start + (y.end - y.start) * point[yDim];
12116 return {
12117 x: center.x + Math.cos(angle) * radius,
12118 y: center.y + Math.sin(angle) * radius
12119 };
12120 };
12121
12122 _proto.invertPoint = function invertPoint(point) {
12123 var self = this;
12124 var center = self.center,
12125 transposed = self.transposed,
12126 x = self.x,
12127 y = self.y;
12128 var xDim = transposed ? 'y' : 'x';
12129 var yDim = transposed ? 'x' : 'y';
12130 var m = [1, 0, 0, 1, 0, 0];
12131 Matrix.rotate(m, m, x.start);
12132 var startV = [1, 0];
12133 Vector2.transformMat2d(startV, startV, m);
12134 startV = [startV[0], startV[1]];
12135 var pointV = [point.x - center.x, point.y - center.y];
12136
12137 if (Vector2.zero(pointV)) {
12138 return {
12139 x: 0,
12140 y: 0
12141 };
12142 }
12143
12144 var theta = Vector2.angleTo(startV, pointV, x.end < x.start);
12145
12146 if (Math.abs(theta - Math.PI * 2) < 0.001) {
12147 theta = 0;
12148 }
12149
12150 var l = Vector2.length(pointV);
12151 var percentX = theta / (x.end - x.start);
12152 percentX = x.end - x.start > 0 ? percentX : -percentX;
12153 var percentY = (l - y.start) / (y.end - y.start);
12154 var rst = {};
12155 rst[xDim] = percentX;
12156 rst[yDim] = percentY;
12157 return rst;
12158 };
12159
12160 return Polar;
12161}(Base);
12162
12163Base.Polar = Polar;
12164module.exports = Polar;
12165
12166/***/ }),
12167/* 113 */
12168/***/ (function(module, exports, __webpack_require__) {
12169
12170function _inheritsLoose(subClass, superClass) {
12171 subClass.prototype = Object.create(superClass.prototype);
12172 subClass.prototype.constructor = subClass;
12173 subClass.__proto__ = superClass;
12174}
12175
12176var Util = __webpack_require__(0);
12177
12178var Abstract = __webpack_require__(25);
12179
12180var Circle =
12181/*#__PURE__*/
12182function (_Abstract) {
12183 _inheritsLoose(Circle, _Abstract);
12184
12185 function Circle() {
12186 return _Abstract.apply(this, arguments) || this;
12187 }
12188
12189 var _proto = Circle.prototype;
12190
12191 _proto._initDefaultCfg = function _initDefaultCfg() {
12192 _Abstract.prototype._initDefaultCfg.call(this);
12193
12194 this.startAngle = -Math.PI / 2; // start angle,in radian
12195
12196 this.endAngle = Math.PI * 3 / 2; // end angle, in radian
12197
12198 this.radius = null; // radius
12199
12200 this.center = null; // center
12201 };
12202
12203 _proto.getOffsetPoint = function getOffsetPoint(value) {
12204 var startAngle = this.startAngle,
12205 endAngle = this.endAngle;
12206 var angle = startAngle + (endAngle - startAngle) * value;
12207 return this._getCirclePoint(angle);
12208 };
12209
12210 _proto._getCirclePoint = function _getCirclePoint(angle, radius) {
12211 var self = this;
12212 var center = self.center;
12213 radius = radius || self.radius;
12214 return {
12215 x: center.x + Math.cos(angle) * radius,
12216 y: center.y + Math.sin(angle) * radius
12217 };
12218 };
12219
12220 _proto.getTextAlignInfo = function getTextAlignInfo(point, offset) {
12221 var self = this;
12222 var offsetVector = self.getOffsetVector(point, offset);
12223 var align;
12224 var baseLine = 'middle';
12225
12226 if (offsetVector[0] > 0) {
12227 align = 'left';
12228 } else if (offsetVector[0] < 0) {
12229 align = 'right';
12230 } else {
12231 align = 'center';
12232
12233 if (offsetVector[1] > 0) {
12234 baseLine = 'top';
12235 } else if (offsetVector[1] < 0) {
12236 baseLine = 'bottom';
12237 }
12238 }
12239
12240 return {
12241 textAlign: align,
12242 textBaseline: baseLine
12243 };
12244 };
12245
12246 _proto.getAxisVector = function getAxisVector(point) {
12247 var center = this.center;
12248 var factor = this.offsetFactor;
12249 return [(point.y - center.y) * factor, (point.x - center.x) * -1 * factor];
12250 };
12251
12252 _proto.drawLine = function drawLine(lineCfg) {
12253 var center = this.center,
12254 radius = this.radius,
12255 startAngle = this.startAngle,
12256 endAngle = this.endAngle;
12257 var container = this.getContainer(lineCfg.top);
12258 container.addShape('arc', {
12259 className: 'axis-line',
12260 attrs: Util.mix({
12261 x: center.x,
12262 y: center.y,
12263 r: radius,
12264 startAngle: startAngle,
12265 endAngle: endAngle
12266 }, lineCfg)
12267 });
12268 };
12269
12270 return Circle;
12271}(Abstract);
12272
12273Abstract.Circle = Circle;
12274module.exports = Circle;
12275
12276/***/ }),
12277/* 114 */
12278/***/ (function(module, exports, __webpack_require__) {
12279
12280var TimeCat = __webpack_require__(115);
12281
12282module.exports = TimeCat;
12283
12284/***/ }),
12285/* 115 */
12286/***/ (function(module, exports, __webpack_require__) {
12287
12288function _inheritsLoose(subClass, superClass) {
12289 subClass.prototype = Object.create(superClass.prototype);
12290 subClass.prototype.constructor = subClass;
12291 subClass.__proto__ = superClass;
12292}
12293/**
12294 * @fileOverview 时间数据作为分类类型
12295 * @author dxq613@gmail.com
12296 */
12297
12298
12299var Base = __webpack_require__(16);
12300
12301var Category = __webpack_require__(34);
12302
12303var fecha = __webpack_require__(116);
12304
12305var catAuto = __webpack_require__(35);
12306
12307var TimeUtil = __webpack_require__(28);
12308
12309var each = __webpack_require__(5);
12310
12311var isNumber = __webpack_require__(14);
12312
12313var isObject = __webpack_require__(17);
12314
12315var isString = __webpack_require__(13);
12316/**
12317 * 度量的构造函数
12318 * @class Scale.TimeCategory
12319 */
12320
12321
12322var TimeCategory =
12323/*#__PURE__*/
12324function (_Category) {
12325 _inheritsLoose(TimeCategory, _Category);
12326
12327 function TimeCategory() {
12328 return _Category.apply(this, arguments) || this;
12329 }
12330
12331 var _proto = TimeCategory.prototype;
12332
12333 _proto._initDefaultCfg = function _initDefaultCfg() {
12334 _Category.prototype._initDefaultCfg.call(this);
12335
12336 this.type = 'timeCat';
12337 /**
12338 * 是否需要排序,默认进行排序
12339 * @type {Boolean}
12340 */
12341
12342 this.sortable = true;
12343 this.tickCount = 5;
12344 /**
12345 * 时间格式化
12346 * @type {String}
12347 */
12348
12349 this.mask = 'YYYY-MM-DD';
12350 };
12351
12352 _proto.init = function init() {
12353 var self = this;
12354 var values = this.values; // 针对时间分类类型,会将时间统一转换为时间戳
12355
12356 each(values, function (v, i) {
12357 values[i] = self._toTimeStamp(v);
12358 });
12359
12360 if (this.sortable) {
12361 // 允许排序
12362 values.sort(function (v1, v2) {
12363 return v1 - v2;
12364 });
12365 }
12366
12367 if (!self.ticks) {
12368 self.ticks = this.calculateTicks();
12369 }
12370 };
12371 /**
12372 * 计算 ticks
12373 * @return {array} 返回 ticks 数组
12374 */
12375
12376
12377 _proto.calculateTicks = function calculateTicks() {
12378 var self = this;
12379 var count = self.tickCount;
12380 var ticks;
12381
12382 if (count) {
12383 var temp = catAuto({
12384 maxCount: count,
12385 data: self.values,
12386 isRounding: self.isRounding
12387 });
12388 ticks = temp.ticks;
12389 } else {
12390 ticks = self.values;
12391 }
12392
12393 return ticks;
12394 };
12395 /**
12396 * @override
12397 */
12398
12399
12400 _proto.translate = function translate(value) {
12401 value = this._toTimeStamp(value);
12402 var index = this.values.indexOf(value);
12403
12404 if (index === -1) {
12405 if (isNumber(value) && value < this.values.length) {
12406 index = value;
12407 } else {
12408 index = NaN;
12409 }
12410 }
12411
12412 return index;
12413 };
12414 /**
12415 * @override
12416 */
12417
12418
12419 _proto.scale = function scale(value) {
12420 var rangeMin = this.rangeMin();
12421 var rangeMax = this.rangeMax();
12422 var index = this.translate(value);
12423 var percent;
12424
12425 if (this.values.length === 1 || isNaN(index)) {
12426 // is index is NAN should not be set as 0
12427 percent = index;
12428 } else if (index > -1) {
12429 percent = index / (this.values.length - 1);
12430 } else {
12431 percent = 0;
12432 }
12433
12434 return rangeMin + percent * (rangeMax - rangeMin);
12435 };
12436 /**
12437 * @override
12438 */
12439
12440
12441 _proto.getText = function getText(value) {
12442 var result = '';
12443 var index = this.translate(value);
12444
12445 if (index > -1) {
12446 result = this.values[index];
12447 } else {
12448 result = value;
12449 }
12450
12451 var formatter = this.formatter;
12452 result = parseInt(result, 10);
12453 result = formatter ? formatter(result) : fecha.format(result, this.mask);
12454 return result;
12455 };
12456 /**
12457 * @override
12458 */
12459
12460
12461 _proto.getTicks = function getTicks() {
12462 var self = this;
12463 var ticks = this.ticks;
12464 var rst = [];
12465 each(ticks, function (tick) {
12466 var obj;
12467
12468 if (isObject(tick)) {
12469 obj = tick;
12470 } else {
12471 obj = {
12472 text: isString(tick) ? tick : self.getText(tick),
12473 value: self.scale(tick),
12474 tickValue: tick // 用于坐标轴上文本动画时确定前后帧的对应关系
12475
12476 };
12477 }
12478
12479 rst.push(obj);
12480 });
12481 return rst;
12482 }; // 将时间转换为时间戳
12483
12484
12485 _proto._toTimeStamp = function _toTimeStamp(value) {
12486 return TimeUtil.toTimeStamp(value);
12487 };
12488
12489 return TimeCategory;
12490}(Category);
12491
12492Base.TimeCat = TimeCategory;
12493module.exports = TimeCategory;
12494
12495/***/ }),
12496/* 116 */
12497/***/ (function(module, exports, __webpack_require__) {
12498
12499var __WEBPACK_AMD_DEFINE_RESULT__;(function (main) {
12500 'use strict';
12501 /**
12502 * Parse or format dates
12503 * @class fecha
12504 */
12505
12506 var fecha = {};
12507 var token = /d{1,4}|M{1,4}|YY(?:YY)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
12508 var twoDigits = /\d\d?/;
12509 var threeDigits = /\d{3}/;
12510 var fourDigits = /\d{4}/;
12511 var word = /[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i;
12512 var literal = /\[([^]*?)\]/gm;
12513
12514 var noop = function () {};
12515
12516 function shorten(arr, sLen) {
12517 var newArr = [];
12518
12519 for (var i = 0, len = arr.length; i < len; i++) {
12520 newArr.push(arr[i].substr(0, sLen));
12521 }
12522
12523 return newArr;
12524 }
12525
12526 function monthUpdate(arrName) {
12527 return function (d, v, i18n) {
12528 var index = i18n[arrName].indexOf(v.charAt(0).toUpperCase() + v.substr(1).toLowerCase());
12529
12530 if (~index) {
12531 d.month = index;
12532 }
12533 };
12534 }
12535
12536 function pad(val, len) {
12537 val = String(val);
12538 len = len || 2;
12539
12540 while (val.length < len) {
12541 val = '0' + val;
12542 }
12543
12544 return val;
12545 }
12546
12547 var dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
12548 var monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
12549 var monthNamesShort = shorten(monthNames, 3);
12550 var dayNamesShort = shorten(dayNames, 3);
12551 fecha.i18n = {
12552 dayNamesShort: dayNamesShort,
12553 dayNames: dayNames,
12554 monthNamesShort: monthNamesShort,
12555 monthNames: monthNames,
12556 amPm: ['am', 'pm'],
12557 DoFn: function DoFn(D) {
12558 return D + ['th', 'st', 'nd', 'rd'][D % 10 > 3 ? 0 : (D - D % 10 !== 10) * D % 10];
12559 }
12560 };
12561 var formatFlags = {
12562 D: function (dateObj) {
12563 return dateObj.getDate();
12564 },
12565 DD: function (dateObj) {
12566 return pad(dateObj.getDate());
12567 },
12568 Do: function (dateObj, i18n) {
12569 return i18n.DoFn(dateObj.getDate());
12570 },
12571 d: function (dateObj) {
12572 return dateObj.getDay();
12573 },
12574 dd: function (dateObj) {
12575 return pad(dateObj.getDay());
12576 },
12577 ddd: function (dateObj, i18n) {
12578 return i18n.dayNamesShort[dateObj.getDay()];
12579 },
12580 dddd: function (dateObj, i18n) {
12581 return i18n.dayNames[dateObj.getDay()];
12582 },
12583 M: function (dateObj) {
12584 return dateObj.getMonth() + 1;
12585 },
12586 MM: function (dateObj) {
12587 return pad(dateObj.getMonth() + 1);
12588 },
12589 MMM: function (dateObj, i18n) {
12590 return i18n.monthNamesShort[dateObj.getMonth()];
12591 },
12592 MMMM: function (dateObj, i18n) {
12593 return i18n.monthNames[dateObj.getMonth()];
12594 },
12595 YY: function (dateObj) {
12596 return String(dateObj.getFullYear()).substr(2);
12597 },
12598 YYYY: function (dateObj) {
12599 return pad(dateObj.getFullYear(), 4);
12600 },
12601 h: function (dateObj) {
12602 return dateObj.getHours() % 12 || 12;
12603 },
12604 hh: function (dateObj) {
12605 return pad(dateObj.getHours() % 12 || 12);
12606 },
12607 H: function (dateObj) {
12608 return dateObj.getHours();
12609 },
12610 HH: function (dateObj) {
12611 return pad(dateObj.getHours());
12612 },
12613 m: function (dateObj) {
12614 return dateObj.getMinutes();
12615 },
12616 mm: function (dateObj) {
12617 return pad(dateObj.getMinutes());
12618 },
12619 s: function (dateObj) {
12620 return dateObj.getSeconds();
12621 },
12622 ss: function (dateObj) {
12623 return pad(dateObj.getSeconds());
12624 },
12625 S: function (dateObj) {
12626 return Math.round(dateObj.getMilliseconds() / 100);
12627 },
12628 SS: function (dateObj) {
12629 return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
12630 },
12631 SSS: function (dateObj) {
12632 return pad(dateObj.getMilliseconds(), 3);
12633 },
12634 a: function (dateObj, i18n) {
12635 return dateObj.getHours() < 12 ? i18n.amPm[0] : i18n.amPm[1];
12636 },
12637 A: function (dateObj, i18n) {
12638 return dateObj.getHours() < 12 ? i18n.amPm[0].toUpperCase() : i18n.amPm[1].toUpperCase();
12639 },
12640 ZZ: function (dateObj) {
12641 var o = dateObj.getTimezoneOffset();
12642 return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
12643 }
12644 };
12645 var parseFlags = {
12646 D: [twoDigits, function (d, v) {
12647 d.day = v;
12648 }],
12649 Do: [new RegExp(twoDigits.source + word.source), function (d, v) {
12650 d.day = parseInt(v, 10);
12651 }],
12652 M: [twoDigits, function (d, v) {
12653 d.month = v - 1;
12654 }],
12655 YY: [twoDigits, function (d, v) {
12656 var da = new Date(),
12657 cent = +('' + da.getFullYear()).substr(0, 2);
12658 d.year = '' + (v > 68 ? cent - 1 : cent) + v;
12659 }],
12660 h: [twoDigits, function (d, v) {
12661 d.hour = v;
12662 }],
12663 m: [twoDigits, function (d, v) {
12664 d.minute = v;
12665 }],
12666 s: [twoDigits, function (d, v) {
12667 d.second = v;
12668 }],
12669 YYYY: [fourDigits, function (d, v) {
12670 d.year = v;
12671 }],
12672 S: [/\d/, function (d, v) {
12673 d.millisecond = v * 100;
12674 }],
12675 SS: [/\d{2}/, function (d, v) {
12676 d.millisecond = v * 10;
12677 }],
12678 SSS: [threeDigits, function (d, v) {
12679 d.millisecond = v;
12680 }],
12681 d: [twoDigits, noop],
12682 ddd: [word, noop],
12683 MMM: [word, monthUpdate('monthNamesShort')],
12684 MMMM: [word, monthUpdate('monthNames')],
12685 a: [word, function (d, v, i18n) {
12686 var val = v.toLowerCase();
12687
12688 if (val === i18n.amPm[0]) {
12689 d.isPm = false;
12690 } else if (val === i18n.amPm[1]) {
12691 d.isPm = true;
12692 }
12693 }],
12694 ZZ: [/([\+\-]\d\d:?\d\d|Z)/, function (d, v) {
12695 if (v === 'Z') v = '+00:00';
12696 var parts = (v + '').match(/([\+\-]|\d\d)/gi),
12697 minutes;
12698
12699 if (parts) {
12700 minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
12701 d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
12702 }
12703 }]
12704 };
12705 parseFlags.dd = parseFlags.d;
12706 parseFlags.dddd = parseFlags.ddd;
12707 parseFlags.DD = parseFlags.D;
12708 parseFlags.mm = parseFlags.m;
12709 parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
12710 parseFlags.MM = parseFlags.M;
12711 parseFlags.ss = parseFlags.s;
12712 parseFlags.A = parseFlags.a; // Some common format strings
12713
12714 fecha.masks = {
12715 default: 'ddd MMM DD YYYY HH:mm:ss',
12716 shortDate: 'M/D/YY',
12717 mediumDate: 'MMM D, YYYY',
12718 longDate: 'MMMM D, YYYY',
12719 fullDate: 'dddd, MMMM D, YYYY',
12720 shortTime: 'HH:mm',
12721 mediumTime: 'HH:mm:ss',
12722 longTime: 'HH:mm:ss.SSS'
12723 };
12724 /***
12725 * Format a date
12726 * @method format
12727 * @param {Date|number} dateObj
12728 * @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate'
12729 */
12730
12731 fecha.format = function (dateObj, mask, i18nSettings) {
12732 var i18n = i18nSettings || fecha.i18n;
12733
12734 if (typeof dateObj === 'number') {
12735 dateObj = new Date(dateObj);
12736 }
12737
12738 if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
12739 throw new Error('Invalid Date in fecha.format');
12740 }
12741
12742 mask = fecha.masks[mask] || mask || fecha.masks['default'];
12743 var literals = []; // Make literals inactive by replacing them with ??
12744
12745 mask = mask.replace(literal, function ($0, $1) {
12746 literals.push($1);
12747 return '??';
12748 }); // Apply formatting rules
12749
12750 mask = mask.replace(token, function ($0) {
12751 return $0 in formatFlags ? formatFlags[$0](dateObj, i18n) : $0.slice(1, $0.length - 1);
12752 }); // Inline literal values back into the formatted value
12753
12754 return mask.replace(/\?\?/g, function () {
12755 return literals.shift();
12756 });
12757 };
12758 /**
12759 * Parse a date string into an object, changes - into /
12760 * @method parse
12761 * @param {string} dateStr Date string
12762 * @param {string} format Date parse format
12763 * @returns {Date|boolean}
12764 */
12765
12766
12767 fecha.parse = function (dateStr, format, i18nSettings) {
12768 var i18n = i18nSettings || fecha.i18n;
12769
12770 if (typeof format !== 'string') {
12771 throw new Error('Invalid format in fecha.parse');
12772 }
12773
12774 format = fecha.masks[format] || format; // Avoid regular expression denial of service, fail early for really long strings
12775 // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
12776
12777 if (dateStr.length > 1000) {
12778 return false;
12779 }
12780
12781 var isValid = true;
12782 var dateInfo = {};
12783 format.replace(token, function ($0) {
12784 if (parseFlags[$0]) {
12785 var info = parseFlags[$0];
12786 var index = dateStr.search(info[0]);
12787
12788 if (!~index) {
12789 isValid = false;
12790 } else {
12791 dateStr.replace(info[0], function (result) {
12792 info[1](dateInfo, result, i18n);
12793 dateStr = dateStr.substr(index + result.length);
12794 return result;
12795 });
12796 }
12797 }
12798
12799 return parseFlags[$0] ? '' : $0.slice(1, $0.length - 1);
12800 });
12801
12802 if (!isValid) {
12803 return false;
12804 }
12805
12806 var today = new Date();
12807
12808 if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
12809 dateInfo.hour = +dateInfo.hour + 12;
12810 } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
12811 dateInfo.hour = 0;
12812 }
12813
12814 var date;
12815
12816 if (dateInfo.timezoneOffset != null) {
12817 dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
12818 date = new Date(Date.UTC(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1, dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0));
12819 } else {
12820 date = new Date(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1, dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0);
12821 }
12822
12823 return date;
12824 };
12825 /* istanbul ignore next */
12826
12827
12828 if (typeof module !== 'undefined' && module.exports) {
12829 module.exports = fecha;
12830 } else if (true) {
12831 !(__WEBPACK_AMD_DEFINE_RESULT__ = (function () {
12832 return fecha;
12833 }).call(exports, __webpack_require__, exports, module),
12834 __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
12835 } else {
12836 main.fecha = fecha;
12837 }
12838})(this);
12839
12840/***/ }),
12841/* 117 */
12842/***/ (function(module, exports, __webpack_require__) {
12843
12844function _inheritsLoose(subClass, superClass) {
12845 subClass.prototype = Object.create(superClass.prototype);
12846 subClass.prototype.constructor = subClass;
12847 subClass.__proto__ = superClass;
12848}
12849
12850var Util = __webpack_require__(0);
12851
12852var GuideBase = __webpack_require__(8);
12853
12854var Arc =
12855/*#__PURE__*/
12856function (_GuideBase) {
12857 _inheritsLoose(Arc, _GuideBase);
12858
12859 function Arc() {
12860 return _GuideBase.apply(this, arguments) || this;
12861 }
12862
12863 var _proto = Arc.prototype;
12864
12865 _proto._initDefaultCfg = function _initDefaultCfg() {
12866 this.type = 'arc';
12867 /**
12868 * start point
12869 * @type {Array | Function}
12870 */
12871
12872 this.start = [];
12873 /**
12874 * end point
12875 * @type {Array | Function}
12876 */
12877
12878 this.end = [];
12879 /**
12880 * style configuration
12881 * @type {Object}
12882 */
12883
12884 this.style = {
12885 stroke: '#999',
12886 lineWidth: 1
12887 };
12888 };
12889
12890 _proto.render = function render(coord, container) {
12891 var self = this;
12892 var start = self.parsePoint(coord, self.start);
12893 var end = self.parsePoint(coord, self.end);
12894
12895 if (!start || !end) {
12896 return;
12897 }
12898
12899 var coordCenter = coord.center;
12900 var radius = Math.sqrt((start.x - coordCenter.x) * (start.x - coordCenter.x) + (start.y - coordCenter.y) * (start.y - coordCenter.y));
12901 var startAngle = Math.atan2(start.y - coordCenter.y, start.x - coordCenter.x);
12902 var endAngle = Math.atan2(end.y - coordCenter.y, end.x - coordCenter.x);
12903 var shape = container.addShape('arc', {
12904 className: 'guide-arc',
12905 attrs: Util.mix({
12906 x: coordCenter.x,
12907 y: coordCenter.y,
12908 r: radius,
12909 startAngle: startAngle,
12910 endAngle: endAngle
12911 }, self.style)
12912 });
12913 self.element = shape;
12914 return shape;
12915 };
12916
12917 return Arc;
12918}(GuideBase);
12919
12920GuideBase.Arc = Arc;
12921module.exports = Arc;
12922
12923/***/ }),
12924/* 118 */
12925/***/ (function(module, exports, __webpack_require__) {
12926
12927function _inheritsLoose(subClass, superClass) {
12928 subClass.prototype = Object.create(superClass.prototype);
12929 subClass.prototype.constructor = subClass;
12930 subClass.__proto__ = superClass;
12931}
12932
12933var Util = __webpack_require__(0);
12934
12935var GuideBase = __webpack_require__(8);
12936
12937var Line =
12938/*#__PURE__*/
12939function (_GuideBase) {
12940 _inheritsLoose(Line, _GuideBase);
12941
12942 function Line() {
12943 return _GuideBase.apply(this, arguments) || this;
12944 }
12945
12946 var _proto = Line.prototype;
12947
12948 _proto._initDefaultCfg = function _initDefaultCfg() {
12949 this.type = 'line';
12950 this.start = [];
12951 this.end = [];
12952 this.style = {
12953 stroke: '#000',
12954 lineWidth: 1
12955 };
12956 };
12957
12958 _proto.render = function render(coord, container) {
12959 var points = [];
12960 points[0] = this.parsePoint(coord, this.start);
12961 points[1] = this.parsePoint(coord, this.end);
12962
12963 if (!points[0] || !points[1]) {
12964 return;
12965 }
12966
12967 var shape = container.addShape('Line', {
12968 className: 'guide-line',
12969 attrs: Util.mix({
12970 x1: points[0].x,
12971 y1: points[0].y,
12972 x2: points[1].x,
12973 y2: points[1].y
12974 }, this.style)
12975 });
12976 this.element = shape;
12977 return shape;
12978 };
12979
12980 return Line;
12981}(GuideBase);
12982
12983GuideBase.Line = Line;
12984module.exports = Line;
12985
12986/***/ }),
12987/* 119 */
12988/***/ (function(module, exports, __webpack_require__) {
12989
12990function _inheritsLoose(subClass, superClass) {
12991 subClass.prototype = Object.create(superClass.prototype);
12992 subClass.prototype.constructor = subClass;
12993 subClass.__proto__ = superClass;
12994}
12995
12996var Util = __webpack_require__(0);
12997
12998var GuideBase = __webpack_require__(8);
12999
13000var Text =
13001/*#__PURE__*/
13002function (_GuideBase) {
13003 _inheritsLoose(Text, _GuideBase);
13004
13005 function Text() {
13006 return _GuideBase.apply(this, arguments) || this;
13007 }
13008
13009 var _proto = Text.prototype;
13010
13011 _proto._initDefaultCfg = function _initDefaultCfg() {
13012 this.type = 'text';
13013 /**
13014 * the position of text
13015 * @type {Function | Array}
13016 */
13017
13018 this.position = null;
13019 /**
13020 * the display content
13021 * @type {String}
13022 */
13023
13024 this.content = null;
13025 /**
13026 * style configuration for text
13027 * @type {Object}
13028 */
13029
13030 this.style = {
13031 fill: '#000'
13032 };
13033 /**
13034 * offset of horizontal direction
13035 * @type {Number}
13036 */
13037
13038 this.offsetX = 0;
13039 /**
13040 * offset of vertical direction
13041 * @type {Number}
13042 */
13043
13044 this.offsetY = 0;
13045 };
13046
13047 _proto.render = function render(coord, container) {
13048 var position = this.position;
13049 var point = this.parsePoint(coord, position);
13050
13051 if (!point) {
13052 return;
13053 }
13054
13055 var content = this.content,
13056 style = this.style,
13057 offsetX = this.offsetX,
13058 offsetY = this.offsetY;
13059
13060 if (offsetX) {
13061 point.x += offsetX;
13062 }
13063
13064 if (offsetY) {
13065 point.y += offsetY;
13066 }
13067
13068 var shape = container.addShape('text', {
13069 className: 'guide-text',
13070 attrs: Util.mix({
13071 x: point.x,
13072 y: point.y,
13073 text: content
13074 }, style)
13075 });
13076 this.element = shape;
13077 return shape;
13078 };
13079
13080 return Text;
13081}(GuideBase);
13082
13083GuideBase.Text = Text;
13084module.exports = Text;
13085
13086/***/ }),
13087/* 120 */
13088/***/ (function(module, exports, __webpack_require__) {
13089
13090function _inheritsLoose(subClass, superClass) {
13091 subClass.prototype = Object.create(superClass.prototype);
13092 subClass.prototype.constructor = subClass;
13093 subClass.__proto__ = superClass;
13094}
13095
13096var Util = __webpack_require__(0);
13097
13098var GuideBase = __webpack_require__(8);
13099
13100var Tag =
13101/*#__PURE__*/
13102function (_GuideBase) {
13103 _inheritsLoose(Tag, _GuideBase);
13104
13105 function Tag() {
13106 return _GuideBase.apply(this, arguments) || this;
13107 }
13108
13109 var _proto = Tag.prototype;
13110
13111 _proto._initDefaultCfg = function _initDefaultCfg() {
13112 this.type = 'tag';
13113 this.position = null;
13114 this.content = null;
13115 this.direct = 'tl';
13116 this.autoAdjust = true;
13117 this.offsetX = 0;
13118 this.offsetY = 0;
13119 this.side = 4;
13120 this.background = {
13121 padding: 5,
13122 radius: 2,
13123 fill: '#1890FF'
13124 };
13125 this.textStyle = {
13126 fontSize: 12,
13127 fill: '#fff',
13128 textAlign: 'center',
13129 textBaseline: 'middle'
13130 };
13131 this.withPoint = true;
13132 this.pointStyle = {
13133 fill: '#1890FF',
13134 r: 3,
13135 lineWidth: 1,
13136 stroke: '#fff'
13137 };
13138 };
13139
13140 _proto._getDirect = function _getDirect(container, point, tagWidth, tagHeight) {
13141 var direct = this.direct;
13142 var side = this.side;
13143 var canvas = container.get('canvas');
13144 var clientWidth = canvas.get('width');
13145 var clientHeight = canvas.get('height');
13146 var x = point.x,
13147 y = point.y;
13148 var vertical = direct[0];
13149 var horizontal = direct[1]; // adjust for vertical direction
13150
13151 if (vertical === 't' && y - side - tagHeight < 0) {
13152 vertical = 'b';
13153 } else if (vertical === 'b' && y + side + tagHeight > clientHeight) {
13154 vertical = 't';
13155 } // adjust for horizontal direction
13156
13157
13158 var diff = vertical === 'c' ? side : 0;
13159
13160 if (horizontal === 'l' && x - diff - tagWidth < 0) {
13161 horizontal = 'r';
13162 } else if (horizontal === 'r' && x + diff + tagWidth > clientWidth) {
13163 horizontal = 'l';
13164 } else if (horizontal === 'c') {
13165 if (tagWidth / 2 + x + diff > clientWidth) {
13166 horizontal = 'l';
13167 } else if (x - tagWidth / 2 - diff < 0) {
13168 horizontal = 'r';
13169 }
13170 }
13171
13172 direct = vertical + horizontal;
13173 return direct;
13174 };
13175
13176 _proto.render = function render(coord, container) {
13177 var position = this.parsePoint(coord, this.position);
13178
13179 if (!position) {
13180 return;
13181 }
13182
13183 var content = this.content,
13184 background = this.background,
13185 textStyle = this.textStyle;
13186 var shapes = [];
13187 var wrapperContainer = container.addGroup({
13188 className: 'guide-tag'
13189 });
13190
13191 if (this.withPoint) {
13192 var pointShape = wrapperContainer.addShape('Circle', {
13193 className: 'guide-tag-point',
13194 attrs: Util.mix({
13195 x: position.x,
13196 y: position.y
13197 }, this.pointStyle)
13198 });
13199 shapes.push(pointShape);
13200 }
13201
13202 var tagContainer = wrapperContainer.addGroup(); // create a text shape
13203
13204 var tagText = tagContainer.addShape('text', {
13205 className: 'guide-tag-text',
13206 zIndex: 1,
13207 attrs: Util.mix({
13208 x: 0,
13209 y: 0,
13210 text: content
13211 }, textStyle)
13212 });
13213 shapes.push(tagText); // create background box
13214
13215 var textBBox = tagText.getBBox();
13216 var padding = Util.parsePadding(background.padding);
13217 var tagWidth = textBBox.width + padding[1] + padding[3];
13218 var tagHeight = textBBox.height + padding[0] + padding[2];
13219 var yMin = textBBox.minY - padding[0];
13220 var xMin = textBBox.minX - padding[3];
13221 var tagBg = tagContainer.addShape('rect', {
13222 className: 'guide-tag-bg',
13223 zIndex: -1,
13224 attrs: Util.mix({
13225 x: xMin,
13226 y: yMin,
13227 width: tagWidth,
13228 height: tagHeight
13229 }, background)
13230 });
13231 shapes.push(tagBg);
13232 var direct = this.autoAdjust ? this._getDirect(container, position, tagWidth, tagHeight) : this.direct;
13233 var side = this.side;
13234 var x = position.x + this.offsetX;
13235 var y = position.y + this.offsetY;
13236 var arrowPoints;
13237 var radius = Util.parsePadding(background.radius);
13238
13239 if (direct === 'tl') {
13240 arrowPoints = [{
13241 x: tagWidth + xMin - side - 1,
13242 y: tagHeight + yMin - 1
13243 }, // 这个 1 是为了防止出现白边
13244 {
13245 x: tagWidth + xMin,
13246 y: tagHeight + yMin - 1
13247 }, {
13248 x: tagWidth + xMin,
13249 y: tagHeight + side + yMin
13250 }];
13251 radius[2] = 0;
13252 x = x - tagWidth;
13253 y = y - side - tagHeight;
13254 } else if (direct === 'cl') {
13255 arrowPoints = [{
13256 x: tagWidth + xMin - 1,
13257 y: (tagHeight - side) / 2 + yMin - 1
13258 }, {
13259 x: tagWidth + xMin - 1,
13260 y: (tagHeight + side) / 2 + yMin + 1
13261 }, {
13262 x: tagWidth + side + xMin,
13263 y: tagHeight / 2 + yMin
13264 }];
13265 x = x - tagWidth - side;
13266 y = y - tagHeight / 2;
13267 } else if (direct === 'bl') {
13268 arrowPoints = [{
13269 x: tagWidth + xMin,
13270 y: -side + yMin
13271 }, {
13272 x: tagWidth + xMin - side - 1,
13273 y: yMin + 1
13274 }, {
13275 x: tagWidth + xMin,
13276 y: yMin + 1
13277 }];
13278 radius[1] = 0;
13279 x = x - tagWidth;
13280 y = y + side;
13281 } else if (direct === 'bc') {
13282 arrowPoints = [{
13283 x: tagWidth / 2 + xMin,
13284 y: -side + yMin
13285 }, {
13286 x: (tagWidth - side) / 2 + xMin - 1,
13287 y: yMin + 1
13288 }, {
13289 x: (tagWidth + side) / 2 + xMin + 1,
13290 y: yMin + 1
13291 }];
13292 x = x - tagWidth / 2;
13293 y = y + side;
13294 } else if (direct === 'br') {
13295 arrowPoints = [{
13296 x: xMin,
13297 y: yMin - side
13298 }, {
13299 x: xMin,
13300 y: yMin + 1
13301 }, {
13302 x: xMin + side + 1,
13303 y: yMin + 1
13304 }];
13305 radius[0] = 0;
13306 y = y + side;
13307 } else if (direct === 'cr') {
13308 arrowPoints = [{
13309 x: xMin - side,
13310 y: tagHeight / 2 + yMin
13311 }, {
13312 x: xMin + 1,
13313 y: (tagHeight - side) / 2 + yMin - 1
13314 }, {
13315 x: xMin + 1,
13316 y: (tagHeight + side) / 2 + yMin + 1
13317 }];
13318 x = x + side;
13319 y = y - tagHeight / 2;
13320 } else if (direct === 'tr') {
13321 arrowPoints = [{
13322 x: xMin,
13323 y: tagHeight + side + yMin
13324 }, {
13325 x: xMin,
13326 y: tagHeight + yMin - 1
13327 }, {
13328 x: side + xMin + 1,
13329 y: tagHeight + yMin - 1
13330 }];
13331 radius[3] = 0;
13332 y = y - tagHeight - side;
13333 } else if (direct === 'tc') {
13334 arrowPoints = [{
13335 x: (tagWidth - side) / 2 + xMin - 1,
13336 y: tagHeight + yMin - 1
13337 }, {
13338 x: (tagWidth + side) / 2 + xMin + 1,
13339 y: tagHeight + yMin - 1
13340 }, {
13341 x: tagWidth / 2 + xMin,
13342 y: tagHeight + side + yMin
13343 }];
13344 x = x - tagWidth / 2;
13345 y = y - tagHeight - side;
13346 }
13347
13348 var sideShape = tagContainer.addShape('Polygon', {
13349 className: 'guide-tag-side',
13350 zIndex: 0,
13351 attrs: {
13352 points: arrowPoints,
13353 fill: background.fill
13354 }
13355 });
13356 shapes.push(sideShape);
13357 tagBg.attr('radius', radius);
13358 tagContainer.moveTo(x - xMin, y - yMin);
13359 tagContainer.sort();
13360 this.element = wrapperContainer;
13361 return shapes;
13362 };
13363
13364 return Tag;
13365}(GuideBase);
13366
13367GuideBase.Tag = Tag;
13368module.exports = Tag;
13369
13370/***/ }),
13371/* 121 */
13372/***/ (function(module, exports, __webpack_require__) {
13373
13374function _inheritsLoose(subClass, superClass) {
13375 subClass.prototype = Object.create(superClass.prototype);
13376 subClass.prototype.constructor = subClass;
13377 subClass.__proto__ = superClass;
13378}
13379
13380var Util = __webpack_require__(0);
13381
13382var GuideBase = __webpack_require__(8);
13383
13384var Rect =
13385/*#__PURE__*/
13386function (_GuideBase) {
13387 _inheritsLoose(Rect, _GuideBase);
13388
13389 function Rect() {
13390 return _GuideBase.apply(this, arguments) || this;
13391 }
13392
13393 var _proto = Rect.prototype;
13394
13395 _proto._initDefaultCfg = function _initDefaultCfg() {
13396 this.type = 'rect';
13397 this.start = [];
13398 this.end = [];
13399 this.style = {
13400 fill: '#CCD7EB',
13401 opacity: 0.4
13402 };
13403 };
13404
13405 _proto.render = function render(coord, container) {
13406 var start = this.parsePoint(coord, this.start);
13407 var end = this.parsePoint(coord, this.end);
13408
13409 if (!start || !end) {
13410 return;
13411 }
13412
13413 var shape = container.addShape('rect', {
13414 className: 'guide-rect',
13415 attrs: Util.mix({
13416 x: Math.min(start.x, end.x),
13417 y: Math.min(start.y, end.y),
13418 width: Math.abs(end.x - start.x),
13419 height: Math.abs(start.y - end.y)
13420 }, this.style)
13421 });
13422 this.element = shape;
13423 return shape;
13424 };
13425
13426 return Rect;
13427}(GuideBase);
13428
13429GuideBase.Rect = Rect;
13430module.exports = Rect;
13431
13432/***/ }),
13433/* 122 */
13434/***/ (function(module, exports, __webpack_require__) {
13435
13436function _inheritsLoose(subClass, superClass) {
13437 subClass.prototype = Object.create(superClass.prototype);
13438 subClass.prototype.constructor = subClass;
13439 subClass.__proto__ = superClass;
13440}
13441
13442var Util = __webpack_require__(0);
13443
13444var GuideBase = __webpack_require__(8);
13445
13446var _require = __webpack_require__(2),
13447 Rect = _require.Rect;
13448
13449var RegionFilter =
13450/*#__PURE__*/
13451function (_GuideBase) {
13452 _inheritsLoose(RegionFilter, _GuideBase);
13453
13454 function RegionFilter() {
13455 return _GuideBase.apply(this, arguments) || this;
13456 }
13457
13458 var _proto = RegionFilter.prototype;
13459
13460 _proto._initDefaultCfg = function _initDefaultCfg() {
13461 this.type = 'regionFilter';
13462 this.start = [];
13463 this.end = [];
13464 this.color = null;
13465 this.style = null;
13466 };
13467
13468 _proto.render = function render(coord) {
13469 var start = this.parsePoint(coord, this.start);
13470 var end = this.parsePoint(coord, this.end);
13471
13472 if (!start || !end) {
13473 return;
13474 }
13475
13476 var clip = new Rect({
13477 attrs: {
13478 x: Math.min(start.x, end.x),
13479 y: Math.min(start.y, end.y),
13480 width: Math.abs(end.x - start.x),
13481 height: Math.abs(end.y - start.y)
13482 }
13483 }); // 新建剪切区域
13484
13485 this.clip = clip;
13486 var chart = this.chart;
13487 var color = this.color;
13488 var style = this.style || {};
13489 var regionElements = [];
13490 var geoms = chart.get('geoms');
13491 geoms.map(function (geom) {
13492 var geomContainer = geom.get('container');
13493 var children = geomContainer.get('children');
13494 var group = geomContainer.addGroup({
13495 zIndex: 10,
13496 className: 'guide-region-filter'
13497 });
13498 children.map(function (c) {
13499 if (c.get('isShape')) {
13500 var type = c.get('type');
13501 var attrs = Util.mix({}, c.get('attrs'), style);
13502
13503 if (color && (attrs.fill || attrs.fillStyle)) {
13504 attrs.fill = attrs.fillStyle = color;
13505 }
13506
13507 if (color && (attrs.stroke || attrs.strokeStyle)) {
13508 attrs.stroke = attrs.strokeStyle = color;
13509 }
13510
13511 var cfg = {
13512 attrs: attrs
13513 };
13514
13515 if (type === 'custom' || type === 'Custom') {
13516 // custom 类型的 shape 会自定义绘制 path 的逻辑
13517 cfg.createPath = c.get('createPath');
13518 cfg.calculateBox = c.get('calculateBox');
13519 }
13520
13521 group.addShape(type, cfg);
13522 }
13523
13524 return c;
13525 });
13526 group.attr('clip', clip);
13527 geomContainer.sort();
13528 regionElements.push(group);
13529 return geom;
13530 });
13531 this.element = regionElements;
13532 };
13533
13534 _proto.remove = function remove() {
13535 var element = this.element;
13536 Util.each(element, function (group) {
13537 group && group.remove(true);
13538 });
13539 this.clip && this.clip.remove(true);
13540 };
13541
13542 return RegionFilter;
13543}(GuideBase);
13544
13545GuideBase.RegionFilter = RegionFilter;
13546module.exports = RegionFilter;
13547
13548/***/ }),
13549/* 123 */
13550/***/ (function(module, exports, __webpack_require__) {
13551
13552function _inheritsLoose(subClass, superClass) {
13553 subClass.prototype = Object.create(superClass.prototype);
13554 subClass.prototype.constructor = subClass;
13555 subClass.__proto__ = superClass;
13556}
13557
13558var Util = __webpack_require__(0);
13559
13560var GuideBase = __webpack_require__(8);
13561
13562var Point =
13563/*#__PURE__*/
13564function (_GuideBase) {
13565 _inheritsLoose(Point, _GuideBase);
13566
13567 function Point() {
13568 return _GuideBase.apply(this, arguments) || this;
13569 }
13570
13571 var _proto = Point.prototype;
13572
13573 _proto._initDefaultCfg = function _initDefaultCfg() {
13574 this.type = 'point';
13575 this.position = null;
13576 this.offsetX = 0;
13577 this.offsetY = 0;
13578 this.style = {
13579 fill: '#1890FF',
13580 r: 3,
13581 lineWidth: 1,
13582 stroke: '#fff'
13583 };
13584 };
13585
13586 _proto.render = function render(coord, container) {
13587 var position = this.parsePoint(coord, this.position);
13588 if (!position) return null;
13589 var shape = container.addShape('Circle', {
13590 className: 'guide-point',
13591 attrs: Util.mix({
13592 x: position.x + this.offsetX,
13593 y: position.y + this.offsetY
13594 }, this.style)
13595 });
13596 this.element = shape;
13597 return shape;
13598 };
13599
13600 return Point;
13601}(GuideBase);
13602
13603GuideBase.Point = Point;
13604module.exports = Point;
13605
13606/***/ }),
13607/* 124 */
13608/***/ (function(module, exports, __webpack_require__) {
13609
13610var Util = __webpack_require__(0);
13611
13612var Global = __webpack_require__(1);
13613
13614var Tooltip = __webpack_require__(125);
13615
13616var Helper = __webpack_require__(19); // Register the default configuration for Tooltip
13617
13618
13619Global.tooltip = Util.deepMix({
13620 triggerOn: ['touchstart', 'touchmove'],
13621 // triggerOff: 'touchend',
13622 alwaysShow: false,
13623 showTitle: false,
13624 showCrosshairs: false,
13625 crosshairsStyle: {
13626 stroke: 'rgba(0, 0, 0, 0.25)',
13627 lineWidth: 1
13628 },
13629 showTooltipMarker: true,
13630 background: {
13631 radius: 1,
13632 fill: 'rgba(0, 0, 0, 0.65)',
13633 padding: [3, 5]
13634 },
13635 titleStyle: {
13636 fontSize: 12,
13637 fill: '#fff',
13638 textAlign: 'start',
13639 textBaseline: 'top'
13640 },
13641 nameStyle: {
13642 fontSize: 12,
13643 fill: 'rgba(255, 255, 255, 0.65)',
13644 textAlign: 'start',
13645 textBaseline: 'middle'
13646 },
13647 valueStyle: {
13648 fontSize: 12,
13649 fill: '#fff',
13650 textAlign: 'start',
13651 textBaseline: 'middle'
13652 },
13653 showItemMarker: true,
13654 itemMarkerStyle: {
13655 radius: 3,
13656 symbol: 'circle',
13657 lineWidth: 1,
13658 stroke: '#fff'
13659 },
13660 layout: 'horizontal',
13661 snap: false
13662}, Global.tooltip || {});
13663
13664function _getTooltipValueScale(geom) {
13665 var colorAttr = geom.getAttr('color');
13666
13667 if (colorAttr) {
13668 var colorScale = colorAttr.getScale(colorAttr.type);
13669
13670 if (colorScale.isLinear) {
13671 return colorScale;
13672 }
13673 }
13674
13675 var xScale = geom.getXScale();
13676 var yScale = geom.getYScale();
13677
13678 if (yScale) {
13679 return yScale;
13680 }
13681
13682 return xScale;
13683}
13684
13685function getTooltipName(geom, origin) {
13686 var name;
13687 var nameScale;
13688
13689 var groupScales = geom._getGroupScales();
13690
13691 if (groupScales.length) {
13692 Util.each(groupScales, function (scale) {
13693 nameScale = scale;
13694 return false;
13695 });
13696 }
13697
13698 if (nameScale) {
13699 var field = nameScale.field;
13700 name = nameScale.getText(origin[field]);
13701 } else {
13702 var valueScale = _getTooltipValueScale(geom);
13703
13704 name = valueScale.alias || valueScale.field;
13705 }
13706
13707 return name;
13708}
13709
13710function getTooltipValue(geom, origin) {
13711 var scale = _getTooltipValueScale(geom);
13712
13713 return scale.getText(origin[scale.field]);
13714}
13715
13716function getTooltipTitle(geom, origin) {
13717 var position = geom.getAttr('position');
13718 var field = position.getFields()[0];
13719 var scale = geom.get('scales')[field];
13720 return scale.getText(origin[scale.field]);
13721}
13722
13723function _indexOfArray(items, item) {
13724 var rst = -1;
13725 Util.each(items, function (sub, index) {
13726 if (sub.title === item.title && sub.name === item.name && sub.value === item.value && sub.color === item.color) {
13727 rst = index;
13728 return false;
13729 }
13730 });
13731 return rst;
13732}
13733
13734function _uniqItems(items) {
13735 var tmp = [];
13736 Util.each(items, function (item) {
13737 var index = _indexOfArray(tmp, item);
13738
13739 if (index === -1) {
13740 tmp.push(item);
13741 } else {
13742 tmp[index] = item;
13743 }
13744 });
13745 return tmp;
13746}
13747
13748function isEqual(arr1, arr2) {
13749 return JSON.stringify(arr1) === JSON.stringify(arr2);
13750}
13751
13752var TooltipController =
13753/*#__PURE__*/
13754function () {
13755 function TooltipController(cfg) {
13756 this.enable = true;
13757 this.cfg = {};
13758 this.tooltip = null;
13759 this.chart = null;
13760 this.timeStamp = 0;
13761 Util.mix(this, cfg);
13762 var chart = this.chart;
13763 this.canvasDom = chart.get('canvas').get('el');
13764 }
13765
13766 var _proto = TooltipController.prototype;
13767
13768 _proto._setCrosshairsCfg = function _setCrosshairsCfg() {
13769 var self = this;
13770 var chart = self.chart;
13771 var defaultCfg = Util.mix({}, Global.tooltip);
13772 var geoms = chart.get('geoms');
13773 var shapes = [];
13774 Util.each(geoms, function (geom) {
13775 var type = geom.get('type');
13776
13777 if (shapes.indexOf(type) === -1) {
13778 shapes.push(type);
13779 }
13780 });
13781 var coordType = chart.get('coord').type;
13782
13783 if (geoms.length && (coordType === 'cartesian' || coordType === 'rect')) {
13784 if (shapes.length === 1 && ['line', 'area', 'path', 'point'].indexOf(shapes[0]) !== -1) {
13785 Util.mix(defaultCfg, {
13786 showCrosshairs: true
13787 });
13788 }
13789 }
13790
13791 return defaultCfg;
13792 };
13793
13794 _proto._getMaxLength = function _getMaxLength(cfg) {
13795 if (cfg === void 0) {
13796 cfg = {};
13797 }
13798
13799 var _cfg = cfg,
13800 layout = _cfg.layout,
13801 plotRange = _cfg.plotRange;
13802 return layout === 'horizontal' ? plotRange.br.x - plotRange.bl.x : plotRange.bl.y - plotRange.tr.y;
13803 };
13804
13805 _proto.render = function render() {
13806 var self = this;
13807
13808 if (self.tooltip) {
13809 return;
13810 }
13811
13812 var chart = self.chart;
13813 var canvas = chart.get('canvas');
13814 var frontPlot = chart.get('frontPlot').addGroup({
13815 className: 'tooltipContainer',
13816 zIndex: 10
13817 });
13818 var backPlot = chart.get('backPlot').addGroup({
13819 className: 'tooltipContainer'
13820 });
13821 var plotRange = chart.get('plotRange');
13822 var coord = chart.get('coord');
13823
13824 var defaultCfg = self._setCrosshairsCfg();
13825
13826 var cfg = self.cfg;
13827 cfg = Util.deepMix({
13828 plotRange: plotRange,
13829 frontPlot: frontPlot,
13830 backPlot: backPlot,
13831 canvas: canvas,
13832 fixed: coord.transposed || coord.isPolar
13833 }, defaultCfg, cfg);
13834 cfg.maxLength = self._getMaxLength(cfg);
13835 this.cfg = cfg;
13836 var tooltip = new Tooltip(cfg);
13837 self.tooltip = tooltip;
13838 self.bindEvents();
13839 };
13840
13841 _proto.clear = function clear() {
13842 var tooltip = this.tooltip;
13843 tooltip && tooltip.destroy();
13844 this.tooltip = null;
13845 this.prePoint = null;
13846 this._lastActive = null;
13847 this.unBindEvents();
13848 };
13849
13850 _proto._getTooltipMarkerStyle = function _getTooltipMarkerStyle(cfg) {
13851 if (cfg === void 0) {
13852 cfg = {};
13853 }
13854
13855 var _cfg2 = cfg,
13856 type = _cfg2.type,
13857 items = _cfg2.items;
13858 var tooltipCfg = this.cfg;
13859
13860 if (type === 'rect') {
13861 var x;
13862 var y;
13863 var width;
13864 var height;
13865 var chart = this.chart;
13866
13867 var _chart$get = chart.get('plotRange'),
13868 tl = _chart$get.tl,
13869 br = _chart$get.br;
13870
13871 var coord = chart.get('coord');
13872 var firstItem = items[0];
13873 var lastItem = items[items.length - 1];
13874 var intervalWidth = firstItem.width;
13875
13876 if (coord.transposed) {
13877 x = tl.x;
13878 y = lastItem.y - intervalWidth * 0.75;
13879 width = br.x - tl.x;
13880 height = firstItem.y - lastItem.y + 1.5 * intervalWidth;
13881 } else {
13882 x = firstItem.x - intervalWidth * 0.75;
13883 y = tl.y;
13884 width = lastItem.x - firstItem.x + 1.5 * intervalWidth;
13885 height = br.y - tl.y;
13886 }
13887
13888 cfg.style = Util.mix({
13889 x: x,
13890 y: y,
13891 width: width,
13892 height: height,
13893 fill: '#CCD6EC',
13894 opacity: 0.3
13895 }, tooltipCfg.tooltipMarkerStyle);
13896 } else {
13897 cfg.style = Util.mix({
13898 radius: 4,
13899 fill: '#fff',
13900 lineWidth: 2
13901 }, tooltipCfg.tooltipMarkerStyle);
13902 }
13903
13904 return cfg;
13905 };
13906
13907 _proto._setTooltip = function _setTooltip(point, items, tooltipMarkerCfg) {
13908 if (tooltipMarkerCfg === void 0) {
13909 tooltipMarkerCfg = {};
13910 }
13911
13912 var lastActive = this._lastActive;
13913 var tooltip = this.tooltip;
13914 var cfg = this.cfg;
13915 items = _uniqItems(items);
13916 var chart = this.chart;
13917 var coord = chart.get('coord');
13918 var yScale = chart.getYScales()[0];
13919 var snap = cfg.snap;
13920
13921 if (snap === false && yScale.isLinear) {
13922 var invertPoint = coord.invertPoint(point);
13923 var plot = chart.get('plotRange');
13924 var tip;
13925 var pos;
13926
13927 if (Helper.isPointInPlot(point, plot)) {
13928 if (coord.transposed) {
13929 tip = yScale.invert(invertPoint.x);
13930 pos = point.x;
13931 tooltip.setXTipContent(tip);
13932 tooltip.setXTipPosition(pos);
13933 tooltip.setYCrosshairPosition(pos);
13934 } else {
13935 tip = yScale.invert(invertPoint.y);
13936 pos = point.y;
13937 tooltip.setYTipContent(tip);
13938 tooltip.setYTipPosition(pos);
13939 tooltip.setXCrosshairPosition(pos);
13940 }
13941 }
13942 }
13943
13944 if (cfg.onShow) {
13945 cfg.onShow({
13946 x: point.x,
13947 y: point.y,
13948 tooltip: tooltip,
13949 items: items,
13950 tooltipMarkerCfg: tooltipMarkerCfg
13951 });
13952 }
13953
13954 if (isEqual(lastActive, items)) {
13955 if (snap === false && (Util.directionEnabled(cfg.crosshairsType, 'y') || cfg.showYTip)) {
13956 var canvas = this.chart.get('canvas');
13957 canvas.draw();
13958 }
13959
13960 return;
13961 }
13962
13963 this._lastActive = items;
13964 var onChange = cfg.onChange;
13965
13966 if (onChange) {
13967 onChange({
13968 x: point.x,
13969 y: point.y,
13970 tooltip: tooltip,
13971 items: items,
13972 tooltipMarkerCfg: tooltipMarkerCfg
13973 });
13974 }
13975
13976 var first = items[0];
13977 var title = first.title || first.name;
13978 var xTipPosX = first.x;
13979
13980 if (items.length > 1) {
13981 xTipPosX = (items[0].x + items[items.length - 1].x) / 2;
13982 }
13983
13984 tooltip.setContent(title, items, coord.transposed);
13985 tooltip.setPosition(items, point);
13986
13987 if (coord.transposed) {
13988 var yTipPosY = first.y;
13989
13990 if (items.length > 1) {
13991 yTipPosY = (items[0].y + items[items.length - 1].y) / 2;
13992 }
13993
13994 tooltip.setYTipContent(title);
13995 tooltip.setYTipPosition(yTipPosY);
13996 tooltip.setXCrosshairPosition(yTipPosY);
13997
13998 if (snap) {
13999 tooltip.setXTipContent(first.value);
14000 tooltip.setXTipPosition(xTipPosX);
14001 tooltip.setYCrosshairPosition(xTipPosX);
14002 }
14003 } else {
14004 tooltip.setXTipContent(title);
14005 tooltip.setXTipPosition(xTipPosX);
14006 tooltip.setYCrosshairPosition(xTipPosX);
14007
14008 if (snap) {
14009 tooltip.setYTipContent(first.value);
14010 tooltip.setYTipPosition(first.y);
14011 tooltip.setXCrosshairPosition(first.y);
14012 }
14013 }
14014
14015 var markerItems = tooltipMarkerCfg.items;
14016
14017 if (cfg.showTooltipMarker && markerItems.length) {
14018 tooltipMarkerCfg = this._getTooltipMarkerStyle(tooltipMarkerCfg);
14019 tooltip.setMarkers(tooltipMarkerCfg);
14020 } else {
14021 tooltip.clearMarkers();
14022 }
14023
14024 tooltip.show();
14025 };
14026
14027 _proto.showTooltip = function showTooltip(point) {
14028 var self = this;
14029 var chart = self.chart;
14030 var tooltipMarkerType;
14031 var tooltipMarkerItems = [];
14032 var items = [];
14033 var cfg = self.cfg;
14034 var marker;
14035
14036 if (cfg.showItemMarker) {
14037 marker = cfg.itemMarkerStyle;
14038 }
14039
14040 var geoms = chart.get('geoms');
14041 var coord = chart.get('coord');
14042 Util.each(geoms, function (geom) {
14043 if (geom.get('visible')) {
14044 var type = geom.get('type');
14045 var records = geom.getSnapRecords(point);
14046 Util.each(records, function (record) {
14047 if (record.x && record.y) {
14048 var x = record.x,
14049 y = record.y,
14050 _origin = record._origin,
14051 color = record.color;
14052 var tooltipItem = {
14053 x: x,
14054 y: Util.isArray(y) ? y[1] : y,
14055 color: color || Global.defaultColor,
14056 origin: _origin,
14057 name: getTooltipName(geom, _origin),
14058 value: getTooltipValue(geom, _origin),
14059 title: getTooltipTitle(geom, _origin)
14060 };
14061
14062 if (marker) {
14063 tooltipItem.marker = Util.mix({
14064 fill: color || Global.defaultColor
14065 }, marker);
14066 }
14067
14068 items.push(tooltipItem);
14069
14070 if (['line', 'area', 'path'].indexOf(type) !== -1) {
14071 tooltipMarkerType = 'circle';
14072 tooltipMarkerItems.push(tooltipItem);
14073 } else if (type === 'interval' && (coord.type === 'cartesian' || coord.type === 'rect')) {
14074 tooltipMarkerType = 'rect';
14075 tooltipItem.width = geom.getSize(record._origin);
14076 tooltipMarkerItems.push(tooltipItem);
14077 }
14078 }
14079 });
14080 }
14081 });
14082
14083 if (items.length) {
14084 var tooltipMarkerCfg = {
14085 items: tooltipMarkerItems,
14086 type: tooltipMarkerType
14087 };
14088
14089 self._setTooltip(point, items, tooltipMarkerCfg);
14090 } else {
14091 self.hideTooltip();
14092 }
14093 };
14094
14095 _proto.hideTooltip = function hideTooltip() {
14096 var cfg = this.cfg;
14097 this._lastActive = null;
14098 var tooltip = this.tooltip;
14099
14100 if (tooltip) {
14101 tooltip.hide();
14102
14103 if (cfg.onHide) {
14104 cfg.onHide({
14105 tooltip: tooltip
14106 });
14107 }
14108
14109 var canvas = this.chart.get('canvas');
14110 canvas.draw();
14111 }
14112 };
14113
14114 _proto.handleShowEvent = function handleShowEvent(ev) {
14115 var chart = this.chart;
14116 if (!this.enable || chart.get('_closeTooltip')) return;
14117 var plot = chart.get('plotRange');
14118 var point = Util.createEvent(ev, chart);
14119
14120 if (!Helper.isPointInPlot(point, plot) && !this.cfg.alwaysShow) {
14121 // not in chart plot
14122 this.hideTooltip();
14123 return;
14124 }
14125
14126 var lastTimeStamp = this.timeStamp;
14127 var timeStamp = +new Date();
14128
14129 if (timeStamp - lastTimeStamp > 16) {
14130 this.showTooltip(point);
14131 this.timeStamp = timeStamp;
14132 }
14133 };
14134
14135 _proto.handleHideEvent = function handleHideEvent() {
14136 var chart = this.chart;
14137 if (!this.enable || chart.get('_closeTooltip')) return;
14138 this.hideTooltip();
14139 };
14140
14141 _proto.handleDocEvent = function handleDocEvent(ev) {
14142 var chart = this.chart;
14143 if (!this.enable || chart.get('_closeTooltip')) return;
14144 var canvasDom = this.canvasDom;
14145
14146 if (ev.target !== canvasDom) {
14147 this.hideTooltip();
14148 }
14149 };
14150
14151 _proto._handleEvent = function _handleEvent(methodName, method, action) {
14152 var canvasDom = this.canvasDom;
14153 Util.each([].concat(methodName), function (aMethod) {
14154 if (action === 'bind') {
14155 Util.addEventListener(canvasDom, aMethod, method);
14156 } else {
14157 Util.removeEventListener(canvasDom, aMethod, method);
14158 }
14159 });
14160 };
14161
14162 _proto.bindEvents = function bindEvents() {
14163 var cfg = this.cfg;
14164 var triggerOn = cfg.triggerOn,
14165 triggerOff = cfg.triggerOff,
14166 alwaysShow = cfg.alwaysShow;
14167 var showMethod = Util.wrapBehavior(this, 'handleShowEvent');
14168 var hideMethod = Util.wrapBehavior(this, 'handleHideEvent');
14169 triggerOn && this._handleEvent(triggerOn, showMethod, 'bind');
14170 triggerOff && this._handleEvent(triggerOff, hideMethod, 'bind'); // TODO: 当用户点击 canvas 外的事件时 tooltip 消失
14171
14172 if (!alwaysShow) {
14173 var docMethod = Util.wrapBehavior(this, 'handleDocEvent');
14174 Util.isBrowser && Util.addEventListener(document, 'touchstart', docMethod);
14175 }
14176 };
14177
14178 _proto.unBindEvents = function unBindEvents() {
14179 var cfg = this.cfg;
14180 var triggerOn = cfg.triggerOn,
14181 triggerOff = cfg.triggerOff,
14182 alwaysShow = cfg.alwaysShow;
14183 var showMethod = Util.getWrapBehavior(this, 'handleShowEvent');
14184 var hideMethod = Util.getWrapBehavior(this, 'handleHideEvent');
14185 triggerOn && this._handleEvent(triggerOn, showMethod, 'unBind');
14186 triggerOff && this._handleEvent(triggerOff, hideMethod, 'unBind');
14187
14188 if (!alwaysShow) {
14189 var docMethod = Util.getWrapBehavior(this, 'handleDocEvent');
14190 Util.isBrowser && Util.removeEventListener(document, 'touchstart', docMethod);
14191 }
14192 };
14193
14194 return TooltipController;
14195}();
14196
14197module.exports = {
14198 init: function init(chart) {
14199 var tooltipController = new TooltipController({
14200 chart: chart
14201 });
14202 chart.set('tooltipController', tooltipController);
14203
14204 chart.tooltip = function (enable, cfg) {
14205 if (Util.isObject(enable)) {
14206 cfg = enable;
14207 enable = true;
14208 }
14209
14210 tooltipController.enable = enable;
14211
14212 if (cfg) {
14213 tooltipController.cfg = cfg;
14214 }
14215
14216 return this;
14217 };
14218 },
14219 afterGeomDraw: function afterGeomDraw(chart) {
14220 var tooltipController = chart.get('tooltipController');
14221 tooltipController.render();
14222
14223 chart.showTooltip = function (point) {
14224 tooltipController.showTooltip(point);
14225 return this;
14226 };
14227
14228 chart.hideTooltip = function () {
14229 tooltipController.hideTooltip();
14230 return this;
14231 };
14232 },
14233 clearInner: function clearInner(chart) {
14234 var tooltipController = chart.get('tooltipController');
14235 tooltipController.clear();
14236 }
14237};
14238
14239/***/ }),
14240/* 125 */
14241/***/ (function(module, exports, __webpack_require__) {
14242
14243var Util = __webpack_require__(0);
14244
14245var Marker = __webpack_require__(44);
14246
14247var Container = __webpack_require__(45);
14248
14249var TextBox = __webpack_require__(126);
14250
14251var GAP = 4;
14252/**
14253 * TODOList:
14254 * 1. 移除 fixed 参数
14255 */
14256
14257var Tooltip =
14258/*#__PURE__*/
14259function () {
14260 var _proto = Tooltip.prototype;
14261
14262 _proto.getDefaultCfg = function getDefaultCfg() {
14263 return {
14264 /**
14265 * wether show the crosshairs
14266 * @type {Object}
14267 */
14268 showCrosshairs: false,
14269
14270 /**
14271 * the style for crosshairs
14272 * @type {Object}
14273 */
14274 crosshairsStyle: {
14275 stroke: 'rgba(0, 0, 0, 0.25)',
14276 lineWidth: 1
14277 },
14278
14279 /**
14280 * the type of crosshairs, optional value is 'x', 'y' or 'xy', default is 'y'
14281 */
14282 crosshairsType: 'y',
14283
14284 /**
14285 * show or hide the x axis tip
14286 */
14287 showXTip: false,
14288
14289 /**
14290 * show or hide the y axis tip
14291 */
14292 showYTip: false,
14293 xTip: null,
14294 xTipBackground: {
14295 radius: 1,
14296 fill: 'rgba(0, 0, 0, 0.65)',
14297 padding: [3, 5]
14298 },
14299 yTip: null,
14300 yTipBackground: {
14301 radius: 1,
14302 fill: 'rgba(0, 0, 0, 0.65)',
14303 padding: [3, 5]
14304 },
14305
14306 /**
14307 * the style for tooltip container's background
14308 * @type {Object}
14309 */
14310 background: null,
14311
14312 /**
14313 * layout, can be horizontal or vertical
14314 * @type {String}
14315 */
14316 layout: 'horizontal',
14317 offsetX: 0,
14318 offsetY: 0
14319 };
14320 };
14321
14322 function Tooltip(cfg) {
14323 Util.deepMix(this, this.getDefaultCfg(), cfg);
14324 var frontPlot = this.frontPlot,
14325 custom = this.custom;
14326
14327 if (!custom) {
14328 // custom means user do customize
14329 var container = new Container(Util.mix({
14330 parent: frontPlot,
14331 zIndex: 3
14332 }, cfg));
14333 this.container = container;
14334 var fixed = this.fixed,
14335 background = this.background;
14336
14337 if (!fixed) {
14338 this.tooltipArrow = frontPlot.addShape('Polygon', {
14339 className: 'tooltip-arrow',
14340 visible: false,
14341 zIndex: 2,
14342 attrs: Util.mix({
14343 points: []
14344 }, background)
14345 });
14346 }
14347 }
14348
14349 if (this.showXTip) {
14350 var xTipBackground = this.xTipBackground;
14351 var xTipBox = new TextBox({
14352 className: 'xTip',
14353 background: xTipBackground,
14354 visible: false
14355 });
14356 frontPlot.add(xTipBox.container);
14357 this.xTipBox = xTipBox;
14358 }
14359
14360 if (this.showYTip) {
14361 var yTipBackground = this.yTipBackground;
14362 var yTipBox = new TextBox({
14363 className: 'yTip',
14364 background: yTipBackground,
14365 visible: false
14366 });
14367 frontPlot.add(yTipBox.container);
14368 this.yTipBox = yTipBox;
14369 }
14370
14371 if (this.showCrosshairs) {
14372 this._renderCrosshairs();
14373 }
14374
14375 frontPlot.sort();
14376 }
14377
14378 _proto.setContent = function setContent(title, items) {
14379 this.title = title;
14380 this.items = items;
14381
14382 if (!this.custom) {
14383 var container = this.container;
14384 container.setTitle(title);
14385 container.setItems(items);
14386 }
14387 };
14388
14389 _proto.setYTipContent = function setYTipContent(val) {
14390 var yTip = this.yTip;
14391
14392 if (Util.isFunction(yTip)) {
14393 val = yTip(val);
14394 } else {
14395 val = Util.mix({
14396 text: val
14397 }, yTip);
14398 }
14399
14400 this.yTipBox && this.yTipBox.updateContent(val);
14401 };
14402
14403 _proto.setYTipPosition = function setYTipPosition(pos) {
14404 var plotRange = this.plotRange;
14405 var crosshairsShapeX = this.crosshairsShapeX;
14406
14407 if (this.showYTip) {
14408 var yTipBox = this.yTipBox;
14409 var yTipHeight = yTipBox.getHeight();
14410 var yTipWidth = yTipBox.getWidth();
14411 var posX = plotRange.tl.x - yTipWidth;
14412 var posY = pos - yTipHeight / 2;
14413
14414 if (posY <= plotRange.tl.y) {
14415 posY = plotRange.tl.y;
14416 }
14417
14418 if (posY + yTipHeight >= plotRange.br.y) {
14419 posY = plotRange.br.y - yTipHeight;
14420 }
14421
14422 if (posX < 0) {
14423 posX = plotRange.tl.x;
14424 crosshairsShapeX && crosshairsShapeX.attr('x1', plotRange.tl.x + yTipWidth);
14425 }
14426
14427 yTipBox.updatePosition(posX, posY);
14428 }
14429 };
14430
14431 _proto.setXTipContent = function setXTipContent(val) {
14432 var xTip = this.xTip;
14433
14434 if (Util.isFunction(xTip)) {
14435 val = xTip(val);
14436 } else {
14437 val = Util.mix({
14438 text: val
14439 }, xTip);
14440 }
14441
14442 this.xTipBox && this.xTipBox.updateContent(val);
14443 };
14444
14445 _proto.setXTipPosition = function setXTipPosition(pos) {
14446 var showXTip = this.showXTip,
14447 canvas = this.canvas,
14448 plotRange = this.plotRange,
14449 xTipBox = this.xTipBox,
14450 crosshairsShapeY = this.crosshairsShapeY;
14451
14452 if (showXTip) {
14453 // const el = canvas.get('el');
14454 // const canvasHeight = Util.getHeight(el);
14455 var canvasHeight = canvas.get('height');
14456 var xTipWidth = xTipBox.getWidth();
14457 var xTipHeight = xTipBox.getHeight();
14458 var posX = pos - xTipWidth / 2;
14459 var posY = plotRange.br.y;
14460
14461 if (posX <= plotRange.tl.x) {
14462 posX = plotRange.tl.x;
14463 }
14464
14465 if (posX + xTipWidth >= plotRange.tr.x) {
14466 posX = plotRange.tr.x - xTipWidth;
14467 }
14468
14469 if (canvasHeight - posY < xTipHeight) {
14470 posY -= xTipHeight;
14471 }
14472
14473 xTipBox.updatePosition(posX, posY);
14474 crosshairsShapeY && crosshairsShapeY.attr('y1', posY);
14475 }
14476 };
14477
14478 _proto.setXCrosshairPosition = function setXCrosshairPosition(pos) {
14479 this.crosshairsShapeX && this.crosshairsShapeX.moveTo(0, pos);
14480 };
14481
14482 _proto.setYCrosshairPosition = function setYCrosshairPosition(pos) {
14483 this.crosshairsShapeY && this.crosshairsShapeY.moveTo(pos, 0);
14484 };
14485
14486 _proto.setPosition = function setPosition(items) {
14487 var container = this.container,
14488 plotRange = this.plotRange,
14489 offsetX = this.offsetX,
14490 offsetY = this.offsetY,
14491 fixed = this.fixed,
14492 tooltipArrow = this.tooltipArrow;
14493
14494 if (!container) {
14495 return;
14496 }
14497
14498 var containerBBox = container.container.getBBox();
14499 var minX = containerBBox.minX,
14500 minY = containerBBox.minY,
14501 width = containerBBox.width,
14502 height = containerBBox.height;
14503 var tl = plotRange.tl,
14504 tr = plotRange.tr;
14505 var posX = 0;
14506 var posY = tl.y - height - GAP + offsetY;
14507
14508 if (fixed) {
14509 var x = (tl.x + tr.x) / 2;
14510 posX = x - width / 2 + offsetX;
14511 } else {
14512 var _x;
14513
14514 if (items.length > 1) {
14515 _x = (items[0].x + items[items.length - 1].x) / 2;
14516 } else {
14517 _x = items[0].x;
14518 }
14519
14520 posX = _x - width / 2 + offsetX;
14521
14522 if (posX < tl.x) {
14523 posX = tl.x;
14524 }
14525
14526 if (posX + width > tr.x) {
14527 posX = tr.x - width;
14528 }
14529
14530 if (tooltipArrow) {
14531 tooltipArrow.attr('points', [{
14532 x: _x - 3,
14533 y: tl.y - GAP + offsetY
14534 }, {
14535 x: _x + 3,
14536 y: tl.y - GAP + offsetY
14537 }, {
14538 x: _x,
14539 y: tl.y + offsetY
14540 }]);
14541 var backShape = container.backShape;
14542 var radius = Util.parsePadding(backShape.attr('radius'));
14543
14544 if (_x === tl.x) {
14545 radius[3] = 0;
14546 tooltipArrow.attr('points', [{
14547 x: tl.x,
14548 y: tl.y + offsetY
14549 }, {
14550 x: tl.x,
14551 y: tl.y - GAP + offsetY
14552 }, {
14553 x: tl.x + GAP,
14554 y: tl.y - GAP + offsetY
14555 }]);
14556 } else if (_x === tr.x) {
14557 radius[2] = 0;
14558 tooltipArrow.attr('points', [{
14559 x: tr.x,
14560 y: tl.y + offsetY
14561 }, {
14562 x: tr.x - GAP,
14563 y: tl.y - GAP + offsetY
14564 }, {
14565 x: tr.x,
14566 y: tl.y - GAP + offsetY
14567 }]);
14568 }
14569
14570 backShape.attr('radius', radius);
14571 }
14572 }
14573
14574 container.moveTo(posX - minX, posY - minY);
14575 };
14576
14577 _proto.setMarkers = function setMarkers(cfg) {
14578 if (cfg === void 0) {
14579 cfg = {};
14580 }
14581
14582 var self = this;
14583 var _cfg = cfg,
14584 items = _cfg.items,
14585 style = _cfg.style,
14586 type = _cfg.type;
14587
14588 var markerGroup = self._getMarkerGroup(type);
14589
14590 if (type === 'circle') {
14591 for (var i = 0, length = items.length; i < length; i++) {
14592 var item = items[i];
14593 var marker = new Marker({
14594 className: 'tooltip-circle-marker',
14595 attrs: Util.mix({
14596 x: item.x,
14597 y: item.y,
14598 stroke: item.color
14599 }, style)
14600 });
14601 markerGroup.add(marker);
14602 }
14603 } else {
14604 markerGroup.addShape('rect', {
14605 className: 'tooltip-rect-marker',
14606 attrs: style
14607 });
14608 }
14609 };
14610
14611 _proto.clearMarkers = function clearMarkers() {
14612 var markerGroup = this.markerGroup;
14613 markerGroup && markerGroup.clear();
14614 };
14615
14616 _proto.show = function show() {
14617 var crosshairsShapeX = this.crosshairsShapeX;
14618 var crosshairsShapeY = this.crosshairsShapeY;
14619 var markerGroup = this.markerGroup;
14620 var container = this.container;
14621 var tooltipArrow = this.tooltipArrow;
14622 var xTipBox = this.xTipBox;
14623 var yTipBox = this.yTipBox;
14624 var canvas = this.canvas;
14625 crosshairsShapeX && crosshairsShapeX.show();
14626 crosshairsShapeY && crosshairsShapeY.show();
14627 markerGroup && markerGroup.show();
14628 container && container.show();
14629 tooltipArrow && tooltipArrow.show();
14630 xTipBox && xTipBox.show();
14631 yTipBox && yTipBox.show();
14632 canvas.draw();
14633 };
14634
14635 _proto.hide = function hide() {
14636 var crosshairsShapeX = this.crosshairsShapeX;
14637 var crosshairsShapeY = this.crosshairsShapeY;
14638 var markerGroup = this.markerGroup;
14639 var container = this.container;
14640 var tooltipArrow = this.tooltipArrow;
14641 var xTipBox = this.xTipBox;
14642 var yTipBox = this.yTipBox;
14643 crosshairsShapeX && crosshairsShapeX.hide();
14644 crosshairsShapeY && crosshairsShapeY.hide();
14645 markerGroup && markerGroup.hide();
14646 container && container.hide();
14647 tooltipArrow && tooltipArrow.hide();
14648 xTipBox && xTipBox.hide();
14649 yTipBox && yTipBox.hide();
14650 };
14651
14652 _proto.destroy = function destroy() {
14653 var crosshairsShapeX = this.crosshairsShapeX;
14654 var crosshairsShapeY = this.crosshairsShapeY;
14655 var markerGroup = this.markerGroup;
14656 var container = this.container;
14657 var tooltipArrow = this.tooltipArrow;
14658 var xTipBox = this.xTipBox;
14659 var yTipBox = this.yTipBox;
14660 crosshairsShapeX && crosshairsShapeX.remove(true);
14661 crosshairsShapeY && crosshairsShapeY.remove(true);
14662 markerGroup && markerGroup.remove(true);
14663 tooltipArrow && tooltipArrow.remove(true);
14664 container && container.clear();
14665 xTipBox && xTipBox.clear();
14666 yTipBox && yTipBox.clear();
14667 this.destroyed = true;
14668 };
14669
14670 _proto._getMarkerGroup = function _getMarkerGroup(type) {
14671 var markerGroup = this.markerGroup;
14672
14673 if (!markerGroup) {
14674 if (type === 'circle') {
14675 markerGroup = this.frontPlot.addGroup({
14676 zIndex: 1
14677 });
14678 this.frontPlot.sort();
14679 } else {
14680 markerGroup = this.backPlot.addGroup();
14681 }
14682
14683 this.markerGroup = markerGroup;
14684 } else {
14685 markerGroup.clear();
14686 }
14687
14688 return markerGroup;
14689 };
14690
14691 _proto._renderCrosshairs = function _renderCrosshairs() {
14692 var crosshairsType = this.crosshairsType,
14693 crosshairsStyle = this.crosshairsStyle,
14694 frontPlot = this.frontPlot,
14695 plotRange = this.plotRange;
14696 var tl = plotRange.tl,
14697 br = plotRange.br;
14698
14699 if (Util.directionEnabled(crosshairsType, 'x')) {
14700 this.crosshairsShapeX = frontPlot.addShape('Line', {
14701 className: 'tooltip-crosshairs-x',
14702 zIndex: 0,
14703 visible: false,
14704 attrs: Util.mix({
14705 x1: tl.x,
14706 y1: 0,
14707 x2: br.x,
14708 y2: 0
14709 }, crosshairsStyle)
14710 });
14711 }
14712
14713 if (Util.directionEnabled(crosshairsType, 'y')) {
14714 this.crosshairsShapeY = frontPlot.addShape('Line', {
14715 className: 'tooltip-crosshairs-y',
14716 zIndex: 0,
14717 visible: false,
14718 attrs: Util.mix({
14719 x1: 0,
14720 y1: br.y,
14721 x2: 0,
14722 y2: tl.y
14723 }, crosshairsStyle)
14724 });
14725 }
14726 };
14727
14728 return Tooltip;
14729}();
14730
14731module.exports = Tooltip;
14732
14733/***/ }),
14734/* 126 */
14735/***/ (function(module, exports, __webpack_require__) {
14736
14737var Util = __webpack_require__(0);
14738
14739var _require = __webpack_require__(3),
14740 Group = _require.Group;
14741
14742var TextBox =
14743/*#__PURE__*/
14744function () {
14745 var _proto = TextBox.prototype;
14746
14747 _proto.getDefaultCfg = function getDefaultCfg() {
14748 return {
14749 x: 0,
14750 y: 0,
14751 content: '',
14752 textStyle: {
14753 fontSize: 12,
14754 fill: '#fff',
14755 textAlign: 'center',
14756 textBaseline: 'middle'
14757 },
14758 background: {
14759 radius: 1,
14760 fill: 'rgba(0, 0, 0, 0.65)',
14761 padding: [3, 5]
14762 },
14763 width: 0,
14764 height: 0,
14765 className: ''
14766 };
14767 };
14768
14769 function TextBox(cfg) {
14770 Util.deepMix(this, this.getDefaultCfg(), cfg);
14771
14772 this._init();
14773
14774 var content = this.content,
14775 x = this.x,
14776 y = this.y;
14777
14778 if (!Util.isNil(content)) {
14779 this.updateContent(content);
14780 }
14781
14782 this.updatePosition(x, y);
14783 }
14784
14785 _proto._init = function _init() {
14786 var content = this.content,
14787 textStyle = this.textStyle,
14788 background = this.background,
14789 className = this.className,
14790 visible = this.visible;
14791 var container = new Group({
14792 className: className,
14793 zIndex: 0,
14794 visible: visible
14795 });
14796 var text = container.addShape('Text', {
14797 className: className + '-text',
14798 zIndex: 1,
14799 attrs: Util.mix({
14800 text: content,
14801 x: 0,
14802 y: 0
14803 }, textStyle)
14804 });
14805 var backgroundShape = container.addShape('Rect', {
14806 className: className + '-bg',
14807 zIndex: -1,
14808 attrs: Util.mix({
14809 x: 0,
14810 y: 0,
14811 width: 0,
14812 height: 0
14813 }, background)
14814 });
14815 container.sort();
14816 this.container = container;
14817 this.textShape = text;
14818 this.backgroundShape = backgroundShape;
14819 };
14820
14821 _proto._getBBox = function _getBBox() {
14822 var textShape = this.textShape;
14823 var background = this.background;
14824 var textBBox = textShape.getBBox();
14825 var padding = Util.parsePadding(background.padding);
14826 var width = textBBox.width + padding[1] + padding[3];
14827 var height = textBBox.height + padding[0] + padding[2];
14828 var x = textBBox.minX - padding[3];
14829 var y = textBBox.minY - padding[0];
14830 return {
14831 x: x,
14832 y: y,
14833 width: width,
14834 height: height
14835 };
14836 };
14837
14838 _proto.updateContent = function updateContent(text) {
14839 var textShape = this.textShape,
14840 backgroundShape = this.backgroundShape;
14841
14842 if (!Util.isNil(text)) {
14843 if (!Util.isObject(text)) {
14844 text = {
14845 text: text
14846 };
14847 }
14848
14849 textShape.attr(text); // update box shape
14850
14851 var _this$_getBBox = this._getBBox(),
14852 x = _this$_getBBox.x,
14853 y = _this$_getBBox.y,
14854 tipWidth = _this$_getBBox.width,
14855 tipHeight = _this$_getBBox.height;
14856
14857 var width = this.width || tipWidth;
14858 var height = this.height || tipHeight;
14859 backgroundShape.attr({
14860 x: x,
14861 y: y,
14862 width: width,
14863 height: height
14864 });
14865 this._width = width;
14866 this._height = height;
14867 this.content = text.text;
14868 }
14869 };
14870
14871 _proto.updatePosition = function updatePosition(x, y) {
14872 var container = this.container;
14873
14874 var _this$_getBBox2 = this._getBBox(),
14875 xMin = _this$_getBBox2.x,
14876 yMin = _this$_getBBox2.y;
14877
14878 container.moveTo(x - xMin, y - yMin);
14879 this.x = x - xMin;
14880 this.y = y - yMin;
14881 };
14882
14883 _proto.getWidth = function getWidth() {
14884 return this._width;
14885 };
14886
14887 _proto.getHeight = function getHeight() {
14888 return this._height;
14889 };
14890
14891 _proto.show = function show() {
14892 this.container.show();
14893 };
14894
14895 _proto.hide = function hide() {
14896 this.container.hide();
14897 };
14898
14899 _proto.clear = function clear() {
14900 var container = this.container;
14901 container.clear();
14902 container.remove(true);
14903 this.container = null;
14904 this.textShape = null;
14905 this.backgroundShape = null;
14906 };
14907
14908 return TextBox;
14909}();
14910
14911module.exports = TextBox;
14912
14913/***/ }),
14914/* 127 */
14915/***/ (function(module, exports, __webpack_require__) {
14916
14917var Util = __webpack_require__(0);
14918
14919var Guide = __webpack_require__(8);
14920
14921var Global = __webpack_require__(1); // register the default configuration for Guide
14922
14923
14924Global.guide = Util.deepMix({
14925 line: {
14926 style: {
14927 stroke: '#a3a3a3',
14928 lineWidth: 1
14929 },
14930 top: true
14931 },
14932 text: {
14933 style: {
14934 fill: '#787878',
14935 textAlign: 'center',
14936 textBaseline: 'middle'
14937 },
14938 offsetX: 0,
14939 offsetY: 0,
14940 top: true
14941 },
14942 rect: {
14943 style: {
14944 fill: '#fafafa'
14945 },
14946 top: false
14947 },
14948 arc: {
14949 style: {
14950 stroke: '#a3a3a3'
14951 },
14952 top: true
14953 },
14954 html: {
14955 offsetX: 0,
14956 offsetY: 0,
14957 alignX: 'center',
14958 alignY: 'middle'
14959 },
14960 tag: {
14961 top: true,
14962 offsetX: 0,
14963 offsetY: 0,
14964 side: 4,
14965 background: {
14966 padding: 5,
14967 radius: 2,
14968 fill: '#1890FF'
14969 },
14970 textStyle: {
14971 fontSize: 12,
14972 fill: '#fff',
14973 textAlign: 'center',
14974 textBaseline: 'middle'
14975 }
14976 },
14977 point: {
14978 top: true,
14979 offsetX: 0,
14980 offsetY: 0,
14981 style: {
14982 fill: '#fff',
14983 r: 3,
14984 lineWidth: 2,
14985 stroke: '#1890ff'
14986 }
14987 }
14988}, Global.guide || {});
14989
14990var GuideController =
14991/*#__PURE__*/
14992function () {
14993 function GuideController(cfg) {
14994 this.guides = [];
14995 this.xScale = null;
14996 this.yScales = null;
14997 this.guideShapes = [];
14998 Util.mix(this, cfg);
14999 }
15000
15001 var _proto = GuideController.prototype;
15002
15003 _proto._toString = function _toString(position) {
15004 if (Util.isFunction(position)) {
15005 position = position(this.xScale, this.yScales);
15006 }
15007
15008 position = position.toString();
15009 return position;
15010 };
15011
15012 _proto._getId = function _getId(shape, guide) {
15013 var id = guide.id;
15014
15015 if (!id) {
15016 var type = guide.type;
15017
15018 if (type === 'arc' || type === 'line' || type === 'rect') {
15019 id = this._toString(guide.start) + '-' + this._toString(guide.end);
15020 } else {
15021 id = this._toString(guide.position);
15022 }
15023 }
15024
15025 return id;
15026 };
15027
15028 _proto.paint = function paint(coord) {
15029 var self = this;
15030 var chart = self.chart,
15031 guides = self.guides,
15032 xScale = self.xScale,
15033 yScales = self.yScales;
15034 var guideShapes = [];
15035 Util.each(guides, function (guide, idx) {
15036 guide.xScale = xScale;
15037 guide.yScales = yScales;
15038 var container;
15039
15040 if (guide.type === 'regionFilter') {
15041 // TODO: RegionFilter support animation
15042 guide.chart = chart;
15043 } else {
15044 container = guide.top ? self.frontPlot : self.backPlot;
15045 }
15046
15047 guide.coord = coord;
15048 guide.container = container;
15049 guide.canvas = chart.get('canvas');
15050 var shape = guide.render(coord, container);
15051
15052 if (shape) {
15053 var id = self._getId(shape, guide);
15054
15055 [].concat(shape).forEach(function (s) {
15056 s._id = s.get('className') + '-' + id;
15057 s.set('index', idx);
15058 guideShapes.push(s);
15059 });
15060 }
15061 });
15062 self.guideShapes = guideShapes;
15063 };
15064
15065 _proto.clear = function clear() {
15066 this.reset();
15067 this.guides = [];
15068 return this;
15069 };
15070
15071 _proto.reset = function reset() {
15072 var guides = this.guides;
15073 Util.each(guides, function (guide) {
15074 guide.remove();
15075 });
15076 };
15077
15078 _proto._createGuide = function _createGuide(type, cfg) {
15079 var ClassName = Util.upperFirst(type);
15080 var guide = new Guide[ClassName](Util.deepMix({}, Global.guide[type], cfg));
15081 this.guides.push(guide);
15082 return guide;
15083 };
15084
15085 _proto.line = function line(cfg) {
15086 if (cfg === void 0) {
15087 cfg = {};
15088 }
15089
15090 return this._createGuide('line', cfg);
15091 };
15092
15093 _proto.text = function text(cfg) {
15094 if (cfg === void 0) {
15095 cfg = {};
15096 }
15097
15098 return this._createGuide('text', cfg);
15099 };
15100
15101 _proto.arc = function arc(cfg) {
15102 if (cfg === void 0) {
15103 cfg = {};
15104 }
15105
15106 return this._createGuide('arc', cfg);
15107 };
15108
15109 _proto.html = function html(cfg) {
15110 if (cfg === void 0) {
15111 cfg = {};
15112 }
15113
15114 return this._createGuide('html', cfg);
15115 };
15116
15117 _proto.rect = function rect(cfg) {
15118 if (cfg === void 0) {
15119 cfg = {};
15120 }
15121
15122 return this._createGuide('rect', cfg);
15123 };
15124
15125 _proto.tag = function tag(cfg) {
15126 if (cfg === void 0) {
15127 cfg = {};
15128 }
15129
15130 return this._createGuide('tag', cfg);
15131 };
15132
15133 _proto.point = function point(cfg) {
15134 if (cfg === void 0) {
15135 cfg = {};
15136 }
15137
15138 return this._createGuide('point', cfg);
15139 };
15140
15141 _proto.regionFilter = function regionFilter(cfg) {
15142 if (cfg === void 0) {
15143 cfg = {};
15144 }
15145
15146 return this._createGuide('regionFilter', cfg);
15147 };
15148
15149 return GuideController;
15150}();
15151
15152module.exports = {
15153 init: function init(chart) {
15154 var guideController = new GuideController({
15155 frontPlot: chart.get('frontPlot').addGroup({
15156 zIndex: 20,
15157 className: 'guideContainer'
15158 }),
15159 backPlot: chart.get('backPlot').addGroup({
15160 className: 'guideContainer'
15161 })
15162 });
15163 chart.set('guideController', guideController);
15164 /**
15165 * 为图表添加 guide
15166 * @return {GuideController} 返回 guide 控制器
15167 */
15168
15169 chart.guide = function () {
15170 return guideController;
15171 };
15172 },
15173 afterGeomDraw: function afterGeomDraw(chart) {
15174 var guideController = chart.get('guideController');
15175
15176 if (!guideController.guides.length) {
15177 return;
15178 }
15179
15180 var xScale = chart.getXScale();
15181 var yScales = chart.getYScales();
15182 var coord = chart.get('coord');
15183 guideController.xScale = xScale;
15184 guideController.yScales = yScales;
15185 guideController.chart = chart; // for regionFilter
15186
15187 guideController.paint(coord);
15188 },
15189 clear: function clear(chart) {
15190 chart.get('guideController').clear();
15191 },
15192 repaint: function repaint(chart) {
15193 chart.get('guideController').reset();
15194 }
15195};
15196
15197/***/ }),
15198/* 128 */
15199/***/ (function(module, exports, __webpack_require__) {
15200
15201var Util = __webpack_require__(0);
15202
15203var List = __webpack_require__(45);
15204
15205var Global = __webpack_require__(1);
15206
15207var LEGEND_GAP = 12;
15208var MARKER_SIZE = 3;
15209var DEFAULT_CFG = {
15210 itemMarginBottom: 12,
15211 itemGap: 10,
15212 showTitle: false,
15213 titleStyle: {
15214 fontSize: 12,
15215 fill: '#808080',
15216 textAlign: 'start',
15217 textBaseline: 'top'
15218 },
15219 nameStyle: {
15220 fill: '#808080',
15221 fontSize: 12,
15222 textAlign: 'start',
15223 textBaseline: 'middle'
15224 },
15225 valueStyle: {
15226 fill: '#000000',
15227 fontSize: 12,
15228 textAlign: 'start',
15229 textBaseline: 'middle'
15230 },
15231 unCheckStyle: {
15232 fill: '#bfbfbf'
15233 },
15234 itemWidth: 'auto',
15235 wordSpace: 6,
15236 selectedMode: 'multiple' // 'multiple' or 'single'
15237
15238}; // Register the default configuration for Legend
15239
15240Global.legend = Util.deepMix({
15241 common: DEFAULT_CFG,
15242 // common legend configuration
15243 right: Util.mix({
15244 position: 'right',
15245 layout: 'vertical'
15246 }, DEFAULT_CFG),
15247 left: Util.mix({
15248 position: 'left',
15249 layout: 'vertical'
15250 }, DEFAULT_CFG),
15251 top: Util.mix({
15252 position: 'top',
15253 layout: 'horizontal'
15254 }, DEFAULT_CFG),
15255 bottom: Util.mix({
15256 position: 'bottom',
15257 layout: 'horizontal'
15258 }, DEFAULT_CFG)
15259}, Global.legend || {});
15260
15261function getPaddingByPos(pos, appendPadding) {
15262 var padding = 0;
15263 appendPadding = Util.parsePadding(appendPadding);
15264
15265 switch (pos) {
15266 case 'top':
15267 padding = appendPadding[0];
15268 break;
15269
15270 case 'right':
15271 padding = appendPadding[1];
15272 break;
15273
15274 case 'bottom':
15275 padding = appendPadding[2];
15276 break;
15277
15278 case 'left':
15279 padding = appendPadding[3];
15280 break;
15281
15282 default:
15283 break;
15284 }
15285
15286 return padding;
15287}
15288
15289var LegendController =
15290/*#__PURE__*/
15291function () {
15292 function LegendController(cfg) {
15293 this.legendCfg = {};
15294 this.enable = true;
15295 this.position = 'top';
15296 Util.mix(this, cfg);
15297 var chart = this.chart;
15298 this.canvasDom = chart.get('canvas').get('el');
15299 this.clear();
15300 }
15301
15302 var _proto = LegendController.prototype;
15303
15304 _proto.addLegend = function addLegend(scale, items, filterVals) {
15305 var self = this;
15306 var legendCfg = self.legendCfg;
15307 var field = scale.field;
15308 var fieldCfg = legendCfg[field];
15309
15310 if (fieldCfg === false) {
15311 return null;
15312 }
15313
15314 if (fieldCfg && fieldCfg.custom) {
15315 self.addCustomLegend(field);
15316 } else {
15317 var position = legendCfg.position || self.position;
15318
15319 if (fieldCfg && fieldCfg.position) {
15320 position = fieldCfg.position;
15321 }
15322
15323 if (scale.isCategory) {
15324 self._addCategoryLegend(scale, items, position, filterVals);
15325 }
15326 }
15327 };
15328
15329 _proto.addCustomLegend = function addCustomLegend(field) {
15330 var self = this;
15331 var legendCfg = self.legendCfg;
15332
15333 if (field && legendCfg[field]) {
15334 legendCfg = legendCfg[field];
15335 }
15336
15337 var position = legendCfg.position || self.position;
15338 var legends = self.legends;
15339 legends[position] = legends[position] || [];
15340 var items = legendCfg.items;
15341
15342 if (!items) {
15343 return null;
15344 }
15345
15346 var container = self.container;
15347 Util.each(items, function (item) {
15348 if (!Util.isPlainObject(item.marker)) {
15349 item.marker = {
15350 symbol: item.marker || 'circle',
15351 fill: item.fill,
15352 radius: MARKER_SIZE
15353 };
15354 } else {
15355 item.marker.radius = item.marker.radius || MARKER_SIZE;
15356 }
15357
15358 item.checked = Util.isNil(item.checked) ? true : item.checked;
15359 item.name = item.name || item.value;
15360 });
15361 var legend = new List(Util.deepMix({}, Global.legend[position], legendCfg, {
15362 maxLength: self._getMaxLength(position),
15363 items: items,
15364 parent: container
15365 }));
15366 legends[position].push(legend);
15367 };
15368
15369 _proto.clear = function clear() {
15370 var legends = this.legends;
15371 Util.each(legends, function (legendItems) {
15372 Util.each(legendItems, function (legend) {
15373 legend.clear();
15374 });
15375 });
15376 this.legends = {};
15377 this.unBindEvents();
15378 };
15379
15380 _proto._isFiltered = function _isFiltered(scale, values, value) {
15381 var rst = false;
15382 Util.each(values, function (val) {
15383 rst = rst || scale.getText(val) === scale.getText(value);
15384
15385 if (rst) {
15386 return false;
15387 }
15388 });
15389 return rst;
15390 };
15391
15392 _proto._getMaxLength = function _getMaxLength(position) {
15393 var chart = this.chart;
15394 var appendPadding = Util.parsePadding(chart.get('appendPadding'));
15395 return position === 'right' || position === 'left' ? chart.get('height') - (appendPadding[0] + appendPadding[2]) : chart.get('width') - (appendPadding[1] + appendPadding[3]);
15396 };
15397
15398 _proto._addCategoryLegend = function _addCategoryLegend(scale, items, position, filterVals) {
15399 var self = this;
15400 var legendCfg = self.legendCfg,
15401 legends = self.legends,
15402 container = self.container,
15403 chart = self.chart;
15404 var field = scale.field;
15405 legends[position] = legends[position] || [];
15406 var symbol = 'circle';
15407
15408 if (legendCfg[field] && legendCfg[field].marker) {
15409 symbol = legendCfg[field].marker;
15410 } else if (legendCfg.marker) {
15411 symbol = legendCfg.marker;
15412 }
15413
15414 Util.each(items, function (item) {
15415 if (Util.isPlainObject(symbol)) {
15416 Util.mix(item.marker, symbol);
15417 } else {
15418 item.marker.symbol = symbol;
15419 }
15420
15421 if (filterVals) {
15422 item.checked = self._isFiltered(scale, filterVals, item.dataValue);
15423 }
15424 });
15425 var legendItems = chart.get('legendItems');
15426 legendItems[field] = items;
15427 var lastCfg = Util.deepMix({}, Global.legend[position], legendCfg[field] || legendCfg, {
15428 maxLength: self._getMaxLength(position),
15429 items: items,
15430 field: field,
15431 filterVals: filterVals,
15432 parent: container
15433 });
15434
15435 if (lastCfg.showTitle) {
15436 Util.deepMix(lastCfg, {
15437 title: scale.alias || scale.field
15438 });
15439 }
15440
15441 var legend = new List(lastCfg);
15442 legends[position].push(legend);
15443 return legend;
15444 };
15445
15446 _proto._alignLegend = function _alignLegend(legend, pre, position) {
15447 var self = this;
15448 var _self$plotRange = self.plotRange,
15449 tl = _self$plotRange.tl,
15450 bl = _self$plotRange.bl;
15451 var chart = self.chart;
15452 var offsetX = legend.offsetX || 0;
15453 var offsetY = legend.offsetY || 0;
15454 var chartWidth = chart.get('width');
15455 var chartHeight = chart.get('height');
15456 var appendPadding = Util.parsePadding(chart.get('appendPadding'));
15457 var legendHeight = legend.getHeight();
15458 var legendWidth = legend.getWidth();
15459 var x = 0;
15460 var y = 0;
15461
15462 if (position === 'left' || position === 'right') {
15463 var verticalAlign = legend.verticalAlign || 'middle';
15464 var height = Math.abs(tl.y - bl.y);
15465 x = position === 'left' ? appendPadding[3] : chartWidth - legendWidth - appendPadding[1];
15466 y = (height - legendHeight) / 2 + tl.y;
15467
15468 if (verticalAlign === 'top') {
15469 y = tl.y;
15470 } else if (verticalAlign === 'bottom') {
15471 y = bl.y - legendHeight;
15472 }
15473
15474 if (pre) {
15475 y = pre.get('y') - legendHeight - LEGEND_GAP;
15476 }
15477 } else {
15478 var align = legend.align || 'left';
15479 x = appendPadding[3];
15480
15481 if (align === 'center') {
15482 x = chartWidth / 2 - legendWidth / 2;
15483 } else if (align === 'right') {
15484 x = chartWidth - (legendWidth + appendPadding[1]);
15485 }
15486
15487 y = position === 'top' ? appendPadding[0] + Math.abs(legend.container.getBBox().minY) : chartHeight - legendHeight;
15488
15489 if (pre) {
15490 var preWidth = pre.getWidth();
15491 x = pre.x + preWidth + LEGEND_GAP;
15492 }
15493 }
15494
15495 if (position === 'bottom' && offsetY > 0) {
15496 offsetY = 0;
15497 }
15498
15499 if (position === 'right' && offsetX > 0) {
15500 offsetX = 0;
15501 }
15502
15503 legend.moveTo(x + offsetX, y + offsetY);
15504 };
15505
15506 _proto.alignLegends = function alignLegends() {
15507 var self = this;
15508 var legends = self.legends;
15509 Util.each(legends, function (legendItems, position) {
15510 Util.each(legendItems, function (legend, index) {
15511 var pre = legendItems[index - 1];
15512
15513 self._alignLegend(legend, pre, position);
15514 });
15515 });
15516 return self;
15517 };
15518
15519 _proto.handleEvent = function handleEvent(ev) {
15520 var self = this;
15521
15522 function findItem(x, y) {
15523 var result = null;
15524 var legends = self.legends;
15525 Util.each(legends, function (legendItems) {
15526 Util.each(legendItems, function (legend) {
15527 var itemsGroup = legend.itemsGroup,
15528 legendHitBoxes = legend.legendHitBoxes;
15529 var children = itemsGroup.get('children');
15530
15531 if (children.length) {
15532 var legendPosX = legend.x;
15533 var legendPosY = legend.y;
15534 Util.each(legendHitBoxes, function (box, index) {
15535 if (x >= box.x + legendPosX && x <= box.x + box.width + legendPosX && y >= box.y + legendPosY && y <= box.height + box.y + legendPosY) {
15536 // inbox
15537 result = {
15538 clickedItem: children[index],
15539 clickedLegend: legend
15540 };
15541 return false;
15542 }
15543 });
15544 }
15545 });
15546 });
15547 return result;
15548 }
15549
15550 var chart = self.chart;
15551
15552 var _Util$createEvent = Util.createEvent(ev, chart),
15553 x = _Util$createEvent.x,
15554 y = _Util$createEvent.y;
15555
15556 var clicked = findItem(x, y);
15557
15558 if (clicked && clicked.clickedLegend.clickable !== false) {
15559 var clickedItem = clicked.clickedItem,
15560 clickedLegend = clicked.clickedLegend;
15561
15562 if (clickedLegend.onClick) {
15563 ev.clickedItem = clickedItem;
15564 clickedLegend.onClick(ev);
15565 } else if (!clickedLegend.custom) {
15566 var checked = clickedItem.get('checked');
15567 var value = clickedItem.get('dataValue');
15568 var filterVals = clickedLegend.filterVals,
15569 field = clickedLegend.field,
15570 selectedMode = clickedLegend.selectedMode;
15571 var isSingeSelected = selectedMode === 'single';
15572
15573 if (isSingeSelected) {
15574 chart.filter(field, function (val) {
15575 return val === value;
15576 });
15577 } else {
15578 if (!checked) {
15579 filterVals.push(value);
15580 } else {
15581 Util.Array.remove(filterVals, value);
15582 }
15583
15584 chart.filter(field, function (val) {
15585 return filterVals.indexOf(val) !== -1;
15586 });
15587 }
15588
15589 chart.repaint();
15590 }
15591 }
15592 };
15593
15594 _proto.bindEvents = function bindEvents() {
15595 var legendCfg = this.legendCfg;
15596 var triggerOn = legendCfg.triggerOn || 'touchstart';
15597 var method = Util.wrapBehavior(this, 'handleEvent');
15598 Util.addEventListener(this.canvasDom, triggerOn, method);
15599 };
15600
15601 _proto.unBindEvents = function unBindEvents() {
15602 var legendCfg = this.legendCfg;
15603 var triggerOn = legendCfg.triggerOn || 'touchstart';
15604 var method = Util.getWrapBehavior(this, 'handleEvent');
15605 Util.removeEventListener(this.canvasDom, triggerOn, method);
15606 };
15607
15608 return LegendController;
15609}();
15610
15611module.exports = {
15612 init: function init(chart) {
15613 var legendController = new LegendController({
15614 container: chart.get('backPlot'),
15615 plotRange: chart.get('plotRange'),
15616 chart: chart
15617 });
15618 chart.set('legendController', legendController);
15619
15620 chart.legend = function (field, cfg) {
15621 var legendCfg = legendController.legendCfg;
15622 legendController.enable = true;
15623
15624 if (Util.isBoolean(field)) {
15625 legendController.enable = field;
15626 legendCfg = cfg || {};
15627 } else if (Util.isObject(field)) {
15628 legendCfg = field;
15629 } else {
15630 legendCfg[field] = cfg;
15631 }
15632
15633 legendController.legendCfg = legendCfg;
15634 return this;
15635 };
15636 },
15637 beforeGeomDraw: function beforeGeomDraw(chart) {
15638 var legendController = chart.get('legendController');
15639 if (!legendController.enable) return null; // legend is not displayed
15640
15641 var legendCfg = legendController.legendCfg;
15642
15643 if (legendCfg && legendCfg.custom) {
15644 legendController.addCustomLegend();
15645 } else {
15646 var legendItems = chart.getLegendItems();
15647 var scales = chart.get('scales');
15648 var filters = chart.get('filters');
15649 Util.each(legendItems, function (items, field) {
15650 var scale = scales[field];
15651 var values = scale.values;
15652 var filterVals;
15653
15654 if (filters && filters[field]) {
15655 filterVals = values.filter(filters[field]);
15656 } else {
15657 filterVals = values.slice(0);
15658 }
15659
15660 legendController.addLegend(scale, items, filterVals);
15661 });
15662 }
15663
15664 if (legendCfg && legendCfg.clickable !== false) {
15665 legendController.bindEvents();
15666 }
15667
15668 var legends = legendController.legends;
15669 var legendRange = {
15670 top: 0,
15671 right: 0,
15672 bottom: 0,
15673 left: 0
15674 };
15675 Util.each(legends, function (legendItems, position) {
15676 var padding = 0;
15677 Util.each(legendItems, function (legend) {
15678 var width = legend.getWidth();
15679 var height = legend.getHeight();
15680
15681 if (position === 'top' || position === 'bottom') {
15682 padding = Math.max(padding, height);
15683
15684 if (legend.offsetY > 0) {
15685 padding += legend.offsetY;
15686 }
15687 } else {
15688 padding = Math.max(padding, width);
15689
15690 if (legend.offsetX > 0) {
15691 padding += legend.offsetX;
15692 }
15693 }
15694 });
15695 legendRange[position] = padding + getPaddingByPos(position, chart.get('appendPadding'));
15696 });
15697 chart.set('legendRange', legendRange);
15698 },
15699 afterGeomDraw: function afterGeomDraw(chart) {
15700 var legendController = chart.get('legendController');
15701 legendController.alignLegends();
15702 },
15703 clearInner: function clearInner(chart) {
15704 var legendController = chart.get('legendController');
15705 legendController.clear();
15706 chart.set('legendRange', null);
15707 }
15708};
15709
15710/***/ }),
15711/* 129 */
15712/***/ (function(module, exports, __webpack_require__) {
15713
15714/**
15715 * Handle the detail animations
15716 * @author sima.zhang1990@gmail.com
15717 */
15718var Util = __webpack_require__(0);
15719
15720var Element = __webpack_require__(26);
15721
15722var Timeline = __webpack_require__(130);
15723
15724var Animator = __webpack_require__(131);
15725
15726var Animate = __webpack_require__(46);
15727
15728var ShapeAction = __webpack_require__(133);
15729
15730var GroupAction = __webpack_require__(134);
15731
15732var Chart = __webpack_require__(11);
15733
15734var timeline;
15735
15736Element.prototype.animate = function () {
15737 var attrs = Util.mix({}, this.get('attrs'));
15738 return new Animator(this, attrs, timeline);
15739};
15740
15741Chart.prototype.animate = function (cfg) {
15742 this.set('animate', cfg);
15743 return this;
15744};
15745
15746Animate.Action = ShapeAction;
15747Animate.defaultCfg = {
15748 interval: {
15749 enter: function enter(coord) {
15750 if (coord.isPolar && coord.transposed) {
15751 // for pie chart
15752 return function (shape) {
15753 shape.set('zIndex', -1);
15754 var container = shape.get('parent');
15755 container.sort();
15756 };
15757 }
15758
15759 return ShapeAction.fadeIn;
15760 }
15761 },
15762 area: {
15763 enter: function enter(coord) {
15764 if (coord.isPolar) return null;
15765 return ShapeAction.fadeIn;
15766 }
15767 },
15768 line: {
15769 enter: function enter(coord) {
15770 if (coord.isPolar) return null;
15771 return ShapeAction.fadeIn;
15772 }
15773 },
15774 path: {
15775 enter: function enter(coord) {
15776 if (coord.isPolar) return null;
15777 return ShapeAction.fadeIn;
15778 }
15779 }
15780};
15781var GROUP_ANIMATION = {
15782 line: function line(coord) {
15783 if (coord.isPolar) {
15784 return GroupAction.groupScaleInXY;
15785 }
15786
15787 return GroupAction.groupWaveIn;
15788 },
15789 area: function area(coord) {
15790 if (coord.isPolar) {
15791 return GroupAction.groupScaleInXY;
15792 }
15793
15794 return GroupAction.groupWaveIn;
15795 },
15796 path: function path(coord) {
15797 if (coord.isPolar) {
15798 return GroupAction.groupScaleInXY;
15799 }
15800
15801 return GroupAction.groupWaveIn;
15802 },
15803 point: function point() {
15804 return GroupAction.shapesScaleInXY;
15805 },
15806 interval: function interval(coord) {
15807 var result;
15808
15809 if (coord.isPolar) {
15810 // polar coodinate
15811 result = GroupAction.groupScaleInXY;
15812
15813 if (coord.transposed) {
15814 // pie chart
15815 result = GroupAction.groupWaveIn;
15816 }
15817 } else {
15818 result = coord.transposed ? GroupAction.groupScaleInX : GroupAction.groupScaleInY;
15819 }
15820
15821 return result;
15822 },
15823 schema: function schema() {
15824 return GroupAction.groupWaveIn;
15825 }
15826};
15827
15828function diff(fromAttrs, toAttrs) {
15829 var endState = {};
15830
15831 for (var k in toAttrs) {
15832 if (Util.isNumber(fromAttrs[k]) && fromAttrs[k] !== toAttrs[k]) {
15833 endState[k] = toAttrs[k];
15834 } else if (Util.isArray(fromAttrs[k]) && JSON.stringify(fromAttrs[k]) !== JSON.stringify(toAttrs[k])) {
15835 endState[k] = toAttrs[k];
15836 }
15837 }
15838
15839 return endState;
15840} // Add a unique id identifier to each shape
15841
15842
15843function _getShapeId(geom, dataObj, geomIdx) {
15844 var type = geom.get('type');
15845 var id = 'geom' + geomIdx + '-' + type;
15846 var xScale = geom.getXScale();
15847 var yScale = geom.getYScale();
15848 var xField = xScale.field || 'x';
15849 var yField = yScale.field || 'y';
15850 var yVal = dataObj[yField];
15851 var xVal;
15852
15853 if (xScale.isIdentity) {
15854 xVal = xScale.value;
15855 } else {
15856 xVal = dataObj[xField];
15857 }
15858
15859 if (type === 'interval' || type === 'schema') {
15860 id += '-' + xVal;
15861 } else if (type === 'line' || type === 'area' || type === 'path') {
15862 id += '-' + type;
15863 } else {
15864 id += xScale.isCategory ? '-' + xVal : '-' + xVal + '-' + yVal;
15865 }
15866
15867 var groupScales = geom._getGroupScales();
15868
15869 Util.each(groupScales, function (groupScale) {
15870 var field = groupScale.field;
15871
15872 if (groupScale.type !== 'identity') {
15873 id += '-' + dataObj[field];
15874 }
15875 });
15876 return id;
15877} // get geometry's shapes
15878
15879
15880function getShapes(geoms, chart, coord) {
15881 var shapes = [];
15882 Util.each(geoms, function (geom, geomIdx) {
15883 var geomContainer = geom.get('container');
15884 var geomShapes = geomContainer.get('children');
15885 var type = geom.get('type');
15886 var animateCfg = Util.isNil(geom.get('animateCfg')) ? _getAnimateCfgByShapeType(type, chart) : geom.get('animateCfg');
15887
15888 if (animateCfg !== false) {
15889 Util.each(geomShapes, function (shape, index) {
15890 if (shape.get('className') === type) {
15891 shape._id = _getShapeId(geom, shape.get('origin')._origin, geomIdx);
15892 shape.set('coord', coord);
15893 shape.set('animateCfg', animateCfg);
15894 shape.set('index', index);
15895 shapes.push(shape);
15896 }
15897 });
15898 }
15899
15900 geom.set('shapes', geomShapes);
15901 });
15902 return shapes;
15903}
15904
15905function cache(shapes) {
15906 var rst = {};
15907
15908 for (var i = 0, len = shapes.length; i < len; i++) {
15909 var shape = shapes[i];
15910 if (!shape._id || shape.isClip) continue;
15911 var id = shape._id;
15912 rst[id] = {
15913 _id: id,
15914 type: shape.get('type'),
15915 // the type of shape
15916 attrs: Util.mix({}, shape._attrs.attrs),
15917 // the graphics attributes of shape
15918 className: shape.get('className'),
15919 geomType: shape.get('className'),
15920 index: shape.get('index'),
15921 coord: shape.get('coord'),
15922 animateCfg: shape.get('animateCfg')
15923 };
15924 }
15925
15926 return rst;
15927}
15928
15929function getAnimate(geomType, coord, animationType, animationName) {
15930 var result;
15931
15932 if (Util.isFunction(animationName)) {
15933 result = animationName;
15934 } else if (Util.isString(animationName)) {
15935 result = Animate.Action[animationName];
15936 } else {
15937 result = Animate.getAnimation(geomType, coord, animationType);
15938 }
15939
15940 return result;
15941}
15942
15943function getAnimateCfg(geomType, animationType, animateCfg) {
15944 if (animateCfg === false || Util.isObject(animateCfg) && animateCfg[animationType] === false) {
15945 return false;
15946 }
15947
15948 var defaultCfg = Animate.getAnimateCfg(geomType, animationType);
15949
15950 if (animateCfg && animateCfg[animationType]) {
15951 return Util.deepMix({}, defaultCfg, animateCfg[animationType]);
15952 }
15953
15954 return defaultCfg;
15955}
15956
15957function addAnimate(cache, shapes, canvas) {
15958 var animate;
15959 var animateCfg; // the order of animation: leave -> update -> enter
15960
15961 var updateShapes = [];
15962 var newShapes = [];
15963 Util.each(shapes, function (shape) {
15964 var result = cache[shape._id];
15965
15966 if (!result) {
15967 newShapes.push(shape);
15968 } else {
15969 shape.set('cacheShape', result);
15970 updateShapes.push(shape);
15971 delete cache[shape._id];
15972 }
15973 }); // first do the leave animation
15974
15975 Util.each(cache, function (deletedShape) {
15976 var className = deletedShape.className,
15977 coord = deletedShape.coord,
15978 _id = deletedShape._id,
15979 attrs = deletedShape.attrs,
15980 index = deletedShape.index,
15981 type = deletedShape.type;
15982 animateCfg = getAnimateCfg(className, 'leave', deletedShape.animateCfg);
15983 if (animateCfg === false) return true;
15984 animate = getAnimate(className, coord, 'leave', animateCfg.animation);
15985
15986 if (Util.isFunction(animate)) {
15987 var tempShape = canvas.addShape(type, {
15988 attrs: attrs,
15989 index: index,
15990 canvas: canvas,
15991 className: className
15992 });
15993 tempShape._id = _id;
15994 animate(tempShape, animateCfg, coord);
15995 }
15996 }); // then do the update animation
15997
15998 Util.each(updateShapes, function (updateShape) {
15999 var className = updateShape.get('className');
16000 animateCfg = getAnimateCfg(className, 'update', updateShape.get('animateCfg'));
16001 if (animateCfg === false) return true;
16002 var coord = updateShape.get('coord');
16003 var cacheAttrs = updateShape.get('cacheShape').attrs;
16004 var endState = diff(cacheAttrs, updateShape._attrs.attrs); // 判断如果属性相同的话就不进行变换
16005
16006 if (Object.keys(endState).length) {
16007 animate = getAnimate(className, coord, 'update', animateCfg.animation);
16008
16009 if (Util.isFunction(animate)) {
16010 animate(updateShape, animateCfg, coord);
16011 } else {
16012 updateShape.attr(cacheAttrs);
16013 updateShape.animate().to({
16014 attrs: endState,
16015 duration: animateCfg.duration,
16016 easing: animateCfg.easing,
16017 delay: animateCfg.delay
16018 }).onEnd(function () {
16019 updateShape.set('cacheShape', null);
16020 });
16021 }
16022 }
16023 }); // last, enter animation
16024
16025 Util.each(newShapes, function (newShape) {
16026 // 新图形元素的进场元素
16027 var className = newShape.get('className');
16028 var coord = newShape.get('coord');
16029 animateCfg = getAnimateCfg(className, 'enter', newShape.get('animateCfg'));
16030 if (animateCfg === false) return true;
16031 animate = getAnimate(className, coord, 'enter', animateCfg.animation);
16032
16033 if (Util.isFunction(animate)) {
16034 if (className === 'interval' && coord.isPolar && coord.transposed) {
16035 var index = newShape.get('index');
16036 var lastShape = updateShapes[index - 1];
16037 animate(newShape, animateCfg, lastShape);
16038 } else {
16039 animate(newShape, animateCfg, coord);
16040 }
16041 }
16042 });
16043}
16044
16045function _getAnimateCfgByShapeType(type, chart) {
16046 if (!type) {
16047 return null;
16048 }
16049
16050 var animateCfg = chart.get('animate');
16051
16052 if (type.indexOf('guide-tag') > -1) {
16053 type = 'guide-tag';
16054 }
16055
16056 if (Util.isObject(animateCfg)) {
16057 return animateCfg[type];
16058 }
16059
16060 if (animateCfg === false) {
16061 return false;
16062 }
16063
16064 return null;
16065}
16066
16067module.exports = {
16068 afterCanvasInit: function afterCanvasInit()
16069 /* chart */
16070 {
16071 timeline = new Timeline();
16072 timeline.play();
16073 },
16074 beforeCanvasDraw: function beforeCanvasDraw(chart) {
16075 if (chart.get('animate') === false) {
16076 return;
16077 }
16078
16079 var isUpdate = chart.get('isUpdate');
16080 var canvas = chart.get('canvas');
16081 var coord = chart.get('coord');
16082 var geoms = chart.get('geoms');
16083 var caches = canvas.get('caches') || [];
16084
16085 if (caches.length === 0) {
16086 isUpdate = false;
16087 }
16088
16089 var cacheShapes = getShapes(geoms, chart, coord);
16090
16091 var _chart$get = chart.get('axisController'),
16092 frontPlot = _chart$get.frontPlot,
16093 backPlot = _chart$get.backPlot;
16094
16095 var axisShapes = frontPlot.get('children').concat(backPlot.get('children'));
16096 var guideShapes = [];
16097
16098 if (chart.get('guideController')) {
16099 guideShapes = chart.get('guideController').guideShapes;
16100 }
16101
16102 var componentShapes = [];
16103 axisShapes.concat(guideShapes).forEach(function (s) {
16104 var className = s.get('className');
16105
16106 var animateCfg = _getAnimateCfgByShapeType(className, chart);
16107
16108 s.set('coord', coord);
16109 s.set('animateCfg', animateCfg);
16110 componentShapes.push(s);
16111 cacheShapes.push(s);
16112 });
16113 canvas.set('caches', cache(cacheShapes));
16114
16115 if (isUpdate) {
16116 addAnimate(caches, cacheShapes, canvas);
16117 } else {
16118 // do the appear animation
16119 var animateCfg;
16120 var animate;
16121 Util.each(geoms, function (geom) {
16122 var type = geom.get('type');
16123 var geomCfg = Util.isNil(geom.get('animateCfg')) ? _getAnimateCfgByShapeType(type, chart) : geom.get('animateCfg');
16124
16125 if (geomCfg !== false) {
16126 animateCfg = getAnimateCfg(type, 'appear', geomCfg);
16127 animate = getAnimate(type, coord, 'appear', animateCfg.animation);
16128
16129 if (Util.isFunction(animate)) {
16130 var shapes = geom.get('shapes');
16131 Util.each(shapes, function (shape) {
16132 animate(shape, animateCfg, coord);
16133 });
16134 } else if (GROUP_ANIMATION[type]) {
16135 // do the default animation
16136 animate = GroupAction[animateCfg.animation] || GROUP_ANIMATION[type](coord);
16137 var yScale = geom.getYScale();
16138 var zeroY = coord.convertPoint({
16139 x: 0,
16140 y: yScale.scale(geom.getYMinValue())
16141 });
16142 var container = geom.get('container');
16143 animate && animate(container, animateCfg, coord, zeroY);
16144 }
16145 }
16146 }); // do the animation of components
16147
16148 Util.each(componentShapes, function (shape) {
16149 var animateCfg = shape.get('animateCfg');
16150 var className = shape.get('className');
16151
16152 if (animateCfg && animateCfg.appear) {
16153 // if user configure
16154 var defaultCfg = Animate.getAnimateCfg(className, 'appear');
16155 var appearCfg = Util.deepMix({}, defaultCfg, animateCfg.appear);
16156
16157 var _animate = getAnimate(className, coord, 'appear', appearCfg.animation);
16158
16159 if (Util.isFunction(_animate)) {
16160 _animate(shape, appearCfg, coord);
16161 }
16162 }
16163 });
16164 }
16165 },
16166 afterCanvasDestroyed: function afterCanvasDestroyed()
16167 /* chart */
16168 {
16169 timeline.stop();
16170 }
16171};
16172
16173/***/ }),
16174/* 130 */
16175/***/ (function(module, exports, __webpack_require__) {
16176
16177var _require = __webpack_require__(38),
16178 requestAnimationFrame = _require.requestAnimationFrame;
16179
16180var clock = typeof performance === 'object' && performance.now ? performance : Date;
16181
16182var Timeline =
16183/*#__PURE__*/
16184function () {
16185 function Timeline() {
16186 this.anims = [];
16187 this.time = null;
16188 this.playing = false;
16189 this.canvas = [];
16190 }
16191
16192 var _proto = Timeline.prototype;
16193
16194 _proto.play = function play() {
16195 var self = this;
16196 self.time = clock.now();
16197 self.playing = true;
16198
16199 function step() {
16200 if (self.playing) {
16201 requestAnimationFrame(step);
16202 self.update();
16203 }
16204 }
16205
16206 requestAnimationFrame(step);
16207 };
16208
16209 _proto.stop = function stop() {
16210 this.playing = false;
16211 this.time = null;
16212 this.canvas = [];
16213 };
16214
16215 _proto.update = function update() {
16216 var currentTime = clock.now();
16217 this.canvas = [];
16218
16219 for (var i = 0; i < this.anims.length; i++) {
16220 var propertyAnim = this.anims[i];
16221
16222 if (currentTime < propertyAnim.startTime || propertyAnim.hasEnded) {
16223 continue;
16224 }
16225
16226 var shape = propertyAnim.shape; // shape
16227
16228 if (shape.get('destroyed')) {
16229 this.anims.splice(i, 1);
16230 i--;
16231 continue;
16232 }
16233
16234 var startState = propertyAnim.startState,
16235 endState = propertyAnim.endState,
16236 interpolate = propertyAnim.interpolate,
16237 duration = propertyAnim.duration;
16238
16239 if (currentTime >= propertyAnim.startTime && !propertyAnim.hasStarted) {
16240 propertyAnim.hasStarted = true;
16241
16242 if (propertyAnim.onStart) {
16243 propertyAnim.onStart();
16244 }
16245 }
16246
16247 var t = (currentTime - propertyAnim.startTime) / duration;
16248 t = Math.max(0, Math.min(t, 1));
16249 t = propertyAnim.easing(t);
16250
16251 if (propertyAnim.onFrame) {
16252 propertyAnim.onFrame(t);
16253 } else {
16254 for (var key in interpolate) {
16255 var diff = interpolate[key];
16256 var value = diff(t);
16257 var newValue = void 0;
16258
16259 if (key === 'points') {
16260 newValue = [];
16261 var aLen = Math.max(startState.points.length, endState.points.length);
16262
16263 for (var j = 0; j < aLen; j += 2) {
16264 newValue.push({
16265 x: value[j],
16266 y: value[j + 1]
16267 });
16268 }
16269 } else {
16270 newValue = value;
16271 }
16272
16273 shape._attrs.attrs[key] = newValue;
16274 shape._attrs.bbox = null; // should clear calculated bbox
16275 }
16276 }
16277
16278 var canvas = shape.get('canvas');
16279
16280 if (this.canvas.indexOf(canvas) === -1) {
16281 this.canvas.push(canvas);
16282 }
16283
16284 if (propertyAnim.onUpdate) {
16285 propertyAnim.onUpdate(t);
16286 }
16287
16288 if (currentTime >= propertyAnim.endTime && !propertyAnim.hasEnded) {
16289 propertyAnim.hasEnded = true;
16290
16291 if (propertyAnim.onEnd) {
16292 propertyAnim.onEnd();
16293 }
16294 }
16295
16296 if (t === 1) {
16297 // end
16298 this.anims.splice(i, 1);
16299 i--;
16300 }
16301 }
16302
16303 this.canvas.map(function (c) {
16304 c.draw();
16305 return c;
16306 });
16307 this.time = clock.now();
16308 };
16309
16310 return Timeline;
16311}();
16312
16313module.exports = Timeline;
16314
16315/***/ }),
16316/* 131 */
16317/***/ (function(module, exports, __webpack_require__) {
16318
16319var Easing = __webpack_require__(132);
16320
16321function plainArray(arr) {
16322 var result = [];
16323
16324 for (var i = 0, len = arr.length; i < len; i++) {
16325 if (arr[i]) {
16326 result.push(arr[i].x);
16327 result.push(arr[i].y);
16328 }
16329 }
16330
16331 return result;
16332}
16333
16334function interpolateNumber(a, b) {
16335 a = +a;
16336 b -= a;
16337 return function (t) {
16338 return a + b * t;
16339 };
16340}
16341
16342function interpolateArray(a, b) {
16343 var nb = b ? b.length : 0;
16344 var na = a ? Math.min(nb, a.length) : 0;
16345 var x = new Array(na);
16346 var c = new Array(nb);
16347 var i;
16348
16349 for (i = 0; i < na; ++i) {
16350 x[i] = interpolateNumber(a[i], b[i]);
16351 }
16352
16353 for (; i < nb; ++i) {
16354 c[i] = b[i];
16355 }
16356
16357 return function (t) {
16358 for (i = 0; i < na; ++i) {
16359 c[i] = x[i](t);
16360 }
16361
16362 return c;
16363 };
16364}
16365
16366var Animator =
16367/*#__PURE__*/
16368function () {
16369 function Animator(shape, source, timeline) {
16370 this.hasStarted = false;
16371 this.hasEnded = false;
16372 this.shape = shape;
16373 this.source = source;
16374 this.timeline = timeline;
16375 this.animate = null;
16376 } // delay, attrs, duration, easing
16377
16378
16379 var _proto = Animator.prototype;
16380
16381 _proto.to = function to(cfg) {
16382 if (cfg === void 0) {
16383 cfg = {};
16384 }
16385
16386 var delay = cfg.delay || 0;
16387 var attrs = cfg.attrs || {};
16388 var duration = cfg.duration || 1000;
16389 var easing; // 缓动函数
16390
16391 if (typeof cfg.easing === 'function') {
16392 easing = cfg.easing;
16393 } else {
16394 easing = Easing[cfg.easing] || Easing.linear;
16395 }
16396
16397 var animInfo = {
16398 shape: this.shape,
16399 startTime: this.timeline.time + delay,
16400 duration: duration,
16401 easing: easing
16402 };
16403 var interpolate = {}; // 差值函数
16404
16405 for (var attrName in attrs) {
16406 var startValue = this.source[attrName];
16407 var endValue = attrs[attrName];
16408
16409 if (attrName === 'points') {
16410 startValue = plainArray(startValue);
16411 endValue = plainArray(endValue);
16412 interpolate.points = interpolateArray(startValue, endValue);
16413 this.source.points = startValue;
16414 attrs.points = endValue;
16415 } else if (attrName === 'matrix') {
16416 interpolate.matrix = interpolateArray(startValue, endValue);
16417 } else {
16418 interpolate[attrName] = interpolateNumber(startValue, endValue);
16419 }
16420 }
16421
16422 animInfo.interpolate = interpolate;
16423 animInfo.startState = this.source;
16424 animInfo.endState = attrs;
16425 animInfo.endTime = animInfo.startTime + duration;
16426 this.timeline.anims.push(animInfo);
16427 this.animate = animInfo;
16428 return this;
16429 };
16430
16431 _proto.onFrame = function onFrame(callback) {
16432 // 自定义每一帧动画的动作
16433 if (this.animate) {
16434 this.animate.onFrame = function (frame) {
16435 callback(frame);
16436 };
16437 }
16438
16439 return this;
16440 };
16441
16442 _proto.onStart = function onStart(callback) {
16443 if (this.animate) {
16444 this.animate.onStart = function () {
16445 callback();
16446 };
16447 }
16448
16449 return this;
16450 };
16451
16452 _proto.onUpdate = function onUpdate(callback) {
16453 if (this.animate) {
16454 this.animate.onUpdate = function (frame) {
16455 callback(frame);
16456 };
16457 }
16458
16459 return this;
16460 };
16461
16462 _proto.onEnd = function onEnd(callback) {
16463 if (this.animate) {
16464 this.animate.onEnd = function () {
16465 callback();
16466 };
16467 }
16468
16469 return this;
16470 };
16471
16472 return Animator;
16473}();
16474
16475module.exports = Animator;
16476
16477/***/ }),
16478/* 132 */
16479/***/ (function(module, exports) {
16480
16481var Easing = {
16482 linear: function linear(k) {
16483 return k;
16484 },
16485 quadraticIn: function quadraticIn(k) {
16486 return k * k;
16487 },
16488 quadraticOut: function quadraticOut(k) {
16489 return k * (2 - k);
16490 },
16491 quadraticInOut: function quadraticInOut(k) {
16492 if ((k *= 2) < 1) {
16493 return 0.5 * k * k;
16494 }
16495
16496 return -0.5 * (--k * (k - 2) - 1);
16497 },
16498 cubicIn: function cubicIn(k) {
16499 return k * k * k;
16500 },
16501 cubicOut: function cubicOut(k) {
16502 return --k * k * k + 1;
16503 },
16504 cubicInOut: function cubicInOut(k) {
16505 if ((k *= 2) < 1) {
16506 return 0.5 * k * k * k;
16507 }
16508
16509 return 0.5 * ((k -= 2) * k * k + 2);
16510 },
16511 elasticIn: function elasticIn(k) {
16512 var s;
16513 var a = 0.1;
16514 var p = 0.4;
16515 if (k === 0) return 0;
16516 if (k === 1) return 1;
16517
16518 if (!p) {
16519 p = 0.3;
16520 }
16521
16522 if (!a || a < 1) {
16523 a = 1;
16524 s = p / 4;
16525 } else {
16526 s = p / (2 * Math.PI) * Math.asin(1 / a);
16527 }
16528
16529 return -(a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
16530 },
16531 elasticOut: function elasticOut(k) {
16532 var s;
16533 var a = 0.1;
16534 var p = 0.4;
16535 if (k === 0) return 0;
16536 if (k === 1) return 1;
16537
16538 if (!p) {
16539 p = 0.3;
16540 }
16541
16542 if (!a || a < 1) {
16543 a = 1;
16544 s = p / 4;
16545 } else {
16546 s = p / (2 * Math.PI) * Math.asin(1 / a);
16547 }
16548
16549 return a * Math.pow(2, -10 * k) * Math.sin((k - s) * (2 * Math.PI) / p) + 1;
16550 },
16551 elasticInOut: function elasticInOut(k) {
16552 var s;
16553 var a = 0.1;
16554 var p = 0.4;
16555 if (k === 0) return 0;
16556 if (k === 1) return 1;
16557
16558 if (!p) {
16559 p = 0.3;
16560 }
16561
16562 if (!a || a < 1) {
16563 a = 1;
16564 s = p / 4;
16565 } else {
16566 s = p / (2 * Math.PI) * Math.asin(1 / a);
16567 }
16568
16569 if ((k *= 2) < 1) {
16570 return -0.5 * (a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
16571 }
16572
16573 return a * Math.pow(2, -10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
16574 },
16575 backIn: function backIn(k) {
16576 var s = 1.70158;
16577 return k * k * ((s + 1) * k - s);
16578 },
16579 backOut: function backOut(k) {
16580 var s = 1.70158;
16581 return (k = k - 1) * k * ((s + 1) * k + s) + 1;
16582 },
16583 backInOut: function backInOut(k) {
16584 var s = 1.70158 * 1.525;
16585
16586 if ((k *= 2) < 1) {
16587 return 0.5 * (k * k * ((s + 1) * k - s));
16588 }
16589
16590 return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
16591 },
16592 bounceIn: function bounceIn(k) {
16593 return 1 - Easing.bounceOut(1 - k);
16594 },
16595 bounceOut: function bounceOut(k) {
16596 if ((k /= 1) < 1 / 2.75) {
16597 return 7.5625 * k * k;
16598 } else if (k < 2 / 2.75) {
16599 return 7.5625 * (k -= 1.5 / 2.75) * k + 0.75;
16600 } else if (k < 2.5 / 2.75) {
16601 return 7.5625 * (k -= 2.25 / 2.75) * k + 0.9375;
16602 }
16603
16604 return 7.5625 * (k -= 2.625 / 2.75) * k + 0.984375;
16605 },
16606 bounceInOut: function bounceInOut(k) {
16607 if (k < 0.5) {
16608 return Easing.bounceIn(k * 2) * 0.5;
16609 }
16610
16611 return Easing.bounceOut(k * 2 - 1) * 0.5 + 0.5;
16612 }
16613};
16614module.exports = Easing;
16615
16616/***/ }),
16617/* 133 */
16618/***/ (function(module, exports, __webpack_require__) {
16619
16620/**
16621 * Animation functions for shape
16622 * @author sima.zhang1990@gmail.com
16623 */
16624var Util = __webpack_require__(0);
16625
16626var Helpers = __webpack_require__(47);
16627/*
16628function waveIn(shape, animateCfg, coord) {
16629 const clip = Helpers.getClip(coord);
16630 clip.set('canvas', shape.get('canvas'));
16631 shape.attr('clip', clip);
16632 const onEnd = function() {
16633 shape.attr('clip', null);
16634 clip.remove(true);
16635 };
16636 Helpers.doAnimation(clip, clip.endState, animateCfg, onEnd);
16637}
16638
16639function scaleInX(shape, animateCfg) {
16640 const box = shape.getBBox();
16641 const points = shape.get('origin').points;
16642 let x;
16643 const y = (box.minY + box.maxY) / 2;
16644
16645 if (points[0].y - points[1].y > 0) { // 当顶点在零点之下
16646 x = box.maxX;
16647 } else {
16648 x = box.minX;
16649 }
16650 const scaledMatrix = Helpers.getScaledMatrix(shape, [ x, y ], 'x');
16651 Helpers.doAnimation(shape, { matrix: scaledMatrix }, animateCfg);
16652}
16653
16654function scaleInY(shape, animateCfg) {
16655 const box = shape.getBBox();
16656 const points = shape.get('origin').points;
16657 const x = (box.minX + box.maxX) / 2;
16658 let y;
16659
16660 if (points[0].y - points[1].y <= 0) { // 当顶点在零点之下
16661 y = box.maxY;
16662 } else {
16663 y = box.minY;
16664 }
16665 const scaledMatrix = Helpers.getScaledMatrix(shape, [ x, y ], 'x');
16666 Helpers.doAnimation(shape, { matrix: scaledMatrix }, animateCfg);
16667}
16668*/
16669
16670
16671function fadeIn(shape, animateCfg) {
16672 var fillOpacity = Util.isNil(shape.attr('fillOpacity')) ? 1 : shape.attr('fillOpacity');
16673 var strokeOpacity = Util.isNil(shape.attr('strokeOpacity')) ? 1 : shape.attr('strokeOpacity');
16674 shape.attr('fillOpacity', 0);
16675 shape.attr('strokeOpacity', 0);
16676 var endState = {
16677 fillOpacity: fillOpacity,
16678 strokeOpacity: strokeOpacity
16679 };
16680 Helpers.doAnimation(shape, endState, animateCfg);
16681}
16682
16683module.exports = {
16684 // waveIn,
16685 // scaleInX,
16686 // scaleInY,
16687 fadeIn: fadeIn
16688};
16689
16690/***/ }),
16691/* 134 */
16692/***/ (function(module, exports, __webpack_require__) {
16693
16694/**
16695 * Group animate functions
16696 * @author sima.zhang1990@gmail.com
16697 */
16698var Util = __webpack_require__(47);
16699
16700var Helper = __webpack_require__(19);
16701
16702var _require = __webpack_require__(3),
16703 Shape = _require.Shape;
16704
16705function _groupScaleIn(container, animateCfg, coord, zeroY, type) {
16706 var _Util$getCoordInfo = Util.getCoordInfo(coord),
16707 start = _Util$getCoordInfo.start,
16708 end = _Util$getCoordInfo.end,
16709 width = _Util$getCoordInfo.width,
16710 height = _Util$getCoordInfo.height;
16711
16712 var x;
16713 var y;
16714 var clip = new Shape.Rect({
16715 attrs: {
16716 x: start.x,
16717 y: end.y,
16718 width: width,
16719 height: height
16720 }
16721 });
16722
16723 if (type === 'y') {
16724 x = start.x + width / 2;
16725 y = zeroY.y < start.y ? zeroY.y : start.y;
16726 } else if (type === 'x') {
16727 x = zeroY.x > start.x ? zeroY.x : start.x;
16728 y = start.y + height / 2;
16729 } else if (type === 'xy') {
16730 if (coord.isPolar) {
16731 x = coord.center.x;
16732 y = coord.center.y;
16733 } else {
16734 x = (start.x + end.x) / 2;
16735 y = (start.y + end.y) / 2;
16736 }
16737 }
16738
16739 var endMatrix = Util.getScaledMatrix(clip, [x, y], type);
16740 clip.isClip = true;
16741 clip.endState = {
16742 matrix: endMatrix
16743 };
16744 clip.set('canvas', container.get('canvas'));
16745 container.attr('clip', clip);
16746
16747 var onEnd = function onEnd() {
16748 container.attr('clip', null);
16749 clip.remove(true);
16750 };
16751
16752 Util.doAnimation(clip, clip.endState, animateCfg, onEnd);
16753}
16754
16755function _shapeScale(container, animateCfg, type) {
16756 var shapes = container.get('children');
16757 var x;
16758 var y;
16759 var endMatrix;
16760
16761 for (var i = 0, len = shapes.length; i < len; i++) {
16762 var shape = shapes[i];
16763 var box = shape.getBBox();
16764 x = (box.minX + box.maxX) / 2;
16765 y = (box.minY + box.maxY) / 2;
16766 endMatrix = Util.getScaledMatrix(shape, [x, y], type);
16767 Util.doAnimation(shape, {
16768 matrix: endMatrix
16769 }, animateCfg);
16770 }
16771}
16772
16773function groupScaleInX(container, animateCfg, coord, zeroY) {
16774 _groupScaleIn(container, animateCfg, coord, zeroY, 'x');
16775}
16776
16777function groupScaleInY(container, animateCfg, coord, zeroY) {
16778 _groupScaleIn(container, animateCfg, coord, zeroY, 'y');
16779}
16780
16781function groupScaleInXY(container, animateCfg, coord, zeroY) {
16782 _groupScaleIn(container, animateCfg, coord, zeroY, 'xy');
16783}
16784
16785function shapesScaleInX(container, animateCfg) {
16786 _shapeScale(container, animateCfg, 'x');
16787}
16788
16789function shapesScaleInY(container, animateCfg) {
16790 _shapeScale(container, animateCfg, 'y');
16791}
16792
16793function shapesScaleInXY(container, animateCfg) {
16794 _shapeScale(container, animateCfg, 'xy');
16795}
16796
16797function groupWaveIn(container, animateCfg, coord) {
16798 var clip = Helper.getClip(coord);
16799 clip.set('canvas', container.get('canvas'));
16800 container.attr('clip', clip);
16801
16802 var onEnd = function onEnd() {
16803 container.attr('clip', null);
16804 clip.remove(true);
16805 };
16806
16807 var endState = {};
16808
16809 if (coord.isPolar) {
16810 var startAngle = coord.startAngle,
16811 endAngle = coord.endAngle;
16812 endState.endAngle = endAngle;
16813 clip.attr('endAngle', startAngle);
16814 } else {
16815 var start = coord.start,
16816 end = coord.end;
16817 var width = Math.abs(start.x - end.x);
16818 var height = Math.abs(start.y - end.y);
16819
16820 if (coord.isTransposed) {
16821 clip.attr('height', 0);
16822 endState.height = height;
16823 } else {
16824 clip.attr('width', 0);
16825 endState.width = width;
16826 }
16827 }
16828
16829 Util.doAnimation(clip, endState, animateCfg, onEnd);
16830}
16831
16832module.exports = {
16833 groupWaveIn: groupWaveIn,
16834 groupScaleInX: groupScaleInX,
16835 groupScaleInY: groupScaleInY,
16836 groupScaleInXY: groupScaleInXY,
16837 shapesScaleInX: shapesScaleInX,
16838 shapesScaleInY: shapesScaleInY,
16839 shapesScaleInXY: shapesScaleInXY
16840};
16841
16842/***/ }),
16843/* 135 */
16844/***/ (function(module, exports, __webpack_require__) {
16845
16846var Helper = __webpack_require__(29);
16847
16848var Util = __webpack_require__(0);
16849
16850var DEFAULT_CFG = {
16851 mode: 'x',
16852 xStyle: {
16853 backgroundColor: 'rgba(202, 215, 239, .2)',
16854 fillerColor: 'rgba(202, 215, 239, .5)',
16855 size: 4,
16856 lineCap: 'round',
16857 offsetX: 0,
16858 offsetY: 8
16859 },
16860 yStyle: {
16861 backgroundColor: 'rgba(202, 215, 239, .2)',
16862 fillerColor: 'rgba(202, 215, 239, .5)',
16863 size: 4,
16864 lineCap: 'round',
16865 offsetX: 8,
16866 offsetY: 0
16867 }
16868};
16869module.exports = {
16870 init: function init(chart) {
16871 chart.set('_limitRange', {});
16872
16873 chart.scrollBar = function (cfg) {
16874 if (cfg === true) {
16875 cfg = DEFAULT_CFG;
16876 } else if (Util.isObject(cfg)) {
16877 cfg = Util.deepMix({}, DEFAULT_CFG, cfg);
16878 }
16879
16880 this.set('_scrollBarCfg', cfg);
16881 };
16882 },
16883 clear: function clear(chart) {
16884 chart.set('_limitRange', {});
16885 },
16886 changeData: function changeData(chart) {
16887 chart.set('_limitRange', {});
16888 },
16889 clearInner: function clearInner(chart) {
16890 var hBar = chart.get('_horizontalBar');
16891 var vBar = chart.get('_verticalBar');
16892 hBar && hBar.remove(true);
16893 vBar && vBar.remove(true);
16894 chart.set('_horizontalBar', null);
16895 chart.set('_verticalBar', null);
16896 },
16897 afterGeomDraw: function afterGeomDraw(chart) {
16898 var scrollBarCfg = chart.get('_scrollBarCfg');
16899 if (!scrollBarCfg) return;
16900 var data = chart.get('data');
16901 var plotRange = chart.get('plotRange');
16902 var backPlot = chart.get('backPlot');
16903 var canvas = chart.get('canvas');
16904 var canvasHeight = canvas.get('height');
16905 var limitRange = chart.get('_limitRange');
16906 var mode = scrollBarCfg.mode;
16907
16908 if (Util.directionEnabled(mode, 'x')) {
16909 var _scrollBarCfg$xStyle = scrollBarCfg.xStyle,
16910 offsetX = _scrollBarCfg$xStyle.offsetX,
16911 offsetY = _scrollBarCfg$xStyle.offsetY,
16912 lineCap = _scrollBarCfg$xStyle.lineCap,
16913 backgroundColor = _scrollBarCfg$xStyle.backgroundColor,
16914 fillerColor = _scrollBarCfg$xStyle.fillerColor,
16915 size = _scrollBarCfg$xStyle.size;
16916 var xScale = chart.getXScale();
16917 var xLimitRange = limitRange[xScale.field];
16918
16919 if (!xLimitRange) {
16920 xLimitRange = Helper.getLimitRange(data, xScale);
16921 limitRange[xScale.field] = xLimitRange;
16922 }
16923
16924 var currentRange = Helper.getFieldRange(xScale, xLimitRange, xScale.type);
16925 var horizontalBar = chart.get('_horizontalBar');
16926 var yPos = canvasHeight - size / 2 + offsetY;
16927
16928 if (horizontalBar) {
16929 var progressLine = horizontalBar.get('children')[1];
16930 progressLine.attr({
16931 x1: Math.max(plotRange.bl.x + plotRange.width * currentRange[0] + offsetX, plotRange.bl.x),
16932 x2: Math.min(plotRange.bl.x + plotRange.width * currentRange[1] + offsetX, plotRange.br.x)
16933 });
16934 } else {
16935 horizontalBar = backPlot.addGroup({
16936 className: 'horizontalBar'
16937 });
16938 horizontalBar.addShape('line', {
16939 attrs: {
16940 x1: plotRange.bl.x + offsetX,
16941 y1: yPos,
16942 x2: plotRange.br.x + offsetX,
16943 y2: yPos,
16944 lineWidth: size,
16945 stroke: backgroundColor,
16946 lineCap: lineCap
16947 }
16948 });
16949 horizontalBar.addShape('line', {
16950 attrs: {
16951 x1: Math.max(plotRange.bl.x + plotRange.width * currentRange[0] + offsetX, plotRange.bl.x),
16952 y1: yPos,
16953 x2: Math.min(plotRange.bl.x + plotRange.width * currentRange[1] + offsetX, plotRange.br.x),
16954 y2: yPos,
16955 lineWidth: size,
16956 stroke: fillerColor,
16957 lineCap: lineCap
16958 }
16959 });
16960 chart.set('_horizontalBar', horizontalBar);
16961 }
16962 }
16963
16964 if (Util.directionEnabled(mode, 'y')) {
16965 var _scrollBarCfg$yStyle = scrollBarCfg.yStyle,
16966 _offsetX = _scrollBarCfg$yStyle.offsetX,
16967 _offsetY = _scrollBarCfg$yStyle.offsetY,
16968 _lineCap = _scrollBarCfg$yStyle.lineCap,
16969 _backgroundColor = _scrollBarCfg$yStyle.backgroundColor,
16970 _fillerColor = _scrollBarCfg$yStyle.fillerColor,
16971 _size = _scrollBarCfg$yStyle.size;
16972 var yScale = chart.getYScales()[0];
16973 var yLimitRange = limitRange[yScale.field];
16974
16975 if (!yLimitRange) {
16976 yLimitRange = Helper.getLimitRange(data, yScale);
16977 limitRange[yScale.field] = yLimitRange;
16978 }
16979
16980 var _currentRange = Helper.getFieldRange(yScale, yLimitRange, yScale.type);
16981
16982 var verticalBar = chart.get('_verticalBar');
16983 var xPos = _size / 2 + _offsetX;
16984
16985 if (verticalBar) {
16986 var _progressLine = verticalBar.get('children')[1];
16987
16988 _progressLine.attr({
16989 y1: Math.max(plotRange.tl.y + plotRange.height * _currentRange[0] + _offsetY, plotRange.tl.y),
16990 y2: Math.min(plotRange.tl.y + plotRange.height * _currentRange[1] + _offsetY, plotRange.bl.y)
16991 });
16992 } else {
16993 verticalBar = backPlot.addGroup({
16994 className: 'verticalBar'
16995 });
16996 verticalBar.addShape('line', {
16997 attrs: {
16998 x1: xPos,
16999 y1: plotRange.tl.y + _offsetY,
17000 x2: xPos,
17001 y2: plotRange.bl.y + _offsetY,
17002 lineWidth: _size,
17003 stroke: _backgroundColor,
17004 lineCap: _lineCap
17005 }
17006 });
17007 verticalBar.addShape('line', {
17008 attrs: {
17009 x1: xPos,
17010 y1: Math.max(plotRange.tl.y + plotRange.height * _currentRange[0] + _offsetY, plotRange.tl.y),
17011 x2: xPos,
17012 y2: Math.min(plotRange.tl.y + plotRange.height * _currentRange[1] + _offsetY, plotRange.bl.y),
17013 lineWidth: _size,
17014 stroke: _fillerColor,
17015 lineCap: _lineCap
17016 }
17017 });
17018 chart.set('_verticalBar', verticalBar);
17019 }
17020 }
17021 }
17022};
17023
17024/***/ }),
17025/* 136 */
17026/***/ (function(module, exports, __webpack_require__) {
17027
17028var Util = __webpack_require__(0);
17029
17030var _require = __webpack_require__(3),
17031 Group = _require.Group;
17032
17033var DEFAULT_CFG = {
17034 anchorOffset: 5,
17035 // 锚点的偏移量
17036 inflectionOffset: 15,
17037 // 拐点的偏移量
17038 sidePadding: 20,
17039 // 文本距离画布四边的距离
17040 lineHeight: 32,
17041 // 文本的行高
17042 adjustOffset: 15,
17043 // 发生调整时的偏移量
17044 skipOverlapLabels: false,
17045 // 是否不展示重叠的文本
17046 triggerOn: 'touchstart',
17047 // 点击行为触发的时间类型
17048 activeShape: false,
17049 // 当有图形被选中的时候,是否激活图形
17050 activeStyle: {
17051 offset: 1,
17052 appendRadius: 8,
17053 fillOpacity: 0.5
17054 },
17055 label1OffsetY: -1,
17056 label2OffsetY: 1
17057};
17058
17059function getEndPoint(center, angle, r) {
17060 return {
17061 x: center.x + r * Math.cos(angle),
17062 y: center.y + r * Math.sin(angle)
17063 };
17064} // 计算中间角度
17065
17066
17067function getMiddleAngle(startAngle, endAngle) {
17068 if (endAngle < startAngle) {
17069 endAngle += Math.PI * 2;
17070 }
17071
17072 return (endAngle + startAngle) / 2;
17073} // 判断两个矩形是否相交
17074
17075
17076function isOverlap(label1, label2) {
17077 var label1BBox = label1.getBBox();
17078 var label2BBox = label2.getBBox();
17079 return Math.max(label1BBox.minX, label2BBox.minX) <= Math.min(label1BBox.maxX, label2BBox.minX) && Math.max(label1BBox.minY, label2BBox.minY) <= Math.min(label1BBox.maxY, label2BBox.maxY);
17080}
17081
17082var controller =
17083/*#__PURE__*/
17084function () {
17085 function controller(cfg) {
17086 Util.mix(this, cfg);
17087 var chart = this.chart;
17088 this.canvasDom = chart.get('canvas').get('el');
17089 }
17090
17091 var _proto = controller.prototype;
17092
17093 _proto.renderLabels = function renderLabels() {
17094 var self = this;
17095 var chart = self.chart,
17096 pieLabelCfg = self.pieLabelCfg,
17097 labelGroup = self.labelGroup;
17098 var halves = [[], // left
17099 [] // right
17100 ]; // 存储左右 labels
17101
17102 var geom = chart.get('geoms')[0];
17103 var shapes = geom.get('container').get('children');
17104 var anchorOffset = pieLabelCfg.anchorOffset,
17105 inflectionOffset = pieLabelCfg.inflectionOffset,
17106 label1 = pieLabelCfg.label1,
17107 label2 = pieLabelCfg.label2,
17108 lineHeight = pieLabelCfg.lineHeight,
17109 skipOverlapLabels = pieLabelCfg.skipOverlapLabels,
17110 label1OffsetY = pieLabelCfg.label1OffsetY,
17111 label2OffsetY = pieLabelCfg.label2OffsetY;
17112 var coord = chart.get('coord');
17113 var center = coord.center,
17114 radius = coord.circleRadius;
17115 shapes.forEach(function (shape) {
17116 var _shape$_attrs$attrs = shape._attrs.attrs,
17117 startAngle = _shape$_attrs$attrs.startAngle,
17118 endAngle = _shape$_attrs$attrs.endAngle;
17119 var middleAngle = getMiddleAngle(startAngle, endAngle);
17120 var anchorPoint = getEndPoint(center, middleAngle, radius + anchorOffset);
17121 var inflectionPoint = getEndPoint(center, middleAngle, radius + inflectionOffset);
17122 var origin = shape.get('origin');
17123 var _origin = origin._origin,
17124 color = origin.color;
17125 var label = {
17126 _anchor: anchorPoint,
17127 _inflection: inflectionPoint,
17128 _data: _origin,
17129 x: inflectionPoint.x,
17130 y: inflectionPoint.y,
17131 r: radius + inflectionOffset,
17132 fill: color
17133 };
17134 var textGroup = new Group({
17135 context: chart.get('canvas').get('context'),
17136 // 兼容 node、小程序环境
17137 data: _origin // 存储原始数据
17138
17139 });
17140 var textAttrs = {
17141 x: 0,
17142 y: 0,
17143 fontSize: 12,
17144 lineHeight: 12,
17145 fill: '#808080'
17146 };
17147
17148 if (Util.isFunction(label1)) {
17149 textGroup.addShape('Text', {
17150 attrs: Util.mix({
17151 textBaseline: 'bottom'
17152 }, textAttrs, label1(_origin, color)),
17153 data: _origin,
17154 // 存储原始数据
17155 offsetY: label1OffsetY
17156 });
17157 }
17158
17159 if (Util.isFunction(label2)) {
17160 textGroup.addShape('Text', {
17161 attrs: Util.mix({
17162 textBaseline: 'top'
17163 }, textAttrs, label2(_origin, color)),
17164 data: _origin,
17165 // 存储原始数据
17166 offsetY: label2OffsetY
17167 });
17168 }
17169
17170 label.textGroup = textGroup; // 判断文本的方向
17171
17172 if (anchorPoint.x < center.x) {
17173 label._side = 'left';
17174 halves[0].push(label);
17175 } else {
17176 label._side = 'right';
17177 halves[1].push(label);
17178 }
17179 });
17180 var drawnLabels = [];
17181
17182 if (skipOverlapLabels) {
17183 var lastLabel; // 存储上一个 label 对象,用于检测文本是否重叠
17184
17185 var labels = halves[1].concat(halves[0]); // 顺时针
17186
17187 for (var i = 0, len = labels.length; i < len; i++) {
17188 var label = labels[i];
17189
17190 var textGroup = self._drawLabel(label);
17191
17192 if (lastLabel) {
17193 if (isOverlap(textGroup, lastLabel)) {
17194 // 重叠了就不绘制
17195 continue;
17196 }
17197 }
17198
17199 labelGroup.add(textGroup);
17200
17201 self._drawLabelLine(label);
17202
17203 lastLabel = textGroup;
17204 drawnLabels.push(textGroup);
17205 }
17206 } else {
17207 var height = chart.get('height');
17208 var maxCountForOneSide = parseInt(height / lineHeight, 10);
17209 halves.forEach(function (half) {
17210 if (half.length > maxCountForOneSide) {
17211 half.splice(maxCountForOneSide, half.length - maxCountForOneSide);
17212 }
17213
17214 half.sort(function (a, b) {
17215 return a.y - b.y;
17216 });
17217
17218 var labels = self._antiCollision(half);
17219
17220 drawnLabels = drawnLabels.concat(labels);
17221 });
17222 }
17223
17224 this.drawnLabels = drawnLabels;
17225 };
17226
17227 _proto.bindEvents = function bindEvents() {
17228 var pieLabelCfg = this.pieLabelCfg;
17229 var triggerOn = pieLabelCfg.triggerOn || 'touchstart';
17230 var method = Util.wrapBehavior(this, '_handleEvent');
17231 Util.addEventListener(this.canvasDom, triggerOn, method);
17232 };
17233
17234 _proto.unBindEvents = function unBindEvents() {
17235 var pieLabelCfg = this.pieLabelCfg;
17236 var triggerOn = pieLabelCfg.triggerOn || 'touchstart';
17237 var method = Util.getWrapBehavior(this, '_handleEvent');
17238 Util.removeEventListener(this.canvasDom, triggerOn, method);
17239 };
17240
17241 _proto.clear = function clear() {
17242 this.labelGroup && this.labelGroup.clear();
17243 this.halo && this.halo.remove(true);
17244 this.lastSelectedData = null;
17245 this.drawnLabels = [];
17246 this.unBindEvents();
17247 };
17248
17249 _proto._drawLabel = function _drawLabel(label) {
17250 var pieLabelCfg = this.pieLabelCfg,
17251 chart = this.chart;
17252 var canvasWidth = chart.get('width');
17253 var sidePadding = pieLabelCfg.sidePadding;
17254 var y = label.y,
17255 textGroup = label.textGroup;
17256 var children = textGroup.get('children');
17257 var textAttrs = {
17258 textAlign: label._side === 'left' ? 'left' : 'right',
17259 x: label._side === 'left' ? sidePadding : canvasWidth - sidePadding
17260 };
17261 children.forEach(function (child) {
17262 child.attr(textAttrs);
17263 child.attr('y', y + child.get('offsetY'));
17264 });
17265 return textGroup;
17266 };
17267
17268 _proto._drawLabelLine = function _drawLabelLine(label, maxLabelWidth) {
17269 var chart = this.chart,
17270 pieLabelCfg = this.pieLabelCfg,
17271 labelGroup = this.labelGroup;
17272 var canvasWidth = chart.get('width');
17273 var sidePadding = pieLabelCfg.sidePadding,
17274 adjustOffset = pieLabelCfg.adjustOffset,
17275 lineStyle = pieLabelCfg.lineStyle,
17276 anchorStyle = pieLabelCfg.anchorStyle,
17277 skipOverlapLabels = pieLabelCfg.skipOverlapLabels;
17278 var _anchor = label._anchor,
17279 _inflection = label._inflection,
17280 fill = label.fill,
17281 y = label.y;
17282 var lastPoint = {
17283 x: label._side === 'left' ? sidePadding : canvasWidth - sidePadding,
17284 y: y
17285 };
17286 var points = [_anchor, _inflection, lastPoint];
17287
17288 if (!skipOverlapLabels && _inflection.y !== y) {
17289 // 展示全部文本文本位置做过调整
17290 if (_inflection.y < y) {
17291 // 文本被调整下去了,则添加拐点连接线
17292 var point1 = _inflection;
17293 var point2 = {
17294 x: label._side === 'left' ? lastPoint.x + maxLabelWidth + adjustOffset : lastPoint.x - maxLabelWidth - adjustOffset,
17295 y: _inflection.y
17296 };
17297 var point3 = {
17298 x: label._side === 'left' ? lastPoint.x + maxLabelWidth : lastPoint.x - maxLabelWidth,
17299 y: lastPoint.y
17300 };
17301 points = [_anchor, point1, point2, point3, lastPoint];
17302
17303 if (label._side === 'right' && point2.x < point1.x || label._side === 'left' && point2.x > point1.x) {
17304 points = [_anchor, point3, lastPoint];
17305 }
17306 } else {
17307 points = [_anchor, {
17308 x: _inflection.x,
17309 y: y
17310 }, lastPoint];
17311 }
17312 }
17313
17314 labelGroup.addShape('Polyline', {
17315 attrs: Util.mix({
17316 points: points,
17317 lineWidth: 1,
17318 stroke: fill
17319 }, lineStyle)
17320 }); // 绘制锚点
17321
17322 labelGroup.addShape('Circle', {
17323 attrs: Util.mix({
17324 x: _anchor.x,
17325 y: _anchor.y,
17326 r: 2,
17327 fill: fill
17328 }, anchorStyle)
17329 });
17330 };
17331
17332 _proto._antiCollision = function _antiCollision(half) {
17333 var self = this;
17334 var chart = self.chart,
17335 pieLabelCfg = self.pieLabelCfg;
17336 var coord = chart.get('coord');
17337 var canvasHeight = chart.get('height');
17338 var center = coord.center,
17339 r = coord.circleRadius;
17340 var inflectionOffset = pieLabelCfg.inflectionOffset,
17341 lineHeight = pieLabelCfg.lineHeight;
17342 var startY = center.y - r - inflectionOffset - lineHeight;
17343 var overlapping = true;
17344 var totalH = canvasHeight;
17345 var i;
17346 var maxY = 0;
17347 var minY = Number.MIN_VALUE;
17348 var maxLabelWidth = 0;
17349 var boxes = half.map(function (label) {
17350 var labelY = label.y;
17351
17352 if (labelY > maxY) {
17353 maxY = labelY;
17354 }
17355
17356 if (labelY < minY) {
17357 minY = labelY;
17358 }
17359
17360 var textGroup = label.textGroup;
17361 var labelWidth = textGroup.getBBox().width;
17362
17363 if (labelWidth >= maxLabelWidth) {
17364 maxLabelWidth = labelWidth;
17365 }
17366
17367 return {
17368 size: lineHeight,
17369 targets: [labelY - startY]
17370 };
17371 });
17372
17373 if (maxY - startY > totalH) {
17374 totalH = maxY - startY;
17375 }
17376
17377 var iteratorBoxed = function iteratorBoxed(boxes) {
17378 boxes.forEach(function (box) {
17379 var target = (Math.min.apply(minY, box.targets) + Math.max.apply(minY, box.targets)) / 2;
17380 box.pos = Math.min(Math.max(minY, target - box.size / 2), totalH - box.size);
17381 });
17382 };
17383
17384 while (overlapping) {
17385 iteratorBoxed(boxes); // detect overlapping and join boxes
17386
17387 overlapping = false;
17388 i = boxes.length;
17389
17390 while (i--) {
17391 if (i > 0) {
17392 var previousBox = boxes[i - 1];
17393 var box = boxes[i];
17394
17395 if (previousBox.pos + previousBox.size > box.pos) {
17396 // overlapping
17397 previousBox.size += box.size;
17398 previousBox.targets = previousBox.targets.concat(box.targets); // overflow, shift up
17399
17400 if (previousBox.pos + previousBox.size > totalH) {
17401 previousBox.pos = totalH - previousBox.size;
17402 }
17403
17404 boxes.splice(i, 1); // removing box
17405
17406 overlapping = true;
17407 }
17408 }
17409 }
17410 }
17411
17412 i = 0;
17413 boxes.forEach(function (b) {
17414 var posInCompositeBox = startY; // middle of the label
17415
17416 b.targets.forEach(function () {
17417 half[i].y = b.pos + posInCompositeBox + lineHeight / 2;
17418 posInCompositeBox += lineHeight;
17419 i++;
17420 });
17421 });
17422 var drawnLabels = [];
17423 half.forEach(function (label) {
17424 var textGroup = self._drawLabel(label);
17425
17426 var labelGroup = self.labelGroup;
17427 labelGroup.add(textGroup);
17428
17429 self._drawLabelLine(label, maxLabelWidth);
17430
17431 drawnLabels.push(textGroup);
17432 });
17433 return drawnLabels;
17434 };
17435
17436 _proto._handleEvent = function _handleEvent(ev) {
17437 var self = this;
17438 var chart = self.chart,
17439 drawnLabels = self.drawnLabels,
17440 pieLabelCfg = self.pieLabelCfg;
17441 var onClick = pieLabelCfg.onClick,
17442 activeShape = pieLabelCfg.activeShape;
17443 var canvasEvent = Util.createEvent(ev, chart);
17444 var x = canvasEvent.x,
17445 y = canvasEvent.y; // 查找被点击的 label
17446
17447 var clickedShape;
17448
17449 for (var i = 0, len = drawnLabels.length; i < len; i++) {
17450 var shape = drawnLabels[i];
17451 var bbox = shape.getBBox(); // 通过最小包围盒来判断击中情况
17452
17453 if (x >= bbox.minX && x <= bbox.maxX && y >= bbox.minY && y <= bbox.maxY) {
17454 clickedShape = shape;
17455 break;
17456 }
17457 }
17458
17459 var pieData = chart.getSnapRecords({
17460 x: x,
17461 y: y
17462 });
17463
17464 if (clickedShape) {
17465 canvasEvent.data = clickedShape.get('data');
17466 } else if (pieData.length) {
17467 // 击中饼图扇形区域
17468 canvasEvent.data = pieData[0]._origin;
17469 }
17470
17471 onClick && onClick(canvasEvent);
17472 canvasEvent.data && activeShape && this._activeShape(canvasEvent.data);
17473 };
17474
17475 _proto._getSelectedShapeByData = function _getSelectedShapeByData(data) {
17476 var selectedShape = null;
17477 var chart = this.chart;
17478 var geom = chart.get('geoms')[0];
17479 var container = geom.get('container');
17480 var children = container.get('children');
17481 Util.each(children, function (child) {
17482 if (child.get('isShape') && child.get('className') === geom.get('type')) {
17483 // get geometry's shape
17484 var shapeData = child.get('origin')._origin;
17485
17486 if (Util.isObjectValueEqual(shapeData, data)) {
17487 selectedShape = child;
17488 return false;
17489 }
17490 }
17491 });
17492 return selectedShape;
17493 };
17494
17495 _proto._activeShape = function _activeShape(data) {
17496 var chart = this.chart,
17497 lastSelectedData = this.lastSelectedData,
17498 pieLabelCfg = this.pieLabelCfg;
17499
17500 if (data === lastSelectedData) {
17501 return;
17502 }
17503
17504 this.lastSelectedData = data;
17505 var activeStyle = pieLabelCfg.activeStyle;
17506
17507 var selectedShape = this._getSelectedShapeByData(data);
17508
17509 var _selectedShape$_attrs = selectedShape._attrs.attrs,
17510 x = _selectedShape$_attrs.x,
17511 y = _selectedShape$_attrs.y,
17512 startAngle = _selectedShape$_attrs.startAngle,
17513 endAngle = _selectedShape$_attrs.endAngle,
17514 r = _selectedShape$_attrs.r,
17515 fill = _selectedShape$_attrs.fill;
17516 var frontPlot = chart.get('frontPlot');
17517 this.halo && this.halo.remove(true);
17518 var halo = frontPlot.addShape('sector', {
17519 attrs: Util.mix({
17520 x: x,
17521 y: y,
17522 r: r + activeStyle.offset + activeStyle.appendRadius,
17523 r0: r + activeStyle.offset,
17524 fill: fill,
17525 startAngle: startAngle,
17526 endAngle: endAngle
17527 }, activeStyle)
17528 });
17529 this.halo = halo;
17530 chart.get('canvas').draw();
17531 };
17532
17533 return controller;
17534}();
17535
17536module.exports = {
17537 init: function init(chart) {
17538 var frontPlot = chart.get('frontPlot');
17539 var labelGroup = frontPlot.addGroup({
17540 className: 'pie-label',
17541 zIndex: 0
17542 });
17543 var pieLabelController = new controller({
17544 chart: chart,
17545 labelGroup: labelGroup
17546 });
17547 chart.set('pieLabelController', pieLabelController);
17548
17549 chart.pieLabel = function (cfg) {
17550 cfg = Util.deepMix({}, DEFAULT_CFG, cfg);
17551 pieLabelController.pieLabelCfg = cfg;
17552 return this;
17553 };
17554 },
17555 afterGeomDraw: function afterGeomDraw(chart) {
17556 var controller = chart.get('pieLabelController');
17557
17558 if (controller.pieLabelCfg) {
17559 // 用户配置了饼图文本
17560 controller.renderLabels();
17561 controller.bindEvents(); // 绑定事件
17562 }
17563 },
17564 clearInner: function clearInner(chart) {
17565 var controller = chart.get('pieLabelController');
17566
17567 if (controller.pieLabelCfg) {
17568 // 用户配置了饼图文本
17569 controller.clear();
17570 }
17571 }
17572};
17573
17574/***/ }),
17575/* 137 */
17576/***/ (function(module, exports, __webpack_require__) {
17577
17578function _inheritsLoose(subClass, superClass) {
17579 subClass.prototype = Object.create(superClass.prototype);
17580 subClass.prototype.constructor = subClass;
17581 subClass.__proto__ = superClass;
17582}
17583
17584function _assertThisInitialized(self) {
17585 if (self === void 0) {
17586 throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
17587 }
17588
17589 return self;
17590}
17591
17592var Util = __webpack_require__(0);
17593
17594var Interaction = __webpack_require__(21);
17595
17596var Chart = __webpack_require__(11);
17597
17598var PieSelect =
17599/*#__PURE__*/
17600function (_Interaction) {
17601 _inheritsLoose(PieSelect, _Interaction);
17602
17603 var _proto = PieSelect.prototype;
17604
17605 _proto.getDefaultCfg = function getDefaultCfg() {
17606 var defaultCfg = _Interaction.prototype.getDefaultCfg.call(this);
17607
17608 defaultCfg = Util.mix({}, defaultCfg, {
17609 startEvent: 'tap',
17610 processEvent: null,
17611 animate: false,
17612 offset: 1,
17613 appendRadius: 8,
17614 style: {
17615 fillOpacity: 0.5
17616 },
17617 cancelable: true,
17618 defaultSelected: null // set the default selected shape
17619
17620 });
17621
17622 if (Util.isWx || Util.isMy) {
17623 // 小程序
17624 defaultCfg.startEvent = 'touchstart';
17625 defaultCfg.endEvent = 'touchend';
17626 }
17627
17628 return defaultCfg;
17629 };
17630
17631 function PieSelect(cfg, chart) {
17632 var _this;
17633
17634 _this = _Interaction.call(this, cfg, chart) || this;
17635
17636 var self = _assertThisInitialized(_assertThisInitialized(_this));
17637
17638 chart.registerPlugins({
17639 clearInner: function clearInner() {
17640 self.halo && self.halo.remove(true);
17641 self.selected = false;
17642 self.selectedShape = null;
17643 self.lastShape = null;
17644 self.halo = null;
17645 self.defaultSelected = null;
17646 }
17647 });
17648 var defaultSelected = self.defaultSelected;
17649
17650 if (Util.isObject(defaultSelected)) {
17651 var selectedShape = self._getSelectedShapeByData(defaultSelected);
17652
17653 selectedShape && self._selectedShape(selectedShape);
17654
17655 _this.canvas.draw();
17656 }
17657
17658 return _this;
17659 }
17660
17661 _proto._getSelectedShapeByData = function _getSelectedShapeByData(data) {
17662 var selectedShape = null;
17663 var chart = this.chart;
17664 var geom = chart.get('geoms')[0];
17665 var container = geom.get('container');
17666 var children = container.get('children');
17667 Util.each(children, function (child) {
17668 if (child.get('isShape') && child.get('className') === geom.get('type')) {
17669 // get geometry's shape
17670 var shapeData = child.get('origin')._origin;
17671
17672 if (Util.isObjectValueEqual(shapeData, data)) {
17673 selectedShape = child;
17674 return false;
17675 }
17676 }
17677 });
17678 return selectedShape;
17679 };
17680
17681 _proto._selectedShape = function _selectedShape(selectedShape) {
17682 var offset = this.offset,
17683 style = this.style,
17684 appendRadius = this.appendRadius,
17685 chart = this.chart;
17686 this.lastShape = selectedShape;
17687 var _selectedShape$_attrs = selectedShape._attrs.attrs,
17688 x = _selectedShape$_attrs.x,
17689 y = _selectedShape$_attrs.y,
17690 startAngle = _selectedShape$_attrs.startAngle,
17691 endAngle = _selectedShape$_attrs.endAngle,
17692 r = _selectedShape$_attrs.r,
17693 fill = _selectedShape$_attrs.fill;
17694 var frontPlot = chart.get('frontPlot');
17695 var halo = frontPlot.addShape('sector', {
17696 attrs: Util.mix({
17697 x: x,
17698 y: y,
17699 r: r + offset + appendRadius,
17700 r0: r + offset,
17701 fill: fill,
17702 startAngle: startAngle,
17703 endAngle: endAngle
17704 }, style)
17705 });
17706 this.halo = halo;
17707 var animate = this.animate;
17708
17709 if (animate) {
17710 if (animate === true) {
17711 animate = {
17712 duration: 300
17713 };
17714 }
17715
17716 halo.attr('r', r + offset);
17717 halo.animate().to(Util.mix({
17718 attrs: {
17719 r: r + offset + appendRadius
17720 }
17721 }, animate));
17722 }
17723 };
17724
17725 _proto.start = function start(ev) {
17726 var chart = this.chart;
17727
17728 if (ev.type === 'tap') {
17729 ev.clientX = ev.center.x;
17730 ev.clientY = ev.center.y;
17731 }
17732
17733 var _Util$createEvent = Util.createEvent(ev, chart),
17734 x = _Util$createEvent.x,
17735 y = _Util$createEvent.y;
17736
17737 this.halo && this.halo.remove(true);
17738 var records = chart.getSnapRecords({
17739 x: x,
17740 y: y
17741 });
17742
17743 if (!records.length) {
17744 this.selected = false;
17745 this.selectedShape = null;
17746 return;
17747 }
17748
17749 var data = records[0]._origin;
17750
17751 var selectedShape = this._getSelectedShapeByData(data);
17752
17753 var lastShape = this.lastShape;
17754 this.selectedShape = selectedShape;
17755 this.selected = true;
17756
17757 if (selectedShape === lastShape) {
17758 if (!this.cancelable) {
17759 return;
17760 }
17761
17762 this.halo && this.halo.remove(true);
17763 this.lastShape = null;
17764 this.selected = false;
17765 } else {
17766 this._selectedShape(selectedShape);
17767 }
17768
17769 this.canvas.draw();
17770 };
17771
17772 _proto.end = function end(ev) {
17773 var selectedShape = this.selectedShape;
17774
17775 if (selectedShape && !selectedShape.get('destroyed')) {
17776 ev.data = selectedShape.get('origin')._origin;
17777 ev.shapeInfo = selectedShape.get('origin');
17778 ev.shape = selectedShape;
17779 ev.selected = !!this.selected;
17780 }
17781 };
17782
17783 return PieSelect;
17784}(Interaction);
17785
17786Chart.registerInteraction('pie-select', PieSelect);
17787module.exports = PieSelect;
17788
17789/***/ }),
17790/* 138 */
17791/***/ (function(module, exports, __webpack_require__) {
17792
17793var __WEBPACK_AMD_DEFINE_RESULT__;/*! Hammer.JS - v2.0.7 - 2016-04-22
17794 * http://hammerjs.github.io/
17795 *
17796 * Copyright (c) 2016 Jorik Tangelder;
17797 * Licensed under the MIT license */
17798(function (window, document, exportName, undefined) {
17799 'use strict';
17800
17801 var VENDOR_PREFIXES = ['', 'webkit', 'Moz', 'MS', 'ms', 'o'];
17802 var TEST_ELEMENT = document.createElement('div');
17803 var TYPE_FUNCTION = 'function';
17804 var round = Math.round;
17805 var abs = Math.abs;
17806 var now = Date.now;
17807 /**
17808 * set a timeout with a given scope
17809 * @param {Function} fn
17810 * @param {Number} timeout
17811 * @param {Object} context
17812 * @returns {number}
17813 */
17814
17815 function setTimeoutContext(fn, timeout, context) {
17816 return setTimeout(bindFn(fn, context), timeout);
17817 }
17818 /**
17819 * if the argument is an array, we want to execute the fn on each entry
17820 * if it aint an array we don't want to do a thing.
17821 * this is used by all the methods that accept a single and array argument.
17822 * @param {*|Array} arg
17823 * @param {String} fn
17824 * @param {Object} [context]
17825 * @returns {Boolean}
17826 */
17827
17828
17829 function invokeArrayArg(arg, fn, context) {
17830 if (Array.isArray(arg)) {
17831 each(arg, context[fn], context);
17832 return true;
17833 }
17834
17835 return false;
17836 }
17837 /**
17838 * walk objects and arrays
17839 * @param {Object} obj
17840 * @param {Function} iterator
17841 * @param {Object} context
17842 */
17843
17844
17845 function each(obj, iterator, context) {
17846 var i;
17847
17848 if (!obj) {
17849 return;
17850 }
17851
17852 if (obj.forEach) {
17853 obj.forEach(iterator, context);
17854 } else if (obj.length !== undefined) {
17855 i = 0;
17856
17857 while (i < obj.length) {
17858 iterator.call(context, obj[i], i, obj);
17859 i++;
17860 }
17861 } else {
17862 for (i in obj) {
17863 obj.hasOwnProperty(i) && iterator.call(context, obj[i], i, obj);
17864 }
17865 }
17866 }
17867 /**
17868 * wrap a method with a deprecation warning and stack trace
17869 * @param {Function} method
17870 * @param {String} name
17871 * @param {String} message
17872 * @returns {Function} A new function wrapping the supplied method.
17873 */
17874
17875
17876 function deprecate(method, name, message) {
17877 var deprecationMessage = 'DEPRECATED METHOD: ' + name + '\n' + message + ' AT \n';
17878 return function () {
17879 var e = new Error('get-stack-trace');
17880 var stack = e && e.stack ? e.stack.replace(/^[^\(]+?[\n$]/gm, '').replace(/^\s+at\s+/gm, '').replace(/^Object.<anonymous>\s*\(/gm, '{anonymous}()@') : 'Unknown Stack Trace';
17881 var log = window.console && (window.console.warn || window.console.log);
17882
17883 if (log) {
17884 log.call(window.console, deprecationMessage, stack);
17885 }
17886
17887 return method.apply(this, arguments);
17888 };
17889 }
17890 /**
17891 * extend object.
17892 * means that properties in dest will be overwritten by the ones in src.
17893 * @param {Object} target
17894 * @param {...Object} objects_to_assign
17895 * @returns {Object} target
17896 */
17897
17898
17899 var assign;
17900
17901 if (typeof Object.assign !== 'function') {
17902 assign = function assign(target) {
17903 if (target === undefined || target === null) {
17904 throw new TypeError('Cannot convert undefined or null to object');
17905 }
17906
17907 var output = Object(target);
17908
17909 for (var index = 1; index < arguments.length; index++) {
17910 var source = arguments[index];
17911
17912 if (source !== undefined && source !== null) {
17913 for (var nextKey in source) {
17914 if (source.hasOwnProperty(nextKey)) {
17915 output[nextKey] = source[nextKey];
17916 }
17917 }
17918 }
17919 }
17920
17921 return output;
17922 };
17923 } else {
17924 assign = Object.assign;
17925 }
17926 /**
17927 * extend object.
17928 * means that properties in dest will be overwritten by the ones in src.
17929 * @param {Object} dest
17930 * @param {Object} src
17931 * @param {Boolean} [merge=false]
17932 * @returns {Object} dest
17933 */
17934
17935
17936 var extend = deprecate(function extend(dest, src, merge) {
17937 var keys = Object.keys(src);
17938 var i = 0;
17939
17940 while (i < keys.length) {
17941 if (!merge || merge && dest[keys[i]] === undefined) {
17942 dest[keys[i]] = src[keys[i]];
17943 }
17944
17945 i++;
17946 }
17947
17948 return dest;
17949 }, 'extend', 'Use `assign`.');
17950 /**
17951 * merge the values from src in the dest.
17952 * means that properties that exist in dest will not be overwritten by src
17953 * @param {Object} dest
17954 * @param {Object} src
17955 * @returns {Object} dest
17956 */
17957
17958 var merge = deprecate(function merge(dest, src) {
17959 return extend(dest, src, true);
17960 }, 'merge', 'Use `assign`.');
17961 /**
17962 * simple class inheritance
17963 * @param {Function} child
17964 * @param {Function} base
17965 * @param {Object} [properties]
17966 */
17967
17968 function inherit(child, base, properties) {
17969 var baseP = base.prototype,
17970 childP;
17971 childP = child.prototype = Object.create(baseP);
17972 childP.constructor = child;
17973 childP._super = baseP;
17974
17975 if (properties) {
17976 assign(childP, properties);
17977 }
17978 }
17979 /**
17980 * simple function bind
17981 * @param {Function} fn
17982 * @param {Object} context
17983 * @returns {Function}
17984 */
17985
17986
17987 function bindFn(fn, context) {
17988 return function boundFn() {
17989 return fn.apply(context, arguments);
17990 };
17991 }
17992 /**
17993 * let a boolean value also be a function that must return a boolean
17994 * this first item in args will be used as the context
17995 * @param {Boolean|Function} val
17996 * @param {Array} [args]
17997 * @returns {Boolean}
17998 */
17999
18000
18001 function boolOrFn(val, args) {
18002 if (typeof val == TYPE_FUNCTION) {
18003 return val.apply(args ? args[0] || undefined : undefined, args);
18004 }
18005
18006 return val;
18007 }
18008 /**
18009 * use the val2 when val1 is undefined
18010 * @param {*} val1
18011 * @param {*} val2
18012 * @returns {*}
18013 */
18014
18015
18016 function ifUndefined(val1, val2) {
18017 return val1 === undefined ? val2 : val1;
18018 }
18019 /**
18020 * addEventListener with multiple events at once
18021 * @param {EventTarget} target
18022 * @param {String} types
18023 * @param {Function} handler
18024 */
18025
18026
18027 function addEventListeners(target, types, handler) {
18028 each(splitStr(types), function (type) {
18029 target.addEventListener(type, handler, false);
18030 });
18031 }
18032 /**
18033 * removeEventListener with multiple events at once
18034 * @param {EventTarget} target
18035 * @param {String} types
18036 * @param {Function} handler
18037 */
18038
18039
18040 function removeEventListeners(target, types, handler) {
18041 each(splitStr(types), function (type) {
18042 target.removeEventListener(type, handler, false);
18043 });
18044 }
18045 /**
18046 * find if a node is in the given parent
18047 * @method hasParent
18048 * @param {HTMLElement} node
18049 * @param {HTMLElement} parent
18050 * @return {Boolean} found
18051 */
18052
18053
18054 function hasParent(node, parent) {
18055 while (node) {
18056 if (node == parent) {
18057 return true;
18058 }
18059
18060 node = node.parentNode;
18061 }
18062
18063 return false;
18064 }
18065 /**
18066 * small indexOf wrapper
18067 * @param {String} str
18068 * @param {String} find
18069 * @returns {Boolean} found
18070 */
18071
18072
18073 function inStr(str, find) {
18074 return str.indexOf(find) > -1;
18075 }
18076 /**
18077 * split string on whitespace
18078 * @param {String} str
18079 * @returns {Array} words
18080 */
18081
18082
18083 function splitStr(str) {
18084 return str.trim().split(/\s+/g);
18085 }
18086 /**
18087 * find if a array contains the object using indexOf or a simple polyFill
18088 * @param {Array} src
18089 * @param {String} find
18090 * @param {String} [findByKey]
18091 * @return {Boolean|Number} false when not found, or the index
18092 */
18093
18094
18095 function inArray(src, find, findByKey) {
18096 if (src.indexOf && !findByKey) {
18097 return src.indexOf(find);
18098 } else {
18099 var i = 0;
18100
18101 while (i < src.length) {
18102 if (findByKey && src[i][findByKey] == find || !findByKey && src[i] === find) {
18103 return i;
18104 }
18105
18106 i++;
18107 }
18108
18109 return -1;
18110 }
18111 }
18112 /**
18113 * convert array-like objects to real arrays
18114 * @param {Object} obj
18115 * @returns {Array}
18116 */
18117
18118
18119 function toArray(obj) {
18120 return Array.prototype.slice.call(obj, 0);
18121 }
18122 /**
18123 * unique array with objects based on a key (like 'id') or just by the array's value
18124 * @param {Array} src [{id:1},{id:2},{id:1}]
18125 * @param {String} [key]
18126 * @param {Boolean} [sort=False]
18127 * @returns {Array} [{id:1},{id:2}]
18128 */
18129
18130
18131 function uniqueArray(src, key, sort) {
18132 var results = [];
18133 var values = [];
18134 var i = 0;
18135
18136 while (i < src.length) {
18137 var val = key ? src[i][key] : src[i];
18138
18139 if (inArray(values, val) < 0) {
18140 results.push(src[i]);
18141 }
18142
18143 values[i] = val;
18144 i++;
18145 }
18146
18147 if (sort) {
18148 if (!key) {
18149 results = results.sort();
18150 } else {
18151 results = results.sort(function sortUniqueArray(a, b) {
18152 return a[key] > b[key];
18153 });
18154 }
18155 }
18156
18157 return results;
18158 }
18159 /**
18160 * get the prefixed property
18161 * @param {Object} obj
18162 * @param {String} property
18163 * @returns {String|Undefined} prefixed
18164 */
18165
18166
18167 function prefixed(obj, property) {
18168 var prefix, prop;
18169 var camelProp = property[0].toUpperCase() + property.slice(1);
18170 var i = 0;
18171
18172 while (i < VENDOR_PREFIXES.length) {
18173 prefix = VENDOR_PREFIXES[i];
18174 prop = prefix ? prefix + camelProp : property;
18175
18176 if (prop in obj) {
18177 return prop;
18178 }
18179
18180 i++;
18181 }
18182
18183 return undefined;
18184 }
18185 /**
18186 * get a unique id
18187 * @returns {number} uniqueId
18188 */
18189
18190
18191 var _uniqueId = 1;
18192
18193 function uniqueId() {
18194 return _uniqueId++;
18195 }
18196 /**
18197 * get the window object of an element
18198 * @param {HTMLElement} element
18199 * @returns {DocumentView|Window}
18200 */
18201
18202
18203 function getWindowForElement(element) {
18204 var doc = element.ownerDocument || element;
18205 return doc.defaultView || doc.parentWindow || window;
18206 }
18207
18208 var MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;
18209 var SUPPORT_TOUCH = 'ontouchstart' in window;
18210 var SUPPORT_POINTER_EVENTS = prefixed(window, 'PointerEvent') !== undefined;
18211 var SUPPORT_ONLY_TOUCH = SUPPORT_TOUCH && MOBILE_REGEX.test(navigator.userAgent);
18212 var INPUT_TYPE_TOUCH = 'touch';
18213 var INPUT_TYPE_PEN = 'pen';
18214 var INPUT_TYPE_MOUSE = 'mouse';
18215 var INPUT_TYPE_KINECT = 'kinect';
18216 var COMPUTE_INTERVAL = 25;
18217 var INPUT_START = 1;
18218 var INPUT_MOVE = 2;
18219 var INPUT_END = 4;
18220 var INPUT_CANCEL = 8;
18221 var DIRECTION_NONE = 1;
18222 var DIRECTION_LEFT = 2;
18223 var DIRECTION_RIGHT = 4;
18224 var DIRECTION_UP = 8;
18225 var DIRECTION_DOWN = 16;
18226 var DIRECTION_HORIZONTAL = DIRECTION_LEFT | DIRECTION_RIGHT;
18227 var DIRECTION_VERTICAL = DIRECTION_UP | DIRECTION_DOWN;
18228 var DIRECTION_ALL = DIRECTION_HORIZONTAL | DIRECTION_VERTICAL;
18229 var PROPS_XY = ['x', 'y'];
18230 var PROPS_CLIENT_XY = ['clientX', 'clientY'];
18231 /**
18232 * create new input type manager
18233 * @param {Manager} manager
18234 * @param {Function} callback
18235 * @returns {Input}
18236 * @constructor
18237 */
18238
18239 function Input(manager, callback) {
18240 var self = this;
18241 this.manager = manager;
18242 this.callback = callback;
18243 this.element = manager.element;
18244 this.target = manager.options.inputTarget; // smaller wrapper around the handler, for the scope and the enabled state of the manager,
18245 // so when disabled the input events are completely bypassed.
18246
18247 this.domHandler = function (ev) {
18248 if (boolOrFn(manager.options.enable, [manager])) {
18249 self.handler(ev);
18250 }
18251 };
18252
18253 this.init();
18254 }
18255
18256 Input.prototype = {
18257 /**
18258 * should handle the inputEvent data and trigger the callback
18259 * @virtual
18260 */
18261 handler: function () {},
18262
18263 /**
18264 * bind the events
18265 */
18266 init: function () {
18267 this.evEl && addEventListeners(this.element, this.evEl, this.domHandler);
18268 this.evTarget && addEventListeners(this.target, this.evTarget, this.domHandler);
18269 this.evWin && addEventListeners(getWindowForElement(this.element), this.evWin, this.domHandler);
18270 },
18271
18272 /**
18273 * unbind the events
18274 */
18275 destroy: function () {
18276 this.evEl && removeEventListeners(this.element, this.evEl, this.domHandler);
18277 this.evTarget && removeEventListeners(this.target, this.evTarget, this.domHandler);
18278 this.evWin && removeEventListeners(getWindowForElement(this.element), this.evWin, this.domHandler);
18279 }
18280 };
18281 /**
18282 * create new input type manager
18283 * called by the Manager constructor
18284 * @param {Hammer} manager
18285 * @returns {Input}
18286 */
18287
18288 function createInputInstance(manager) {
18289 var Type;
18290 var inputClass = manager.options.inputClass;
18291
18292 if (inputClass) {
18293 Type = inputClass;
18294 } else if (SUPPORT_POINTER_EVENTS) {
18295 Type = PointerEventInput;
18296 } else if (SUPPORT_ONLY_TOUCH) {
18297 Type = TouchInput;
18298 } else if (!SUPPORT_TOUCH) {
18299 Type = MouseInput;
18300 } else {
18301 Type = TouchMouseInput;
18302 }
18303
18304 return new Type(manager, inputHandler);
18305 }
18306 /**
18307 * handle input events
18308 * @param {Manager} manager
18309 * @param {String} eventType
18310 * @param {Object} input
18311 */
18312
18313
18314 function inputHandler(manager, eventType, input) {
18315 var pointersLen = input.pointers.length;
18316 var changedPointersLen = input.changedPointers.length;
18317 var isFirst = eventType & INPUT_START && pointersLen - changedPointersLen === 0;
18318 var isFinal = eventType & (INPUT_END | INPUT_CANCEL) && pointersLen - changedPointersLen === 0;
18319 input.isFirst = !!isFirst;
18320 input.isFinal = !!isFinal;
18321
18322 if (isFirst) {
18323 manager.session = {};
18324 } // source event is the normalized value of the domEvents
18325 // like 'touchstart, mouseup, pointerdown'
18326
18327
18328 input.eventType = eventType; // compute scale, rotation etc
18329
18330 computeInputData(manager, input); // emit secret event
18331
18332 manager.emit('hammer.input', input);
18333 manager.recognize(input);
18334 manager.session.prevInput = input;
18335 }
18336 /**
18337 * extend the data with some usable properties like scale, rotate, velocity etc
18338 * @param {Object} manager
18339 * @param {Object} input
18340 */
18341
18342
18343 function computeInputData(manager, input) {
18344 var session = manager.session;
18345 var pointers = input.pointers;
18346 var pointersLength = pointers.length; // store the first input to calculate the distance and direction
18347
18348 if (!session.firstInput) {
18349 session.firstInput = simpleCloneInputData(input);
18350 } // to compute scale and rotation we need to store the multiple touches
18351
18352
18353 if (pointersLength > 1 && !session.firstMultiple) {
18354 session.firstMultiple = simpleCloneInputData(input);
18355 } else if (pointersLength === 1) {
18356 session.firstMultiple = false;
18357 }
18358
18359 var firstInput = session.firstInput;
18360 var firstMultiple = session.firstMultiple;
18361 var offsetCenter = firstMultiple ? firstMultiple.center : firstInput.center;
18362 var center = input.center = getCenter(pointers);
18363 input.timeStamp = now();
18364 input.deltaTime = input.timeStamp - firstInput.timeStamp;
18365 input.angle = getAngle(offsetCenter, center);
18366 input.distance = getDistance(offsetCenter, center);
18367 computeDeltaXY(session, input);
18368 input.offsetDirection = getDirection(input.deltaX, input.deltaY);
18369 var overallVelocity = getVelocity(input.deltaTime, input.deltaX, input.deltaY);
18370 input.overallVelocityX = overallVelocity.x;
18371 input.overallVelocityY = overallVelocity.y;
18372 input.overallVelocity = abs(overallVelocity.x) > abs(overallVelocity.y) ? overallVelocity.x : overallVelocity.y;
18373 input.scale = firstMultiple ? getScale(firstMultiple.pointers, pointers) : 1;
18374 input.rotation = firstMultiple ? getRotation(firstMultiple.pointers, pointers) : 0;
18375 input.maxPointers = !session.prevInput ? input.pointers.length : input.pointers.length > session.prevInput.maxPointers ? input.pointers.length : session.prevInput.maxPointers;
18376 computeIntervalInputData(session, input); // find the correct target
18377
18378 var target = manager.element;
18379
18380 if (hasParent(input.srcEvent.target, target)) {
18381 target = input.srcEvent.target;
18382 }
18383
18384 input.target = target;
18385 }
18386
18387 function computeDeltaXY(session, input) {
18388 var center = input.center;
18389 var offset = session.offsetDelta || {};
18390 var prevDelta = session.prevDelta || {};
18391 var prevInput = session.prevInput || {};
18392
18393 if (input.eventType === INPUT_START || prevInput.eventType === INPUT_END) {
18394 prevDelta = session.prevDelta = {
18395 x: prevInput.deltaX || 0,
18396 y: prevInput.deltaY || 0
18397 };
18398 offset = session.offsetDelta = {
18399 x: center.x,
18400 y: center.y
18401 };
18402 }
18403
18404 input.deltaX = prevDelta.x + (center.x - offset.x);
18405 input.deltaY = prevDelta.y + (center.y - offset.y);
18406 }
18407 /**
18408 * velocity is calculated every x ms
18409 * @param {Object} session
18410 * @param {Object} input
18411 */
18412
18413
18414 function computeIntervalInputData(session, input) {
18415 var last = session.lastInterval || input,
18416 deltaTime = input.timeStamp - last.timeStamp,
18417 velocity,
18418 velocityX,
18419 velocityY,
18420 direction;
18421
18422 if (input.eventType != INPUT_CANCEL && (deltaTime > COMPUTE_INTERVAL || last.velocity === undefined)) {
18423 var deltaX = input.deltaX - last.deltaX;
18424 var deltaY = input.deltaY - last.deltaY;
18425 var v = getVelocity(deltaTime, deltaX, deltaY);
18426 velocityX = v.x;
18427 velocityY = v.y;
18428 velocity = abs(v.x) > abs(v.y) ? v.x : v.y;
18429 direction = getDirection(deltaX, deltaY);
18430 session.lastInterval = input;
18431 } else {
18432 // use latest velocity info if it doesn't overtake a minimum period
18433 velocity = last.velocity;
18434 velocityX = last.velocityX;
18435 velocityY = last.velocityY;
18436 direction = last.direction;
18437 }
18438
18439 input.velocity = velocity;
18440 input.velocityX = velocityX;
18441 input.velocityY = velocityY;
18442 input.direction = direction;
18443 }
18444 /**
18445 * create a simple clone from the input used for storage of firstInput and firstMultiple
18446 * @param {Object} input
18447 * @returns {Object} clonedInputData
18448 */
18449
18450
18451 function simpleCloneInputData(input) {
18452 // make a simple copy of the pointers because we will get a reference if we don't
18453 // we only need clientXY for the calculations
18454 var pointers = [];
18455 var i = 0;
18456
18457 while (i < input.pointers.length) {
18458 pointers[i] = {
18459 clientX: round(input.pointers[i].clientX),
18460 clientY: round(input.pointers[i].clientY)
18461 };
18462 i++;
18463 }
18464
18465 return {
18466 timeStamp: now(),
18467 pointers: pointers,
18468 center: getCenter(pointers),
18469 deltaX: input.deltaX,
18470 deltaY: input.deltaY
18471 };
18472 }
18473 /**
18474 * get the center of all the pointers
18475 * @param {Array} pointers
18476 * @return {Object} center contains `x` and `y` properties
18477 */
18478
18479
18480 function getCenter(pointers) {
18481 var pointersLength = pointers.length; // no need to loop when only one touch
18482
18483 if (pointersLength === 1) {
18484 return {
18485 x: round(pointers[0].clientX),
18486 y: round(pointers[0].clientY)
18487 };
18488 }
18489
18490 var x = 0,
18491 y = 0,
18492 i = 0;
18493
18494 while (i < pointersLength) {
18495 x += pointers[i].clientX;
18496 y += pointers[i].clientY;
18497 i++;
18498 }
18499
18500 return {
18501 x: round(x / pointersLength),
18502 y: round(y / pointersLength)
18503 };
18504 }
18505 /**
18506 * calculate the velocity between two points. unit is in px per ms.
18507 * @param {Number} deltaTime
18508 * @param {Number} x
18509 * @param {Number} y
18510 * @return {Object} velocity `x` and `y`
18511 */
18512
18513
18514 function getVelocity(deltaTime, x, y) {
18515 return {
18516 x: x / deltaTime || 0,
18517 y: y / deltaTime || 0
18518 };
18519 }
18520 /**
18521 * get the direction between two points
18522 * @param {Number} x
18523 * @param {Number} y
18524 * @return {Number} direction
18525 */
18526
18527
18528 function getDirection(x, y) {
18529 if (x === y) {
18530 return DIRECTION_NONE;
18531 }
18532
18533 if (abs(x) >= abs(y)) {
18534 return x < 0 ? DIRECTION_LEFT : DIRECTION_RIGHT;
18535 }
18536
18537 return y < 0 ? DIRECTION_UP : DIRECTION_DOWN;
18538 }
18539 /**
18540 * calculate the absolute distance between two points
18541 * @param {Object} p1 {x, y}
18542 * @param {Object} p2 {x, y}
18543 * @param {Array} [props] containing x and y keys
18544 * @return {Number} distance
18545 */
18546
18547
18548 function getDistance(p1, p2, props) {
18549 if (!props) {
18550 props = PROPS_XY;
18551 }
18552
18553 var x = p2[props[0]] - p1[props[0]],
18554 y = p2[props[1]] - p1[props[1]];
18555 return Math.sqrt(x * x + y * y);
18556 }
18557 /**
18558 * calculate the angle between two coordinates
18559 * @param {Object} p1
18560 * @param {Object} p2
18561 * @param {Array} [props] containing x and y keys
18562 * @return {Number} angle
18563 */
18564
18565
18566 function getAngle(p1, p2, props) {
18567 if (!props) {
18568 props = PROPS_XY;
18569 }
18570
18571 var x = p2[props[0]] - p1[props[0]],
18572 y = p2[props[1]] - p1[props[1]];
18573 return Math.atan2(y, x) * 180 / Math.PI;
18574 }
18575 /**
18576 * calculate the rotation degrees between two pointersets
18577 * @param {Array} start array of pointers
18578 * @param {Array} end array of pointers
18579 * @return {Number} rotation
18580 */
18581
18582
18583 function getRotation(start, end) {
18584 return getAngle(end[1], end[0], PROPS_CLIENT_XY) + getAngle(start[1], start[0], PROPS_CLIENT_XY);
18585 }
18586 /**
18587 * calculate the scale factor between two pointersets
18588 * no scale is 1, and goes down to 0 when pinched together, and bigger when pinched out
18589 * @param {Array} start array of pointers
18590 * @param {Array} end array of pointers
18591 * @return {Number} scale
18592 */
18593
18594
18595 function getScale(start, end) {
18596 return getDistance(end[0], end[1], PROPS_CLIENT_XY) / getDistance(start[0], start[1], PROPS_CLIENT_XY);
18597 }
18598
18599 var MOUSE_INPUT_MAP = {
18600 mousedown: INPUT_START,
18601 mousemove: INPUT_MOVE,
18602 mouseup: INPUT_END
18603 };
18604 var MOUSE_ELEMENT_EVENTS = 'mousedown';
18605 var MOUSE_WINDOW_EVENTS = 'mousemove mouseup';
18606 /**
18607 * Mouse events input
18608 * @constructor
18609 * @extends Input
18610 */
18611
18612 function MouseInput() {
18613 this.evEl = MOUSE_ELEMENT_EVENTS;
18614 this.evWin = MOUSE_WINDOW_EVENTS;
18615 this.pressed = false; // mousedown state
18616
18617 Input.apply(this, arguments);
18618 }
18619
18620 inherit(MouseInput, Input, {
18621 /**
18622 * handle mouse events
18623 * @param {Object} ev
18624 */
18625 handler: function MEhandler(ev) {
18626 var eventType = MOUSE_INPUT_MAP[ev.type]; // on start we want to have the left mouse button down
18627
18628 if (eventType & INPUT_START && ev.button === 0) {
18629 this.pressed = true;
18630 }
18631
18632 if (eventType & INPUT_MOVE && ev.which !== 1) {
18633 eventType = INPUT_END;
18634 } // mouse must be down
18635
18636
18637 if (!this.pressed) {
18638 return;
18639 }
18640
18641 if (eventType & INPUT_END) {
18642 this.pressed = false;
18643 }
18644
18645 this.callback(this.manager, eventType, {
18646 pointers: [ev],
18647 changedPointers: [ev],
18648 pointerType: INPUT_TYPE_MOUSE,
18649 srcEvent: ev
18650 });
18651 }
18652 });
18653 var POINTER_INPUT_MAP = {
18654 pointerdown: INPUT_START,
18655 pointermove: INPUT_MOVE,
18656 pointerup: INPUT_END,
18657 pointercancel: INPUT_CANCEL,
18658 pointerout: INPUT_CANCEL
18659 }; // in IE10 the pointer types is defined as an enum
18660
18661 var IE10_POINTER_TYPE_ENUM = {
18662 2: INPUT_TYPE_TOUCH,
18663 3: INPUT_TYPE_PEN,
18664 4: INPUT_TYPE_MOUSE,
18665 5: INPUT_TYPE_KINECT // see https://twitter.com/jacobrossi/status/480596438489890816
18666
18667 };
18668 var POINTER_ELEMENT_EVENTS = 'pointerdown';
18669 var POINTER_WINDOW_EVENTS = 'pointermove pointerup pointercancel'; // IE10 has prefixed support, and case-sensitive
18670
18671 if (window.MSPointerEvent && !window.PointerEvent) {
18672 POINTER_ELEMENT_EVENTS = 'MSPointerDown';
18673 POINTER_WINDOW_EVENTS = 'MSPointerMove MSPointerUp MSPointerCancel';
18674 }
18675 /**
18676 * Pointer events input
18677 * @constructor
18678 * @extends Input
18679 */
18680
18681
18682 function PointerEventInput() {
18683 this.evEl = POINTER_ELEMENT_EVENTS;
18684 this.evWin = POINTER_WINDOW_EVENTS;
18685 Input.apply(this, arguments);
18686 this.store = this.manager.session.pointerEvents = [];
18687 }
18688
18689 inherit(PointerEventInput, Input, {
18690 /**
18691 * handle mouse events
18692 * @param {Object} ev
18693 */
18694 handler: function PEhandler(ev) {
18695 var store = this.store;
18696 var removePointer = false;
18697 var eventTypeNormalized = ev.type.toLowerCase().replace('ms', '');
18698 var eventType = POINTER_INPUT_MAP[eventTypeNormalized];
18699 var pointerType = IE10_POINTER_TYPE_ENUM[ev.pointerType] || ev.pointerType;
18700 var isTouch = pointerType == INPUT_TYPE_TOUCH; // get index of the event in the store
18701
18702 var storeIndex = inArray(store, ev.pointerId, 'pointerId'); // start and mouse must be down
18703
18704 if (eventType & INPUT_START && (ev.button === 0 || isTouch)) {
18705 if (storeIndex < 0) {
18706 store.push(ev);
18707 storeIndex = store.length - 1;
18708 }
18709 } else if (eventType & (INPUT_END | INPUT_CANCEL)) {
18710 removePointer = true;
18711 } // it not found, so the pointer hasn't been down (so it's probably a hover)
18712
18713
18714 if (storeIndex < 0) {
18715 return;
18716 } // update the event in the store
18717
18718
18719 store[storeIndex] = ev;
18720 this.callback(this.manager, eventType, {
18721 pointers: store,
18722 changedPointers: [ev],
18723 pointerType: pointerType,
18724 srcEvent: ev
18725 });
18726
18727 if (removePointer) {
18728 // remove from the store
18729 store.splice(storeIndex, 1);
18730 }
18731 }
18732 });
18733 var SINGLE_TOUCH_INPUT_MAP = {
18734 touchstart: INPUT_START,
18735 touchmove: INPUT_MOVE,
18736 touchend: INPUT_END,
18737 touchcancel: INPUT_CANCEL
18738 };
18739 var SINGLE_TOUCH_TARGET_EVENTS = 'touchstart';
18740 var SINGLE_TOUCH_WINDOW_EVENTS = 'touchstart touchmove touchend touchcancel';
18741 /**
18742 * Touch events input
18743 * @constructor
18744 * @extends Input
18745 */
18746
18747 function SingleTouchInput() {
18748 this.evTarget = SINGLE_TOUCH_TARGET_EVENTS;
18749 this.evWin = SINGLE_TOUCH_WINDOW_EVENTS;
18750 this.started = false;
18751 Input.apply(this, arguments);
18752 }
18753
18754 inherit(SingleTouchInput, Input, {
18755 handler: function TEhandler(ev) {
18756 var type = SINGLE_TOUCH_INPUT_MAP[ev.type]; // should we handle the touch events?
18757
18758 if (type === INPUT_START) {
18759 this.started = true;
18760 }
18761
18762 if (!this.started) {
18763 return;
18764 }
18765
18766 var touches = normalizeSingleTouches.call(this, ev, type); // when done, reset the started state
18767
18768 if (type & (INPUT_END | INPUT_CANCEL) && touches[0].length - touches[1].length === 0) {
18769 this.started = false;
18770 }
18771
18772 this.callback(this.manager, type, {
18773 pointers: touches[0],
18774 changedPointers: touches[1],
18775 pointerType: INPUT_TYPE_TOUCH,
18776 srcEvent: ev
18777 });
18778 }
18779 });
18780 /**
18781 * @this {TouchInput}
18782 * @param {Object} ev
18783 * @param {Number} type flag
18784 * @returns {undefined|Array} [all, changed]
18785 */
18786
18787 function normalizeSingleTouches(ev, type) {
18788 var all = toArray(ev.touches);
18789 var changed = toArray(ev.changedTouches);
18790
18791 if (type & (INPUT_END | INPUT_CANCEL)) {
18792 all = uniqueArray(all.concat(changed), 'identifier', true);
18793 }
18794
18795 return [all, changed];
18796 }
18797
18798 var TOUCH_INPUT_MAP = {
18799 touchstart: INPUT_START,
18800 touchmove: INPUT_MOVE,
18801 touchend: INPUT_END,
18802 touchcancel: INPUT_CANCEL
18803 };
18804 var TOUCH_TARGET_EVENTS = 'touchstart touchmove touchend touchcancel';
18805 /**
18806 * Multi-user touch events input
18807 * @constructor
18808 * @extends Input
18809 */
18810
18811 function TouchInput() {
18812 this.evTarget = TOUCH_TARGET_EVENTS;
18813 this.targetIds = {};
18814 Input.apply(this, arguments);
18815 }
18816
18817 inherit(TouchInput, Input, {
18818 handler: function MTEhandler(ev) {
18819 var type = TOUCH_INPUT_MAP[ev.type];
18820 var touches = getTouches.call(this, ev, type);
18821
18822 if (!touches) {
18823 return;
18824 }
18825
18826 this.callback(this.manager, type, {
18827 pointers: touches[0],
18828 changedPointers: touches[1],
18829 pointerType: INPUT_TYPE_TOUCH,
18830 srcEvent: ev
18831 });
18832 }
18833 });
18834 /**
18835 * @this {TouchInput}
18836 * @param {Object} ev
18837 * @param {Number} type flag
18838 * @returns {undefined|Array} [all, changed]
18839 */
18840
18841 function getTouches(ev, type) {
18842 var allTouches = toArray(ev.touches);
18843 var targetIds = this.targetIds; // when there is only one touch, the process can be simplified
18844
18845 if (type & (INPUT_START | INPUT_MOVE) && allTouches.length === 1) {
18846 targetIds[allTouches[0].identifier] = true;
18847 return [allTouches, allTouches];
18848 }
18849
18850 var i,
18851 targetTouches,
18852 changedTouches = toArray(ev.changedTouches),
18853 changedTargetTouches = [],
18854 target = this.target; // get target touches from touches
18855
18856 targetTouches = allTouches.filter(function (touch) {
18857 return hasParent(touch.target, target);
18858 }); // collect touches
18859
18860 if (type === INPUT_START) {
18861 i = 0;
18862
18863 while (i < targetTouches.length) {
18864 targetIds[targetTouches[i].identifier] = true;
18865 i++;
18866 }
18867 } // filter changed touches to only contain touches that exist in the collected target ids
18868
18869
18870 i = 0;
18871
18872 while (i < changedTouches.length) {
18873 if (targetIds[changedTouches[i].identifier]) {
18874 changedTargetTouches.push(changedTouches[i]);
18875 } // cleanup removed touches
18876
18877
18878 if (type & (INPUT_END | INPUT_CANCEL)) {
18879 delete targetIds[changedTouches[i].identifier];
18880 }
18881
18882 i++;
18883 }
18884
18885 if (!changedTargetTouches.length) {
18886 return;
18887 }
18888
18889 return [// merge targetTouches with changedTargetTouches so it contains ALL touches, including 'end' and 'cancel'
18890 uniqueArray(targetTouches.concat(changedTargetTouches), 'identifier', true), changedTargetTouches];
18891 }
18892 /**
18893 * Combined touch and mouse input
18894 *
18895 * Touch has a higher priority then mouse, and while touching no mouse events are allowed.
18896 * This because touch devices also emit mouse events while doing a touch.
18897 *
18898 * @constructor
18899 * @extends Input
18900 */
18901
18902
18903 var DEDUP_TIMEOUT = 2500;
18904 var DEDUP_DISTANCE = 25;
18905
18906 function TouchMouseInput() {
18907 Input.apply(this, arguments);
18908 var handler = bindFn(this.handler, this);
18909 this.touch = new TouchInput(this.manager, handler);
18910 this.mouse = new MouseInput(this.manager, handler);
18911 this.primaryTouch = null;
18912 this.lastTouches = [];
18913 }
18914
18915 inherit(TouchMouseInput, Input, {
18916 /**
18917 * handle mouse and touch events
18918 * @param {Hammer} manager
18919 * @param {String} inputEvent
18920 * @param {Object} inputData
18921 */
18922 handler: function TMEhandler(manager, inputEvent, inputData) {
18923 var isTouch = inputData.pointerType == INPUT_TYPE_TOUCH,
18924 isMouse = inputData.pointerType == INPUT_TYPE_MOUSE;
18925
18926 if (isMouse && inputData.sourceCapabilities && inputData.sourceCapabilities.firesTouchEvents) {
18927 return;
18928 } // when we're in a touch event, record touches to de-dupe synthetic mouse event
18929
18930
18931 if (isTouch) {
18932 recordTouches.call(this, inputEvent, inputData);
18933 } else if (isMouse && isSyntheticEvent.call(this, inputData)) {
18934 return;
18935 }
18936
18937 this.callback(manager, inputEvent, inputData);
18938 },
18939
18940 /**
18941 * remove the event listeners
18942 */
18943 destroy: function destroy() {
18944 this.touch.destroy();
18945 this.mouse.destroy();
18946 }
18947 });
18948
18949 function recordTouches(eventType, eventData) {
18950 if (eventType & INPUT_START) {
18951 this.primaryTouch = eventData.changedPointers[0].identifier;
18952 setLastTouch.call(this, eventData);
18953 } else if (eventType & (INPUT_END | INPUT_CANCEL)) {
18954 setLastTouch.call(this, eventData);
18955 }
18956 }
18957
18958 function setLastTouch(eventData) {
18959 var touch = eventData.changedPointers[0];
18960
18961 if (touch.identifier === this.primaryTouch) {
18962 var lastTouch = {
18963 x: touch.clientX,
18964 y: touch.clientY
18965 };
18966 this.lastTouches.push(lastTouch);
18967 var lts = this.lastTouches;
18968
18969 var removeLastTouch = function () {
18970 var i = lts.indexOf(lastTouch);
18971
18972 if (i > -1) {
18973 lts.splice(i, 1);
18974 }
18975 };
18976
18977 setTimeout(removeLastTouch, DEDUP_TIMEOUT);
18978 }
18979 }
18980
18981 function isSyntheticEvent(eventData) {
18982 var x = eventData.srcEvent.clientX,
18983 y = eventData.srcEvent.clientY;
18984
18985 for (var i = 0; i < this.lastTouches.length; i++) {
18986 var t = this.lastTouches[i];
18987 var dx = Math.abs(x - t.x),
18988 dy = Math.abs(y - t.y);
18989
18990 if (dx <= DEDUP_DISTANCE && dy <= DEDUP_DISTANCE) {
18991 return true;
18992 }
18993 }
18994
18995 return false;
18996 }
18997
18998 var PREFIXED_TOUCH_ACTION = prefixed(TEST_ELEMENT.style, 'touchAction');
18999 var NATIVE_TOUCH_ACTION = PREFIXED_TOUCH_ACTION !== undefined; // magical touchAction value
19000
19001 var TOUCH_ACTION_COMPUTE = 'compute';
19002 var TOUCH_ACTION_AUTO = 'auto';
19003 var TOUCH_ACTION_MANIPULATION = 'manipulation'; // not implemented
19004
19005 var TOUCH_ACTION_NONE = 'none';
19006 var TOUCH_ACTION_PAN_X = 'pan-x';
19007 var TOUCH_ACTION_PAN_Y = 'pan-y';
19008 var TOUCH_ACTION_MAP = getTouchActionProps();
19009 /**
19010 * Touch Action
19011 * sets the touchAction property or uses the js alternative
19012 * @param {Manager} manager
19013 * @param {String} value
19014 * @constructor
19015 */
19016
19017 function TouchAction(manager, value) {
19018 this.manager = manager;
19019 this.set(value);
19020 }
19021
19022 TouchAction.prototype = {
19023 /**
19024 * set the touchAction value on the element or enable the polyfill
19025 * @param {String} value
19026 */
19027 set: function (value) {
19028 // find out the touch-action by the event handlers
19029 if (value == TOUCH_ACTION_COMPUTE) {
19030 value = this.compute();
19031 }
19032
19033 if (NATIVE_TOUCH_ACTION && this.manager.element.style && TOUCH_ACTION_MAP[value]) {
19034 this.manager.element.style[PREFIXED_TOUCH_ACTION] = value;
19035 }
19036
19037 this.actions = value.toLowerCase().trim();
19038 },
19039
19040 /**
19041 * just re-set the touchAction value
19042 */
19043 update: function () {
19044 this.set(this.manager.options.touchAction);
19045 },
19046
19047 /**
19048 * compute the value for the touchAction property based on the recognizer's settings
19049 * @returns {String} value
19050 */
19051 compute: function () {
19052 var actions = [];
19053 each(this.manager.recognizers, function (recognizer) {
19054 if (boolOrFn(recognizer.options.enable, [recognizer])) {
19055 actions = actions.concat(recognizer.getTouchAction());
19056 }
19057 });
19058 return cleanTouchActions(actions.join(' '));
19059 },
19060
19061 /**
19062 * this method is called on each input cycle and provides the preventing of the browser behavior
19063 * @param {Object} input
19064 */
19065 preventDefaults: function (input) {
19066 var srcEvent = input.srcEvent;
19067 var direction = input.offsetDirection; // if the touch action did prevented once this session
19068
19069 if (this.manager.session.prevented) {
19070 srcEvent.preventDefault();
19071 return;
19072 }
19073
19074 var actions = this.actions;
19075 var hasNone = inStr(actions, TOUCH_ACTION_NONE) && !TOUCH_ACTION_MAP[TOUCH_ACTION_NONE];
19076 var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y) && !TOUCH_ACTION_MAP[TOUCH_ACTION_PAN_Y];
19077 var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X) && !TOUCH_ACTION_MAP[TOUCH_ACTION_PAN_X];
19078
19079 if (hasNone) {
19080 //do not prevent defaults if this is a tap gesture
19081 var isTapPointer = input.pointers.length === 1;
19082 var isTapMovement = input.distance < 2;
19083 var isTapTouchTime = input.deltaTime < 250;
19084
19085 if (isTapPointer && isTapMovement && isTapTouchTime) {
19086 return;
19087 }
19088 }
19089
19090 if (hasPanX && hasPanY) {
19091 // `pan-x pan-y` means browser handles all scrolling/panning, do not prevent
19092 return;
19093 }
19094
19095 if (hasNone || hasPanY && direction & DIRECTION_HORIZONTAL || hasPanX && direction & DIRECTION_VERTICAL) {
19096 return this.preventSrc(srcEvent);
19097 }
19098 },
19099
19100 /**
19101 * call preventDefault to prevent the browser's default behavior (scrolling in most cases)
19102 * @param {Object} srcEvent
19103 */
19104 preventSrc: function (srcEvent) {
19105 this.manager.session.prevented = true;
19106 srcEvent.preventDefault();
19107 }
19108 };
19109 /**
19110 * when the touchActions are collected they are not a valid value, so we need to clean things up. *
19111 * @param {String} actions
19112 * @returns {*}
19113 */
19114
19115 function cleanTouchActions(actions) {
19116 // none
19117 if (inStr(actions, TOUCH_ACTION_NONE)) {
19118 return TOUCH_ACTION_NONE;
19119 }
19120
19121 var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X);
19122 var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y); // if both pan-x and pan-y are set (different recognizers
19123 // for different directions, e.g. horizontal pan but vertical swipe?)
19124 // we need none (as otherwise with pan-x pan-y combined none of these
19125 // recognizers will work, since the browser would handle all panning
19126
19127 if (hasPanX && hasPanY) {
19128 return TOUCH_ACTION_NONE;
19129 } // pan-x OR pan-y
19130
19131
19132 if (hasPanX || hasPanY) {
19133 return hasPanX ? TOUCH_ACTION_PAN_X : TOUCH_ACTION_PAN_Y;
19134 } // manipulation
19135
19136
19137 if (inStr(actions, TOUCH_ACTION_MANIPULATION)) {
19138 return TOUCH_ACTION_MANIPULATION;
19139 }
19140
19141 return TOUCH_ACTION_AUTO;
19142 }
19143
19144 function getTouchActionProps() {
19145 if (!NATIVE_TOUCH_ACTION) {
19146 return false;
19147 }
19148
19149 var touchMap = {};
19150 var cssSupports = window.CSS && window.CSS.supports;
19151 ['auto', 'manipulation', 'pan-y', 'pan-x', 'pan-x pan-y', 'none'].forEach(function (val) {
19152 // If css.supports is not supported but there is native touch-action assume it supports
19153 // all values. This is the case for IE 10 and 11.
19154 touchMap[val] = cssSupports ? window.CSS.supports('touch-action', val) : true;
19155 });
19156 return touchMap;
19157 }
19158 /**
19159 * Recognizer flow explained; *
19160 * All recognizers have the initial state of POSSIBLE when a input session starts.
19161 * The definition of a input session is from the first input until the last input, with all it's movement in it. *
19162 * Example session for mouse-input: mousedown -> mousemove -> mouseup
19163 *
19164 * On each recognizing cycle (see Manager.recognize) the .recognize() method is executed
19165 * which determines with state it should be.
19166 *
19167 * If the recognizer has the state FAILED, CANCELLED or RECOGNIZED (equals ENDED), it is reset to
19168 * POSSIBLE to give it another change on the next cycle.
19169 *
19170 * Possible
19171 * |
19172 * +-----+---------------+
19173 * | |
19174 * +-----+-----+ |
19175 * | | |
19176 * Failed Cancelled |
19177 * +-------+------+
19178 * | |
19179 * Recognized Began
19180 * |
19181 * Changed
19182 * |
19183 * Ended/Recognized
19184 */
19185
19186
19187 var STATE_POSSIBLE = 1;
19188 var STATE_BEGAN = 2;
19189 var STATE_CHANGED = 4;
19190 var STATE_ENDED = 8;
19191 var STATE_RECOGNIZED = STATE_ENDED;
19192 var STATE_CANCELLED = 16;
19193 var STATE_FAILED = 32;
19194 /**
19195 * Recognizer
19196 * Every recognizer needs to extend from this class.
19197 * @constructor
19198 * @param {Object} options
19199 */
19200
19201 function Recognizer(options) {
19202 this.options = assign({}, this.defaults, options || {});
19203 this.id = uniqueId();
19204 this.manager = null; // default is enable true
19205
19206 this.options.enable = ifUndefined(this.options.enable, true);
19207 this.state = STATE_POSSIBLE;
19208 this.simultaneous = {};
19209 this.requireFail = [];
19210 }
19211
19212 Recognizer.prototype = {
19213 /**
19214 * @virtual
19215 * @type {Object}
19216 */
19217 defaults: {},
19218
19219 /**
19220 * set options
19221 * @param {Object} options
19222 * @return {Recognizer}
19223 */
19224 set: function (options) {
19225 assign(this.options, options); // also update the touchAction, in case something changed about the directions/enabled state
19226
19227 this.manager && this.manager.touchAction.update();
19228 return this;
19229 },
19230
19231 /**
19232 * recognize simultaneous with an other recognizer.
19233 * @param {Recognizer} otherRecognizer
19234 * @returns {Recognizer} this
19235 */
19236 recognizeWith: function (otherRecognizer) {
19237 if (invokeArrayArg(otherRecognizer, 'recognizeWith', this)) {
19238 return this;
19239 }
19240
19241 var simultaneous = this.simultaneous;
19242 otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
19243
19244 if (!simultaneous[otherRecognizer.id]) {
19245 simultaneous[otherRecognizer.id] = otherRecognizer;
19246 otherRecognizer.recognizeWith(this);
19247 }
19248
19249 return this;
19250 },
19251
19252 /**
19253 * drop the simultaneous link. it doesnt remove the link on the other recognizer.
19254 * @param {Recognizer} otherRecognizer
19255 * @returns {Recognizer} this
19256 */
19257 dropRecognizeWith: function (otherRecognizer) {
19258 if (invokeArrayArg(otherRecognizer, 'dropRecognizeWith', this)) {
19259 return this;
19260 }
19261
19262 otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
19263 delete this.simultaneous[otherRecognizer.id];
19264 return this;
19265 },
19266
19267 /**
19268 * recognizer can only run when an other is failing
19269 * @param {Recognizer} otherRecognizer
19270 * @returns {Recognizer} this
19271 */
19272 requireFailure: function (otherRecognizer) {
19273 if (invokeArrayArg(otherRecognizer, 'requireFailure', this)) {
19274 return this;
19275 }
19276
19277 var requireFail = this.requireFail;
19278 otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
19279
19280 if (inArray(requireFail, otherRecognizer) === -1) {
19281 requireFail.push(otherRecognizer);
19282 otherRecognizer.requireFailure(this);
19283 }
19284
19285 return this;
19286 },
19287
19288 /**
19289 * drop the requireFailure link. it does not remove the link on the other recognizer.
19290 * @param {Recognizer} otherRecognizer
19291 * @returns {Recognizer} this
19292 */
19293 dropRequireFailure: function (otherRecognizer) {
19294 if (invokeArrayArg(otherRecognizer, 'dropRequireFailure', this)) {
19295 return this;
19296 }
19297
19298 otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
19299 var index = inArray(this.requireFail, otherRecognizer);
19300
19301 if (index > -1) {
19302 this.requireFail.splice(index, 1);
19303 }
19304
19305 return this;
19306 },
19307
19308 /**
19309 * has require failures boolean
19310 * @returns {boolean}
19311 */
19312 hasRequireFailures: function () {
19313 return this.requireFail.length > 0;
19314 },
19315
19316 /**
19317 * if the recognizer can recognize simultaneous with an other recognizer
19318 * @param {Recognizer} otherRecognizer
19319 * @returns {Boolean}
19320 */
19321 canRecognizeWith: function (otherRecognizer) {
19322 return !!this.simultaneous[otherRecognizer.id];
19323 },
19324
19325 /**
19326 * You should use `tryEmit` instead of `emit` directly to check
19327 * that all the needed recognizers has failed before emitting.
19328 * @param {Object} input
19329 */
19330 emit: function (input) {
19331 var self = this;
19332 var state = this.state;
19333
19334 function emit(event) {
19335 self.manager.emit(event, input);
19336 } // 'panstart' and 'panmove'
19337
19338
19339 if (state < STATE_ENDED) {
19340 emit(self.options.event + stateStr(state));
19341 }
19342
19343 emit(self.options.event); // simple 'eventName' events
19344
19345 if (input.additionalEvent) {
19346 // additional event(panleft, panright, pinchin, pinchout...)
19347 emit(input.additionalEvent);
19348 } // panend and pancancel
19349
19350
19351 if (state >= STATE_ENDED) {
19352 emit(self.options.event + stateStr(state));
19353 }
19354 },
19355
19356 /**
19357 * Check that all the require failure recognizers has failed,
19358 * if true, it emits a gesture event,
19359 * otherwise, setup the state to FAILED.
19360 * @param {Object} input
19361 */
19362 tryEmit: function (input) {
19363 if (this.canEmit()) {
19364 return this.emit(input);
19365 } // it's failing anyway
19366
19367
19368 this.state = STATE_FAILED;
19369 },
19370
19371 /**
19372 * can we emit?
19373 * @returns {boolean}
19374 */
19375 canEmit: function () {
19376 var i = 0;
19377
19378 while (i < this.requireFail.length) {
19379 if (!(this.requireFail[i].state & (STATE_FAILED | STATE_POSSIBLE))) {
19380 return false;
19381 }
19382
19383 i++;
19384 }
19385
19386 return true;
19387 },
19388
19389 /**
19390 * update the recognizer
19391 * @param {Object} inputData
19392 */
19393 recognize: function (inputData) {
19394 // make a new copy of the inputData
19395 // so we can change the inputData without messing up the other recognizers
19396 var inputDataClone = assign({}, inputData); // is is enabled and allow recognizing?
19397
19398 if (!boolOrFn(this.options.enable, [this, inputDataClone])) {
19399 this.reset();
19400 this.state = STATE_FAILED;
19401 return;
19402 } // reset when we've reached the end
19403
19404
19405 if (this.state & (STATE_RECOGNIZED | STATE_CANCELLED | STATE_FAILED)) {
19406 this.state = STATE_POSSIBLE;
19407 }
19408
19409 this.state = this.process(inputDataClone); // the recognizer has recognized a gesture
19410 // so trigger an event
19411
19412 if (this.state & (STATE_BEGAN | STATE_CHANGED | STATE_ENDED | STATE_CANCELLED)) {
19413 this.tryEmit(inputDataClone);
19414 }
19415 },
19416
19417 /**
19418 * return the state of the recognizer
19419 * the actual recognizing happens in this method
19420 * @virtual
19421 * @param {Object} inputData
19422 * @returns {Const} STATE
19423 */
19424 process: function (inputData) {},
19425 // jshint ignore:line
19426
19427 /**
19428 * return the preferred touch-action
19429 * @virtual
19430 * @returns {Array}
19431 */
19432 getTouchAction: function () {},
19433
19434 /**
19435 * called when the gesture isn't allowed to recognize
19436 * like when another is being recognized or it is disabled
19437 * @virtual
19438 */
19439 reset: function () {}
19440 };
19441 /**
19442 * get a usable string, used as event postfix
19443 * @param {Const} state
19444 * @returns {String} state
19445 */
19446
19447 function stateStr(state) {
19448 if (state & STATE_CANCELLED) {
19449 return 'cancel';
19450 } else if (state & STATE_ENDED) {
19451 return 'end';
19452 } else if (state & STATE_CHANGED) {
19453 return 'move';
19454 } else if (state & STATE_BEGAN) {
19455 return 'start';
19456 }
19457
19458 return '';
19459 }
19460 /**
19461 * direction cons to string
19462 * @param {Const} direction
19463 * @returns {String}
19464 */
19465
19466
19467 function directionStr(direction) {
19468 if (direction == DIRECTION_DOWN) {
19469 return 'down';
19470 } else if (direction == DIRECTION_UP) {
19471 return 'up';
19472 } else if (direction == DIRECTION_LEFT) {
19473 return 'left';
19474 } else if (direction == DIRECTION_RIGHT) {
19475 return 'right';
19476 }
19477
19478 return '';
19479 }
19480 /**
19481 * get a recognizer by name if it is bound to a manager
19482 * @param {Recognizer|String} otherRecognizer
19483 * @param {Recognizer} recognizer
19484 * @returns {Recognizer}
19485 */
19486
19487
19488 function getRecognizerByNameIfManager(otherRecognizer, recognizer) {
19489 var manager = recognizer.manager;
19490
19491 if (manager) {
19492 return manager.get(otherRecognizer);
19493 }
19494
19495 return otherRecognizer;
19496 }
19497 /**
19498 * This recognizer is just used as a base for the simple attribute recognizers.
19499 * @constructor
19500 * @extends Recognizer
19501 */
19502
19503
19504 function AttrRecognizer() {
19505 Recognizer.apply(this, arguments);
19506 }
19507
19508 inherit(AttrRecognizer, Recognizer, {
19509 /**
19510 * @namespace
19511 * @memberof AttrRecognizer
19512 */
19513 defaults: {
19514 /**
19515 * @type {Number}
19516 * @default 1
19517 */
19518 pointers: 1
19519 },
19520
19521 /**
19522 * Used to check if it the recognizer receives valid input, like input.distance > 10.
19523 * @memberof AttrRecognizer
19524 * @param {Object} input
19525 * @returns {Boolean} recognized
19526 */
19527 attrTest: function (input) {
19528 var optionPointers = this.options.pointers;
19529 return optionPointers === 0 || input.pointers.length === optionPointers;
19530 },
19531
19532 /**
19533 * Process the input and return the state for the recognizer
19534 * @memberof AttrRecognizer
19535 * @param {Object} input
19536 * @returns {*} State
19537 */
19538 process: function (input) {
19539 var state = this.state;
19540 var eventType = input.eventType;
19541 var isRecognized = state & (STATE_BEGAN | STATE_CHANGED);
19542 var isValid = this.attrTest(input); // on cancel input and we've recognized before, return STATE_CANCELLED
19543
19544 if (isRecognized && (eventType & INPUT_CANCEL || !isValid)) {
19545 return state | STATE_CANCELLED;
19546 } else if (isRecognized || isValid) {
19547 if (eventType & INPUT_END) {
19548 return state | STATE_ENDED;
19549 } else if (!(state & STATE_BEGAN)) {
19550 return STATE_BEGAN;
19551 }
19552
19553 return state | STATE_CHANGED;
19554 }
19555
19556 return STATE_FAILED;
19557 }
19558 });
19559 /**
19560 * Pan
19561 * Recognized when the pointer is down and moved in the allowed direction.
19562 * @constructor
19563 * @extends AttrRecognizer
19564 */
19565
19566 function PanRecognizer() {
19567 AttrRecognizer.apply(this, arguments);
19568 this.pX = null;
19569 this.pY = null;
19570 }
19571
19572 inherit(PanRecognizer, AttrRecognizer, {
19573 /**
19574 * @namespace
19575 * @memberof PanRecognizer
19576 */
19577 defaults: {
19578 event: 'pan',
19579 threshold: 10,
19580 pointers: 1,
19581 direction: DIRECTION_ALL
19582 },
19583 getTouchAction: function () {
19584 var direction = this.options.direction;
19585 var actions = [];
19586
19587 if (direction & DIRECTION_HORIZONTAL) {
19588 actions.push(TOUCH_ACTION_PAN_Y);
19589 }
19590
19591 if (direction & DIRECTION_VERTICAL) {
19592 actions.push(TOUCH_ACTION_PAN_X);
19593 }
19594
19595 return actions;
19596 },
19597 directionTest: function (input) {
19598 var options = this.options;
19599 var hasMoved = true;
19600 var distance = input.distance;
19601 var direction = input.direction;
19602 var x = input.deltaX;
19603 var y = input.deltaY; // lock to axis?
19604
19605 if (!(direction & options.direction)) {
19606 if (options.direction & DIRECTION_HORIZONTAL) {
19607 direction = x === 0 ? DIRECTION_NONE : x < 0 ? DIRECTION_LEFT : DIRECTION_RIGHT;
19608 hasMoved = x != this.pX;
19609 distance = Math.abs(input.deltaX);
19610 } else {
19611 direction = y === 0 ? DIRECTION_NONE : y < 0 ? DIRECTION_UP : DIRECTION_DOWN;
19612 hasMoved = y != this.pY;
19613 distance = Math.abs(input.deltaY);
19614 }
19615 }
19616
19617 input.direction = direction;
19618 return hasMoved && distance > options.threshold && direction & options.direction;
19619 },
19620 attrTest: function (input) {
19621 return AttrRecognizer.prototype.attrTest.call(this, input) && (this.state & STATE_BEGAN || !(this.state & STATE_BEGAN) && this.directionTest(input));
19622 },
19623 emit: function (input) {
19624 this.pX = input.deltaX;
19625 this.pY = input.deltaY;
19626 var direction = directionStr(input.direction);
19627
19628 if (direction) {
19629 input.additionalEvent = this.options.event + direction;
19630 }
19631
19632 this._super.emit.call(this, input);
19633 }
19634 });
19635 /**
19636 * Pinch
19637 * Recognized when two or more pointers are moving toward (zoom-in) or away from each other (zoom-out).
19638 * @constructor
19639 * @extends AttrRecognizer
19640 */
19641
19642 function PinchRecognizer() {
19643 AttrRecognizer.apply(this, arguments);
19644 }
19645
19646 inherit(PinchRecognizer, AttrRecognizer, {
19647 /**
19648 * @namespace
19649 * @memberof PinchRecognizer
19650 */
19651 defaults: {
19652 event: 'pinch',
19653 threshold: 0,
19654 pointers: 2
19655 },
19656 getTouchAction: function () {
19657 return [TOUCH_ACTION_NONE];
19658 },
19659 attrTest: function (input) {
19660 return this._super.attrTest.call(this, input) && (Math.abs(input.scale - 1) > this.options.threshold || this.state & STATE_BEGAN);
19661 },
19662 emit: function (input) {
19663 if (input.scale !== 1) {
19664 var inOut = input.scale < 1 ? 'in' : 'out';
19665 input.additionalEvent = this.options.event + inOut;
19666 }
19667
19668 this._super.emit.call(this, input);
19669 }
19670 });
19671 /**
19672 * Press
19673 * Recognized when the pointer is down for x ms without any movement.
19674 * @constructor
19675 * @extends Recognizer
19676 */
19677
19678 function PressRecognizer() {
19679 Recognizer.apply(this, arguments);
19680 this._timer = null;
19681 this._input = null;
19682 }
19683
19684 inherit(PressRecognizer, Recognizer, {
19685 /**
19686 * @namespace
19687 * @memberof PressRecognizer
19688 */
19689 defaults: {
19690 event: 'press',
19691 pointers: 1,
19692 time: 251,
19693 // minimal time of the pointer to be pressed
19694 threshold: 9 // a minimal movement is ok, but keep it low
19695
19696 },
19697 getTouchAction: function () {
19698 return [TOUCH_ACTION_AUTO];
19699 },
19700 process: function (input) {
19701 var options = this.options;
19702 var validPointers = input.pointers.length === options.pointers;
19703 var validMovement = input.distance < options.threshold;
19704 var validTime = input.deltaTime > options.time;
19705 this._input = input; // we only allow little movement
19706 // and we've reached an end event, so a tap is possible
19707
19708 if (!validMovement || !validPointers || input.eventType & (INPUT_END | INPUT_CANCEL) && !validTime) {
19709 this.reset();
19710 } else if (input.eventType & INPUT_START) {
19711 this.reset();
19712 this._timer = setTimeoutContext(function () {
19713 this.state = STATE_RECOGNIZED;
19714 this.tryEmit();
19715 }, options.time, this);
19716 } else if (input.eventType & INPUT_END) {
19717 return STATE_RECOGNIZED;
19718 }
19719
19720 return STATE_FAILED;
19721 },
19722 reset: function () {
19723 clearTimeout(this._timer);
19724 },
19725 emit: function (input) {
19726 if (this.state !== STATE_RECOGNIZED) {
19727 return;
19728 }
19729
19730 if (input && input.eventType & INPUT_END) {
19731 this.manager.emit(this.options.event + 'up', input);
19732 } else {
19733 this._input.timeStamp = now();
19734 this.manager.emit(this.options.event, this._input);
19735 }
19736 }
19737 });
19738 /**
19739 * Rotate
19740 * Recognized when two or more pointer are moving in a circular motion.
19741 * @constructor
19742 * @extends AttrRecognizer
19743 */
19744
19745 function RotateRecognizer() {
19746 AttrRecognizer.apply(this, arguments);
19747 }
19748
19749 inherit(RotateRecognizer, AttrRecognizer, {
19750 /**
19751 * @namespace
19752 * @memberof RotateRecognizer
19753 */
19754 defaults: {
19755 event: 'rotate',
19756 threshold: 0,
19757 pointers: 2
19758 },
19759 getTouchAction: function () {
19760 return [TOUCH_ACTION_NONE];
19761 },
19762 attrTest: function (input) {
19763 return this._super.attrTest.call(this, input) && (Math.abs(input.rotation) > this.options.threshold || this.state & STATE_BEGAN);
19764 }
19765 });
19766 /**
19767 * Swipe
19768 * Recognized when the pointer is moving fast (velocity), with enough distance in the allowed direction.
19769 * @constructor
19770 * @extends AttrRecognizer
19771 */
19772
19773 function SwipeRecognizer() {
19774 AttrRecognizer.apply(this, arguments);
19775 }
19776
19777 inherit(SwipeRecognizer, AttrRecognizer, {
19778 /**
19779 * @namespace
19780 * @memberof SwipeRecognizer
19781 */
19782 defaults: {
19783 event: 'swipe',
19784 threshold: 10,
19785 velocity: 0.3,
19786 direction: DIRECTION_HORIZONTAL | DIRECTION_VERTICAL,
19787 pointers: 1
19788 },
19789 getTouchAction: function () {
19790 return PanRecognizer.prototype.getTouchAction.call(this);
19791 },
19792 attrTest: function (input) {
19793 var direction = this.options.direction;
19794 var velocity;
19795
19796 if (direction & (DIRECTION_HORIZONTAL | DIRECTION_VERTICAL)) {
19797 velocity = input.overallVelocity;
19798 } else if (direction & DIRECTION_HORIZONTAL) {
19799 velocity = input.overallVelocityX;
19800 } else if (direction & DIRECTION_VERTICAL) {
19801 velocity = input.overallVelocityY;
19802 }
19803
19804 return this._super.attrTest.call(this, input) && direction & input.offsetDirection && input.distance > this.options.threshold && input.maxPointers == this.options.pointers && abs(velocity) > this.options.velocity && input.eventType & INPUT_END;
19805 },
19806 emit: function (input) {
19807 var direction = directionStr(input.offsetDirection);
19808
19809 if (direction) {
19810 this.manager.emit(this.options.event + direction, input);
19811 }
19812
19813 this.manager.emit(this.options.event, input);
19814 }
19815 });
19816 /**
19817 * A tap is ecognized when the pointer is doing a small tap/click. Multiple taps are recognized if they occur
19818 * between the given interval and position. The delay option can be used to recognize multi-taps without firing
19819 * a single tap.
19820 *
19821 * The eventData from the emitted event contains the property `tapCount`, which contains the amount of
19822 * multi-taps being recognized.
19823 * @constructor
19824 * @extends Recognizer
19825 */
19826
19827 function TapRecognizer() {
19828 Recognizer.apply(this, arguments); // previous time and center,
19829 // used for tap counting
19830
19831 this.pTime = false;
19832 this.pCenter = false;
19833 this._timer = null;
19834 this._input = null;
19835 this.count = 0;
19836 }
19837
19838 inherit(TapRecognizer, Recognizer, {
19839 /**
19840 * @namespace
19841 * @memberof PinchRecognizer
19842 */
19843 defaults: {
19844 event: 'tap',
19845 pointers: 1,
19846 taps: 1,
19847 interval: 300,
19848 // max time between the multi-tap taps
19849 time: 250,
19850 // max time of the pointer to be down (like finger on the screen)
19851 threshold: 9,
19852 // a minimal movement is ok, but keep it low
19853 posThreshold: 10 // a multi-tap can be a bit off the initial position
19854
19855 },
19856 getTouchAction: function () {
19857 return [TOUCH_ACTION_MANIPULATION];
19858 },
19859 process: function (input) {
19860 var options = this.options;
19861 var validPointers = input.pointers.length === options.pointers;
19862 var validMovement = input.distance < options.threshold;
19863 var validTouchTime = input.deltaTime < options.time;
19864 this.reset();
19865
19866 if (input.eventType & INPUT_START && this.count === 0) {
19867 return this.failTimeout();
19868 } // we only allow little movement
19869 // and we've reached an end event, so a tap is possible
19870
19871
19872 if (validMovement && validTouchTime && validPointers) {
19873 if (input.eventType != INPUT_END) {
19874 return this.failTimeout();
19875 }
19876
19877 var validInterval = this.pTime ? input.timeStamp - this.pTime < options.interval : true;
19878 var validMultiTap = !this.pCenter || getDistance(this.pCenter, input.center) < options.posThreshold;
19879 this.pTime = input.timeStamp;
19880 this.pCenter = input.center;
19881
19882 if (!validMultiTap || !validInterval) {
19883 this.count = 1;
19884 } else {
19885 this.count += 1;
19886 }
19887
19888 this._input = input; // if tap count matches we have recognized it,
19889 // else it has began recognizing...
19890
19891 var tapCount = this.count % options.taps;
19892
19893 if (tapCount === 0) {
19894 // no failing requirements, immediately trigger the tap event
19895 // or wait as long as the multitap interval to trigger
19896 if (!this.hasRequireFailures()) {
19897 return STATE_RECOGNIZED;
19898 } else {
19899 this._timer = setTimeoutContext(function () {
19900 this.state = STATE_RECOGNIZED;
19901 this.tryEmit();
19902 }, options.interval, this);
19903 return STATE_BEGAN;
19904 }
19905 }
19906 }
19907
19908 return STATE_FAILED;
19909 },
19910 failTimeout: function () {
19911 this._timer = setTimeoutContext(function () {
19912 this.state = STATE_FAILED;
19913 }, this.options.interval, this);
19914 return STATE_FAILED;
19915 },
19916 reset: function () {
19917 clearTimeout(this._timer);
19918 },
19919 emit: function () {
19920 if (this.state == STATE_RECOGNIZED) {
19921 this._input.tapCount = this.count;
19922 this.manager.emit(this.options.event, this._input);
19923 }
19924 }
19925 });
19926 /**
19927 * Simple way to create a manager with a default set of recognizers.
19928 * @param {HTMLElement} element
19929 * @param {Object} [options]
19930 * @constructor
19931 */
19932
19933 function Hammer(element, options) {
19934 options = options || {};
19935 options.recognizers = ifUndefined(options.recognizers, Hammer.defaults.preset);
19936 return new Manager(element, options);
19937 }
19938 /**
19939 * @const {string}
19940 */
19941
19942
19943 Hammer.VERSION = '2.0.7';
19944 /**
19945 * default settings
19946 * @namespace
19947 */
19948
19949 Hammer.defaults = {
19950 /**
19951 * set if DOM events are being triggered.
19952 * But this is slower and unused by simple implementations, so disabled by default.
19953 * @type {Boolean}
19954 * @default false
19955 */
19956 domEvents: false,
19957
19958 /**
19959 * The value for the touchAction property/fallback.
19960 * When set to `compute` it will magically set the correct value based on the added recognizers.
19961 * @type {String}
19962 * @default compute
19963 */
19964 touchAction: TOUCH_ACTION_COMPUTE,
19965
19966 /**
19967 * @type {Boolean}
19968 * @default true
19969 */
19970 enable: true,
19971
19972 /**
19973 * EXPERIMENTAL FEATURE -- can be removed/changed
19974 * Change the parent input target element.
19975 * If Null, then it is being set the to main element.
19976 * @type {Null|EventTarget}
19977 * @default null
19978 */
19979 inputTarget: null,
19980
19981 /**
19982 * force an input class
19983 * @type {Null|Function}
19984 * @default null
19985 */
19986 inputClass: null,
19987
19988 /**
19989 * Default recognizer setup when calling `Hammer()`
19990 * When creating a new Manager these will be skipped.
19991 * @type {Array}
19992 */
19993 preset: [// RecognizerClass, options, [recognizeWith, ...], [requireFailure, ...]
19994 [RotateRecognizer, {
19995 enable: false
19996 }], [PinchRecognizer, {
19997 enable: false
19998 }, ['rotate']], [SwipeRecognizer, {
19999 direction: DIRECTION_HORIZONTAL
20000 }], [PanRecognizer, {
20001 direction: DIRECTION_HORIZONTAL
20002 }, ['swipe']], [TapRecognizer], [TapRecognizer, {
20003 event: 'doubletap',
20004 taps: 2
20005 }, ['tap']], [PressRecognizer]],
20006
20007 /**
20008 * Some CSS properties can be used to improve the working of Hammer.
20009 * Add them to this method and they will be set when creating a new Manager.
20010 * @namespace
20011 */
20012 cssProps: {
20013 /**
20014 * Disables text selection to improve the dragging gesture. Mainly for desktop browsers.
20015 * @type {String}
20016 * @default 'none'
20017 */
20018 userSelect: 'none',
20019
20020 /**
20021 * Disable the Windows Phone grippers when pressing an element.
20022 * @type {String}
20023 * @default 'none'
20024 */
20025 touchSelect: 'none',
20026
20027 /**
20028 * Disables the default callout shown when you touch and hold a touch target.
20029 * On iOS, when you touch and hold a touch target such as a link, Safari displays
20030 * a callout containing information about the link. This property allows you to disable that callout.
20031 * @type {String}
20032 * @default 'none'
20033 */
20034 touchCallout: 'none',
20035
20036 /**
20037 * Specifies whether zooming is enabled. Used by IE10>
20038 * @type {String}
20039 * @default 'none'
20040 */
20041 contentZooming: 'none',
20042
20043 /**
20044 * Specifies that an entire element should be draggable instead of its contents. Mainly for desktop browsers.
20045 * @type {String}
20046 * @default 'none'
20047 */
20048 userDrag: 'none',
20049
20050 /**
20051 * Overrides the highlight color shown when the user taps a link or a JavaScript
20052 * clickable element in iOS. This property obeys the alpha value, if specified.
20053 * @type {String}
20054 * @default 'rgba(0,0,0,0)'
20055 */
20056 tapHighlightColor: 'rgba(0,0,0,0)'
20057 }
20058 };
20059 var STOP = 1;
20060 var FORCED_STOP = 2;
20061 /**
20062 * Manager
20063 * @param {HTMLElement} element
20064 * @param {Object} [options]
20065 * @constructor
20066 */
20067
20068 function Manager(element, options) {
20069 this.options = assign({}, Hammer.defaults, options || {});
20070 this.options.inputTarget = this.options.inputTarget || element;
20071 this.handlers = {};
20072 this.session = {};
20073 this.recognizers = [];
20074 this.oldCssProps = {};
20075 this.element = element;
20076 this.input = createInputInstance(this);
20077 this.touchAction = new TouchAction(this, this.options.touchAction);
20078 toggleCssProps(this, true);
20079 each(this.options.recognizers, function (item) {
20080 var recognizer = this.add(new item[0](item[1]));
20081 item[2] && recognizer.recognizeWith(item[2]);
20082 item[3] && recognizer.requireFailure(item[3]);
20083 }, this);
20084 }
20085
20086 Manager.prototype = {
20087 /**
20088 * set options
20089 * @param {Object} options
20090 * @returns {Manager}
20091 */
20092 set: function (options) {
20093 assign(this.options, options); // Options that need a little more setup
20094
20095 if (options.touchAction) {
20096 this.touchAction.update();
20097 }
20098
20099 if (options.inputTarget) {
20100 // Clean up existing event listeners and reinitialize
20101 this.input.destroy();
20102 this.input.target = options.inputTarget;
20103 this.input.init();
20104 }
20105
20106 return this;
20107 },
20108
20109 /**
20110 * stop recognizing for this session.
20111 * This session will be discarded, when a new [input]start event is fired.
20112 * When forced, the recognizer cycle is stopped immediately.
20113 * @param {Boolean} [force]
20114 */
20115 stop: function (force) {
20116 this.session.stopped = force ? FORCED_STOP : STOP;
20117 },
20118
20119 /**
20120 * run the recognizers!
20121 * called by the inputHandler function on every movement of the pointers (touches)
20122 * it walks through all the recognizers and tries to detect the gesture that is being made
20123 * @param {Object} inputData
20124 */
20125 recognize: function (inputData) {
20126 var session = this.session;
20127
20128 if (session.stopped) {
20129 return;
20130 } // run the touch-action polyfill
20131
20132
20133 this.touchAction.preventDefaults(inputData);
20134 var recognizer;
20135 var recognizers = this.recognizers; // this holds the recognizer that is being recognized.
20136 // so the recognizer's state needs to be BEGAN, CHANGED, ENDED or RECOGNIZED
20137 // if no recognizer is detecting a thing, it is set to `null`
20138
20139 var curRecognizer = session.curRecognizer; // reset when the last recognizer is recognized
20140 // or when we're in a new session
20141
20142 if (!curRecognizer || curRecognizer && curRecognizer.state & STATE_RECOGNIZED) {
20143 curRecognizer = session.curRecognizer = null;
20144 }
20145
20146 var i = 0;
20147
20148 while (i < recognizers.length) {
20149 recognizer = recognizers[i]; // find out if we are allowed try to recognize the input for this one.
20150 // 1. allow if the session is NOT forced stopped (see the .stop() method)
20151 // 2. allow if we still haven't recognized a gesture in this session, or the this recognizer is the one
20152 // that is being recognized.
20153 // 3. allow if the recognizer is allowed to run simultaneous with the current recognized recognizer.
20154 // this can be setup with the `recognizeWith()` method on the recognizer.
20155
20156 if (session.stopped !== FORCED_STOP && ( // 1
20157 !curRecognizer || recognizer == curRecognizer || // 2
20158 recognizer.canRecognizeWith(curRecognizer))) {
20159 // 3
20160 recognizer.recognize(inputData);
20161 } else {
20162 recognizer.reset();
20163 } // if the recognizer has been recognizing the input as a valid gesture, we want to store this one as the
20164 // current active recognizer. but only if we don't already have an active recognizer
20165
20166
20167 if (!curRecognizer && recognizer.state & (STATE_BEGAN | STATE_CHANGED | STATE_ENDED)) {
20168 curRecognizer = session.curRecognizer = recognizer;
20169 }
20170
20171 i++;
20172 }
20173 },
20174
20175 /**
20176 * get a recognizer by its event name.
20177 * @param {Recognizer|String} recognizer
20178 * @returns {Recognizer|Null}
20179 */
20180 get: function (recognizer) {
20181 if (recognizer instanceof Recognizer) {
20182 return recognizer;
20183 }
20184
20185 var recognizers = this.recognizers;
20186
20187 for (var i = 0; i < recognizers.length; i++) {
20188 if (recognizers[i].options.event == recognizer) {
20189 return recognizers[i];
20190 }
20191 }
20192
20193 return null;
20194 },
20195
20196 /**
20197 * add a recognizer to the manager
20198 * existing recognizers with the same event name will be removed
20199 * @param {Recognizer} recognizer
20200 * @returns {Recognizer|Manager}
20201 */
20202 add: function (recognizer) {
20203 if (invokeArrayArg(recognizer, 'add', this)) {
20204 return this;
20205 } // remove existing
20206
20207
20208 var existing = this.get(recognizer.options.event);
20209
20210 if (existing) {
20211 this.remove(existing);
20212 }
20213
20214 this.recognizers.push(recognizer);
20215 recognizer.manager = this;
20216 this.touchAction.update();
20217 return recognizer;
20218 },
20219
20220 /**
20221 * remove a recognizer by name or instance
20222 * @param {Recognizer|String} recognizer
20223 * @returns {Manager}
20224 */
20225 remove: function (recognizer) {
20226 if (invokeArrayArg(recognizer, 'remove', this)) {
20227 return this;
20228 }
20229
20230 recognizer = this.get(recognizer); // let's make sure this recognizer exists
20231
20232 if (recognizer) {
20233 var recognizers = this.recognizers;
20234 var index = inArray(recognizers, recognizer);
20235
20236 if (index !== -1) {
20237 recognizers.splice(index, 1);
20238 this.touchAction.update();
20239 }
20240 }
20241
20242 return this;
20243 },
20244
20245 /**
20246 * bind event
20247 * @param {String} events
20248 * @param {Function} handler
20249 * @returns {EventEmitter} this
20250 */
20251 on: function (events, handler) {
20252 if (events === undefined) {
20253 return;
20254 }
20255
20256 if (handler === undefined) {
20257 return;
20258 }
20259
20260 var handlers = this.handlers;
20261 each(splitStr(events), function (event) {
20262 handlers[event] = handlers[event] || [];
20263 handlers[event].push(handler);
20264 });
20265 return this;
20266 },
20267
20268 /**
20269 * unbind event, leave emit blank to remove all handlers
20270 * @param {String} events
20271 * @param {Function} [handler]
20272 * @returns {EventEmitter} this
20273 */
20274 off: function (events, handler) {
20275 if (events === undefined) {
20276 return;
20277 }
20278
20279 var handlers = this.handlers;
20280 each(splitStr(events), function (event) {
20281 if (!handler) {
20282 delete handlers[event];
20283 } else {
20284 handlers[event] && handlers[event].splice(inArray(handlers[event], handler), 1);
20285 }
20286 });
20287 return this;
20288 },
20289
20290 /**
20291 * emit event to the listeners
20292 * @param {String} event
20293 * @param {Object} data
20294 */
20295 emit: function (event, data) {
20296 // we also want to trigger dom events
20297 if (this.options.domEvents) {
20298 triggerDomEvent(event, data);
20299 } // no handlers, so skip it all
20300
20301
20302 var handlers = this.handlers[event] && this.handlers[event].slice();
20303
20304 if (!handlers || !handlers.length) {
20305 return;
20306 }
20307
20308 data.type = event;
20309
20310 data.preventDefault = function () {
20311 data.srcEvent.preventDefault();
20312 };
20313
20314 var i = 0;
20315
20316 while (i < handlers.length) {
20317 handlers[i](data);
20318 i++;
20319 }
20320 },
20321
20322 /**
20323 * destroy the manager and unbinds all events
20324 * it doesn't unbind dom events, that is the user own responsibility
20325 */
20326 destroy: function () {
20327 this.element && toggleCssProps(this, false);
20328 this.handlers = {};
20329 this.session = {};
20330 this.input.destroy();
20331 this.element = null;
20332 }
20333 };
20334 /**
20335 * add/remove the css properties as defined in manager.options.cssProps
20336 * @param {Manager} manager
20337 * @param {Boolean} add
20338 */
20339
20340 function toggleCssProps(manager, add) {
20341 var element = manager.element;
20342
20343 if (!element.style) {
20344 return;
20345 }
20346
20347 var prop;
20348 each(manager.options.cssProps, function (value, name) {
20349 prop = prefixed(element.style, name);
20350
20351 if (add) {
20352 manager.oldCssProps[prop] = element.style[prop];
20353 element.style[prop] = value;
20354 } else {
20355 element.style[prop] = manager.oldCssProps[prop] || '';
20356 }
20357 });
20358
20359 if (!add) {
20360 manager.oldCssProps = {};
20361 }
20362 }
20363 /**
20364 * trigger dom event
20365 * @param {String} event
20366 * @param {Object} data
20367 */
20368
20369
20370 function triggerDomEvent(event, data) {
20371 var gestureEvent = document.createEvent('Event');
20372 gestureEvent.initEvent(event, true, true);
20373 gestureEvent.gesture = data;
20374 data.target.dispatchEvent(gestureEvent);
20375 }
20376
20377 assign(Hammer, {
20378 INPUT_START: INPUT_START,
20379 INPUT_MOVE: INPUT_MOVE,
20380 INPUT_END: INPUT_END,
20381 INPUT_CANCEL: INPUT_CANCEL,
20382 STATE_POSSIBLE: STATE_POSSIBLE,
20383 STATE_BEGAN: STATE_BEGAN,
20384 STATE_CHANGED: STATE_CHANGED,
20385 STATE_ENDED: STATE_ENDED,
20386 STATE_RECOGNIZED: STATE_RECOGNIZED,
20387 STATE_CANCELLED: STATE_CANCELLED,
20388 STATE_FAILED: STATE_FAILED,
20389 DIRECTION_NONE: DIRECTION_NONE,
20390 DIRECTION_LEFT: DIRECTION_LEFT,
20391 DIRECTION_RIGHT: DIRECTION_RIGHT,
20392 DIRECTION_UP: DIRECTION_UP,
20393 DIRECTION_DOWN: DIRECTION_DOWN,
20394 DIRECTION_HORIZONTAL: DIRECTION_HORIZONTAL,
20395 DIRECTION_VERTICAL: DIRECTION_VERTICAL,
20396 DIRECTION_ALL: DIRECTION_ALL,
20397 Manager: Manager,
20398 Input: Input,
20399 TouchAction: TouchAction,
20400 TouchInput: TouchInput,
20401 MouseInput: MouseInput,
20402 PointerEventInput: PointerEventInput,
20403 TouchMouseInput: TouchMouseInput,
20404 SingleTouchInput: SingleTouchInput,
20405 Recognizer: Recognizer,
20406 AttrRecognizer: AttrRecognizer,
20407 Tap: TapRecognizer,
20408 Pan: PanRecognizer,
20409 Swipe: SwipeRecognizer,
20410 Pinch: PinchRecognizer,
20411 Rotate: RotateRecognizer,
20412 Press: PressRecognizer,
20413 on: addEventListeners,
20414 off: removeEventListeners,
20415 each: each,
20416 merge: merge,
20417 extend: extend,
20418 assign: assign,
20419 inherit: inherit,
20420 bindFn: bindFn,
20421 prefixed: prefixed
20422 }); // this prevents errors when Hammer is loaded in the presence of an AMD
20423 // style loader but by script tag, not by the loader.
20424
20425 var freeGlobal = typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {}; // jshint ignore:line
20426
20427 freeGlobal.Hammer = Hammer;
20428
20429 if (true) {
20430 !(__WEBPACK_AMD_DEFINE_RESULT__ = (function () {
20431 return Hammer;
20432 }).call(exports, __webpack_require__, exports, module),
20433 __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
20434 } else if (typeof module != 'undefined' && module.exports) {
20435 module.exports = Hammer;
20436 } else {
20437 window[exportName] = Hammer;
20438 }
20439})(window, document, 'Hammer');
20440
20441/***/ }),
20442/* 139 */
20443/***/ (function(module, exports, __webpack_require__) {
20444
20445function _inheritsLoose(subClass, superClass) {
20446 subClass.prototype = Object.create(superClass.prototype);
20447 subClass.prototype.constructor = subClass;
20448 subClass.__proto__ = superClass;
20449}
20450
20451var Util = __webpack_require__(0);
20452
20453var Helper = __webpack_require__(19);
20454
20455var Interaction = __webpack_require__(21);
20456
20457var Chart = __webpack_require__(11);
20458
20459var IntervalSelect =
20460/*#__PURE__*/
20461function (_Interaction) {
20462 _inheritsLoose(IntervalSelect, _Interaction);
20463
20464 var _proto = IntervalSelect.prototype;
20465
20466 _proto.getDefaultCfg = function getDefaultCfg() {
20467 var defaultCfg = _Interaction.prototype.getDefaultCfg.call(this);
20468
20469 defaultCfg = Util.mix({}, defaultCfg, {
20470 startEvent: 'tap',
20471 processEvent: null,
20472 selectAxis: true,
20473 selectAxisStyle: {
20474 fontWeight: 'bold'
20475 },
20476 mode: 'shape',
20477 selectStyle: {
20478 fillOpacity: 1
20479 },
20480 unSelectStyle: {
20481 fillOpacity: 0.4
20482 },
20483 cancelable: true,
20484 defaultSelected: null // set the default selected shape
20485
20486 });
20487
20488 if (Util.isWx || Util.isMy) {
20489 // 小程序
20490 defaultCfg.startEvent = 'touchstart';
20491 defaultCfg.endEvent = 'touchend';
20492 }
20493
20494 return defaultCfg;
20495 };
20496
20497 function IntervalSelect(cfg, chart) {
20498 var _this;
20499
20500 _this = _Interaction.call(this, cfg, chart) || this;
20501 var defaultSelected = _this.defaultSelected;
20502
20503 if (Util.isObject(defaultSelected)) {
20504 var _this$_selectShapesBy = _this._selectShapesByData(defaultSelected),
20505 selectedShape = _this$_selectShapesBy.selectedShape,
20506 unSelectedShapes = _this$_selectShapesBy.unSelectedShapes;
20507
20508 selectedShape && _this._selectShapes(selectedShape, unSelectedShapes);
20509 _this.selectedShape = selectedShape;
20510 }
20511
20512 return _this;
20513 }
20514
20515 _proto._getIntervalShapes = function _getIntervalShapes() {
20516 var children = [];
20517 var chart = this.chart;
20518 var geoms = chart.get('geoms');
20519 geoms.forEach(function (geom) {
20520 if (geom.get('type') === 'interval') {
20521 // only works for Interval geometry type
20522 var container = geom.get('container');
20523 children = children.concat(container.get('children'));
20524 }
20525 });
20526 return children;
20527 };
20528
20529 _proto._resetShape = function _resetShape(shape) {
20530 var originAttrs = shape.get('_originAttrs');
20531
20532 if (originAttrs) {
20533 shape._attrs.attrs = originAttrs;
20534 shape.set('_originAttrs', null);
20535 }
20536 };
20537
20538 _proto._setEventData = function _setEventData(ev) {
20539 var selectedShape = this.selectedShape;
20540
20541 if (selectedShape && !selectedShape.get('destroyed')) {
20542 ev.data = selectedShape.get('origin')._origin;
20543 ev.shapeInfo = selectedShape.get('origin');
20544 ev.shape = selectedShape;
20545 ev.selected = !!selectedShape.get('_selected');
20546 }
20547 };
20548
20549 _proto._selectShapesByData = function _selectShapesByData(data) {
20550 var children = this._getIntervalShapes();
20551
20552 var selectedShape = null;
20553 var unSelectedShapes = [];
20554 Util.each(children, function (child) {
20555 if (child.get('isShape') && child.get('className') === 'interval') {
20556 // get geometry's shape
20557 var shapeData = child.get('origin')._origin;
20558
20559 if (Util.isObjectValueEqual(shapeData, data)) {
20560 selectedShape = child;
20561 } else {
20562 unSelectedShapes.push(child);
20563 }
20564 }
20565 });
20566 return {
20567 selectedShape: selectedShape,
20568 unSelectedShapes: unSelectedShapes
20569 };
20570 };
20571
20572 _proto._selectShapes = function _selectShapes(selectedShape, unSelectedShapes) {
20573 var selectStyle = this.selectStyle,
20574 unSelectStyle = this.unSelectStyle,
20575 selectAxisStyle = this.selectAxisStyle,
20576 chart = this.chart;
20577
20578 if (!selectedShape.get('_originAttrs')) {
20579 var originAttrs = Object.assign({}, selectedShape.attr());
20580 selectedShape.set('_originAttrs', originAttrs);
20581 }
20582
20583 selectedShape.attr(selectStyle);
20584 Util.each(unSelectedShapes, function (child) {
20585 if (!child.get('_originAttrs')) {
20586 var _originAttrs = Object.assign({}, child.attr());
20587
20588 child.set('_originAttrs', _originAttrs);
20589 } else {
20590 child.attr(child.get('_originAttrs'));
20591 }
20592
20593 child.set('_selected', false);
20594 unSelectStyle && child.attr(unSelectStyle);
20595 });
20596 selectedShape.set('_selected', true);
20597
20598 if (this.selectAxis) {
20599 if (this.selectedAxisShape) {
20600 this._resetShape(this.selectedAxisShape);
20601 }
20602
20603 var xScale = chart.getXScale();
20604
20605 var origin = selectedShape.get('origin')._origin;
20606
20607 var _chart$get = chart.get('axisController'),
20608 frontPlot = _chart$get.frontPlot,
20609 backPlot = _chart$get.backPlot;
20610
20611 var axisShape;
20612 Util.each(frontPlot.get('children').concat(backPlot.get('children')), function (s) {
20613 if (s.get('value') === xScale.scale(origin[xScale.field])) {
20614 axisShape = s;
20615 return false;
20616 }
20617 });
20618 this.selectedAxisShape = axisShape;
20619 axisShape.set('_originAttrs', Object.assign({}, axisShape.attr()));
20620 axisShape.attr(selectAxisStyle);
20621 }
20622
20623 this.canvas.draw();
20624 };
20625
20626 _proto.reset = function reset() {
20627 var self = this;
20628
20629 if (!self.selectedShape) {
20630 return;
20631 }
20632
20633 var children = self._getIntervalShapes();
20634
20635 Util.each(children, function (child) {
20636 self._resetShape(child);
20637
20638 child.set('_selected', false);
20639 });
20640
20641 if (self.selectedAxisShape) {
20642 self._resetShape(self.selectedAxisShape);
20643 }
20644
20645 self.canvas.draw();
20646 self.selectedShape = null;
20647 self.selectedAxisShape = null;
20648 };
20649
20650 _proto.start = function start(ev) {
20651 var chart = this.chart;
20652
20653 if (ev.type === 'tap') {
20654 ev.clientX = ev.center.x;
20655 ev.clientY = ev.center.y;
20656 }
20657
20658 var _Util$createEvent = Util.createEvent(ev, chart),
20659 x = _Util$createEvent.x,
20660 y = _Util$createEvent.y;
20661
20662 var mode = this.mode;
20663
20664 var children = this._getIntervalShapes();
20665
20666 var selectedShape;
20667 var unSelectedShapes = [];
20668
20669 if (mode === 'shape') {
20670 var plot = chart.get('plotRange');
20671
20672 if (!Helper.isPointInPlot({
20673 x: x,
20674 y: y
20675 }, plot)) {
20676 this.reset();
20677 return;
20678 }
20679
20680 Util.each(children, function (child) {
20681 var box = child.getBBox();
20682
20683 if (x >= box.x && x <= box.x + box.width && y >= box.y && y <= box.height + box.y) {
20684 // inbox
20685 selectedShape = child;
20686 } else {
20687 unSelectedShapes.push(child);
20688 }
20689 });
20690 } else if (mode === 'range') {
20691 var records = chart.getSnapRecords({
20692 x: x,
20693 y: y
20694 });
20695
20696 if (!records.length) {
20697 this.reset();
20698 return;
20699 }
20700
20701 var data = records[0]._origin;
20702
20703 var result = this._selectShapesByData(data);
20704
20705 selectedShape = result.selectedShape;
20706 unSelectedShapes = result.unSelectedShapes;
20707 }
20708
20709 if (selectedShape) {
20710 this.selectedShape = selectedShape;
20711
20712 if (selectedShape.get('_selected')) {
20713 if (!this.cancelable) {
20714 this._setEventData(ev);
20715
20716 return;
20717 }
20718
20719 this.reset();
20720 } else {
20721 this._selectShapes(selectedShape, unSelectedShapes);
20722 }
20723 } else {
20724 this.reset();
20725 }
20726
20727 this._setEventData(ev);
20728 };
20729
20730 _proto.end = function end(ev) {
20731 this._setEventData(ev);
20732 };
20733
20734 return IntervalSelect;
20735}(Interaction);
20736
20737Chart.registerInteraction('interval-select', IntervalSelect);
20738module.exports = IntervalSelect;
20739
20740/***/ }),
20741/* 140 */
20742/***/ (function(module, exports, __webpack_require__) {
20743
20744function _inheritsLoose(subClass, superClass) {
20745 subClass.prototype = Object.create(superClass.prototype);
20746 subClass.prototype.constructor = subClass;
20747 subClass.__proto__ = superClass;
20748}
20749
20750function _assertThisInitialized(self) {
20751 if (self === void 0) {
20752 throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
20753 }
20754
20755 return self;
20756}
20757
20758var Util = __webpack_require__(0);
20759
20760var Interaction = __webpack_require__(21);
20761
20762var Chart = __webpack_require__(11);
20763
20764var FilterPlugin = __webpack_require__(141);
20765
20766var MoveMixin = __webpack_require__(142);
20767
20768var PressTooltipMixin = __webpack_require__(143);
20769
20770var UpdateScaleMixin = __webpack_require__(144);
20771
20772var Pan =
20773/*#__PURE__*/
20774function (_Interaction) {
20775 _inheritsLoose(Pan, _Interaction);
20776
20777 var _proto = Pan.prototype;
20778
20779 _proto.getDefaultCfg = function getDefaultCfg() {
20780 var defaultCfg = _Interaction.prototype.getDefaultCfg.call(this);
20781
20782 defaultCfg = Util.mix({}, defaultCfg, {
20783 startEvent: 'panstart',
20784 processEvent: 'panmove',
20785 endEvent: 'panend',
20786 resetEvent: 'touchend',
20787 mode: 'x',
20788 panThreshold: 10,
20789 // Minimal pan distance required before recognizing
20790 pressThreshold: 9,
20791 // Minimal movement that is allowed while pressing
20792 pressTime: 251,
20793 // Minimal press time in ms
20794 currentDeltaX: null,
20795 currentDeltaY: null,
20796 limitRange: {},
20797 _timestamp: 0,
20798 lastPoint: null,
20799 _panCumulativeDelta: 0,
20800 speed: 5
20801 });
20802
20803 if (Util.isWx || Util.isMy) {
20804 // 小程序
20805 defaultCfg.startEvent = 'touchstart';
20806 defaultCfg.processEvent = 'touchmove';
20807 defaultCfg.endEvent = 'touchend';
20808 }
20809
20810 return defaultCfg;
20811 };
20812
20813 function Pan(cfg, chart) {
20814 var _this;
20815
20816 _this = _Interaction.call(this, cfg, chart) || this;
20817
20818 var self = _assertThisInitialized(_assertThisInitialized(_this));
20819
20820 var hammer = self.hammer,
20821 panThreshold = self.panThreshold;
20822
20823 if (hammer) {
20824 hammer.get('pan').set({
20825 threshold: panThreshold
20826 });
20827 }
20828
20829 chart.registerPlugins([FilterPlugin, {
20830 changeData: function changeData() {
20831 self.limitRange = {};
20832 },
20833 clear: function clear() {
20834 self.limitRange = {};
20835 }
20836 }]);
20837 Util.mix(_assertThisInitialized(_assertThisInitialized(_this)), UpdateScaleMixin, MoveMixin, PressTooltipMixin);
20838
20839 _this._bindPress();
20840
20841 return _this;
20842 }
20843
20844 _proto.start = function start(e) {
20845 if (this.pressed) return;
20846 this.currentDeltaX = 0;
20847 this.currentDeltaY = 0;
20848
20849 if (e.type === 'touchstart' || e.type === 'touchStart') {
20850 this.lastPoint = e.touches[0];
20851 }
20852
20853 this._handleMove(e);
20854 };
20855
20856 _proto.process = function process(e) {
20857 if (this.pressed) return;
20858
20859 this._handleMove(e);
20860 };
20861
20862 _proto.end = function end() {
20863 if (this.pressed) return;
20864 this.currentDeltaX = null;
20865 this.currentDeltaY = null;
20866 this.lastPoint = null;
20867 this._panCumulativeDelta = 0;
20868 };
20869
20870 return Pan;
20871}(Interaction);
20872
20873Chart.registerInteraction('pan', Pan);
20874module.exports = Pan;
20875
20876/***/ }),
20877/* 141 */
20878/***/ (function(module, exports, __webpack_require__) {
20879
20880/**
20881 * filter the data out of scale' range
20882 */
20883var Util = __webpack_require__(0);
20884
20885var TimeUtil = __webpack_require__(28);
20886
20887module.exports = {
20888 beforeGeomInit: function beforeGeomInit(chart) {
20889 chart.set('limitInPlot', true);
20890 var data = chart.get('filteredData');
20891 var colDefs = chart.get('colDefs');
20892 if (!colDefs) return data;
20893 var geoms = chart.get('geoms');
20894 var isSpecialGeom = false; // TODO
20895
20896 Util.each(geoms, function (geom) {
20897 if (['area', 'line', 'path'].indexOf(geom.get('type')) !== -1) {
20898 isSpecialGeom = true;
20899 return false;
20900 }
20901 });
20902 var fields = [];
20903 Util.each(colDefs, function (def, key) {
20904 if (!isSpecialGeom && def && (def.values || def.min || def.max)) {
20905 fields.push(key);
20906 }
20907 });
20908
20909 if (fields.length === 0) {
20910 return data;
20911 }
20912
20913 var geomData = [];
20914 Util.each(data, function (obj) {
20915 var flag = true;
20916 Util.each(fields, function (field) {
20917 var value = obj[field];
20918
20919 if (value) {
20920 var colDef = colDefs[field];
20921
20922 if (colDef.type === 'timeCat') {
20923 var values = colDef.values;
20924
20925 if (Util.isNumber(values[0])) {
20926 value = TimeUtil.toTimeStamp(value);
20927 }
20928 }
20929
20930 if (colDef.values && colDef.values.indexOf(value) === -1 || colDef.min && value < colDef.min || colDef.max && value > colDef.max) {
20931 flag = false;
20932 }
20933 }
20934 });
20935
20936 if (flag) {
20937 geomData.push(obj);
20938 }
20939 });
20940 chart.set('filteredData', geomData);
20941 }
20942};
20943
20944/***/ }),
20945/* 142 */
20946/***/ (function(module, exports, __webpack_require__) {
20947
20948var Util = __webpack_require__(0);
20949
20950var Helper = __webpack_require__(29);
20951
20952var TOUCH_EVENTS = ['touchstart', 'touchmove', 'touchend', 'touchStart', 'touchMove', 'touchEnd'];
20953var DAY_TIMESTAMPS = 86400000;
20954module.exports = {
20955 _handleMove: function _handleMove(e) {
20956 if (e.type === 'swipe' && e.deltaTime > 350) {
20957 // 区分 pan 操作和 swipe 操作
20958 return null;
20959 }
20960
20961 var currentDeltaX = this.currentDeltaX,
20962 currentDeltaY = this.currentDeltaY,
20963 lastPoint = this.lastPoint;
20964 var deltaX;
20965 var deltaY;
20966
20967 if (TOUCH_EVENTS.indexOf(e.type) !== -1) {
20968 // support touch and miniprogram
20969 var currentPoint = e.touches[0];
20970 deltaX = currentPoint.x - lastPoint.x;
20971 deltaY = currentPoint.y - lastPoint.y;
20972 this.lastPoint = currentPoint;
20973 } else if (currentDeltaX !== null && currentDeltaY !== null) {
20974 deltaX = e.deltaX - currentDeltaX;
20975 deltaY = e.deltaY - currentDeltaY;
20976 this.currentDeltaX = e.deltaX;
20977 this.currentDeltaY = e.deltaY;
20978 }
20979
20980 if (Math.abs(deltaX) > 0 || Math.abs(deltaY) > 0) {
20981 var lastTimestamp = this._timestamp;
20982 var now = +new Date();
20983
20984 if (now - lastTimestamp > 16) {
20985 this._doMove(deltaX, deltaY);
20986
20987 this._timestamp = now;
20988 }
20989 }
20990 },
20991 _doMove: function _doMove(deltaX, deltaY) {
20992 var self = this;
20993 var mode = self.mode,
20994 chart = self.chart,
20995 limitRange = self.limitRange;
20996 var coord = chart.get('coord');
20997 var start = coord.start,
20998 end = coord.end;
20999 var data = chart.get('data');
21000
21001 if (Util.directionEnabled(mode, 'x') && deltaX !== 0) {
21002 var xScale = chart.getXScale();
21003 var xField = xScale.field;
21004
21005 if (!limitRange[xField]) {
21006 limitRange[xField] = Helper.getLimitRange(data, xScale);
21007 }
21008
21009 var coordWidth = end.x - start.x;
21010
21011 if (xScale.isCategory) {
21012 self._handleCatScale(xScale, deltaX, coordWidth);
21013 } else if (xScale.isLinear) {
21014 self._handleLinearScale(xScale, deltaX, coordWidth, 'x');
21015 }
21016
21017 var xDef = Helper.getColDef(chart, xField);
21018 self.xRange = Helper.getFieldRange(xDef, limitRange[xField], xScale.type);
21019 }
21020
21021 if (Util.directionEnabled(mode, 'y') && deltaY !== 0) {
21022 var coordHeight = start.y - end.y;
21023 var yScales = chart.getYScales();
21024 Util.each(yScales, function (yScale) {
21025 var yField = yScale.field;
21026
21027 if (!limitRange[yField]) {
21028 limitRange[yField] = Helper.getLimitRange(data, yScale);
21029 }
21030
21031 yScale.isLinear && self._handleLinearScale(yScale, deltaY, coordHeight, 'y');
21032 });
21033 var yDef = Helper.getColDef(chart, yScales[0].field);
21034 self.yRange = Helper.getFieldRange(yDef, limitRange[yScales[0].field], yScales[0].type);
21035 }
21036
21037 chart.repaint();
21038 },
21039 _handleLinearScale: function _handleLinearScale(scale, delta, range, flag) {
21040 var field = scale.field,
21041 min = scale.min,
21042 max = scale.max;
21043 var limitRange = this.limitRange;
21044 if (min === limitRange[field].min && max === limitRange[field].max) return;
21045 var ratio = delta / range;
21046 var panValue = ratio * (max - min);
21047 var newMax = flag === 'x' ? max - panValue : max + panValue;
21048 var newMin = flag === 'x' ? min - panValue : min + panValue;
21049
21050 if (limitRange[field] && !Util.isNil(limitRange[field].min) && newMin <= limitRange[field].min) {
21051 newMin = limitRange[field].min;
21052 newMax = max - min + newMin;
21053 }
21054
21055 if (limitRange[field] && !Util.isNil(limitRange[field].max) && newMax >= limitRange[field].max) {
21056 newMax = limitRange[field].max;
21057 newMin = newMax - (max - min);
21058 }
21059
21060 this.updateLinearScale(field, newMin, newMax);
21061 },
21062 _handleCatScale: function _handleCatScale(scale, delta, range) {
21063 var type = scale.type,
21064 field = scale.field,
21065 values = scale.values,
21066 ticks = scale.ticks;
21067 var originValues = this.limitRange[field];
21068 var lastValueIndex = originValues.length - 1;
21069 var currentLength = values.length;
21070 var speed = this.speed || 1;
21071 var step = range / (currentLength * speed);
21072 var firstIndex = originValues.indexOf(values[0]);
21073 var lastIndex = originValues.indexOf(values[currentLength - 1]);
21074 var minIndex = firstIndex;
21075 var maxIndex = lastIndex;
21076 var ratio = Math.abs(delta / range);
21077 var panStep = this.step || Math.max(1, parseInt(ratio * currentLength));
21078 this._panCumulativeDelta += delta;
21079 minIndex = this._panCumulativeDelta > step ? Math.max(0, minIndex - panStep) : this._panCumulativeDelta < -step ? Math.min(lastValueIndex - currentLength + 1, minIndex + panStep) : minIndex;
21080 maxIndex = Math.min(lastValueIndex, minIndex + currentLength - 1);
21081
21082 if (minIndex === firstIndex && maxIndex === lastIndex) {
21083 return null;
21084 }
21085
21086 var newValues = originValues.slice(minIndex, maxIndex + 1);
21087 var newTicks = null;
21088
21089 if (type === 'timeCat') {
21090 var tickGap = ticks.length > 2 ? ticks[1] - ticks[0] : DAY_TIMESTAMPS;
21091
21092 if (this._panCumulativeDelta > step) {
21093 for (var i = ticks[0] - tickGap; i >= newValues[0]; i -= tickGap) {
21094 ticks.unshift(i);
21095 }
21096 } else if (this._panCumulativeDelta < -step) {
21097 for (var _i = ticks[ticks.length - 1] + tickGap; _i <= newValues[newValues.length - 1]; _i += tickGap) {
21098 ticks.push(_i);
21099 }
21100 }
21101
21102 newTicks = ticks;
21103 }
21104
21105 this.updateCatScale(field, newValues, newTicks, originValues, minIndex, maxIndex);
21106 this._panCumulativeDelta = minIndex !== firstIndex ? 0 : this._panCumulativeDelta;
21107 }
21108};
21109
21110/***/ }),
21111/* 143 */
21112/***/ (function(module, exports, __webpack_require__) {
21113
21114var Util = __webpack_require__(0);
21115
21116module.exports = {
21117 _bindPress: function _bindPress() {
21118 var chart = this.chart,
21119 hammer = this.hammer,
21120 el = this.el,
21121 pressThreshold = this.pressThreshold,
21122 pressTime = this.pressTime;
21123 var tooltipController = chart.get('tooltipController');
21124
21125 if (tooltipController && tooltipController.enable) {
21126 chart.set('_closeTooltip', true); // 用于交互的特殊标示量
21127
21128 if (hammer) {
21129 hammer.get('press').set({
21130 threshold: pressThreshold,
21131 time: pressTime
21132 });
21133 hammer.on('press', Util.wrapBehavior(this, '_handlePress'));
21134 } else {
21135 Util.addEventListener(el, 'press', Util.wrapBehavior(this, '_handlePress'));
21136 }
21137 }
21138 },
21139 reset: function reset() {
21140 var chart = this.chart;
21141 var tooltipController = chart.get('tooltipController');
21142
21143 if (tooltipController) {
21144 this.pressed = false;
21145 !tooltipController.cfg.alwaysShow && chart.hideTooltip();
21146 chart.set('_closeTooltip', true); // 用于交互的特殊标示量
21147 }
21148 },
21149 _handlePress: function _handlePress(e) {
21150 this.pressed = true;
21151 var center = e.center || e.touches[0];
21152 this.chart.set('_closeTooltip', false); // 用于交互的特殊标示量
21153
21154 this.chart.showTooltip(center);
21155 }
21156};
21157
21158/***/ }),
21159/* 144 */
21160/***/ (function(module, exports, __webpack_require__) {
21161
21162var Helper = __webpack_require__(29);
21163
21164var Util = __webpack_require__(0);
21165
21166module.exports = {
21167 updateLinearScale: function updateLinearScale(field, min, max) {
21168 var chart = this.chart;
21169 var colDef = Helper.getColDef(chart, field);
21170 chart.scale(field, Util.mix({}, colDef, {
21171 min: min,
21172 max: max,
21173 nice: false
21174 }));
21175 },
21176 updateCatScale: function updateCatScale(field, newValues, ticks, values, minIndex, maxIndex) {
21177 var chart = this.chart;
21178 var colDef = Helper.getColDef(chart, field);
21179 chart.scale(field, Util.mix({}, colDef, {
21180 values: newValues,
21181 ticks: ticks,
21182 scale: function scale(value) {
21183 if (this.type === 'timeCat') {
21184 value = this._toTimeStamp(value);
21185 }
21186
21187 var rangeMin = this.rangeMin();
21188 var rangeMax = this.rangeMax();
21189 var range = rangeMax - rangeMin;
21190 var min;
21191 var max;
21192 var percent;
21193 var currentIndex = values.indexOf(value); // 在完整数据集中的索引值
21194
21195 if (currentIndex >= 0 && currentIndex < minIndex) {
21196 // 不在范围内,左侧数据
21197 max = rangeMin > 0 ? -0.1 : rangeMin - 0.1;
21198 min = max - range;
21199 percent = currentIndex / minIndex;
21200 } else if (currentIndex >= 0 && currentIndex > maxIndex) {
21201 // 不在范围内,右侧数据
21202 min = rangeMax < 1 ? 1.1 : rangeMax + 0.1;
21203 max = min + range;
21204 percent = (currentIndex - maxIndex - 1) / (values.length - 1 - maxIndex);
21205 } else {
21206 // 数值在当前 this.values 范围内
21207 var index = this.translate(value);
21208
21209 if (this.values.length === 1) {
21210 percent = index;
21211 } else {
21212 percent = index / (this.values.length - 1);
21213 }
21214
21215 min = rangeMin;
21216 max = rangeMax;
21217 }
21218
21219 return min + percent * (max - min);
21220 },
21221 getTicks: function getTicks() {
21222 var self = this;
21223 var ticks = this.ticks;
21224 var rst = [];
21225 Util.each(ticks, function (tick) {
21226 var obj;
21227
21228 if (Util.isObject(tick)) {
21229 obj = tick;
21230 } else {
21231 var value = self.scale(tick);
21232 value = value >= 0 && value <= 1 ? value : NaN;
21233 obj = {
21234 text: Util.isString(tick) ? tick : self.getText(tick),
21235 value: value,
21236 tickValue: tick // 用于坐标轴上文本动画时确定前后帧的对应关系
21237
21238 };
21239 }
21240
21241 rst.push(obj);
21242 });
21243 return rst;
21244 }
21245 }));
21246 }
21247};
21248
21249/***/ })
21250/******/ ]);
21251});
21252//# sourceMappingURL=my-f2.js.map
\No newline at end of file