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() {
|
11 | return (function(modules) {
|
12 |
|
13 | var installedModules = {};
|
14 |
|
15 |
|
16 | function __webpack_require__(moduleId) {
|
17 |
|
18 |
|
19 | if(installedModules[moduleId]) {
|
20 | return installedModules[moduleId].exports;
|
21 | }
|
22 |
|
23 | var module = installedModules[moduleId] = {
|
24 | i: moduleId,
|
25 | l: false,
|
26 | exports: {}
|
27 | };
|
28 |
|
29 |
|
30 | modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
31 |
|
32 |
|
33 | module.l = true;
|
34 |
|
35 |
|
36 | return module.exports;
|
37 | }
|
38 |
|
39 |
|
40 |
|
41 | __webpack_require__.m = modules;
|
42 |
|
43 |
|
44 | __webpack_require__.c = installedModules;
|
45 |
|
46 |
|
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 |
|
67 | __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
68 |
|
69 |
|
70 | __webpack_require__.p = "";
|
71 |
|
72 |
|
73 | return __webpack_require__(__webpack_require__.s = 47);
|
74 | })
|
75 |
|
76 | ([
|
77 |
|
78 | (function(module, exports, __webpack_require__) {
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 | var DomUtil = __webpack_require__(53);
|
85 |
|
86 | var Util = {
|
87 | upperFirst: __webpack_require__(54),
|
88 | lowerFirst: __webpack_require__(55),
|
89 | isString: __webpack_require__(14),
|
90 | isNumber: __webpack_require__(15),
|
91 | isBoolean: __webpack_require__(56),
|
92 | isFunction: __webpack_require__(57),
|
93 | isDate: __webpack_require__(31),
|
94 | isArray: __webpack_require__(11),
|
95 | isNil: __webpack_require__(9),
|
96 | isObject: __webpack_require__(17),
|
97 | isPlainObject: __webpack_require__(32),
|
98 | deepMix: __webpack_require__(59),
|
99 | mix: __webpack_require__(18),
|
100 | each: __webpack_require__(4),
|
101 | isObjectValueEqual: function isObjectValueEqual(a, b) {
|
102 |
|
103 | a = Object.assign({}, a);
|
104 | b = Object.assign({}, b);
|
105 | var aProps = Object.getOwnPropertyNames(a);
|
106 | var bProps = Object.getOwnPropertyNames(b);
|
107 |
|
108 | if (aProps.length !== bProps.length) {
|
109 | return false;
|
110 | }
|
111 |
|
112 | for (var i = 0, len = aProps.length; i < len; i++) {
|
113 | var propName = aProps[i];
|
114 |
|
115 | if (a[propName] !== b[propName]) {
|
116 | return false;
|
117 | }
|
118 | }
|
119 |
|
120 | return true;
|
121 | },
|
122 | wrapBehavior: function wrapBehavior(obj, action) {
|
123 | if (obj['_wrap_' + action]) {
|
124 | return obj['_wrap_' + action];
|
125 | }
|
126 |
|
127 | var method = function method(e) {
|
128 | obj[action](e);
|
129 | };
|
130 |
|
131 | obj['_wrap_' + action] = method;
|
132 | return method;
|
133 | },
|
134 | getWrapBehavior: function getWrapBehavior(obj, action) {
|
135 | return obj['_wrap_' + action];
|
136 | },
|
137 | parsePadding: function parsePadding(padding) {
|
138 | var top;
|
139 | var right;
|
140 | var bottom;
|
141 | var left;
|
142 |
|
143 | if (Util.isNumber(padding) || Util.isString(padding)) {
|
144 | top = bottom = left = right = padding;
|
145 | } else if (Util.isArray(padding)) {
|
146 | top = padding[0];
|
147 | right = !Util.isNil(padding[1]) ? padding[1] : padding[0];
|
148 | bottom = !Util.isNil(padding[2]) ? padding[2] : padding[0];
|
149 | left = !Util.isNil(padding[3]) ? padding[3] : right;
|
150 | }
|
151 |
|
152 | return [top, right, bottom, left];
|
153 | },
|
154 | directionEnabled: function directionEnabled(mode, dir) {
|
155 | if (mode === undefined) {
|
156 | return true;
|
157 | } else if (typeof mode === 'string') {
|
158 | return mode.indexOf(dir) !== -1;
|
159 | }
|
160 |
|
161 | return false;
|
162 | }
|
163 | };
|
164 | Util.Array = {
|
165 | merge: function merge(dataArray) {
|
166 | var rst = [];
|
167 |
|
168 | for (var i = 0, len = dataArray.length; i < len; i++) {
|
169 | rst = rst.concat(dataArray[i]);
|
170 | }
|
171 |
|
172 | return rst;
|
173 | },
|
174 | values: function values(data, name) {
|
175 | var rst = [];
|
176 | var tmpMap = {};
|
177 |
|
178 | for (var i = 0, len = data.length; i < len; i++) {
|
179 | var obj = data[i];
|
180 | var value = obj[name];
|
181 |
|
182 | if (!Util.isNil(value)) {
|
183 | if (!Util.isArray(value)) {
|
184 | if (!tmpMap[value]) {
|
185 | rst.push(value);
|
186 | tmpMap[value] = true;
|
187 | }
|
188 | } else {
|
189 | Util.each(value, function (val) {
|
190 | if (!tmpMap[val]) {
|
191 | rst.push(val);
|
192 | tmpMap[val] = true;
|
193 | }
|
194 | });
|
195 | }
|
196 | }
|
197 | }
|
198 |
|
199 | return rst;
|
200 | },
|
201 | firstValue: function firstValue(data, name) {
|
202 | var rst = null;
|
203 |
|
204 | for (var i = 0, len = data.length; i < len; i++) {
|
205 | var obj = data[i];
|
206 | var value = obj[name];
|
207 |
|
208 | if (!Util.isNil(value)) {
|
209 | if (Util.isArray(value)) {
|
210 | rst = value[0];
|
211 | } else {
|
212 | rst = value;
|
213 | }
|
214 |
|
215 | break;
|
216 | }
|
217 | }
|
218 |
|
219 | return rst;
|
220 | },
|
221 | group: function group(data, fields, appendConditions) {
|
222 | if (appendConditions === void 0) {
|
223 | appendConditions = {};
|
224 | }
|
225 |
|
226 | if (!fields) {
|
227 | return [data];
|
228 | }
|
229 |
|
230 | var groups = Util.Array.groupToMap(data, fields);
|
231 | var array = [];
|
232 |
|
233 | if (fields.length === 1 && appendConditions[fields[0]]) {
|
234 | var values = appendConditions[fields[0]];
|
235 | Util.each(values, function (value) {
|
236 | value = '_' + value;
|
237 | array.push(groups[value]);
|
238 | });
|
239 | } else {
|
240 | for (var i in groups) {
|
241 | array.push(groups[i]);
|
242 | }
|
243 | }
|
244 |
|
245 | return array;
|
246 | },
|
247 | groupToMap: function groupToMap(data, fields) {
|
248 | if (!fields) {
|
249 | return {
|
250 | 0: data
|
251 | };
|
252 | }
|
253 |
|
254 | var callback = function callback(row) {
|
255 | var unique = '_';
|
256 |
|
257 | for (var i = 0, l = fields.length; i < l; i++) {
|
258 | unique += row[fields[i]] && row[fields[i]].toString();
|
259 | }
|
260 |
|
261 | return unique;
|
262 | };
|
263 |
|
264 | var groups = {};
|
265 |
|
266 | for (var i = 0, len = data.length; i < len; i++) {
|
267 | var row = data[i];
|
268 | var key = callback(row);
|
269 |
|
270 | if (groups[key]) {
|
271 | groups[key].push(row);
|
272 | } else {
|
273 | groups[key] = [row];
|
274 | }
|
275 | }
|
276 |
|
277 | return groups;
|
278 | },
|
279 | remove: function remove(arr, obj) {
|
280 | if (!arr) {
|
281 | return;
|
282 | }
|
283 |
|
284 | var index = arr.indexOf(obj);
|
285 |
|
286 | if (index !== -1) {
|
287 | arr.splice(index, 1);
|
288 | }
|
289 | },
|
290 | getRange: function getRange(values) {
|
291 | if (!values.length) {
|
292 | return {
|
293 | min: 0,
|
294 | max: 0
|
295 | };
|
296 | }
|
297 |
|
298 | var max = Math.max.apply(null, values);
|
299 | var min = Math.min.apply(null, values);
|
300 | return {
|
301 | min: min,
|
302 | max: max
|
303 | };
|
304 | }
|
305 | };
|
306 | Util.mix(Util, DomUtil);
|
307 | module.exports = Util;
|
308 |
|
309 | }),
|
310 |
|
311 | (function(module, exports, __webpack_require__) {
|
312 |
|
313 | var Theme = __webpack_require__(52);
|
314 |
|
315 | var Util = __webpack_require__(0);
|
316 |
|
317 | var Global = {
|
318 | version: '3.3.1',
|
319 | trackable: true,
|
320 | scales: {},
|
321 | widthRatio: {
|
322 | column: 1 / 2,
|
323 | rose: 0.999999,
|
324 | multiplePie: 3 / 4
|
325 | },
|
326 | lineDash: [4, 4]
|
327 | };
|
328 |
|
329 | Global.setTheme = function (theme) {
|
330 | Util.deepMix(this, theme);
|
331 | };
|
332 |
|
333 | Global.setTheme(Theme);
|
334 | module.exports = Global;
|
335 |
|
336 | }),
|
337 |
|
338 | (function(module, exports, __webpack_require__) {
|
339 |
|
340 | function _inheritsLoose(subClass, superClass) {
|
341 | subClass.prototype = Object.create(superClass.prototype);
|
342 | subClass.prototype.constructor = subClass;
|
343 | subClass.__proto__ = superClass;
|
344 | }
|
345 |
|
346 | var Util = __webpack_require__(0);
|
347 |
|
348 | var Element = __webpack_require__(26);
|
349 |
|
350 | var Shape =
|
351 |
|
352 | function (_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 |
|
436 | module.exports = Shape;
|
437 |
|
438 | }),
|
439 |
|
440 | (function(module, exports, __webpack_require__) {
|
441 |
|
442 | var G = {
|
443 | Canvas: __webpack_require__(78),
|
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__(80);
|
451 |
|
452 | __webpack_require__(81);
|
453 |
|
454 | __webpack_require__(82);
|
455 |
|
456 | __webpack_require__(83);
|
457 |
|
458 | __webpack_require__(84);
|
459 |
|
460 | __webpack_require__(85);
|
461 |
|
462 | __webpack_require__(86);
|
463 |
|
464 | __webpack_require__(87);
|
465 |
|
466 | __webpack_require__(88);
|
467 |
|
468 | module.exports = G;
|
469 |
|
470 | }),
|
471 |
|
472 | (function(module, exports, __webpack_require__) {
|
473 |
|
474 | var isObject = __webpack_require__(17);
|
475 |
|
476 | var isArray = __webpack_require__(11);
|
477 |
|
478 | var each = function each(elements, func) {
|
479 | if (!elements) {
|
480 | return;
|
481 | }
|
482 |
|
483 | var rst = void 0;
|
484 |
|
485 | if (isArray(elements)) {
|
486 | for (var i = 0, len = elements.length; i < len; i++) {
|
487 | rst = func(elements[i], i);
|
488 |
|
489 | if (rst === false) {
|
490 | break;
|
491 | }
|
492 | }
|
493 | } else if (isObject(elements)) {
|
494 | for (var k in elements) {
|
495 | if (elements.hasOwnProperty(k)) {
|
496 | rst = func(elements[k], k);
|
497 |
|
498 | if (rst === false) {
|
499 | break;
|
500 | }
|
501 | }
|
502 | }
|
503 | }
|
504 | };
|
505 |
|
506 | module.exports = each;
|
507 |
|
508 | }),
|
509 |
|
510 | (function(module, exports, __webpack_require__) {
|
511 |
|
512 | function _inheritsLoose(subClass, superClass) {
|
513 | subClass.prototype = Object.create(superClass.prototype);
|
514 | subClass.prototype.constructor = subClass;
|
515 | subClass.__proto__ = superClass;
|
516 | }
|
517 |
|
518 | var Util = __webpack_require__(0);
|
519 |
|
520 | var Base = __webpack_require__(33);
|
521 |
|
522 | var GROUP_ATTRS = ['color', 'size', 'shape'];
|
523 | var FIELD_ORIGIN = '_origin';
|
524 | var FIELD_ORIGIN_Y = '_originY';
|
525 |
|
526 | var Global = __webpack_require__(1);
|
527 |
|
528 | var Attr = __webpack_require__(63);
|
529 |
|
530 | var GeometryShape = __webpack_require__(6);
|
531 |
|
532 | var Adjust = __webpack_require__(24);
|
533 |
|
534 | function parseFields(field) {
|
535 | if (Util.isArray(field)) {
|
536 | return field;
|
537 | }
|
538 |
|
539 | if (Util.isString(field)) {
|
540 | return field.split('*');
|
541 | }
|
542 |
|
543 | return [field];
|
544 | }
|
545 |
|
546 |
|
547 |
|
548 |
|
549 |
|
550 |
|
551 | var Geom =
|
552 |
|
553 | function (_Base) {
|
554 | _inheritsLoose(Geom, _Base);
|
555 |
|
556 | function Geom() {
|
557 | return _Base.apply(this, arguments) || this;
|
558 | }
|
559 |
|
560 | var _proto = Geom.prototype;
|
561 |
|
562 | _proto.getDefaultCfg = function getDefaultCfg() {
|
563 | return {
|
564 | |
565 |
|
566 |
|
567 |
|
568 | type: null,
|
569 |
|
570 | |
571 |
|
572 |
|
573 |
|
574 | data: null,
|
575 |
|
576 | |
577 |
|
578 |
|
579 |
|
580 | attrs: {},
|
581 | scales: {},
|
582 |
|
583 | |
584 |
|
585 |
|
586 |
|
587 | container: null,
|
588 |
|
589 | |
590 |
|
591 |
|
592 |
|
593 | styleOptions: null,
|
594 | chart: null,
|
595 | shapeType: '',
|
596 |
|
597 | |
598 |
|
599 |
|
600 |
|
601 |
|
602 | generatePoints: false,
|
603 | attrOptions: {},
|
604 | sortable: false,
|
605 | startOnZero: true,
|
606 | visible: true,
|
607 | connectNulls: false
|
608 | };
|
609 | };
|
610 |
|
611 | _proto.init = function init() {
|
612 | var self = this;
|
613 |
|
614 | self._initAttrs();
|
615 |
|
616 | var dataArray = self._processData();
|
617 |
|
618 | if (self.get('adjust')) {
|
619 | self._adjustData(dataArray);
|
620 | }
|
621 |
|
622 | self.set('dataArray', dataArray);
|
623 | };
|
624 |
|
625 | _proto._getGroupScales = function _getGroupScales() {
|
626 | var self = this;
|
627 | var scales = [];
|
628 | Util.each(GROUP_ATTRS, function (attrName) {
|
629 | var attr = self.getAttr(attrName);
|
630 |
|
631 | if (attr) {
|
632 | var attrScales = attr.scales;
|
633 | Util.each(attrScales, function (scale) {
|
634 | if (scale && scale.isCategory && scales.indexOf(scale) === -1) {
|
635 | scales.push(scale);
|
636 | }
|
637 | });
|
638 | }
|
639 | });
|
640 | return scales;
|
641 | };
|
642 |
|
643 | _proto._groupData = function _groupData(data) {
|
644 | var self = this;
|
645 | var colDefs = self.get('colDefs');
|
646 |
|
647 | var groupScales = self._getGroupScales();
|
648 |
|
649 | if (groupScales.length) {
|
650 | var appendConditions = {};
|
651 | var names = [];
|
652 | Util.each(groupScales, function (scale) {
|
653 | var field = scale.field;
|
654 | names.push(field);
|
655 |
|
656 | if (colDefs && colDefs[field] && colDefs[field].values) {
|
657 |
|
658 | appendConditions[scale.field] = colDefs[field].values;
|
659 | }
|
660 | });
|
661 | return Util.Array.group(data, names, appendConditions);
|
662 | }
|
663 |
|
664 | return [data];
|
665 | };
|
666 |
|
667 | _proto._setAttrOptions = function _setAttrOptions(attrName, attrCfg) {
|
668 | var options = this.get('attrOptions');
|
669 | options[attrName] = attrCfg;
|
670 | };
|
671 |
|
672 | _proto._createAttrOption = function _createAttrOption(attrName, field, cfg, defaultValues) {
|
673 | var attrCfg = {};
|
674 | attrCfg.field = field;
|
675 |
|
676 | if (cfg) {
|
677 | if (Util.isFunction(cfg)) {
|
678 | attrCfg.callback = cfg;
|
679 | } else {
|
680 | attrCfg.values = cfg;
|
681 | }
|
682 | } else {
|
683 | attrCfg.values = defaultValues;
|
684 | }
|
685 |
|
686 | this._setAttrOptions(attrName, attrCfg);
|
687 | };
|
688 |
|
689 | _proto._initAttrs = function _initAttrs() {
|
690 | var self = this;
|
691 | var attrs = self.get('attrs');
|
692 | var attrOptions = self.get('attrOptions');
|
693 | var coord = self.get('coord');
|
694 |
|
695 | for (var type in attrOptions) {
|
696 | if (attrOptions.hasOwnProperty(type)) {
|
697 | var option = attrOptions[type];
|
698 | var className = Util.upperFirst(type);
|
699 | var fields = parseFields(option.field);
|
700 |
|
701 | if (type === 'position') {
|
702 | option.coord = coord;
|
703 | }
|
704 |
|
705 | var scales = [];
|
706 |
|
707 | for (var i = 0, len = fields.length; i < len; i++) {
|
708 | var field = fields[i];
|
709 |
|
710 | var scale = self._createScale(field);
|
711 |
|
712 | scales.push(scale);
|
713 | }
|
714 |
|
715 | if (type === 'position') {
|
716 | var yScale = scales[1];
|
717 |
|
718 | if (coord.type === 'polar' && coord.transposed && self.hasAdjust('stack')) {
|
719 | if (yScale.values.length) {
|
720 | yScale.change({
|
721 | nice: false,
|
722 | min: 0,
|
723 | max: Math.max.apply(null, yScale.values)
|
724 | });
|
725 | }
|
726 | }
|
727 | }
|
728 |
|
729 | option.scales = scales;
|
730 | var attr = new Attr[className](option);
|
731 | attrs[type] = attr;
|
732 | }
|
733 | }
|
734 | };
|
735 |
|
736 | _proto._createScale = function _createScale(field) {
|
737 | var scales = this.get('scales');
|
738 | var scale = scales[field];
|
739 |
|
740 | if (!scale) {
|
741 | scale = this.get('chart').createScale(field);
|
742 | scales[field] = scale;
|
743 | }
|
744 |
|
745 | return scale;
|
746 | };
|
747 |
|
748 | _proto._processData = function _processData() {
|
749 | var self = this;
|
750 | var data = this.get('data');
|
751 | var dataArray = [];
|
752 |
|
753 | var groupedArray = this._groupData(data);
|
754 |
|
755 | for (var i = 0, len = groupedArray.length; i < len; i++) {
|
756 | var subData = groupedArray[i];
|
757 |
|
758 | var tempData = self._saveOrigin(subData);
|
759 |
|
760 | if (this.hasAdjust('dodge')) {
|
761 | self._numberic(tempData);
|
762 | }
|
763 |
|
764 | dataArray.push(tempData);
|
765 | }
|
766 |
|
767 | return dataArray;
|
768 | };
|
769 |
|
770 | _proto._saveOrigin = function _saveOrigin(data) {
|
771 | var rst = [];
|
772 |
|
773 | for (var i = 0, len = data.length; i < len; i++) {
|
774 | var origin = data[i];
|
775 | var obj = {};
|
776 |
|
777 | for (var k in origin) {
|
778 | obj[k] = origin[k];
|
779 | }
|
780 |
|
781 | obj[FIELD_ORIGIN] = origin;
|
782 | rst.push(obj);
|
783 | }
|
784 |
|
785 | return rst;
|
786 | };
|
787 |
|
788 | _proto._numberic = function _numberic(data) {
|
789 | var positionAttr = this.getAttr('position');
|
790 | var scales = positionAttr.scales;
|
791 |
|
792 | for (var j = 0, len = data.length; j < len; j++) {
|
793 | var obj = data[j];
|
794 | var count = Math.min(2, scales.length);
|
795 |
|
796 | for (var i = 0; i < count; i++) {
|
797 | var scale = scales[i];
|
798 |
|
799 | if (scale.isCategory) {
|
800 | var field = scale.field;
|
801 | obj[field] = scale.translate(obj[field]);
|
802 | }
|
803 | }
|
804 | }
|
805 | };
|
806 |
|
807 | _proto._adjustData = function _adjustData(dataArray) {
|
808 | var self = this;
|
809 | var adjust = self.get('adjust');
|
810 |
|
811 | if (adjust) {
|
812 | var adjustType = Util.upperFirst(adjust.type);
|
813 |
|
814 | if (!Adjust[adjustType]) {
|
815 | throw new Error('not support such adjust : ' + adjust);
|
816 | }
|
817 |
|
818 | var xScale = self.getXScale();
|
819 | var yScale = self.getYScale();
|
820 | var cfg = Util.mix({
|
821 | xField: xScale.field,
|
822 | yField: yScale.field
|
823 | }, adjust);
|
824 | var adjustObject = new Adjust[adjustType](cfg);
|
825 | adjustObject.processAdjust(dataArray);
|
826 |
|
827 | if (adjustType === 'Stack') {
|
828 | self._updateStackRange(yScale.field, yScale, dataArray);
|
829 | }
|
830 | }
|
831 | };
|
832 |
|
833 | _proto._updateStackRange = function _updateStackRange(field, scale, dataArray) {
|
834 | var mergeArray = Util.Array.merge(dataArray);
|
835 | var min = scale.min;
|
836 | var max = scale.max;
|
837 |
|
838 | for (var i = 0, len = mergeArray.length; i < len; i++) {
|
839 | var obj = mergeArray[i];
|
840 | var tmpMin = Math.min.apply(null, obj[field]);
|
841 | var tmpMax = Math.max.apply(null, obj[field]);
|
842 |
|
843 | if (tmpMin < min) {
|
844 | min = tmpMin;
|
845 | }
|
846 |
|
847 | if (tmpMax > max) {
|
848 | max = tmpMax;
|
849 | }
|
850 | }
|
851 |
|
852 | if (min < scale.min || max > scale.max) {
|
853 | scale.change({
|
854 | min: min,
|
855 | max: max
|
856 | });
|
857 | }
|
858 | };
|
859 |
|
860 | _proto._sort = function _sort(mappedArray) {
|
861 | var self = this;
|
862 | var xScale = self.getXScale();
|
863 | var field = xScale.field,
|
864 | type = xScale.type;
|
865 |
|
866 | if (type !== 'identity' && xScale.values.length > 1) {
|
867 | Util.each(mappedArray, function (itemArr) {
|
868 | itemArr.sort(function (obj1, obj2) {
|
869 | if (type === 'timeCat') {
|
870 | return xScale._toTimeStamp(obj1[FIELD_ORIGIN][field]) - xScale._toTimeStamp(obj2[FIELD_ORIGIN][field]);
|
871 | }
|
872 |
|
873 | return xScale.translate(obj1[FIELD_ORIGIN][field]) - xScale.translate(obj2[FIELD_ORIGIN][field]);
|
874 | });
|
875 | });
|
876 | }
|
877 |
|
878 | self.set('hasSorted', true);
|
879 | self.set('dataArray', mappedArray);
|
880 | };
|
881 |
|
882 | _proto.paint = function paint() {
|
883 | var self = this;
|
884 | var dataArray = self.get('dataArray');
|
885 | var mappedArray = [];
|
886 | var shapeFactory = self.getShapeFactory();
|
887 | shapeFactory.setCoord(self.get('coord'));
|
888 |
|
889 | self._beforeMapping(dataArray);
|
890 |
|
891 | for (var i = 0, len = dataArray.length; i < len; i++) {
|
892 | var data = dataArray[i];
|
893 |
|
894 | if (data.length) {
|
895 | data = self._mapping(data);
|
896 | mappedArray.push(data);
|
897 | self.draw(data, shapeFactory);
|
898 | }
|
899 | }
|
900 |
|
901 | self.set('dataArray', mappedArray);
|
902 | };
|
903 |
|
904 | _proto.getShapeFactory = function getShapeFactory() {
|
905 | var shapeFactory = this.get('shapeFactory');
|
906 |
|
907 | if (!shapeFactory) {
|
908 | var shapeType = this.get('shapeType');
|
909 | shapeFactory = GeometryShape.getShapeFactory(shapeType);
|
910 | this.set('shapeFactory', shapeFactory);
|
911 | }
|
912 |
|
913 | return shapeFactory;
|
914 | };
|
915 |
|
916 | _proto._mapping = function _mapping(data) {
|
917 | var self = this;
|
918 | var attrs = self.get('attrs');
|
919 | var yField = self.getYScale().field;
|
920 | var mappedData = [];
|
921 |
|
922 | for (var i = 0, len = data.length; i < len; i++) {
|
923 | var record = data[i];
|
924 | var newRecord = {};
|
925 | newRecord[FIELD_ORIGIN] = record[FIELD_ORIGIN];
|
926 | newRecord.points = record.points;
|
927 |
|
928 | newRecord[FIELD_ORIGIN_Y] = record[yField];
|
929 |
|
930 | for (var k in attrs) {
|
931 | if (attrs.hasOwnProperty(k)) {
|
932 | var attr = attrs[k];
|
933 | var names = attr.names;
|
934 |
|
935 | var values = self._getAttrValues(attr, record);
|
936 |
|
937 | if (names.length > 1) {
|
938 | for (var j = 0, _len = values.length; j < _len; j++) {
|
939 | var val = values[j];
|
940 | var name = names[j];
|
941 | newRecord[name] = Util.isArray(val) && val.length === 1 ? val[0] : val;
|
942 | }
|
943 | } else {
|
944 | newRecord[names[0]] = values.length === 1 ? values[0] : values;
|
945 | }
|
946 | }
|
947 | }
|
948 |
|
949 | mappedData.push(newRecord);
|
950 | }
|
951 |
|
952 | return mappedData;
|
953 | };
|
954 |
|
955 | _proto._getAttrValues = function _getAttrValues(attr, record) {
|
956 | var scales = attr.scales;
|
957 | var params = [];
|
958 |
|
959 | for (var i = 0, len = scales.length; i < len; i++) {
|
960 | var scale = scales[i];
|
961 | var field = scale.field;
|
962 |
|
963 | if (scale.type === 'identity') {
|
964 | params.push(scale.value);
|
965 | } else {
|
966 | params.push(record[field]);
|
967 | }
|
968 | }
|
969 |
|
970 | var values = attr.mapping.apply(attr, params);
|
971 | return values;
|
972 | };
|
973 |
|
974 | _proto.getAttrValue = function getAttrValue(attrName, record) {
|
975 | var attr = this.getAttr(attrName);
|
976 | var rst = null;
|
977 |
|
978 | if (attr) {
|
979 | var values = this._getAttrValues(attr, record);
|
980 |
|
981 | rst = values[0];
|
982 | }
|
983 |
|
984 | return rst;
|
985 | };
|
986 |
|
987 | _proto._beforeMapping = function _beforeMapping(dataArray) {
|
988 | var self = this;
|
989 |
|
990 | if (self.get('sortable')) {
|
991 | self._sort(dataArray);
|
992 | }
|
993 |
|
994 | if (self.get('generatePoints')) {
|
995 | Util.each(dataArray, function (data) {
|
996 | self._generatePoints(data);
|
997 | });
|
998 | }
|
999 | };
|
1000 |
|
1001 | _proto.isInCircle = function isInCircle() {
|
1002 | var coord = this.get('coord');
|
1003 | return coord && coord.isPolar;
|
1004 | };
|
1005 |
|
1006 | _proto.getCallbackCfg = function getCallbackCfg(fields, cfg, origin) {
|
1007 | if (!fields) {
|
1008 | return cfg;
|
1009 | }
|
1010 |
|
1011 | var tmpCfg = {};
|
1012 | var params = fields.map(function (field) {
|
1013 | return origin[field];
|
1014 | });
|
1015 | Util.each(cfg, function (v, k) {
|
1016 | if (Util.isFunction(v)) {
|
1017 | tmpCfg[k] = v.apply(null, params);
|
1018 | } else {
|
1019 | tmpCfg[k] = v;
|
1020 | }
|
1021 | });
|
1022 | return tmpCfg;
|
1023 | };
|
1024 |
|
1025 | _proto.getDrawCfg = function getDrawCfg(obj) {
|
1026 | var self = this;
|
1027 | var isInCircle = self.isInCircle();
|
1028 | var cfg = {
|
1029 | origin: obj,
|
1030 | x: obj.x,
|
1031 | y: obj.y,
|
1032 | color: obj.color,
|
1033 | size: obj.size,
|
1034 | shape: obj.shape,
|
1035 | isInCircle: isInCircle,
|
1036 | opacity: obj.opacity
|
1037 | };
|
1038 | var styleOptions = self.get('styleOptions');
|
1039 |
|
1040 | if (styleOptions && styleOptions.style) {
|
1041 | cfg.style = self.getCallbackCfg(styleOptions.fields, styleOptions.style, obj[FIELD_ORIGIN]);
|
1042 | }
|
1043 |
|
1044 | if (self.get('generatePoints')) {
|
1045 | cfg.points = obj.points;
|
1046 | }
|
1047 |
|
1048 | if (isInCircle) {
|
1049 | cfg.center = self.get('coord').center;
|
1050 | }
|
1051 |
|
1052 | return cfg;
|
1053 | };
|
1054 |
|
1055 | _proto.draw = function draw(data, shapeFactory) {
|
1056 | var self = this;
|
1057 | var container = self.get('container');
|
1058 | var yScale = self.getYScale();
|
1059 | Util.each(data, function (obj, index) {
|
1060 | if (yScale && Util.isNil(obj._origin[yScale.field])) {
|
1061 | return;
|
1062 | }
|
1063 |
|
1064 | obj.index = index;
|
1065 | var cfg = self.getDrawCfg(obj);
|
1066 | var shape = obj.shape;
|
1067 | self.drawShape(shape, obj, cfg, container, shapeFactory);
|
1068 | });
|
1069 | };
|
1070 |
|
1071 | _proto.drawShape = function drawShape(shape, shapeData, cfg, container, shapeFactory) {
|
1072 | var gShape = shapeFactory.drawShape(shape, cfg, container);
|
1073 |
|
1074 | if (gShape) {
|
1075 | Util.each([].concat(gShape), function (s) {
|
1076 | s.set('origin', shapeData);
|
1077 | });
|
1078 | }
|
1079 | };
|
1080 |
|
1081 | _proto._generatePoints = function _generatePoints(data) {
|
1082 | var self = this;
|
1083 | var shapeFactory = self.getShapeFactory();
|
1084 | var shapeAttr = self.getAttr('shape');
|
1085 |
|
1086 | for (var i = 0, len = data.length; i < len; i++) {
|
1087 | var obj = data[i];
|
1088 | var cfg = self.createShapePointsCfg(obj);
|
1089 | var shape = shapeAttr ? self._getAttrValues(shapeAttr, obj) : null;
|
1090 | var points = shapeFactory.getShapePoints(shape, cfg);
|
1091 | obj.points = points;
|
1092 | }
|
1093 | };
|
1094 | |
1095 |
|
1096 |
|
1097 |
|
1098 |
|
1099 |
|
1100 |
|
1101 |
|
1102 | _proto.createShapePointsCfg = function createShapePointsCfg(obj) {
|
1103 | var xScale = this.getXScale();
|
1104 | var yScale = this.getYScale();
|
1105 |
|
1106 | var x = this._normalizeValues(obj[xScale.field], xScale);
|
1107 |
|
1108 | var y;
|
1109 |
|
1110 | if (yScale) {
|
1111 | y = this._normalizeValues(obj[yScale.field], yScale);
|
1112 | } else {
|
1113 | y = obj.y ? obj.y : 0.1;
|
1114 | }
|
1115 |
|
1116 | return {
|
1117 | x: x,
|
1118 | y: y,
|
1119 | y0: yScale ? yScale.scale(this.getYMinValue()) : undefined
|
1120 | };
|
1121 | };
|
1122 |
|
1123 | _proto.getYMinValue = function getYMinValue() {
|
1124 | var yScale = this.getYScale();
|
1125 | var min = yScale.min,
|
1126 | max = yScale.max;
|
1127 | var value;
|
1128 |
|
1129 | if (this.get('startOnZero')) {
|
1130 | if (max <= 0 && min <= 0) {
|
1131 | value = max;
|
1132 | } else {
|
1133 | value = min >= 0 ? min : 0;
|
1134 | }
|
1135 | } else {
|
1136 | value = min;
|
1137 | }
|
1138 |
|
1139 | return value;
|
1140 | };
|
1141 |
|
1142 | _proto._normalizeValues = function _normalizeValues(values, scale) {
|
1143 | var rst = [];
|
1144 |
|
1145 | if (Util.isArray(values)) {
|
1146 | for (var i = 0, len = values.length; i < len; i++) {
|
1147 | var v = values[i];
|
1148 | rst.push(scale.scale(v));
|
1149 | }
|
1150 | } else {
|
1151 | rst = scale.scale(values);
|
1152 | }
|
1153 |
|
1154 | return rst;
|
1155 | };
|
1156 |
|
1157 | _proto.getAttr = function getAttr(name) {
|
1158 | return this.get('attrs')[name];
|
1159 | };
|
1160 |
|
1161 | _proto.getXScale = function getXScale() {
|
1162 | return this.getAttr('position').scales[0];
|
1163 | };
|
1164 |
|
1165 | _proto.getYScale = function getYScale() {
|
1166 | return this.getAttr('position').scales[1];
|
1167 | };
|
1168 |
|
1169 | _proto.hasAdjust = function hasAdjust(adjust) {
|
1170 | return this.get('adjust') && this.get('adjust').type === adjust;
|
1171 | };
|
1172 |
|
1173 | _proto._getSnap = function _getSnap(scale, item, arr) {
|
1174 | var i = 0;
|
1175 | var values;
|
1176 | var yField = this.getYScale().field;
|
1177 |
|
1178 | if (this.hasAdjust('stack') && scale.field === yField) {
|
1179 | values = [];
|
1180 | arr.forEach(function (obj) {
|
1181 | values.push(obj[FIELD_ORIGIN_Y]);
|
1182 | });
|
1183 |
|
1184 | for (var len = values.length; i < len; i++) {
|
1185 | if (values[0][0] > item) {
|
1186 | break;
|
1187 | }
|
1188 |
|
1189 | if (values[values.length - 1][1] <= item) {
|
1190 | i = values.length - 1;
|
1191 | break;
|
1192 | }
|
1193 |
|
1194 | if (values[i][0] <= item && values[i][1] > item) {
|
1195 | break;
|
1196 | }
|
1197 | }
|
1198 | } else {
|
1199 | values = scale.values;
|
1200 | values.sort(function (a, b) {
|
1201 | return a - b;
|
1202 | });
|
1203 |
|
1204 | for (var _len2 = values.length; i < _len2; i++) {
|
1205 | if ((values[0] + values[1]) / 2 > item) {
|
1206 | break;
|
1207 | }
|
1208 |
|
1209 | if ((values[i - 1] + values[i]) / 2 <= item && (values[i + 1] + values[i]) / 2 > item) {
|
1210 | break;
|
1211 | }
|
1212 |
|
1213 | if ((values[values.length - 2] + values[values.length - 1]) / 2 <= item) {
|
1214 | i = values.length - 1;
|
1215 | break;
|
1216 | }
|
1217 | }
|
1218 | }
|
1219 |
|
1220 | var result = values[i];
|
1221 | return result;
|
1222 | };
|
1223 |
|
1224 | _proto.getSnapRecords = function getSnapRecords(point) {
|
1225 | var self = this;
|
1226 | var coord = self.get('coord');
|
1227 | var xScale = self.getXScale();
|
1228 | var yScale = self.getYScale();
|
1229 | var xfield = xScale.field;
|
1230 | var dataArray = self.get('dataArray');
|
1231 |
|
1232 | if (!this.get('hasSorted')) {
|
1233 | this._sort(dataArray);
|
1234 | }
|
1235 |
|
1236 | var rst = [];
|
1237 | var invertPoint = coord.invertPoint(point);
|
1238 | var invertPointX = invertPoint.x;
|
1239 |
|
1240 | if (self.isInCircle() && !coord.transposed && invertPointX > (1 + xScale.rangeMax()) / 2) {
|
1241 | invertPointX = xScale.rangeMin();
|
1242 | }
|
1243 |
|
1244 | var xValue = xScale.invert(invertPointX);
|
1245 |
|
1246 | if (!xScale.isCategory) {
|
1247 | xValue = self._getSnap(xScale, xValue);
|
1248 | }
|
1249 |
|
1250 | var tmp = [];
|
1251 | dataArray.forEach(function (data) {
|
1252 | data.forEach(function (obj) {
|
1253 | var originValue = Util.isNil(obj[FIELD_ORIGIN]) ? obj[xfield] : obj[FIELD_ORIGIN][xfield];
|
1254 |
|
1255 | if (self._isEqual(originValue, xValue, xScale)) {
|
1256 | tmp.push(obj);
|
1257 | }
|
1258 | });
|
1259 | });
|
1260 |
|
1261 | if (this.hasAdjust('stack') && coord.isPolar && coord.transposed && xScale.values.length === 1) {
|
1262 | if (invertPointX >= 0 && invertPointX <= 1) {
|
1263 | var yValue = yScale.invert(invertPoint.y);
|
1264 | yValue = self._getSnap(yScale, yValue, tmp);
|
1265 | tmp.forEach(function (obj) {
|
1266 | if (Util.isArray(yValue) ? obj[FIELD_ORIGIN_Y].toString() === yValue.toString() : obj[FIELD_ORIGIN_Y] === yValue) {
|
1267 | rst.push(obj);
|
1268 | }
|
1269 | });
|
1270 | }
|
1271 | } else {
|
1272 | rst = tmp;
|
1273 | }
|
1274 |
|
1275 | return rst;
|
1276 | };
|
1277 |
|
1278 | _proto._isEqual = function _isEqual(originValue, value, scale) {
|
1279 | if (scale.type === 'timeCat') {
|
1280 | return scale._toTimeStamp(originValue) === value;
|
1281 | }
|
1282 |
|
1283 | return value === originValue;
|
1284 | };
|
1285 |
|
1286 | _proto.position = function position(field) {
|
1287 | this._setAttrOptions('position', {
|
1288 | field: field
|
1289 | });
|
1290 |
|
1291 | return this;
|
1292 | };
|
1293 |
|
1294 | _proto.color = function color(field, values) {
|
1295 | this._createAttrOption('color', field, values, Global.colors);
|
1296 |
|
1297 | return this;
|
1298 | };
|
1299 |
|
1300 | _proto.size = function size(field, values) {
|
1301 | this._createAttrOption('size', field, values, Global.sizes);
|
1302 |
|
1303 | return this;
|
1304 | };
|
1305 |
|
1306 | _proto.shape = function shape(field, values) {
|
1307 | var type = this.get('type');
|
1308 | var shapes = Global.shapes[type] || [];
|
1309 |
|
1310 | this._createAttrOption('shape', field, values, shapes);
|
1311 |
|
1312 | return this;
|
1313 | };
|
1314 |
|
1315 | _proto.style = function style(field, cfg) {
|
1316 | var styleOptions = this.get('styleOptions');
|
1317 |
|
1318 | if (!styleOptions) {
|
1319 | styleOptions = {};
|
1320 | this.set('styleOptions', styleOptions);
|
1321 | }
|
1322 |
|
1323 | if (Util.isObject(field)) {
|
1324 | cfg = field;
|
1325 | field = null;
|
1326 | }
|
1327 |
|
1328 | var fields;
|
1329 |
|
1330 | if (field) {
|
1331 | fields = parseFields(field);
|
1332 | }
|
1333 |
|
1334 | styleOptions.fields = fields;
|
1335 | styleOptions.style = cfg;
|
1336 | return this;
|
1337 | };
|
1338 |
|
1339 | _proto.adjust = function adjust(type) {
|
1340 | if (Util.isString(type)) {
|
1341 | type = {
|
1342 | type: type
|
1343 | };
|
1344 | }
|
1345 |
|
1346 | this.set('adjust', type);
|
1347 | return this;
|
1348 | };
|
1349 |
|
1350 | _proto.animate = function animate(cfg) {
|
1351 | this.set('animateCfg', cfg);
|
1352 | return this;
|
1353 | };
|
1354 |
|
1355 | _proto.reset = function reset() {
|
1356 | this.set('attrOptions', {});
|
1357 | this.set('adjust', null);
|
1358 | this.clearInner();
|
1359 | };
|
1360 |
|
1361 | _proto.clearInner = function clearInner() {
|
1362 | var container = this.get('container');
|
1363 |
|
1364 | if (container) {
|
1365 | container.clear();
|
1366 | container.setMatrix([1, 0, 0, 1, 0, 0]);
|
1367 | }
|
1368 |
|
1369 | container && container.clear();
|
1370 | this.set('attrs', {});
|
1371 | this.set('groupScales', null);
|
1372 | this.set('xDistance', null);
|
1373 | this.set('_width', null);
|
1374 | };
|
1375 |
|
1376 | _proto.clear = function clear() {
|
1377 | this.clearInner();
|
1378 | this.set('scales', {});
|
1379 | };
|
1380 |
|
1381 | _proto.destroy = function destroy() {
|
1382 | this.clear();
|
1383 |
|
1384 | _Base.prototype.destroy.call(this);
|
1385 | };
|
1386 |
|
1387 | _proto._display = function _display(visible) {
|
1388 | this.set('visible', visible);
|
1389 | var container = this.get('container');
|
1390 | var canvas = container.get('canvas');
|
1391 | container.set('visible', visible);
|
1392 | canvas.draw();
|
1393 | };
|
1394 |
|
1395 | _proto.show = function show() {
|
1396 | this._display(true);
|
1397 | };
|
1398 |
|
1399 | _proto.hide = function hide() {
|
1400 | this._display(false);
|
1401 | };
|
1402 |
|
1403 | return Geom;
|
1404 | }(Base);
|
1405 |
|
1406 | module.exports = Geom;
|
1407 |
|
1408 | }),
|
1409 |
|
1410 | (function(module, exports, __webpack_require__) {
|
1411 |
|
1412 | var Util = __webpack_require__(0);
|
1413 |
|
1414 | var Global = __webpack_require__(1);
|
1415 |
|
1416 | var Shape = {};
|
1417 | var ShapeBase = {
|
1418 | _coord: null,
|
1419 |
|
1420 | |
1421 |
|
1422 |
|
1423 |
|
1424 |
|
1425 | draw: function draw(cfg, container) {
|
1426 | if (this.drawShape) {
|
1427 | this.drawShape(cfg, container);
|
1428 | }
|
1429 | },
|
1430 |
|
1431 | |
1432 |
|
1433 |
|
1434 |
|
1435 | setCoord: function setCoord(coord) {
|
1436 | this._coord = coord;
|
1437 | },
|
1438 |
|
1439 | |
1440 |
|
1441 |
|
1442 |
|
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 |
|
1457 |
|
1458 |
|
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 | };
|
1470 | var 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 |
|
1508 | Shape.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 |
|
1516 | Shape.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 |
|
1524 | Shape.registShape = Shape.registerShape;
|
1525 |
|
1526 | Shape.getShapeFactory = function (factoryName) {
|
1527 | var self = this;
|
1528 | factoryName = factoryName || 'point';
|
1529 | var className = Util.upperFirst(factoryName);
|
1530 | return self[className];
|
1531 | };
|
1532 |
|
1533 | module.exports = Shape;
|
1534 |
|
1535 | }),
|
1536 |
|
1537 | (function(module, exports) {
|
1538 |
|
1539 |
|
1540 |
|
1541 |
|
1542 |
|
1543 | module.exports = {
|
1544 | |
1545 |
|
1546 |
|
1547 |
|
1548 |
|
1549 | create: function create() {
|
1550 | return [0, 0];
|
1551 | },
|
1552 |
|
1553 | |
1554 |
|
1555 |
|
1556 |
|
1557 |
|
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 |
|
1567 |
|
1568 |
|
1569 |
|
1570 |
|
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 |
|
1588 |
|
1589 |
|
1590 |
|
1591 |
|
1592 |
|
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 |
|
1602 |
|
1603 |
|
1604 |
|
1605 |
|
1606 |
|
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 |
|
1616 |
|
1617 |
|
1618 |
|
1619 |
|
1620 |
|
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 |
|
1630 |
|
1631 |
|
1632 |
|
1633 |
|
1634 |
|
1635 | dot: function dot(v1, v2) {
|
1636 | return v1[0] * v2[0] + v1[1] * v2[1];
|
1637 | },
|
1638 |
|
1639 | |
1640 |
|
1641 |
|
1642 |
|
1643 |
|
1644 |
|
1645 |
|
1646 | direction: function direction(v1, v2) {
|
1647 | return v1[0] * v2[1] - v2[0] * v1[1];
|
1648 | },
|
1649 |
|
1650 | |
1651 |
|
1652 |
|
1653 |
|
1654 |
|
1655 |
|
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 |
|
1664 |
|
1665 |
|
1666 |
|
1667 |
|
1668 |
|
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 |
|
1691 |
|
1692 |
|
1693 |
|
1694 |
|
1695 | zero: function zero(v) {
|
1696 | return v[0] === 0 && v[1] === 0;
|
1697 | },
|
1698 |
|
1699 | |
1700 |
|
1701 |
|
1702 |
|
1703 |
|
1704 |
|
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 |
|
1714 |
|
1715 |
|
1716 |
|
1717 |
|
1718 | clone: function clone(v) {
|
1719 | return [v[0], v[1]];
|
1720 | },
|
1721 |
|
1722 | |
1723 |
|
1724 |
|
1725 |
|
1726 |
|
1727 |
|
1728 |
|
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 |
|
1738 |
|
1739 |
|
1740 |
|
1741 |
|
1742 |
|
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 |
|
1752 |
|
1753 |
|
1754 |
|
1755 |
|
1756 |
|
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 |
|
1769 | (function(module, exports, __webpack_require__) {
|
1770 |
|
1771 | var Util = __webpack_require__(0);
|
1772 |
|
1773 | var KEYWORDS_PERCENT = {
|
1774 | min: 0,
|
1775 | median: 0.5,
|
1776 | max: 1
|
1777 | };
|
1778 |
|
1779 | var GuideBase =
|
1780 |
|
1781 | function () {
|
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);
|
1826 | }
|
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 |
|
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 |
|
1855 |
|
1856 |
|
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 |
|
1897 | module.exports = GuideBase;
|
1898 |
|
1899 | }),
|
1900 |
|
1901 | (function(module, exports) {
|
1902 |
|
1903 |
|
1904 | var isNil = function isNil(value) {
|
1905 | |
1906 |
|
1907 |
|
1908 |
|
1909 | return value === null || value === undefined;
|
1910 | };
|
1911 |
|
1912 | module.exports = isNil;
|
1913 |
|
1914 | }),
|
1915 |
|
1916 | (function(module, exports) {
|
1917 |
|
1918 | var toString = {}.toString;
|
1919 |
|
1920 | var isType = function isType(value, type) {
|
1921 | return toString.call(value) === '[object ' + type + ']';
|
1922 | };
|
1923 |
|
1924 | module.exports = isType;
|
1925 |
|
1926 | }),
|
1927 |
|
1928 | (function(module, exports, __webpack_require__) {
|
1929 |
|
1930 | var isType = __webpack_require__(10);
|
1931 |
|
1932 | var isArray = Array.isArray ? Array.isArray : function (value) {
|
1933 | return isType(value, 'Array');
|
1934 | };
|
1935 | module.exports = isArray;
|
1936 |
|
1937 | }),
|
1938 |
|
1939 | (function(module, exports, __webpack_require__) {
|
1940 |
|
1941 | function _inheritsLoose(subClass, superClass) {
|
1942 | subClass.prototype = Object.create(superClass.prototype);
|
1943 | subClass.prototype.constructor = subClass;
|
1944 | subClass.__proto__ = superClass;
|
1945 | }
|
1946 |
|
1947 | function _assertThisInitialized(self) {
|
1948 | if (self === void 0) {
|
1949 | throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
1950 | }
|
1951 |
|
1952 | return self;
|
1953 | }
|
1954 |
|
1955 | var Base = __webpack_require__(33);
|
1956 |
|
1957 | var Plot = __webpack_require__(60);
|
1958 |
|
1959 | var Util = __webpack_require__(0);
|
1960 |
|
1961 | var Coord = __webpack_require__(61);
|
1962 |
|
1963 | var Geom = __webpack_require__(5);
|
1964 |
|
1965 | var ScaleController = __webpack_require__(69);
|
1966 |
|
1967 | var AxisController = __webpack_require__(75);
|
1968 |
|
1969 | var Global = __webpack_require__(1);
|
1970 |
|
1971 | var _require = __webpack_require__(3),
|
1972 | Canvas = _require.Canvas;
|
1973 |
|
1974 | var Helper = __webpack_require__(20);
|
1975 |
|
1976 | function isFullCircle(coord) {
|
1977 | var startAngle = coord.startAngle;
|
1978 | var endAngle = coord.endAngle;
|
1979 |
|
1980 | if (!Util.isNil(startAngle) && !Util.isNil(endAngle) && endAngle - startAngle < Math.PI * 2) {
|
1981 | return false;
|
1982 | }
|
1983 |
|
1984 | return true;
|
1985 | }
|
1986 |
|
1987 | function compare(a, b) {
|
1988 | return a - b;
|
1989 | }
|
1990 |
|
1991 | function _isScaleExist(scales, compareScale) {
|
1992 | var flag = false;
|
1993 | Util.each(scales, function (scale) {
|
1994 | var scaleValues = [].concat(scale.values);
|
1995 | var compareScaleValues = [].concat(compareScale.values);
|
1996 |
|
1997 | if (scale.type === compareScale.type && scale.field === compareScale.field && scaleValues.sort(compare).toString() === compareScaleValues.sort(compare).toString()) {
|
1998 | flag = true;
|
1999 | return;
|
2000 | }
|
2001 | });
|
2002 | return flag;
|
2003 | }
|
2004 |
|
2005 | var Chart =
|
2006 |
|
2007 | function (_Base) {
|
2008 | _inheritsLoose(Chart, _Base);
|
2009 |
|
2010 | Chart.initPlugins = function initPlugins() {
|
2011 | return {
|
2012 | _plugins: [],
|
2013 | _cacheId: 0,
|
2014 | register: function register(plugins) {
|
2015 | var p = this._plugins;
|
2016 | [].concat(plugins).forEach(function (plugin) {
|
2017 | if (p.indexOf(plugin) === -1) {
|
2018 | p.push(plugin);
|
2019 | }
|
2020 | });
|
2021 | this._cacheId++;
|
2022 | },
|
2023 | unregister: function unregister(plugins) {
|
2024 | var p = this._plugins;
|
2025 | [].concat(plugins).forEach(function (plugin) {
|
2026 | var idx = p.indexOf(plugin);
|
2027 |
|
2028 | if (idx !== -1) {
|
2029 | p.splice(idx, 1);
|
2030 | }
|
2031 | });
|
2032 | this._cacheId++;
|
2033 | },
|
2034 | clear: function clear() {
|
2035 | this._plugins = [];
|
2036 | this._cacheId++;
|
2037 | },
|
2038 | count: function count() {
|
2039 | return this._plugins.length;
|
2040 | },
|
2041 | getAll: function getAll() {
|
2042 | return this._plugins;
|
2043 | },
|
2044 | notify: function notify(chart, hook, args) {
|
2045 | var descriptors = this.descriptors(chart);
|
2046 | var ilen = descriptors.length;
|
2047 | var i;
|
2048 | var descriptor;
|
2049 | var plugin;
|
2050 | var params;
|
2051 | var method;
|
2052 |
|
2053 | for (i = 0; i < ilen; ++i) {
|
2054 | descriptor = descriptors[i];
|
2055 | plugin = descriptor.plugin;
|
2056 | method = plugin[hook];
|
2057 |
|
2058 | if (typeof method === 'function') {
|
2059 | params = [chart].concat(args || []);
|
2060 |
|
2061 | if (method.apply(plugin, params) === false) {
|
2062 | return false;
|
2063 | }
|
2064 | }
|
2065 | }
|
2066 |
|
2067 | return true;
|
2068 | },
|
2069 | descriptors: function descriptors(chart) {
|
2070 | var cache = chart._plugins || (chart._plugins = {});
|
2071 |
|
2072 | if (cache.id === this._cacheId) {
|
2073 | return cache.descriptors;
|
2074 | }
|
2075 |
|
2076 | var plugins = [];
|
2077 | var descriptors = [];
|
2078 |
|
2079 | this._plugins.concat(chart && chart.get('plugins') || []).forEach(function (plugin) {
|
2080 | var idx = plugins.indexOf(plugin);
|
2081 |
|
2082 | if (idx !== -1) {
|
2083 | return;
|
2084 | }
|
2085 |
|
2086 | plugins.push(plugin);
|
2087 | descriptors.push({
|
2088 | plugin: plugin
|
2089 | });
|
2090 | });
|
2091 |
|
2092 | cache.descriptors = descriptors;
|
2093 | cache.id = this._cacheId;
|
2094 | return descriptors;
|
2095 | }
|
2096 | };
|
2097 | };
|
2098 |
|
2099 | var _proto = Chart.prototype;
|
2100 |
|
2101 | _proto.getDefaultCfg = function getDefaultCfg() {
|
2102 | return {
|
2103 | |
2104 |
|
2105 |
|
2106 |
|
2107 | id: null,
|
2108 |
|
2109 | |
2110 |
|
2111 |
|
2112 |
|
2113 | padding: Global.padding,
|
2114 |
|
2115 | |
2116 |
|
2117 |
|
2118 |
|
2119 | data: null,
|
2120 |
|
2121 | |
2122 |
|
2123 |
|
2124 |
|
2125 | scales: {},
|
2126 |
|
2127 | |
2128 |
|
2129 |
|
2130 |
|
2131 |
|
2132 | geoms: null,
|
2133 |
|
2134 | |
2135 |
|
2136 |
|
2137 |
|
2138 | colDefs: null,
|
2139 | pixelRatio: Global.pixelRatio,
|
2140 |
|
2141 | |
2142 |
|
2143 |
|
2144 |
|
2145 | filters: null,
|
2146 | appendPadding: Global.appendPadding
|
2147 | };
|
2148 | };
|
2149 |
|
2150 | _proto._syncYScales = function _syncYScales() {
|
2151 | var geoms = this.get('geoms');
|
2152 | var syncScales = [];
|
2153 | var min = [];
|
2154 | var max = [];
|
2155 | Util.each(geoms, function (geom) {
|
2156 | var yScale = geom.getYScale();
|
2157 |
|
2158 | if (yScale.isLinear) {
|
2159 | syncScales.push(yScale);
|
2160 | min.push(yScale.min);
|
2161 | max.push(yScale.max);
|
2162 | }
|
2163 | });
|
2164 | min = Math.min.apply(null, min);
|
2165 | max = Math.max.apply(null, max);
|
2166 | Util.each(syncScales, function (scale) {
|
2167 | scale.min = min;
|
2168 | scale.max = max;
|
2169 | });
|
2170 | };
|
2171 |
|
2172 | _proto._getFieldsForLegend = function _getFieldsForLegend() {
|
2173 | var fields = [];
|
2174 | var geoms = this.get('geoms');
|
2175 | Util.each(geoms, function (geom) {
|
2176 | var attrOptions = geom.get('attrOptions');
|
2177 | var attrCfg = attrOptions.color;
|
2178 |
|
2179 | if (attrCfg && attrCfg.field && Util.isString(attrCfg.field)) {
|
2180 | var arr = attrCfg.field.split('*');
|
2181 | Util.each(arr, function (item) {
|
2182 | if (fields.indexOf(item) === -1) {
|
2183 | fields.push(item);
|
2184 | }
|
2185 | });
|
2186 | }
|
2187 | });
|
2188 | return fields;
|
2189 | };
|
2190 |
|
2191 | _proto._createScale = function _createScale(field, data) {
|
2192 | var scaleController = this.get('scaleController');
|
2193 | return scaleController.createScale(field, data);
|
2194 | };
|
2195 |
|
2196 | _proto._adjustScale = function _adjustScale() {
|
2197 | var self = this;
|
2198 | var coord = self.get('coord');
|
2199 | var xScale = self.getXScale();
|
2200 | var yScales = self.getYScales();
|
2201 | var scales = [];
|
2202 | xScale && scales.push(xScale);
|
2203 | scales = scales.concat(yScales);
|
2204 | var inFullCircle = coord.isPolar && isFullCircle(coord);
|
2205 | var scaleController = self.get('scaleController');
|
2206 | var colDefs = scaleController.defs;
|
2207 | Util.each(scales, function (scale) {
|
2208 | if ((scale.isCategory || scale.isIdentity) && scale.values && !(colDefs[scale.field] && colDefs[scale.field].range)) {
|
2209 | var count = scale.values.length;
|
2210 | var range;
|
2211 |
|
2212 | if (count === 1) {
|
2213 | range = [0.5, 1];
|
2214 | } else {
|
2215 | var widthRatio = 1;
|
2216 | var offset = 0;
|
2217 |
|
2218 | if (inFullCircle) {
|
2219 | if (!coord.transposed) {
|
2220 | range = [0, 1 - 1 / count];
|
2221 | } else {
|
2222 | widthRatio = Global.widthRatio.multiplePie;
|
2223 | offset = 1 / count * widthRatio;
|
2224 | range = [offset / 2, 1 - offset / 2];
|
2225 | }
|
2226 | } else {
|
2227 | offset = 1 / count * 1 / 2;
|
2228 | range = [offset, 1 - offset];
|
2229 | }
|
2230 | }
|
2231 |
|
2232 | scale.range = range;
|
2233 | }
|
2234 | });
|
2235 | var geoms = this.get('geoms');
|
2236 |
|
2237 | for (var i = 0; i < geoms.length; i++) {
|
2238 | var geom = geoms[i];
|
2239 |
|
2240 | if (geom.get('type') === 'interval') {
|
2241 | var yScale = geom.getYScale();
|
2242 | var field = yScale.field,
|
2243 | min = yScale.min,
|
2244 | max = yScale.max,
|
2245 | type = yScale.type;
|
2246 |
|
2247 | if (!(colDefs[field] && colDefs[field].min) && type !== 'time') {
|
2248 | if (min > 0) {
|
2249 | yScale.change({
|
2250 | min: 0
|
2251 | });
|
2252 | } else if (max <= 0) {
|
2253 | yScale.change({
|
2254 | max: 0
|
2255 | });
|
2256 | }
|
2257 | }
|
2258 | }
|
2259 | }
|
2260 | };
|
2261 |
|
2262 | _proto._removeGeoms = function _removeGeoms() {
|
2263 | var geoms = this.get('geoms');
|
2264 |
|
2265 | while (geoms.length > 0) {
|
2266 | var geom = geoms.shift();
|
2267 | geom.destroy();
|
2268 | }
|
2269 | };
|
2270 |
|
2271 | _proto._clearGeoms = function _clearGeoms() {
|
2272 | var geoms = this.get('geoms');
|
2273 |
|
2274 | for (var i = 0, length = geoms.length; i < length; i++) {
|
2275 | var geom = geoms[i];
|
2276 | geom.clear();
|
2277 | }
|
2278 | };
|
2279 |
|
2280 | _proto._clearInner = function _clearInner() {
|
2281 | this.set('scales', {});
|
2282 | this.set('legendItems', null);
|
2283 |
|
2284 | this._clearGeoms();
|
2285 |
|
2286 | Chart.plugins.notify(this, 'clearInner');
|
2287 | this.get('axisController') && this.get('axisController').clear();
|
2288 | };
|
2289 |
|
2290 | _proto._execFilter = function _execFilter(data) {
|
2291 | var filters = this.get('filters');
|
2292 |
|
2293 | if (filters) {
|
2294 | data = data.filter(function (obj) {
|
2295 | var rst = true;
|
2296 | Util.each(filters, function (fn, k) {
|
2297 | if (fn) {
|
2298 | rst = fn(obj[k], obj);
|
2299 |
|
2300 | if (!rst) {
|
2301 | return false;
|
2302 | }
|
2303 | }
|
2304 | });
|
2305 | return rst;
|
2306 | });
|
2307 | }
|
2308 |
|
2309 | return data;
|
2310 | };
|
2311 |
|
2312 | _proto._initGeoms = function _initGeoms(geoms) {
|
2313 | var coord = this.get('coord');
|
2314 | var data = this.get('filteredData');
|
2315 | var colDefs = this.get('colDefs');
|
2316 |
|
2317 | for (var i = 0, length = geoms.length; i < length; i++) {
|
2318 | var geom = geoms[i];
|
2319 | geom.set('data', data);
|
2320 | geom.set('coord', coord);
|
2321 | geom.set('colDefs', colDefs);
|
2322 | geom.init();
|
2323 | }
|
2324 | };
|
2325 |
|
2326 | _proto._initCoord = function _initCoord() {
|
2327 | var plot = this.get('plotRange');
|
2328 | var coordCfg = Util.mix({
|
2329 | type: 'cartesian'
|
2330 | }, this.get('coordCfg'), {
|
2331 | plot: plot
|
2332 | });
|
2333 | var type = coordCfg.type;
|
2334 | var C = Coord[Util.upperFirst(type)];
|
2335 | var coord = new C(coordCfg);
|
2336 | this.set('coord', coord);
|
2337 | };
|
2338 |
|
2339 | _proto._initLayout = function _initLayout() {
|
2340 | var padding = this.get('_padding');
|
2341 |
|
2342 | if (!padding) {
|
2343 | padding = this.get('margin') || this.get('padding');
|
2344 | padding = Util.parsePadding(padding);
|
2345 | }
|
2346 |
|
2347 | var top = padding[0] === 'auto' ? 0 : padding[0];
|
2348 | var right = padding[1] === 'auto' ? 0 : padding[1];
|
2349 | var bottom = padding[2] === 'auto' ? 0 : padding[2];
|
2350 | var left = padding[3] === 'auto' ? 0 : padding[3];
|
2351 | var width = this.get('width');
|
2352 | var height = this.get('height');
|
2353 | var plot = new Plot({
|
2354 | start: {
|
2355 | x: left,
|
2356 | y: top
|
2357 | },
|
2358 | end: {
|
2359 | x: width - right,
|
2360 | y: height - bottom
|
2361 | }
|
2362 | });
|
2363 | this.set('plotRange', plot);
|
2364 | this.set('plot', plot);
|
2365 | };
|
2366 |
|
2367 | _proto._initCanvas = function _initCanvas() {
|
2368 | var self = this;
|
2369 |
|
2370 | try {
|
2371 | var canvas = new Canvas({
|
2372 | el: self.get('el') || self.get('id'),
|
2373 | context: self.get('context'),
|
2374 | pixelRatio: self.get('pixelRatio'),
|
2375 | width: self.get('width'),
|
2376 | height: self.get('height'),
|
2377 | fontFamily: Global.fontFamily
|
2378 | });
|
2379 | self.set('canvas', canvas);
|
2380 | self.set('width', canvas.get('width'));
|
2381 | self.set('height', canvas.get('height'));
|
2382 | } catch (error) {
|
2383 | throw error;
|
2384 | }
|
2385 |
|
2386 | Chart.plugins.notify(self, 'afterCanvasInit');
|
2387 |
|
2388 | self._initLayout();
|
2389 | };
|
2390 |
|
2391 | _proto._initLayers = function _initLayers() {
|
2392 | var canvas = this.get('canvas');
|
2393 | this.set('backPlot', canvas.addGroup());
|
2394 | this.set('middlePlot', canvas.addGroup({
|
2395 | zIndex: 10
|
2396 | }));
|
2397 | this.set('frontPlot', canvas.addGroup({
|
2398 | zIndex: 20
|
2399 | }));
|
2400 | };
|
2401 |
|
2402 | _proto._init = function _init() {
|
2403 | var self = this;
|
2404 |
|
2405 | self._initCanvas();
|
2406 |
|
2407 | self._initLayers();
|
2408 |
|
2409 | self.set('geoms', []);
|
2410 | self.set('scaleController', new ScaleController());
|
2411 | self.set('axisController', new AxisController({
|
2412 | frontPlot: self.get('frontPlot').addGroup({
|
2413 | className: 'axisContainer'
|
2414 | }),
|
2415 | backPlot: self.get('backPlot').addGroup({
|
2416 | className: 'axisContainer'
|
2417 | }),
|
2418 | chart: self
|
2419 | }));
|
2420 | Chart.plugins.notify(self, 'init');
|
2421 | };
|
2422 |
|
2423 | function Chart(cfg) {
|
2424 | var _this;
|
2425 |
|
2426 | _this = _Base.call(this, cfg) || this;
|
2427 |
|
2428 | var self = _assertThisInitialized(_assertThisInitialized(_this));
|
2429 |
|
2430 | Util.each(Geom, function (geomConstructor, className) {
|
2431 | var methodName = Util.lowerFirst(className);
|
2432 |
|
2433 | self[methodName] = function (cfg) {
|
2434 | var geom = new geomConstructor(cfg);
|
2435 | self.addGeom(geom);
|
2436 | return geom;
|
2437 | };
|
2438 | });
|
2439 |
|
2440 | self._init();
|
2441 |
|
2442 | return _this;
|
2443 | }
|
2444 | |
2445 |
|
2446 |
|
2447 |
|
2448 |
|
2449 |
|
2450 |
|
2451 |
|
2452 |
|
2453 | _proto.source = function source(data, colDefs) {
|
2454 | this.set('data', data);
|
2455 |
|
2456 | if (colDefs) {
|
2457 | this.scale(colDefs);
|
2458 | }
|
2459 |
|
2460 | return this;
|
2461 | };
|
2462 |
|
2463 | _proto.scale = function scale(field, cfg) {
|
2464 | var colDefs = this.get('colDefs') || {};
|
2465 |
|
2466 | if (Util.isObject(field)) {
|
2467 | Util.mix(colDefs, field);
|
2468 | } else {
|
2469 | colDefs[field] = cfg;
|
2470 | }
|
2471 |
|
2472 | this.set('colDefs', colDefs);
|
2473 | var scaleController = this.get('scaleController');
|
2474 | scaleController.defs = colDefs;
|
2475 | return this;
|
2476 | };
|
2477 | |
2478 |
|
2479 |
|
2480 |
|
2481 |
|
2482 |
|
2483 |
|
2484 |
|
2485 |
|
2486 | _proto.axis = function axis(field, cfg) {
|
2487 | var axisController = this.get('axisController');
|
2488 |
|
2489 | if (!field) {
|
2490 | axisController.axisCfg = null;
|
2491 | } else {
|
2492 | axisController.axisCfg = axisController.axisCfg || {};
|
2493 | axisController.axisCfg[field] = cfg;
|
2494 | }
|
2495 |
|
2496 | return this;
|
2497 | };
|
2498 | |
2499 |
|
2500 |
|
2501 |
|
2502 |
|
2503 |
|
2504 |
|
2505 |
|
2506 |
|
2507 | _proto.coord = function coord(type, cfg) {
|
2508 | var coordCfg;
|
2509 |
|
2510 | if (Util.isObject(type)) {
|
2511 | coordCfg = type;
|
2512 | } else {
|
2513 | coordCfg = cfg || {};
|
2514 | coordCfg.type = type || 'cartesian';
|
2515 | }
|
2516 |
|
2517 | this.set('coordCfg', coordCfg);
|
2518 | return this;
|
2519 | };
|
2520 |
|
2521 | _proto.filter = function filter(field, condition) {
|
2522 | var filters = this.get('filters') || {};
|
2523 | filters[field] = condition;
|
2524 | this.set('filters', filters);
|
2525 | };
|
2526 | |
2527 |
|
2528 |
|
2529 |
|
2530 |
|
2531 |
|
2532 |
|
2533 | _proto.render = function render() {
|
2534 | var canvas = this.get('canvas');
|
2535 | var geoms = this.get('geoms');
|
2536 | var data = this.get('data') || [];
|
2537 |
|
2538 | var filteredData = this._execFilter(data);
|
2539 |
|
2540 |
|
2541 | this.set('filteredData', filteredData);
|
2542 |
|
2543 | this._initCoord();
|
2544 |
|
2545 |
|
2546 | Chart.plugins.notify(this, 'beforeGeomInit');
|
2547 |
|
2548 | this._initGeoms(geoms);
|
2549 |
|
2550 |
|
2551 | this.get('syncY') && this._syncYScales();
|
2552 |
|
2553 | this._adjustScale();
|
2554 |
|
2555 |
|
2556 | Chart.plugins.notify(this, 'beforeGeomDraw');
|
2557 |
|
2558 | this._renderAxis();
|
2559 |
|
2560 | var middlePlot = this.get('middlePlot');
|
2561 |
|
2562 | if (this.get('limitInPlot') && !middlePlot.attr('clip')) {
|
2563 | var coord = this.get('coord');
|
2564 | var clip = Helper.getClip(coord);
|
2565 | clip.set('canvas', middlePlot.get('canvas'));
|
2566 | middlePlot.attr('clip', clip);
|
2567 | }
|
2568 |
|
2569 | for (var i = 0, length = geoms.length; i < length; i++) {
|
2570 | var geom = geoms[i];
|
2571 | geom.paint();
|
2572 | }
|
2573 |
|
2574 | Chart.plugins.notify(this, 'afterGeomDraw');
|
2575 | canvas.sort();
|
2576 | this.get('frontPlot').sort();
|
2577 | Chart.plugins.notify(this, 'beforeCanvasDraw');
|
2578 | canvas.draw();
|
2579 | return this;
|
2580 | };
|
2581 | |
2582 |
|
2583 |
|
2584 |
|
2585 |
|
2586 |
|
2587 |
|
2588 | _proto.clear = function clear() {
|
2589 | Chart.plugins.notify(this, 'clear');
|
2590 |
|
2591 | this._removeGeoms();
|
2592 |
|
2593 | this._clearInner();
|
2594 |
|
2595 | this.set('filters', null);
|
2596 | this.set('isUpdate', false);
|
2597 | this.set('_padding', null);
|
2598 | var canvas = this.get('canvas');
|
2599 | canvas.draw();
|
2600 | return this;
|
2601 | };
|
2602 |
|
2603 | _proto.repaint = function repaint() {
|
2604 | this.set('isUpdate', true);
|
2605 | Chart.plugins.notify(this, 'repaint');
|
2606 |
|
2607 | this._clearInner();
|
2608 |
|
2609 | this.render();
|
2610 | };
|
2611 |
|
2612 | _proto.changeData = function changeData(data) {
|
2613 | this.set('data', data);
|
2614 | Chart.plugins.notify(this, 'changeData');
|
2615 | this.set('_padding', null);
|
2616 | this.repaint();
|
2617 | };
|
2618 |
|
2619 | _proto.changeSize = function changeSize(width, height) {
|
2620 | if (width) {
|
2621 | this.set('width', width);
|
2622 | } else {
|
2623 | width = this.get('width');
|
2624 | }
|
2625 |
|
2626 | if (height) {
|
2627 | this.set('height', height);
|
2628 | } else {
|
2629 | height = this.get('height');
|
2630 | }
|
2631 |
|
2632 | var canvas = this.get('canvas');
|
2633 | canvas.changeSize(width, height);
|
2634 |
|
2635 | this._initLayout();
|
2636 |
|
2637 | this.repaint();
|
2638 | return this;
|
2639 | };
|
2640 |
|
2641 | _proto.destroy = function destroy() {
|
2642 | this.clear();
|
2643 | var canvas = this.get('canvas');
|
2644 | canvas.destroy();
|
2645 | Chart.plugins.notify(this, 'afterCanvasDestroyed');
|
2646 |
|
2647 | if (this._interactions) {
|
2648 | Util.each(this._interactions, function (interaction) {
|
2649 | interaction.destroy();
|
2650 | });
|
2651 | }
|
2652 |
|
2653 | _Base.prototype.destroy.call(this);
|
2654 | };
|
2655 | |
2656 |
|
2657 |
|
2658 |
|
2659 |
|
2660 |
|
2661 |
|
2662 | _proto.getPosition = function getPosition(record) {
|
2663 | var self = this;
|
2664 | var coord = self.get('coord');
|
2665 | var xScale = self.getXScale();
|
2666 | var yScale = self.getYScales()[0];
|
2667 | var xField = xScale.field;
|
2668 | var x = xScale.scale(record[xField]);
|
2669 | var yField = yScale.field;
|
2670 | var y = yScale.scale(record[yField]);
|
2671 | return coord.convertPoint({
|
2672 | x: x,
|
2673 | y: y
|
2674 | });
|
2675 | };
|
2676 | |
2677 |
|
2678 |
|
2679 |
|
2680 |
|
2681 |
|
2682 |
|
2683 | _proto.getRecord = function getRecord(point) {
|
2684 | var self = this;
|
2685 | var coord = self.get('coord');
|
2686 | var xScale = self.getXScale();
|
2687 | var yScale = self.getYScales()[0];
|
2688 | var invertPoint = coord.invertPoint(point);
|
2689 | var record = {};
|
2690 | record[xScale.field] = xScale.invert(invertPoint.x);
|
2691 | record[yScale.field] = yScale.invert(invertPoint.y);
|
2692 | return record;
|
2693 | };
|
2694 | |
2695 |
|
2696 |
|
2697 |
|
2698 |
|
2699 |
|
2700 |
|
2701 | _proto.getSnapRecords = function getSnapRecords(point) {
|
2702 | var geom = this.get('geoms')[0];
|
2703 | var data = [];
|
2704 |
|
2705 | if (geom) {
|
2706 |
|
2707 | data = geom.getSnapRecords(point);
|
2708 | }
|
2709 |
|
2710 | return data;
|
2711 | };
|
2712 | |
2713 |
|
2714 |
|
2715 |
|
2716 |
|
2717 |
|
2718 |
|
2719 | _proto.createScale = function createScale(field) {
|
2720 | var data = this.get('data');
|
2721 | var filteredData = this.get('filteredData');
|
2722 |
|
2723 | if (filteredData.length) {
|
2724 | var legendFields = this._getFieldsForLegend();
|
2725 |
|
2726 | if (legendFields.indexOf(field) === -1) {
|
2727 | data = filteredData;
|
2728 | }
|
2729 | }
|
2730 |
|
2731 | var scales = this.get('scales');
|
2732 |
|
2733 | if (!scales[field]) {
|
2734 | scales[field] = this._createScale(field, data);
|
2735 | }
|
2736 |
|
2737 | return scales[field];
|
2738 | };
|
2739 | |
2740 |
|
2741 |
|
2742 |
|
2743 |
|
2744 |
|
2745 |
|
2746 | _proto.addGeom = function addGeom(geom) {
|
2747 | var geoms = this.get('geoms');
|
2748 | var middlePlot = this.get('middlePlot');
|
2749 | geoms.push(geom);
|
2750 | geom.set('chart', this);
|
2751 | geom.set('container', middlePlot.addGroup());
|
2752 | };
|
2753 | |
2754 |
|
2755 |
|
2756 |
|
2757 |
|
2758 |
|
2759 | _proto.getXScale = function getXScale() {
|
2760 | var self = this;
|
2761 | var geoms = self.get('geoms');
|
2762 | var xScale = geoms[0].getXScale();
|
2763 | return xScale;
|
2764 | };
|
2765 | |
2766 |
|
2767 |
|
2768 |
|
2769 |
|
2770 |
|
2771 | _proto.getYScales = function getYScales() {
|
2772 | var geoms = this.get('geoms');
|
2773 | var rst = [];
|
2774 | Util.each(geoms, function (geom) {
|
2775 | var yScale = geom.getYScale();
|
2776 |
|
2777 | if (rst.indexOf(yScale) === -1) {
|
2778 | rst.push(yScale);
|
2779 | }
|
2780 | });
|
2781 | return rst;
|
2782 | };
|
2783 |
|
2784 | _proto.getLegendItems = function getLegendItems() {
|
2785 | if (this.get('legendItems')) {
|
2786 | return this.get('legendItems');
|
2787 | }
|
2788 |
|
2789 | var legendItems = {};
|
2790 | var scales = [];
|
2791 | var geoms = this.get('geoms');
|
2792 | Util.each(geoms, function (geom) {
|
2793 | var colorAttr = geom.getAttr('color');
|
2794 |
|
2795 | if (colorAttr) {
|
2796 | var scale = colorAttr.getScale('color');
|
2797 |
|
2798 | if (scale.type !== 'identity' && !_isScaleExist(scales, scale)) {
|
2799 | scales.push(scale);
|
2800 | var field = scale.field;
|
2801 | var ticks = scale.getTicks();
|
2802 | var items = [];
|
2803 | Util.each(ticks, function (tick) {
|
2804 | var text = tick.text;
|
2805 | var name = text;
|
2806 | var scaleValue = tick.value;
|
2807 | var value = scale.invert(scaleValue);
|
2808 | var color = colorAttr.mapping(value).join('') || Global.defaultColor;
|
2809 | var marker = {
|
2810 | fill: color,
|
2811 | radius: 3,
|
2812 | symbol: 'circle',
|
2813 | stroke: '#fff'
|
2814 | };
|
2815 | items.push({
|
2816 | name: name,
|
2817 |
|
2818 | dataValue: value,
|
2819 |
|
2820 | checked: true,
|
2821 | marker: marker
|
2822 | });
|
2823 | });
|
2824 | legendItems[field] = items;
|
2825 | }
|
2826 | }
|
2827 | });
|
2828 | this.set('legendItems', legendItems);
|
2829 | return legendItems;
|
2830 | };
|
2831 |
|
2832 |
|
2833 | _proto.registerPlugins = function registerPlugins(plugins) {
|
2834 | var self = this;
|
2835 | var chartPlugins = self.get('plugins') || [];
|
2836 |
|
2837 | if (!Util.isArray(chartPlugins)) {
|
2838 | chartPlugins = [chartPlugins];
|
2839 | }
|
2840 |
|
2841 | [].concat(plugins).forEach(function (plugin) {
|
2842 | if (chartPlugins.indexOf(plugin) === -1) {
|
2843 | plugin.init && plugin.init(self);
|
2844 |
|
2845 | chartPlugins.push(plugin);
|
2846 | }
|
2847 | });
|
2848 | Chart.plugins._cacheId++;
|
2849 | self.set('plugins', chartPlugins);
|
2850 | };
|
2851 |
|
2852 | _proto._renderAxis = function _renderAxis() {
|
2853 | var axisController = this.get('axisController');
|
2854 | var xScale = this.getXScale();
|
2855 | var yScales = this.getYScales();
|
2856 | var coord = this.get('coord');
|
2857 | Chart.plugins.notify(this, 'beforeRenderAxis');
|
2858 | axisController.createAxis(coord, xScale, yScales);
|
2859 | };
|
2860 |
|
2861 | _proto._isAutoPadding = function _isAutoPadding() {
|
2862 | if (this.get('_padding')) {
|
2863 | return false;
|
2864 | }
|
2865 |
|
2866 | var padding = this.get('padding');
|
2867 |
|
2868 | if (Util.isArray(padding)) {
|
2869 | return padding.indexOf('auto') !== -1;
|
2870 | }
|
2871 |
|
2872 | return padding === 'auto';
|
2873 | };
|
2874 |
|
2875 | _proto._updateLayout = function _updateLayout(padding) {
|
2876 | var width = this.get('width');
|
2877 | var height = this.get('height');
|
2878 | var start = {
|
2879 | x: padding[3],
|
2880 | y: padding[0]
|
2881 | };
|
2882 | var end = {
|
2883 | x: width - padding[1],
|
2884 | y: height - padding[2]
|
2885 | };
|
2886 | var plot = this.get('plot');
|
2887 | var coord = this.get('coord');
|
2888 | plot.reset(start, end);
|
2889 | coord.reset(plot);
|
2890 | };
|
2891 |
|
2892 | return Chart;
|
2893 | }(Base);
|
2894 |
|
2895 | Chart.plugins = Chart.initPlugins();
|
2896 | module.exports = Chart;
|
2897 |
|
2898 | }),
|
2899 |
|
2900 | (function(module, exports, __webpack_require__) {
|
2901 |
|
2902 | var Vector2 = __webpack_require__(7);
|
2903 |
|
2904 | var start = Vector2.create();
|
2905 | var end = Vector2.create();
|
2906 | var extremity = Vector2.create();
|
2907 |
|
2908 | function getCubicBezierXYatT(startPt, controlPt1, controlPt2, endPt, T) {
|
2909 | var x = CubicN(T, startPt.x, controlPt1.x, controlPt2.x, endPt.x);
|
2910 | var y = CubicN(T, startPt.y, controlPt1.y, controlPt2.y, endPt.y);
|
2911 | return {
|
2912 | x: x,
|
2913 | y: y
|
2914 | };
|
2915 | }
|
2916 |
|
2917 |
|
2918 | function CubicN(T, a, b, c, d) {
|
2919 | var t2 = T * T;
|
2920 | var t3 = t2 * T;
|
2921 | 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;
|
2922 | }
|
2923 |
|
2924 | function cubicBezierBounds(c) {
|
2925 | var minX = Infinity;
|
2926 | var maxX = -Infinity;
|
2927 | var minY = Infinity;
|
2928 | var maxY = -Infinity;
|
2929 | var s = {
|
2930 | x: c[0],
|
2931 | y: c[1]
|
2932 | };
|
2933 | var c1 = {
|
2934 | x: c[2],
|
2935 | y: c[3]
|
2936 | };
|
2937 | var c2 = {
|
2938 | x: c[4],
|
2939 | y: c[5]
|
2940 | };
|
2941 | var e = {
|
2942 | x: c[6],
|
2943 | y: c[7]
|
2944 | };
|
2945 |
|
2946 | for (var t = 0; t < 100; t++) {
|
2947 | var pt = getCubicBezierXYatT(s, c1, c2, e, t / 100);
|
2948 |
|
2949 | if (pt.x < minX) {
|
2950 | minX = pt.x;
|
2951 | }
|
2952 |
|
2953 | if (pt.x > maxX) {
|
2954 | maxX = pt.x;
|
2955 | }
|
2956 |
|
2957 | if (pt.y < minY) {
|
2958 | minY = pt.y;
|
2959 | }
|
2960 |
|
2961 | if (pt.y > maxY) {
|
2962 | maxY = pt.y;
|
2963 | }
|
2964 | }
|
2965 |
|
2966 | return {
|
2967 | minX: minX,
|
2968 | minY: minY,
|
2969 | maxX: maxX,
|
2970 | maxY: maxY
|
2971 | };
|
2972 | }
|
2973 |
|
2974 | module.exports = {
|
2975 | getBBoxFromPoints: function getBBoxFromPoints(points, lineWidth) {
|
2976 | if (points.length === 0) {
|
2977 | return;
|
2978 | }
|
2979 |
|
2980 | var p = points[0];
|
2981 | var left = p.x;
|
2982 | var right = p.x;
|
2983 | var top = p.y;
|
2984 | var bottom = p.y;
|
2985 | var len = points.length;
|
2986 |
|
2987 | for (var i = 1; i < len; i++) {
|
2988 | p = points[i];
|
2989 | left = Math.min(left, p.x);
|
2990 | right = Math.max(right, p.x);
|
2991 | top = Math.min(top, p.y);
|
2992 | bottom = Math.max(bottom, p.y);
|
2993 | }
|
2994 |
|
2995 | lineWidth = lineWidth / 2 || 0;
|
2996 | return {
|
2997 | minX: left - lineWidth,
|
2998 | minY: top - lineWidth,
|
2999 | maxX: right + lineWidth,
|
3000 | maxY: bottom + lineWidth
|
3001 | };
|
3002 | },
|
3003 | getBBoxFromLine: function getBBoxFromLine(x0, y0, x1, y1, lineWidth) {
|
3004 | lineWidth = lineWidth / 2 || 0;
|
3005 | return {
|
3006 | minX: Math.min(x0, x1) - lineWidth,
|
3007 | minY: Math.min(y0, y1) - lineWidth,
|
3008 | maxX: Math.max(x0, x1) + lineWidth,
|
3009 | maxY: Math.max(y0, y1) + lineWidth
|
3010 | };
|
3011 | },
|
3012 | getBBoxFromArc: function getBBoxFromArc(x, y, r, startAngle, endAngle, anticlockwise) {
|
3013 | var diff = Math.abs(startAngle - endAngle);
|
3014 |
|
3015 | if (diff % Math.PI * 2 < 1e-4 && diff > 1e-4) {
|
3016 |
|
3017 | return {
|
3018 | minX: x - r,
|
3019 | minY: y - r,
|
3020 | maxX: x + r,
|
3021 | maxY: y + r
|
3022 | };
|
3023 | }
|
3024 |
|
3025 | start[0] = Math.cos(startAngle) * r + x;
|
3026 | start[1] = Math.sin(startAngle) * r + y;
|
3027 | end[0] = Math.cos(endAngle) * r + x;
|
3028 | end[1] = Math.sin(endAngle) * r + y;
|
3029 | var min = [0, 0];
|
3030 | var max = [0, 0];
|
3031 | Vector2.min(min, start, end);
|
3032 | Vector2.max(max, start, end);
|
3033 |
|
3034 | startAngle = startAngle % (Math.PI * 2);
|
3035 |
|
3036 | if (startAngle < 0) {
|
3037 | startAngle = startAngle + Math.PI * 2;
|
3038 | }
|
3039 |
|
3040 | endAngle = endAngle % (Math.PI * 2);
|
3041 |
|
3042 | if (endAngle < 0) {
|
3043 | endAngle = endAngle + Math.PI * 2;
|
3044 | }
|
3045 |
|
3046 | if (startAngle > endAngle && !anticlockwise) {
|
3047 | endAngle += Math.PI * 2;
|
3048 | } else if (startAngle < endAngle && anticlockwise) {
|
3049 | startAngle += Math.PI * 2;
|
3050 | }
|
3051 |
|
3052 | if (anticlockwise) {
|
3053 | var tmp = endAngle;
|
3054 | endAngle = startAngle;
|
3055 | startAngle = tmp;
|
3056 | }
|
3057 |
|
3058 | for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
|
3059 | if (angle > startAngle) {
|
3060 | extremity[0] = Math.cos(angle) * r + x;
|
3061 | extremity[1] = Math.sin(angle) * r + y;
|
3062 | Vector2.min(min, extremity, min);
|
3063 | Vector2.max(max, extremity, max);
|
3064 | }
|
3065 | }
|
3066 |
|
3067 | return {
|
3068 | minX: min[0],
|
3069 | minY: min[1],
|
3070 | maxX: max[0],
|
3071 | maxY: max[1]
|
3072 | };
|
3073 | },
|
3074 | getBBoxFromBezierGroup: function getBBoxFromBezierGroup(points, lineWidth) {
|
3075 | var minX = Infinity;
|
3076 | var maxX = -Infinity;
|
3077 | var minY = Infinity;
|
3078 | var maxY = -Infinity;
|
3079 |
|
3080 | for (var i = 0, len = points.length; i < len; i++) {
|
3081 | var bbox = cubicBezierBounds(points[i]);
|
3082 |
|
3083 | if (bbox.minX < minX) {
|
3084 | minX = bbox.minX;
|
3085 | }
|
3086 |
|
3087 | if (bbox.maxX > maxX) {
|
3088 | maxX = bbox.maxX;
|
3089 | }
|
3090 |
|
3091 | if (bbox.minY < minY) {
|
3092 | minY = bbox.minY;
|
3093 | }
|
3094 |
|
3095 | if (bbox.maxY > maxY) {
|
3096 | maxY = bbox.maxY;
|
3097 | }
|
3098 | }
|
3099 |
|
3100 | lineWidth = lineWidth / 2 || 0;
|
3101 | return {
|
3102 | minX: minX - lineWidth,
|
3103 | minY: minY - lineWidth,
|
3104 | maxX: maxX + lineWidth,
|
3105 | maxY: maxY + lineWidth
|
3106 | };
|
3107 | }
|
3108 | };
|
3109 |
|
3110 | }),
|
3111 |
|
3112 | (function(module, exports, __webpack_require__) {
|
3113 |
|
3114 | var isType = __webpack_require__(10);
|
3115 |
|
3116 | var isString = function isString(str) {
|
3117 | return isType(str, 'String');
|
3118 | };
|
3119 |
|
3120 | module.exports = isString;
|
3121 |
|
3122 | }),
|
3123 |
|
3124 | (function(module, exports, __webpack_require__) {
|
3125 |
|
3126 |
|
3127 |
|
3128 |
|
3129 |
|
3130 | var isType = __webpack_require__(10);
|
3131 |
|
3132 | var isNumber = function isNumber(value) {
|
3133 | return isType(value, 'Number');
|
3134 | };
|
3135 |
|
3136 | module.exports = isNumber;
|
3137 |
|
3138 | }),
|
3139 |
|
3140 | (function(module, exports, __webpack_require__) {
|
3141 |
|
3142 | var mix = __webpack_require__(18);
|
3143 |
|
3144 | var each = __webpack_require__(4);
|
3145 |
|
3146 | var isObject = __webpack_require__(17);
|
3147 |
|
3148 | var isNil = __webpack_require__(9);
|
3149 |
|
3150 | var Scale =
|
3151 |
|
3152 | function () {
|
3153 | var _proto = Scale.prototype;
|
3154 |
|
3155 | _proto._initDefaultCfg = function _initDefaultCfg() {
|
3156 | this.type = 'base';
|
3157 | |
3158 |
|
3159 |
|
3160 |
|
3161 |
|
3162 | this.formatter = null;
|
3163 | |
3164 |
|
3165 |
|
3166 |
|
3167 |
|
3168 | this.range = [0, 1];
|
3169 | |
3170 |
|
3171 |
|
3172 |
|
3173 |
|
3174 | this.ticks = null;
|
3175 | |
3176 |
|
3177 |
|
3178 |
|
3179 |
|
3180 | this.values = [];
|
3181 | };
|
3182 |
|
3183 | function Scale(cfg) {
|
3184 | this._initDefaultCfg();
|
3185 |
|
3186 | mix(this, cfg);
|
3187 | this.init();
|
3188 | }
|
3189 | |
3190 |
|
3191 |
|
3192 |
|
3193 |
|
3194 |
|
3195 | _proto.init = function init() {};
|
3196 | |
3197 |
|
3198 |
|
3199 |
|
3200 |
|
3201 |
|
3202 |
|
3203 |
|
3204 |
|
3205 |
|
3206 |
|
3207 |
|
3208 |
|
3209 |
|
3210 |
|
3211 |
|
3212 |
|
3213 |
|
3214 |
|
3215 | _proto.getTicks = function getTicks() {
|
3216 | var self = this;
|
3217 | var ticks = self.ticks;
|
3218 | var rst = [];
|
3219 | each(ticks, function (tick) {
|
3220 | var obj;
|
3221 |
|
3222 | if (isObject(tick)) {
|
3223 | obj = tick;
|
3224 | } else {
|
3225 | obj = {
|
3226 | text: self.getText(tick),
|
3227 | tickValue: tick,
|
3228 | value: self.scale(tick)
|
3229 | };
|
3230 | }
|
3231 |
|
3232 | rst.push(obj);
|
3233 | });
|
3234 | return rst;
|
3235 | };
|
3236 | |
3237 |
|
3238 |
|
3239 |
|
3240 |
|
3241 |
|
3242 |
|
3243 |
|
3244 | _proto.getText = function getText(value, key) {
|
3245 | var formatter = this.formatter;
|
3246 | value = formatter ? formatter(value, key) : value;
|
3247 |
|
3248 | if (isNil(value) || !value.toString) {
|
3249 | value = '';
|
3250 | }
|
3251 |
|
3252 | return value.toString();
|
3253 | };
|
3254 | |
3255 |
|
3256 |
|
3257 |
|
3258 |
|
3259 |
|
3260 |
|
3261 | _proto.rangeMin = function rangeMin() {
|
3262 | return this.range[0];
|
3263 | };
|
3264 | |
3265 |
|
3266 |
|
3267 |
|
3268 |
|
3269 |
|
3270 |
|
3271 | _proto.rangeMax = function rangeMax() {
|
3272 | var range = this.range;
|
3273 | return range[range.length - 1];
|
3274 | };
|
3275 | |
3276 |
|
3277 |
|
3278 |
|
3279 |
|
3280 |
|
3281 |
|
3282 | _proto.invert = function invert(value) {
|
3283 | return value;
|
3284 | };
|
3285 | |
3286 |
|
3287 |
|
3288 |
|
3289 |
|
3290 |
|
3291 |
|
3292 | _proto.translate = function translate(value) {
|
3293 | return value;
|
3294 | };
|
3295 | |
3296 |
|
3297 |
|
3298 |
|
3299 |
|
3300 |
|
3301 |
|
3302 | _proto.scale = function scale(value) {
|
3303 | return value;
|
3304 | };
|
3305 | |
3306 |
|
3307 |
|
3308 |
|
3309 |
|
3310 |
|
3311 | _proto.clone = function clone() {
|
3312 | var self = this;
|
3313 | var constr = self.constructor;
|
3314 | var cfg = {};
|
3315 | each(self, function (v, k) {
|
3316 | cfg[k] = self[k];
|
3317 | });
|
3318 | return new constr(cfg);
|
3319 | };
|
3320 | |
3321 |
|
3322 |
|
3323 |
|
3324 |
|
3325 |
|
3326 |
|
3327 |
|
3328 | _proto.change = function change(info) {
|
3329 | this.ticks = null;
|
3330 | mix(this, info);
|
3331 | this.init();
|
3332 | return this;
|
3333 | };
|
3334 |
|
3335 | return Scale;
|
3336 | }();
|
3337 |
|
3338 | module.exports = Scale;
|
3339 |
|
3340 | }),
|
3341 |
|
3342 | (function(module, exports) {
|
3343 |
|
3344 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
|
3345 | return typeof obj;
|
3346 | } : function (obj) {
|
3347 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
3348 | };
|
3349 |
|
3350 | var isObject = function isObject(value) {
|
3351 | |
3352 |
|
3353 |
|
3354 |
|
3355 |
|
3356 |
|
3357 | var type = typeof value === 'undefined' ? 'undefined' : _typeof(value);
|
3358 | return value !== null && type === 'object' || type === 'function';
|
3359 | };
|
3360 |
|
3361 | module.exports = isObject;
|
3362 |
|
3363 | }),
|
3364 |
|
3365 | (function(module, exports) {
|
3366 |
|
3367 | function _mix(dist, obj) {
|
3368 | for (var key in obj) {
|
3369 | if (obj.hasOwnProperty(key) && key !== 'constructor' && obj[key] !== undefined) {
|
3370 | dist[key] = obj[key];
|
3371 | }
|
3372 | }
|
3373 | }
|
3374 |
|
3375 | var mix = function mix(dist, src1, src2, src3) {
|
3376 | if (src1) _mix(dist, src1);
|
3377 | if (src2) _mix(dist, src2);
|
3378 | if (src3) _mix(dist, src3);
|
3379 | return dist;
|
3380 | };
|
3381 |
|
3382 | module.exports = mix;
|
3383 |
|
3384 | }),
|
3385 |
|
3386 | (function(module, exports, __webpack_require__) {
|
3387 |
|
3388 |
|
3389 |
|
3390 |
|
3391 | var isString = __webpack_require__(14);
|
3392 |
|
3393 | var isArray = __webpack_require__(11);
|
3394 |
|
3395 | var mix = __webpack_require__(18);
|
3396 |
|
3397 | var each = __webpack_require__(4);
|
3398 |
|
3399 | function toScaleString(scale, value) {
|
3400 | if (isString(value)) {
|
3401 | return value;
|
3402 | }
|
3403 |
|
3404 | return scale.invert(scale.scale(value));
|
3405 | }
|
3406 |
|
3407 |
|
3408 |
|
3409 |
|
3410 |
|
3411 |
|
3412 | var AttributeBase =
|
3413 |
|
3414 | function () {
|
3415 | function AttributeBase(cfg) {
|
3416 | |
3417 |
|
3418 |
|
3419 |
|
3420 | this.type = 'base';
|
3421 | |
3422 |
|
3423 |
|
3424 |
|
3425 |
|
3426 | this.name = null;
|
3427 | |
3428 |
|
3429 |
|
3430 |
|
3431 |
|
3432 | this.method = null;
|
3433 | |
3434 |
|
3435 |
|
3436 |
|
3437 |
|
3438 | this.values = [];
|
3439 | |
3440 |
|
3441 |
|
3442 |
|
3443 |
|
3444 | this.scales = [];
|
3445 | |
3446 |
|
3447 |
|
3448 |
|
3449 |
|
3450 | this.linear = null;
|
3451 | mix(this, cfg);
|
3452 | }
|
3453 |
|
3454 |
|
3455 | var _proto = AttributeBase.prototype;
|
3456 |
|
3457 | _proto._getAttrValue = function _getAttrValue(scale, value) {
|
3458 | var values = this.values;
|
3459 |
|
3460 | if (scale.isCategory && !this.linear) {
|
3461 | var index = scale.translate(value);
|
3462 | return values[index % values.length];
|
3463 | }
|
3464 |
|
3465 | var percent = scale.scale(value);
|
3466 | return this.getLinearValue(percent);
|
3467 | };
|
3468 | |
3469 |
|
3470 |
|
3471 |
|
3472 |
|
3473 |
|
3474 |
|
3475 |
|
3476 | _proto.getLinearValue = function getLinearValue(percent) {
|
3477 | var values = this.values;
|
3478 | var steps = values.length - 1;
|
3479 | var step = Math.floor(steps * percent);
|
3480 | var leftPercent = steps * percent - step;
|
3481 | var start = values[step];
|
3482 | var end = step === steps ? start : values[step + 1];
|
3483 | var rstValue = start + (end - start) * leftPercent;
|
3484 | return rstValue;
|
3485 | };
|
3486 | |
3487 |
|
3488 |
|
3489 |
|
3490 |
|
3491 |
|
3492 |
|
3493 |
|
3494 | _proto.callback = function callback(value) {
|
3495 | var self = this;
|
3496 | var scale = self.scales[0];
|
3497 | var rstValue = null;
|
3498 |
|
3499 | if (scale.type === 'identity') {
|
3500 | rstValue = scale.value;
|
3501 | } else {
|
3502 | rstValue = self._getAttrValue(scale, value);
|
3503 | }
|
3504 |
|
3505 | return rstValue;
|
3506 | };
|
3507 | |
3508 |
|
3509 |
|
3510 |
|
3511 |
|
3512 |
|
3513 | _proto.getNames = function getNames() {
|
3514 | var scales = this.scales;
|
3515 | var names = this.names;
|
3516 | var length = Math.min(scales.length, names.length);
|
3517 | var rst = [];
|
3518 |
|
3519 | for (var i = 0; i < length; i++) {
|
3520 | rst.push(names[i]);
|
3521 | }
|
3522 |
|
3523 | return rst;
|
3524 | };
|
3525 | |
3526 |
|
3527 |
|
3528 |
|
3529 |
|
3530 |
|
3531 | _proto.getFields = function getFields() {
|
3532 | var scales = this.scales;
|
3533 | var rst = [];
|
3534 | each(scales, function (scale) {
|
3535 | rst.push(scale.field);
|
3536 | });
|
3537 | return rst;
|
3538 | };
|
3539 | |
3540 |
|
3541 |
|
3542 |
|
3543 |
|
3544 |
|
3545 |
|
3546 | _proto.getScale = function getScale(name) {
|
3547 | var scales = this.scales;
|
3548 | var names = this.names;
|
3549 | var index = names.indexOf(name);
|
3550 | return scales[index];
|
3551 | };
|
3552 | |
3553 |
|
3554 |
|
3555 |
|
3556 |
|
3557 |
|
3558 |
|
3559 | _proto.mapping = function mapping() {
|
3560 | var scales = this.scales;
|
3561 | var callback = this.callback;
|
3562 |
|
3563 | for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
|
3564 | params[_key] = arguments[_key];
|
3565 | }
|
3566 |
|
3567 | var values = params;
|
3568 |
|
3569 | if (callback) {
|
3570 | for (var i = 0, len = params.length; i < len; i++) {
|
3571 | params[i] = this._toOriginParam(params[i], scales[i]);
|
3572 | }
|
3573 |
|
3574 | values = callback.apply(this, params);
|
3575 | }
|
3576 |
|
3577 | values = [].concat(values);
|
3578 | return values;
|
3579 | };
|
3580 |
|
3581 |
|
3582 | _proto._toOriginParam = function _toOriginParam(param, scale) {
|
3583 | var rst = param;
|
3584 |
|
3585 | if (!scale.isLinear) {
|
3586 | if (isArray(param)) {
|
3587 | rst = [];
|
3588 |
|
3589 | for (var i = 0, len = param.length; i < len; i++) {
|
3590 | rst.push(toScaleString(scale, param[i]));
|
3591 | }
|
3592 | } else {
|
3593 | rst = toScaleString(scale, param);
|
3594 | }
|
3595 | }
|
3596 |
|
3597 | return rst;
|
3598 | };
|
3599 |
|
3600 | return AttributeBase;
|
3601 | }();
|
3602 |
|
3603 | module.exports = AttributeBase;
|
3604 |
|
3605 | }),
|
3606 |
|
3607 | (function(module, exports, __webpack_require__) {
|
3608 |
|
3609 | var _require = __webpack_require__(3),
|
3610 | Shape = _require.Shape;
|
3611 |
|
3612 | module.exports = {
|
3613 | getClip: function getClip(coord) {
|
3614 | var start = coord.start;
|
3615 | var end = coord.end;
|
3616 | var width = end.x - start.x;
|
3617 | var height = Math.abs(end.y - start.y);
|
3618 | var margin = 10;
|
3619 | var clip;
|
3620 |
|
3621 | if (coord.isPolar) {
|
3622 | var circleRadius = coord.circleRadius,
|
3623 | center = coord.center,
|
3624 | startAngle = coord.startAngle,
|
3625 | endAngle = coord.endAngle;
|
3626 | clip = new Shape.Sector({
|
3627 | attrs: {
|
3628 | x: center.x,
|
3629 | y: center.y,
|
3630 | r: circleRadius,
|
3631 | r0: 0,
|
3632 | startAngle: startAngle,
|
3633 | endAngle: endAngle
|
3634 | }
|
3635 | });
|
3636 | } else {
|
3637 | clip = new Shape.Rect({
|
3638 | attrs: {
|
3639 | x: start.x,
|
3640 | y: end.y - margin,
|
3641 | width: width,
|
3642 | height: height + 2 * margin
|
3643 | }
|
3644 | });
|
3645 | }
|
3646 |
|
3647 | clip.isClip = true;
|
3648 | return clip;
|
3649 | },
|
3650 | isPointInPlot: function isPointInPlot(point, plot) {
|
3651 | var x = point.x,
|
3652 | y = point.y;
|
3653 | var tl = plot.tl,
|
3654 | tr = plot.tr,
|
3655 | br = plot.br;
|
3656 | return x >= tl.x && x <= tr.x && y >= tl.y && y <= br.y;
|
3657 | }
|
3658 | };
|
3659 |
|
3660 | }),
|
3661 |
|
3662 | (function(module, exports, __webpack_require__) {
|
3663 |
|
3664 |
|
3665 |
|
3666 |
|
3667 |
|
3668 | var Util = __webpack_require__(0);
|
3669 |
|
3670 | var ShapeUtil = {
|
3671 | splitPoints: function splitPoints(obj) {
|
3672 | var points = [];
|
3673 | var x = obj.x;
|
3674 | var y = obj.y;
|
3675 | y = Util.isArray(y) ? y : [y];
|
3676 | y.forEach(function (yItem, index) {
|
3677 | var point = {
|
3678 | x: Util.isArray(x) ? x[index] : x,
|
3679 | y: yItem
|
3680 | };
|
3681 | points.push(point);
|
3682 | });
|
3683 | return points;
|
3684 | },
|
3685 | splitArray: function splitArray(data, yField, connectNulls) {
|
3686 | if (!data.length) return [];
|
3687 | var arr = [];
|
3688 | var tmp = [];
|
3689 | var yValue;
|
3690 | Util.each(data, function (obj) {
|
3691 | yValue = obj._origin ? obj._origin[yField] : obj[yField];
|
3692 |
|
3693 | if (connectNulls) {
|
3694 | if (!Util.isNil(yValue)) {
|
3695 | tmp.push(obj);
|
3696 | }
|
3697 | } else {
|
3698 | if (Util.isArray(yValue) && Util.isNil(yValue[0]) || Util.isNil(yValue)) {
|
3699 | if (tmp.length) {
|
3700 | arr.push(tmp);
|
3701 | tmp = [];
|
3702 | }
|
3703 | } else {
|
3704 | tmp.push(obj);
|
3705 | }
|
3706 | }
|
3707 | });
|
3708 |
|
3709 | if (tmp.length) {
|
3710 | arr.push(tmp);
|
3711 | }
|
3712 |
|
3713 | return arr;
|
3714 | }
|
3715 | };
|
3716 | module.exports = ShapeUtil;
|
3717 |
|
3718 | }),
|
3719 |
|
3720 | (function(module, exports, __webpack_require__) {
|
3721 |
|
3722 |
|
3723 |
|
3724 |
|
3725 |
|
3726 | var Util = __webpack_require__(0);
|
3727 |
|
3728 | var Chart = __webpack_require__(12);
|
3729 |
|
3730 | var Hammer;
|
3731 |
|
3732 | if (!Util.isWx && !Util.isMy) {
|
3733 | Hammer = __webpack_require__(133);
|
3734 | }
|
3735 |
|
3736 | var TOUCH_EVENTS = ['touchstart', 'touchmove', 'touchend'];
|
3737 |
|
3738 | var Interaction =
|
3739 |
|
3740 | function () {
|
3741 | var _proto = Interaction.prototype;
|
3742 |
|
3743 | _proto.getDefaultCfg = function getDefaultCfg() {
|
3744 | return {
|
3745 | startEvent: TOUCH_EVENTS[0],
|
3746 | processEvent: TOUCH_EVENTS[1],
|
3747 | endEvent: TOUCH_EVENTS[2],
|
3748 | resetEvent: null
|
3749 | };
|
3750 | };
|
3751 |
|
3752 | _proto._start = function _start(ev) {
|
3753 | this.preStart && this.preStart(ev);
|
3754 | this.start(ev);
|
3755 | this.onStart && this.onStart(ev);
|
3756 | };
|
3757 |
|
3758 | _proto._process = function _process(ev) {
|
3759 | this.preProcess && this.preProcess(ev);
|
3760 | this.process(ev);
|
3761 | this.onProcess && this.onProcess(ev);
|
3762 | };
|
3763 |
|
3764 | _proto._end = function _end(ev) {
|
3765 | this.preEnd && this.preEnd(ev);
|
3766 | this.end(ev);
|
3767 | this.onEnd && this.onEnd(ev);
|
3768 | };
|
3769 |
|
3770 | _proto._reset = function _reset(ev) {
|
3771 | this.preReset && this.preReset(ev);
|
3772 | this.reset(ev);
|
3773 | this.onReset && this.onReset(ev);
|
3774 | };
|
3775 |
|
3776 |
|
3777 | _proto.start = function start() {};
|
3778 |
|
3779 |
|
3780 | _proto.process = function process() {};
|
3781 |
|
3782 |
|
3783 | _proto.end = function end() {};
|
3784 |
|
3785 |
|
3786 | _proto.reset = function reset() {};
|
3787 |
|
3788 | function Interaction(cfg, chart) {
|
3789 | var defaultCfg = this.getDefaultCfg();
|
3790 | Util.deepMix(this, defaultCfg, cfg);
|
3791 | this.chart = chart;
|
3792 | this.canvas = chart.get('canvas');
|
3793 | this.el = chart.get('canvas').get('el');
|
3794 |
|
3795 | this._bindEvents();
|
3796 | }
|
3797 |
|
3798 | _proto._bindEvents = function _bindEvents() {
|
3799 | this._clearEvents();
|
3800 |
|
3801 |
|
3802 | var startEvent = this.startEvent,
|
3803 | processEvent = this.processEvent,
|
3804 | endEvent = this.endEvent,
|
3805 | resetEvent = this.resetEvent,
|
3806 | el = this.el;
|
3807 |
|
3808 | if (Hammer) {
|
3809 | this.hammer = new Hammer(el);
|
3810 | }
|
3811 |
|
3812 | this._bindEvent(startEvent, '_start');
|
3813 |
|
3814 | this._bindEvent(processEvent, '_process');
|
3815 |
|
3816 | this._bindEvent(endEvent, '_end');
|
3817 |
|
3818 | this._bindEvent(resetEvent, '_reset');
|
3819 | };
|
3820 |
|
3821 | _proto._clearEvents = function _clearEvents() {
|
3822 | var startEvent = this.startEvent,
|
3823 | processEvent = this.processEvent,
|
3824 | endEvent = this.endEvent,
|
3825 | resetEvent = this.resetEvent;
|
3826 |
|
3827 | if (this.hammer) {
|
3828 | this.hammer.destroy();
|
3829 | this.hammer = null;
|
3830 | }
|
3831 |
|
3832 | this._clearTouchEvent(startEvent, '_start');
|
3833 |
|
3834 | this._clearTouchEvent(processEvent, '_process');
|
3835 |
|
3836 | this._clearTouchEvent(endEvent, '_end');
|
3837 |
|
3838 | this._clearTouchEvent(resetEvent, '_reset');
|
3839 | };
|
3840 |
|
3841 | _proto._bindEvent = function _bindEvent(eventName, methodName) {
|
3842 | var el = this.el;
|
3843 |
|
3844 | if (eventName) {
|
3845 | if (TOUCH_EVENTS.indexOf(eventName) !== -1) {
|
3846 | Util.addEventListener(el, eventName, Util.wrapBehavior(this, methodName));
|
3847 | } else if (this.hammer) {
|
3848 | this.hammer.on(eventName, Util.wrapBehavior(this, methodName));
|
3849 | }
|
3850 | }
|
3851 | };
|
3852 |
|
3853 | _proto._clearTouchEvent = function _clearTouchEvent(eventName, methodName) {
|
3854 | var el = this.el;
|
3855 |
|
3856 | if (eventName && TOUCH_EVENTS.indexOf(eventName) !== -1) {
|
3857 | Util.removeEventListener(el, eventName, Util.getWrapBehavior(this, methodName));
|
3858 | }
|
3859 | };
|
3860 |
|
3861 | _proto.destroy = function destroy() {
|
3862 | this._clearEvents();
|
3863 | };
|
3864 |
|
3865 | return Interaction;
|
3866 | }();
|
3867 |
|
3868 | Chart._Interactions = {};
|
3869 |
|
3870 | Chart.registerInteraction = function (type, constructor) {
|
3871 | Chart._Interactions[type] = constructor;
|
3872 | };
|
3873 |
|
3874 | Chart.getInteraction = function (type) {
|
3875 | return Chart._Interactions[type];
|
3876 | };
|
3877 |
|
3878 | Chart.prototype.interaction = function (type, cfg) {
|
3879 | var interactions = this._interactions || {};
|
3880 |
|
3881 | if (interactions[type]) {
|
3882 |
|
3883 | interactions[type].destroy();
|
3884 | }
|
3885 |
|
3886 | var Ctor = Chart.getInteraction(type);
|
3887 | var interact = new Ctor(cfg, this);
|
3888 | interactions[type] = interact;
|
3889 | this._interactions = interactions;
|
3890 | return this;
|
3891 | };
|
3892 |
|
3893 | Chart.prototype.clearInteraction = function (type) {
|
3894 | var interactions = this._interactions;
|
3895 | if (!interactions) return;
|
3896 |
|
3897 | if (type) {
|
3898 | interactions[type] && interactions[type].destroy();
|
3899 | delete interactions[type];
|
3900 | } else {
|
3901 | Util.each(interactions, function (interaction, key) {
|
3902 | interaction.destroy();
|
3903 | delete interactions[key];
|
3904 | });
|
3905 | }
|
3906 |
|
3907 | return this;
|
3908 | };
|
3909 |
|
3910 | module.exports = Interaction;
|
3911 |
|
3912 | }),
|
3913 |
|
3914 | (function(module, exports, __webpack_require__) {
|
3915 |
|
3916 | var Util = __webpack_require__(0);
|
3917 |
|
3918 | var Base =
|
3919 |
|
3920 | function () {
|
3921 | var _proto = Base.prototype;
|
3922 |
|
3923 | _proto._initDefaultCfg = function _initDefaultCfg() {};
|
3924 |
|
3925 | function Base(cfg) {
|
3926 | this._initDefaultCfg();
|
3927 |
|
3928 | Util.mix(this, cfg);
|
3929 | var start;
|
3930 | var end;
|
3931 |
|
3932 | if (this.plot) {
|
3933 | start = this.plot.bl;
|
3934 | end = this.plot.tr;
|
3935 | this.start = start;
|
3936 | this.end = end;
|
3937 | } else {
|
3938 | start = this.start;
|
3939 | end = this.end;
|
3940 | }
|
3941 |
|
3942 | this.init(start, end);
|
3943 | }
|
3944 |
|
3945 | _proto.init = function init() {};
|
3946 |
|
3947 | _proto.convertPoint = function convertPoint(point) {
|
3948 | return point;
|
3949 | };
|
3950 |
|
3951 | _proto.invertPoint = function invertPoint(point) {
|
3952 | return point;
|
3953 | };
|
3954 |
|
3955 | _proto.reset = function reset(plot) {
|
3956 | this.plot = plot;
|
3957 | var bl = plot.bl,
|
3958 | tr = plot.tr;
|
3959 | this.start = bl;
|
3960 | this.end = tr;
|
3961 | this.init(bl, tr);
|
3962 | };
|
3963 |
|
3964 | return Base;
|
3965 | }();
|
3966 |
|
3967 | module.exports = Base;
|
3968 |
|
3969 | }),
|
3970 |
|
3971 | (function(module, exports, __webpack_require__) {
|
3972 |
|
3973 | var mix = __webpack_require__(18);
|
3974 |
|
3975 | var Adjust =
|
3976 |
|
3977 | function () {
|
3978 | var _proto = Adjust.prototype;
|
3979 |
|
3980 | _proto._initDefaultCfg = function _initDefaultCfg() {
|
3981 | this.adjustNames = ['x', 'y'];
|
3982 | };
|
3983 |
|
3984 | function Adjust(cfg) {
|
3985 | this._initDefaultCfg();
|
3986 |
|
3987 | mix(this, cfg);
|
3988 | }
|
3989 | |
3990 |
|
3991 |
|
3992 |
|
3993 |
|
3994 | _proto.processAdjust = function processAdjust()
|
3995 | /* dataArray */
|
3996 | {};
|
3997 |
|
3998 | return Adjust;
|
3999 | }();
|
4000 |
|
4001 | module.exports = Adjust;
|
4002 |
|
4003 | }),
|
4004 |
|
4005 | (function(module, exports, __webpack_require__) {
|
4006 |
|
4007 | var Util = __webpack_require__(0);
|
4008 |
|
4009 | var Global = __webpack_require__(1);
|
4010 |
|
4011 | var Vector2 = __webpack_require__(7);
|
4012 |
|
4013 | var Abastract =
|
4014 |
|
4015 | function () {
|
4016 | var _proto = Abastract.prototype;
|
4017 |
|
4018 | _proto._initDefaultCfg = function _initDefaultCfg() {
|
4019 | |
4020 |
|
4021 |
|
4022 |
|
4023 | this.ticks = [];
|
4024 | |
4025 |
|
4026 |
|
4027 |
|
4028 |
|
4029 | this.tickLine = {};
|
4030 | |
4031 |
|
4032 |
|
4033 |
|
4034 |
|
4035 | this.offsetFactor = 1;
|
4036 | |
4037 |
|
4038 |
|
4039 |
|
4040 |
|
4041 | this.frontContainer = null;
|
4042 | |
4043 |
|
4044 |
|
4045 |
|
4046 |
|
4047 | this.backContainer = null;
|
4048 | |
4049 |
|
4050 |
|
4051 |
|
4052 |
|
4053 | this.gridPoints = [];
|
4054 | };
|
4055 |
|
4056 | function Abastract(cfg) {
|
4057 | this._initDefaultCfg();
|
4058 |
|
4059 | Util.mix(this, cfg);
|
4060 | this.draw();
|
4061 | }
|
4062 |
|
4063 | _proto.draw = function draw() {
|
4064 | var line = this.line,
|
4065 | tickLine = this.tickLine,
|
4066 | label = this.label,
|
4067 | grid = this.grid;
|
4068 | grid && this.drawGrid(grid);
|
4069 |
|
4070 | tickLine && this.drawTicks(tickLine);
|
4071 |
|
4072 | line && this.drawLine(line);
|
4073 |
|
4074 | label && this.drawLabels();
|
4075 | };
|
4076 |
|
4077 | _proto.drawTicks = function drawTicks(tickCfg) {
|
4078 | var self = this;
|
4079 | var ticks = self.ticks;
|
4080 | var length = tickCfg.length;
|
4081 | var container = self.getContainer(tickCfg.top);
|
4082 | Util.each(ticks, function (tick) {
|
4083 | var start = self.getOffsetPoint(tick.value);
|
4084 | var end = self.getSidePoint(start, length);
|
4085 | var shape = container.addShape('line', {
|
4086 | className: 'axis-tick',
|
4087 | attrs: Util.mix({
|
4088 | x1: start.x,
|
4089 | y1: start.y,
|
4090 | x2: end.x,
|
4091 | y2: end.y
|
4092 | }, tickCfg)
|
4093 | });
|
4094 | shape._id = self._id + '-ticks';
|
4095 | });
|
4096 | };
|
4097 |
|
4098 | _proto.drawLabels = function drawLabels() {
|
4099 | var self = this;
|
4100 | var labelOffset = self.labelOffset;
|
4101 | var labels = self.labels;
|
4102 | Util.each(labels, function (labelShape) {
|
4103 | var container = self.getContainer(labelShape.get('top'));
|
4104 | var start = self.getOffsetPoint(labelShape.get('value'));
|
4105 |
|
4106 | var _self$getSidePoint = self.getSidePoint(start, labelOffset),
|
4107 | x = _self$getSidePoint.x,
|
4108 | y = _self$getSidePoint.y;
|
4109 |
|
4110 | labelShape.attr(Util.mix({
|
4111 | x: x,
|
4112 | y: y
|
4113 | }, self.getTextAlignInfo(start, labelOffset), labelShape.get('textStyle')));
|
4114 | labelShape._id = self._id + '-' + labelShape.attr('text');
|
4115 | container.add(labelShape);
|
4116 | });
|
4117 | };
|
4118 |
|
4119 | _proto.drawLine = function drawLine() {};
|
4120 |
|
4121 | _proto.drawGrid = function drawGrid(grid) {
|
4122 | var self = this;
|
4123 | var gridPoints = self.gridPoints,
|
4124 | ticks = self.ticks;
|
4125 | var gridCfg = grid;
|
4126 | var count = gridPoints.length;
|
4127 | Util.each(gridPoints, function (subPoints, index) {
|
4128 | if (Util.isFunction(grid)) {
|
4129 | var tick = ticks[index] || {};
|
4130 | gridCfg = Util.mix({}, Global._defaultAxis.grid, grid(tick.text, index, count));
|
4131 | }
|
4132 |
|
4133 | if (gridCfg) {
|
4134 | var type = gridCfg.type;
|
4135 |
|
4136 | var points = subPoints.points;
|
4137 | var container = self.getContainer(gridCfg.top);
|
4138 | var shape;
|
4139 |
|
4140 | if (type === 'arc') {
|
4141 | var center = self.center,
|
4142 | startAngle = self.startAngle,
|
4143 | endAngle = self.endAngle;
|
4144 | var radius = Vector2.length([points[0].x - center.x, points[0].y - center.y]);
|
4145 | shape = container.addShape('Arc', {
|
4146 | className: 'axis-grid',
|
4147 | attrs: Util.mix({
|
4148 | x: center.x,
|
4149 | y: center.y,
|
4150 | startAngle: startAngle,
|
4151 | endAngle: endAngle,
|
4152 | r: radius
|
4153 | }, gridCfg)
|
4154 | });
|
4155 | } else {
|
4156 | shape = container.addShape('Polyline', {
|
4157 | className: 'axis-grid',
|
4158 | attrs: Util.mix({
|
4159 | points: points
|
4160 | }, gridCfg)
|
4161 | });
|
4162 | }
|
4163 |
|
4164 | shape._id = subPoints._id;
|
4165 | }
|
4166 | });
|
4167 | };
|
4168 |
|
4169 | _proto.getOffsetPoint = function getOffsetPoint() {};
|
4170 |
|
4171 | _proto.getAxisVector = function getAxisVector() {};
|
4172 |
|
4173 | _proto.getOffsetVector = function getOffsetVector(point, offset) {
|
4174 | var self = this;
|
4175 | var axisVector = self.getAxisVector(point);
|
4176 | var normal = Vector2.normalize([], axisVector);
|
4177 | var factor = self.offsetFactor;
|
4178 | var verticalVector = [normal[1] * -1 * factor, normal[0] * factor];
|
4179 | return Vector2.scale([], verticalVector, offset);
|
4180 | };
|
4181 |
|
4182 | _proto.getSidePoint = function getSidePoint(point, offset) {
|
4183 | var self = this;
|
4184 | var offsetVector = self.getOffsetVector(point, offset);
|
4185 | return {
|
4186 | x: point.x + offsetVector[0],
|
4187 | y: point.y + offsetVector[1]
|
4188 | };
|
4189 | };
|
4190 |
|
4191 | _proto.getTextAlignInfo = function getTextAlignInfo(point, offset) {
|
4192 | var self = this;
|
4193 | var offsetVector = self.getOffsetVector(point, offset);
|
4194 | var align;
|
4195 | var baseLine;
|
4196 |
|
4197 | if (offsetVector[0] > 0) {
|
4198 | align = 'left';
|
4199 | } else if (offsetVector[0] < 0) {
|
4200 | align = 'right';
|
4201 | } else {
|
4202 | align = 'center';
|
4203 | }
|
4204 |
|
4205 | if (offsetVector[1] > 0) {
|
4206 | baseLine = 'top';
|
4207 | } else if (offsetVector[1] < 0) {
|
4208 | baseLine = 'bottom';
|
4209 | } else {
|
4210 | baseLine = 'middle';
|
4211 | }
|
4212 |
|
4213 | return {
|
4214 | textAlign: align,
|
4215 | textBaseline: baseLine
|
4216 | };
|
4217 | };
|
4218 |
|
4219 | _proto.getContainer = function getContainer(isTop) {
|
4220 | var frontContainer = this.frontContainer,
|
4221 | backContainer = this.backContainer;
|
4222 | return isTop ? frontContainer : backContainer;
|
4223 | };
|
4224 |
|
4225 | return Abastract;
|
4226 | }();
|
4227 |
|
4228 | module.exports = Abastract;
|
4229 |
|
4230 | }),
|
4231 |
|
4232 | (function(module, exports, __webpack_require__) {
|
4233 |
|
4234 | var Util = __webpack_require__(0);
|
4235 |
|
4236 | var MatrixUtil = __webpack_require__(27);
|
4237 |
|
4238 | var Vector2 = __webpack_require__(7);
|
4239 |
|
4240 | var StyleUtil = __webpack_require__(79);
|
4241 |
|
4242 | function isUnchanged(m) {
|
4243 | return m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1 && m[4] === 0 && m[5] === 0;
|
4244 | }
|
4245 |
|
4246 | var ALIAS_ATTRS_MAP = {
|
4247 | stroke: 'strokeStyle',
|
4248 | fill: 'fillStyle',
|
4249 | opacity: 'globalAlpha'
|
4250 | };
|
4251 | var SHAPE_ATTRS = ['fillStyle', 'font', 'globalAlpha', 'lineCap', 'lineWidth', 'lineJoin', 'miterLimit', 'shadowBlur', 'shadowColor', 'shadowOffsetX', 'shadowOffsetY', 'strokeStyle', 'textAlign', 'textBaseline', 'lineDash'];
|
4252 | var CLIP_SHAPES = ['circle', 'sector', 'polygon', 'rect', 'polyline'];
|
4253 |
|
4254 | var Element =
|
4255 |
|
4256 | function () {
|
4257 | var _proto = Element.prototype;
|
4258 |
|
4259 | _proto._initProperties = function _initProperties() {
|
4260 | this._attrs = {
|
4261 | zIndex: 0,
|
4262 | visible: true,
|
4263 | destroyed: false
|
4264 | };
|
4265 | };
|
4266 |
|
4267 | function Element(cfg) {
|
4268 | this._initProperties();
|
4269 |
|
4270 | Util.mix(this._attrs, cfg);
|
4271 | var attrs = this._attrs.attrs;
|
4272 |
|
4273 | if (attrs) {
|
4274 | this.initAttrs(attrs);
|
4275 | }
|
4276 |
|
4277 | this.initTransform();
|
4278 | }
|
4279 |
|
4280 | _proto.get = function get(name) {
|
4281 | return this._attrs[name];
|
4282 | };
|
4283 |
|
4284 | _proto.set = function set(name, value) {
|
4285 | this._attrs[name] = value;
|
4286 | };
|
4287 |
|
4288 | _proto.isGroup = function isGroup() {
|
4289 | return this.get('isGroup');
|
4290 | };
|
4291 |
|
4292 | _proto.isShape = function isShape() {
|
4293 | return this.get('isShape');
|
4294 | };
|
4295 |
|
4296 | _proto.initAttrs = function initAttrs(attrs) {
|
4297 | this.attr(Util.mix(this.getDefaultAttrs(), attrs));
|
4298 | };
|
4299 |
|
4300 | _proto.getDefaultAttrs = function getDefaultAttrs() {
|
4301 | return {};
|
4302 | };
|
4303 |
|
4304 | _proto._setAttr = function _setAttr(name, value) {
|
4305 | var attrs = this._attrs.attrs;
|
4306 |
|
4307 | if (name === 'clip') {
|
4308 | value = this._setAttrClip(value);
|
4309 | } else {
|
4310 | var alias = ALIAS_ATTRS_MAP[name];
|
4311 |
|
4312 | if (alias) {
|
4313 | attrs[alias] = value;
|
4314 | }
|
4315 | }
|
4316 |
|
4317 | attrs[name] = value;
|
4318 | };
|
4319 |
|
4320 | _proto._getAttr = function _getAttr(name) {
|
4321 | return this._attrs.attrs[name];
|
4322 | };
|
4323 |
|
4324 |
|
4325 | _proto._setAttrClip = function _setAttrClip(clip) {
|
4326 | if (clip && CLIP_SHAPES.indexOf(clip._attrs.type) > -1) {
|
4327 | if (clip.get('canvas') === null) {
|
4328 | clip = Object.assign({}, clip);
|
4329 | }
|
4330 |
|
4331 | clip.set('parent', this.get('parent'));
|
4332 | clip.set('context', this.get('context'));
|
4333 | return clip;
|
4334 | }
|
4335 |
|
4336 | return null;
|
4337 | };
|
4338 |
|
4339 | _proto.attr = function attr(name, value) {
|
4340 | var self = this;
|
4341 | if (self.get('destroyed')) return null;
|
4342 | var argumentsLen = arguments.length;
|
4343 |
|
4344 | if (argumentsLen === 0) {
|
4345 | return self._attrs.attrs;
|
4346 | }
|
4347 |
|
4348 | if (Util.isObject(name)) {
|
4349 | this._attrs.bbox = null;
|
4350 |
|
4351 | for (var k in name) {
|
4352 | self._setAttr(k, name[k]);
|
4353 | }
|
4354 |
|
4355 | if (self._afterAttrsSet) {
|
4356 | self._afterAttrsSet();
|
4357 | }
|
4358 |
|
4359 | return self;
|
4360 | }
|
4361 |
|
4362 | if (argumentsLen === 2) {
|
4363 | this._attrs.bbox = null;
|
4364 |
|
4365 | self._setAttr(name, value);
|
4366 |
|
4367 | if (self._afterAttrsSet) {
|
4368 | self._afterAttrsSet();
|
4369 | }
|
4370 |
|
4371 | return self;
|
4372 | }
|
4373 |
|
4374 | return self._getAttr(name);
|
4375 | };
|
4376 |
|
4377 | _proto.getParent = function getParent() {
|
4378 | return this.get('parent');
|
4379 | };
|
4380 |
|
4381 | _proto.draw = function draw(context) {
|
4382 | if (this.get('destroyed')) {
|
4383 | return;
|
4384 | }
|
4385 |
|
4386 | if (this.get('visible')) {
|
4387 | this.setContext(context);
|
4388 | this.drawInner(context);
|
4389 | this.restoreContext(context);
|
4390 | }
|
4391 | };
|
4392 |
|
4393 | _proto.setContext = function setContext(context) {
|
4394 | var clip = this._attrs.attrs.clip;
|
4395 | context.save();
|
4396 |
|
4397 | if (clip) {
|
4398 | clip.resetTransform(context);
|
4399 | clip.createPath(context);
|
4400 | context.clip();
|
4401 | }
|
4402 |
|
4403 | this.resetContext(context);
|
4404 | this.resetTransform(context);
|
4405 | };
|
4406 |
|
4407 | _proto.restoreContext = function restoreContext(context) {
|
4408 | context.restore();
|
4409 | };
|
4410 |
|
4411 | _proto.resetContext = function resetContext(context) {
|
4412 | var elAttrs = this._attrs.attrs;
|
4413 |
|
4414 | if (!this._attrs.isGroup) {
|
4415 | for (var k in elAttrs) {
|
4416 | if (SHAPE_ATTRS.indexOf(k) > -1) {
|
4417 | var v = elAttrs[k];
|
4418 |
|
4419 | if (k === 'fillStyle' || k === 'strokeStyle') {
|
4420 | v = StyleUtil.parseStyle(v, this, context);
|
4421 | }
|
4422 |
|
4423 | if (k === 'lineDash' && context.setLineDash && Util.isArray(v)) {
|
4424 | context.setLineDash(v);
|
4425 | } else {
|
4426 | context[k] = v;
|
4427 | }
|
4428 | }
|
4429 | }
|
4430 | }
|
4431 | };
|
4432 |
|
4433 | _proto.hasFill = function hasFill() {
|
4434 | return this.get('canFill') && this._attrs.attrs.fillStyle;
|
4435 | };
|
4436 |
|
4437 | _proto.hasStroke = function hasStroke() {
|
4438 | return this.get('canStroke') && this._attrs.attrs.strokeStyle;
|
4439 | };
|
4440 |
|
4441 | _proto.drawInner = function drawInner()
|
4442 | /* context */
|
4443 | {};
|
4444 |
|
4445 | _proto.show = function show() {
|
4446 | this.set('visible', true);
|
4447 | return this;
|
4448 | };
|
4449 |
|
4450 | _proto.hide = function hide() {
|
4451 | this.set('visible', false);
|
4452 | return this;
|
4453 | };
|
4454 |
|
4455 | _proto.isVisible = function isVisible() {
|
4456 | return this.get('visible');
|
4457 | };
|
4458 |
|
4459 | _proto._removeFromParent = function _removeFromParent() {
|
4460 | var parent = this.get('parent');
|
4461 |
|
4462 | if (parent) {
|
4463 | var children = parent.get('children');
|
4464 | Util.Array.remove(children, this);
|
4465 | }
|
4466 |
|
4467 | return this;
|
4468 | };
|
4469 |
|
4470 | _proto.remove = function remove(destroy) {
|
4471 | if (destroy) {
|
4472 | this.destroy();
|
4473 | } else {
|
4474 | this._removeFromParent();
|
4475 | }
|
4476 | };
|
4477 |
|
4478 | _proto.destroy = function destroy() {
|
4479 | var destroyed = this.get('destroyed');
|
4480 |
|
4481 | if (destroyed) {
|
4482 | return null;
|
4483 | }
|
4484 |
|
4485 | this._removeFromParent();
|
4486 |
|
4487 | this._attrs = {};
|
4488 | this.set('destroyed', true);
|
4489 | };
|
4490 |
|
4491 | _proto.getBBox = function getBBox() {
|
4492 | return {
|
4493 | minX: 0,
|
4494 | maxX: 0,
|
4495 | minY: 0,
|
4496 | maxY: 0,
|
4497 | width: 0,
|
4498 | height: 0
|
4499 | };
|
4500 | };
|
4501 |
|
4502 | _proto.initTransform = function initTransform() {
|
4503 | var attrs = this._attrs.attrs || {};
|
4504 |
|
4505 | if (!attrs.matrix) {
|
4506 | attrs.matrix = [1, 0, 0, 1, 0, 0];
|
4507 | }
|
4508 |
|
4509 | this._attrs.attrs = attrs;
|
4510 | };
|
4511 |
|
4512 | _proto.getMatrix = function getMatrix() {
|
4513 | return this._attrs.attrs.matrix;
|
4514 | };
|
4515 |
|
4516 | _proto.setMatrix = function setMatrix(m) {
|
4517 | this._attrs.attrs.matrix = [m[0], m[1], m[2], m[3], m[4], m[5]];
|
4518 | };
|
4519 |
|
4520 | _proto.transform = function transform(actions) {
|
4521 | var matrix = this._attrs.attrs.matrix;
|
4522 | this._attrs.attrs.matrix = MatrixUtil.transform(matrix, actions);
|
4523 | return this;
|
4524 | };
|
4525 |
|
4526 | _proto.setTransform = function setTransform(actions) {
|
4527 | this._attrs.attrs.matrix = [1, 0, 0, 1, 0, 0];
|
4528 | return this.transform(actions);
|
4529 | };
|
4530 |
|
4531 | _proto.translate = function translate(x, y) {
|
4532 | var matrix = this._attrs.attrs.matrix;
|
4533 | MatrixUtil.translate(matrix, matrix, [x, y]);
|
4534 | };
|
4535 |
|
4536 | _proto.rotate = function rotate(rad) {
|
4537 | var matrix = this._attrs.attrs.matrix;
|
4538 | MatrixUtil.rotate(matrix, matrix, rad);
|
4539 | };
|
4540 |
|
4541 | _proto.scale = function scale(sx, sy) {
|
4542 | var matrix = this._attrs.attrs.matrix;
|
4543 | MatrixUtil.scale(matrix, matrix, [sx, sy]);
|
4544 | };
|
4545 |
|
4546 | _proto.moveTo = function moveTo(x, y) {
|
4547 | var cx = this._attrs.x || 0;
|
4548 | var cy = this._attrs.y || 0;
|
4549 | this.translate(x - cx, y - cy);
|
4550 | this.set('x', x);
|
4551 | this.set('y', y);
|
4552 | };
|
4553 |
|
4554 | _proto.apply = function apply(v) {
|
4555 | var m = this._attrs.attrs.matrix;
|
4556 | Vector2.transformMat2d(v, v, m);
|
4557 | return this;
|
4558 | };
|
4559 |
|
4560 | _proto.resetTransform = function resetTransform(context) {
|
4561 | var mo = this._attrs.attrs.matrix;
|
4562 |
|
4563 | if (!isUnchanged(mo)) {
|
4564 | context.transform(mo[0], mo[1], mo[2], mo[3], mo[4], mo[5]);
|
4565 | }
|
4566 | };
|
4567 |
|
4568 | _proto.isDestroyed = function isDestroyed() {
|
4569 | return this.get('destroyed');
|
4570 | };
|
4571 |
|
4572 | return Element;
|
4573 | }();
|
4574 |
|
4575 | module.exports = Element;
|
4576 |
|
4577 | }),
|
4578 |
|
4579 | (function(module, exports) {
|
4580 |
|
4581 | var Matrix = {
|
4582 | multiply: function multiply(m1, m2) {
|
4583 | var m11 = m1[0] * m2[0] + m1[2] * m2[1];
|
4584 | var m12 = m1[1] * m2[0] + m1[3] * m2[1];
|
4585 | var m21 = m1[0] * m2[2] + m1[2] * m2[3];
|
4586 | var m22 = m1[1] * m2[2] + m1[3] * m2[3];
|
4587 | var dx = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
|
4588 | var dy = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
|
4589 | return [m11, m12, m21, m22, dx, dy];
|
4590 | },
|
4591 | scale: function scale(out, m, v) {
|
4592 | out[0] = m[0] * v[0];
|
4593 | out[1] = m[1] * v[0];
|
4594 | out[2] = m[2] * v[1];
|
4595 | out[3] = m[3] * v[1];
|
4596 | out[4] = m[4];
|
4597 | out[5] = m[5];
|
4598 | return out;
|
4599 | },
|
4600 | rotate: function rotate(out, m, radian) {
|
4601 | var c = Math.cos(radian);
|
4602 | var s = Math.sin(radian);
|
4603 | var m11 = m[0] * c + m[2] * s;
|
4604 | var m12 = m[1] * c + m[3] * s;
|
4605 | var m21 = m[0] * -s + m[2] * c;
|
4606 | var m22 = m[1] * -s + m[3] * c;
|
4607 | out[0] = m11;
|
4608 | out[1] = m12;
|
4609 | out[2] = m21;
|
4610 | out[3] = m22;
|
4611 | out[4] = m[4];
|
4612 | out[5] = m[5];
|
4613 | return out;
|
4614 | },
|
4615 | translate: function translate(out, m, v) {
|
4616 | out[0] = m[0];
|
4617 | out[1] = m[1];
|
4618 | out[2] = m[2];
|
4619 | out[3] = m[3];
|
4620 | out[4] = m[4] + m[0] * v[0] + m[2] * v[1];
|
4621 | out[5] = m[5] + m[1] * v[0] + m[3] * v[1];
|
4622 | return out;
|
4623 | },
|
4624 | transform: function transform(m, actions) {
|
4625 | var out = [].concat(m);
|
4626 |
|
4627 | for (var i = 0, len = actions.length; i < len; i++) {
|
4628 | var action = actions[i];
|
4629 |
|
4630 | switch (action[0]) {
|
4631 | case 't':
|
4632 | Matrix.translate(out, out, [action[1], action[2]]);
|
4633 | break;
|
4634 |
|
4635 | case 's':
|
4636 | Matrix.scale(out, out, [action[1], action[2]]);
|
4637 | break;
|
4638 |
|
4639 | case 'r':
|
4640 | Matrix.rotate(out, out, action[1]);
|
4641 | break;
|
4642 |
|
4643 | default:
|
4644 | break;
|
4645 | }
|
4646 | }
|
4647 |
|
4648 | return out;
|
4649 | }
|
4650 | };
|
4651 | module.exports = Matrix;
|
4652 |
|
4653 | }),
|
4654 |
|
4655 | (function(module, exports, __webpack_require__) {
|
4656 |
|
4657 |
|
4658 |
|
4659 |
|
4660 |
|
4661 | var isString = __webpack_require__(14);
|
4662 |
|
4663 | var isDate = __webpack_require__(31);
|
4664 |
|
4665 | module.exports = {
|
4666 | toTimeStamp: function toTimeStamp(value) {
|
4667 | if (isString(value)) {
|
4668 | if (value.indexOf('T') > 0) {
|
4669 | value = new Date(value).getTime();
|
4670 | } else {
|
4671 | value = new Date(value.replace(/-/ig, '/')).getTime();
|
4672 | }
|
4673 | }
|
4674 |
|
4675 | if (isDate(value)) {
|
4676 | value = value.getTime();
|
4677 | }
|
4678 |
|
4679 | return value;
|
4680 | }
|
4681 | };
|
4682 |
|
4683 | }),
|
4684 |
|
4685 | (function(module, exports, __webpack_require__) {
|
4686 |
|
4687 | var TimeUtil = __webpack_require__(28);
|
4688 |
|
4689 | var Util = __webpack_require__(0);
|
4690 |
|
4691 | module.exports = {
|
4692 | getColDef: function getColDef(chart, field) {
|
4693 | var colDef;
|
4694 |
|
4695 | if (chart.get('colDefs') && chart.get('colDefs')[field]) {
|
4696 | colDef = chart.get('colDefs')[field];
|
4697 | }
|
4698 |
|
4699 | return colDef;
|
4700 | },
|
4701 | getFieldRange: function getFieldRange(scale, limitRange, type) {
|
4702 | if (!scale) return [0, 1];
|
4703 | var minRatio = 0;
|
4704 | var maxRatio = 0;
|
4705 |
|
4706 | if (type === 'linear') {
|
4707 | var min = limitRange.min,
|
4708 | max = limitRange.max;
|
4709 | minRatio = (scale.min - min) / (max - min);
|
4710 | maxRatio = (scale.max - min) / (max - min);
|
4711 | } else {
|
4712 | var originValues = limitRange;
|
4713 | var values = scale.values;
|
4714 | var firstIndex = originValues.indexOf(values[0]);
|
4715 | var lastIndex = originValues.indexOf(values[values.length - 1]);
|
4716 | minRatio = firstIndex / (originValues.length - 1);
|
4717 | maxRatio = lastIndex / (originValues.length - 1);
|
4718 | }
|
4719 |
|
4720 | return [minRatio, maxRatio];
|
4721 | },
|
4722 | getLimitRange: function getLimitRange(data, scale) {
|
4723 | var result;
|
4724 | var field = scale.field,
|
4725 | type = scale.type;
|
4726 | var values = Util.Array.values(data, field);
|
4727 |
|
4728 | if (type === 'linear') {
|
4729 | result = Util.Array.getRange(values);
|
4730 |
|
4731 | if (scale.min < result.min) {
|
4732 | result.min = scale.min;
|
4733 | }
|
4734 |
|
4735 | if (scale.max > result.max) {
|
4736 | result.max = scale.max;
|
4737 | }
|
4738 | } else if (type === 'timeCat') {
|
4739 | Util.each(values, function (v, i) {
|
4740 | values[i] = TimeUtil.toTimeStamp(v);
|
4741 | });
|
4742 | values.sort(function (v1, v2) {
|
4743 | return v1 - v2;
|
4744 | });
|
4745 | result = values;
|
4746 | } else {
|
4747 | result = values;
|
4748 | }
|
4749 |
|
4750 | return result;
|
4751 | }
|
4752 | };
|
4753 |
|
4754 | }),
|
4755 |
|
4756 | (function(module, exports, __webpack_require__) {
|
4757 |
|
4758 | var isNil = __webpack_require__(9);
|
4759 |
|
4760 | function toString(value) {
|
4761 | if (isNil(value)) return '';
|
4762 | return value.toString();
|
4763 | }
|
4764 |
|
4765 | module.exports = toString;
|
4766 |
|
4767 | }),
|
4768 |
|
4769 | (function(module, exports, __webpack_require__) {
|
4770 |
|
4771 | var isType = __webpack_require__(10);
|
4772 |
|
4773 | var isDate = function isDate(value) {
|
4774 | return isType(value, 'Date');
|
4775 | };
|
4776 |
|
4777 | module.exports = isDate;
|
4778 |
|
4779 | }),
|
4780 |
|
4781 | (function(module, exports, __webpack_require__) {
|
4782 |
|
4783 | var isObjectLike = __webpack_require__(58);
|
4784 |
|
4785 | var isType = __webpack_require__(10);
|
4786 |
|
4787 | var isPlainObject = function isPlainObject(value) {
|
4788 | |
4789 |
|
4790 |
|
4791 |
|
4792 |
|
4793 |
|
4794 | if (!isObjectLike(value) || !isType(value, 'Object')) {
|
4795 | return false;
|
4796 | }
|
4797 |
|
4798 | if (Object.getPrototypeOf(value) === null) {
|
4799 | return true;
|
4800 | }
|
4801 |
|
4802 | var proto = value;
|
4803 |
|
4804 | while (Object.getPrototypeOf(proto) !== null) {
|
4805 | proto = Object.getPrototypeOf(proto);
|
4806 | }
|
4807 |
|
4808 | return Object.getPrototypeOf(value) === proto;
|
4809 | };
|
4810 |
|
4811 | module.exports = isPlainObject;
|
4812 |
|
4813 | }),
|
4814 |
|
4815 | (function(module, exports, __webpack_require__) {
|
4816 |
|
4817 |
|
4818 |
|
4819 |
|
4820 |
|
4821 | var Util = __webpack_require__(0);
|
4822 |
|
4823 | var Base =
|
4824 |
|
4825 | function () {
|
4826 | var _proto = Base.prototype;
|
4827 |
|
4828 | _proto.getDefaultCfg = function getDefaultCfg() {
|
4829 | return {};
|
4830 | };
|
4831 |
|
4832 | function Base(cfg) {
|
4833 | var attrs = {};
|
4834 | var defaultCfg = this.getDefaultCfg();
|
4835 | this._attrs = attrs;
|
4836 | Util.mix(attrs, defaultCfg, cfg);
|
4837 | }
|
4838 |
|
4839 | _proto.get = function get(name) {
|
4840 | return this._attrs[name];
|
4841 | };
|
4842 |
|
4843 | _proto.set = function set(name, value) {
|
4844 | this._attrs[name] = value;
|
4845 | };
|
4846 |
|
4847 | _proto.destroy = function destroy() {
|
4848 | this._attrs = {};
|
4849 | this.destroyed = true;
|
4850 | };
|
4851 |
|
4852 | return Base;
|
4853 | }();
|
4854 |
|
4855 | module.exports = Base;
|
4856 |
|
4857 | }),
|
4858 |
|
4859 | (function(module, exports, __webpack_require__) {
|
4860 |
|
4861 | function _inheritsLoose(subClass, superClass) {
|
4862 | subClass.prototype = Object.create(superClass.prototype);
|
4863 | subClass.prototype.constructor = subClass;
|
4864 | subClass.__proto__ = superClass;
|
4865 | }
|
4866 |
|
4867 | var Base = __webpack_require__(16);
|
4868 |
|
4869 | var catAuto = __webpack_require__(35);
|
4870 |
|
4871 | var each = __webpack_require__(4);
|
4872 |
|
4873 | var isNumber = __webpack_require__(15);
|
4874 |
|
4875 | var isString = __webpack_require__(14);
|
4876 |
|
4877 | var Category =
|
4878 |
|
4879 | function (_Base) {
|
4880 | _inheritsLoose(Category, _Base);
|
4881 |
|
4882 | function Category() {
|
4883 | return _Base.apply(this, arguments) || this;
|
4884 | }
|
4885 |
|
4886 | var _proto = Category.prototype;
|
4887 |
|
4888 | _proto._initDefaultCfg = function _initDefaultCfg() {
|
4889 | _Base.prototype._initDefaultCfg.call(this);
|
4890 |
|
4891 | this.type = 'cat';
|
4892 | |
4893 |
|
4894 |
|
4895 |
|
4896 |
|
4897 | this.isCategory = true;
|
4898 | this.isRounding = true;
|
4899 | };
|
4900 | |
4901 |
|
4902 |
|
4903 |
|
4904 |
|
4905 | _proto.init = function init() {
|
4906 | var self = this;
|
4907 | var values = self.values;
|
4908 | var tickCount = self.tickCount;
|
4909 | each(values, function (v, i) {
|
4910 | values[i] = v.toString();
|
4911 | });
|
4912 |
|
4913 | if (!self.ticks) {
|
4914 | var ticks = values;
|
4915 |
|
4916 | if (tickCount) {
|
4917 | var temp = catAuto({
|
4918 | maxCount: tickCount,
|
4919 | data: values,
|
4920 | isRounding: self.isRounding
|
4921 | });
|
4922 | ticks = temp.ticks;
|
4923 | }
|
4924 |
|
4925 | this.ticks = ticks;
|
4926 | }
|
4927 | };
|
4928 | |
4929 |
|
4930 |
|
4931 |
|
4932 |
|
4933 | _proto.getText = function getText(value) {
|
4934 | if (this.values.indexOf(value) === -1 && isNumber(value)) {
|
4935 | value = this.values[Math.round(value)];
|
4936 | }
|
4937 |
|
4938 | return _Base.prototype.getText.call(this, value);
|
4939 | };
|
4940 | |
4941 |
|
4942 |
|
4943 |
|
4944 |
|
4945 | _proto.translate = function translate(value) {
|
4946 | var index = this.values.indexOf(value);
|
4947 |
|
4948 | if (index === -1 && isNumber(value)) {
|
4949 | index = value;
|
4950 | } else if (index === -1) {
|
4951 | index = NaN;
|
4952 | }
|
4953 |
|
4954 | return index;
|
4955 | };
|
4956 | |
4957 |
|
4958 |
|
4959 |
|
4960 |
|
4961 | _proto.scale = function scale(value) {
|
4962 | var rangeMin = this.rangeMin();
|
4963 | var rangeMax = this.rangeMax();
|
4964 | var percent;
|
4965 |
|
4966 | if (isString(value) || this.values.indexOf(value) !== -1) {
|
4967 | value = this.translate(value);
|
4968 | }
|
4969 |
|
4970 | if (this.values.length > 1) {
|
4971 | percent = value / (this.values.length - 1);
|
4972 | } else {
|
4973 | percent = value;
|
4974 | }
|
4975 |
|
4976 | return rangeMin + percent * (rangeMax - rangeMin);
|
4977 | };
|
4978 | |
4979 |
|
4980 |
|
4981 |
|
4982 |
|
4983 | _proto.invert = function invert(value) {
|
4984 | if (isString(value)) {
|
4985 |
|
4986 | return value;
|
4987 | }
|
4988 |
|
4989 | var min = this.rangeMin();
|
4990 | var max = this.rangeMax();
|
4991 |
|
4992 | if (value < min) {
|
4993 | value = min;
|
4994 | }
|
4995 |
|
4996 | if (value > max) {
|
4997 | value = max;
|
4998 | }
|
4999 |
|
5000 | var percent = (value - min) / (max - min);
|
5001 | var index = Math.round(percent * (this.values.length - 1)) % this.values.length;
|
5002 | index = index || 0;
|
5003 | return this.values[index];
|
5004 | };
|
5005 |
|
5006 | return Category;
|
5007 | }(Base);
|
5008 |
|
5009 | Base.Cat = Category;
|
5010 | module.exports = Category;
|
5011 |
|
5012 | }),
|
5013 |
|
5014 | (function(module, exports, __webpack_require__) {
|
5015 |
|
5016 |
|
5017 |
|
5018 |
|
5019 |
|
5020 | var each = __webpack_require__(4);
|
5021 |
|
5022 | var MAX_COUNT = 8;
|
5023 | var SUB_COUNT = 4;
|
5024 |
|
5025 | function getSimpleArray(data) {
|
5026 | var arr = [];
|
5027 | each(data, function (sub) {
|
5028 | arr = arr.concat(sub);
|
5029 | });
|
5030 | return arr;
|
5031 | }
|
5032 |
|
5033 | function getGreatestFactor(count, number) {
|
5034 | var i;
|
5035 |
|
5036 | for (i = number; i > 0; i--) {
|
5037 | if (count % i === 0) {
|
5038 | break;
|
5039 | }
|
5040 | }
|
5041 |
|
5042 |
|
5043 | if (i === 1) {
|
5044 | for (i = number; i > 0; i--) {
|
5045 | if ((count - 1) % i === 0) {
|
5046 | break;
|
5047 | }
|
5048 | }
|
5049 | }
|
5050 |
|
5051 | return i;
|
5052 | }
|
5053 |
|
5054 | module.exports = function (info) {
|
5055 | var rst = {};
|
5056 | var ticks = [];
|
5057 | var isRounding = info.isRounding;
|
5058 | var categories = getSimpleArray(info.data);
|
5059 | var length = categories.length;
|
5060 | var maxCount = info.maxCount || MAX_COUNT;
|
5061 | var tickCount;
|
5062 |
|
5063 | if (isRounding) {
|
5064 |
|
5065 | tickCount = getGreatestFactor(length - 1, maxCount - 1) + 1;
|
5066 |
|
5067 | if (tickCount === 2) {
|
5068 | tickCount = maxCount;
|
5069 | } else if (tickCount < maxCount - SUB_COUNT) {
|
5070 | tickCount = maxCount - SUB_COUNT;
|
5071 | }
|
5072 | } else {
|
5073 | tickCount = maxCount;
|
5074 | }
|
5075 |
|
5076 | if (!isRounding && length <= tickCount + tickCount / 2) {
|
5077 | ticks = [].concat(categories);
|
5078 | } else {
|
5079 | var step = parseInt(length / (tickCount - 1), 10);
|
5080 | var groups = categories.map(function (e, i) {
|
5081 | return i % step === 0 ? categories.slice(i, i + step) : null;
|
5082 | }).filter(function (e) {
|
5083 | return e;
|
5084 | });
|
5085 |
|
5086 | for (var i = 1, groupLen = groups.length; i < groupLen && (isRounding ? i * step < length - step : i < tickCount - 1); i++) {
|
5087 | ticks.push(groups[i][0]);
|
5088 | }
|
5089 |
|
5090 | if (categories.length) {
|
5091 | ticks.unshift(categories[0]);
|
5092 | var last = categories[length - 1];
|
5093 |
|
5094 | if (ticks.indexOf(last) === -1) {
|
5095 | ticks.push(last);
|
5096 | }
|
5097 | }
|
5098 | }
|
5099 |
|
5100 | rst.categories = categories;
|
5101 | rst.ticks = ticks;
|
5102 | return rst;
|
5103 | };
|
5104 |
|
5105 | }),
|
5106 |
|
5107 | (function(module, exports, __webpack_require__) {
|
5108 |
|
5109 | var Util = __webpack_require__(0);
|
5110 |
|
5111 | var Shape = __webpack_require__(2);
|
5112 |
|
5113 | var SHAPE_MAP = {};
|
5114 | var INDEX = '_INDEX';
|
5115 |
|
5116 | function getComparer(compare) {
|
5117 | return function (left, right) {
|
5118 | var result = compare(left, right);
|
5119 | return result === 0 ? left[INDEX] - right[INDEX] : result;
|
5120 | };
|
5121 | }
|
5122 |
|
5123 | module.exports = {
|
5124 | getGroupClass: function getGroupClass() {},
|
5125 | getChildren: function getChildren() {
|
5126 | return this.get('children');
|
5127 | },
|
5128 | addShape: function addShape(type, cfg) {
|
5129 | if (cfg === void 0) {
|
5130 | cfg = {};
|
5131 | }
|
5132 |
|
5133 | var canvas = this.get('canvas');
|
5134 | var shapeType = SHAPE_MAP[type];
|
5135 |
|
5136 | if (!shapeType) {
|
5137 | shapeType = Util.upperFirst(type);
|
5138 | SHAPE_MAP[type] = shapeType;
|
5139 | }
|
5140 |
|
5141 | cfg.canvas = canvas;
|
5142 |
|
5143 | if (shapeType === 'Text' && canvas && canvas.get('fontFamily')) {
|
5144 | cfg.attrs.fontFamily = cfg.attrs.fontFamily || canvas.get('fontFamily');
|
5145 | }
|
5146 |
|
5147 | var shape = new Shape[shapeType](cfg);
|
5148 | this.add(shape);
|
5149 | return shape;
|
5150 | },
|
5151 | addGroup: function addGroup(cfg) {
|
5152 | var canvas = this.get('canvas');
|
5153 | var groupClass = this.getGroupClass();
|
5154 | cfg = Util.mix({}, cfg);
|
5155 | cfg.canvas = canvas;
|
5156 | cfg.parent = this;
|
5157 | var rst = new groupClass(cfg);
|
5158 | this.add(rst);
|
5159 | return rst;
|
5160 | },
|
5161 | contain: function contain(item) {
|
5162 | var children = this.get('children');
|
5163 | return children.indexOf(item) > -1;
|
5164 | },
|
5165 | sort: function sort() {
|
5166 | var children = this.get('children');
|
5167 |
|
5168 | for (var i = 0, len = children.length; i < len; i++) {
|
5169 | var child = children[i];
|
5170 | child[INDEX] = i;
|
5171 | }
|
5172 |
|
5173 | children.sort(getComparer(function (obj1, obj2) {
|
5174 | return obj1.get('zIndex') - obj2.get('zIndex');
|
5175 | }));
|
5176 | return this;
|
5177 | },
|
5178 | clear: function clear() {
|
5179 | var children = this.get('children');
|
5180 |
|
5181 | while (children.length !== 0) {
|
5182 | children[children.length - 1].remove(true);
|
5183 | }
|
5184 |
|
5185 | return this;
|
5186 | },
|
5187 | add: function add(items) {
|
5188 | var self = this;
|
5189 | var children = self.get('children');
|
5190 |
|
5191 | if (!Util.isArray(items)) {
|
5192 | items = [items];
|
5193 | }
|
5194 |
|
5195 | for (var i = 0, len = items.length; i < len; i++) {
|
5196 | var item = items[i];
|
5197 | var parent = item.get('parent');
|
5198 |
|
5199 | if (parent) {
|
5200 | var descendants = parent.get('children');
|
5201 | Util.Array.remove(descendants, item);
|
5202 | }
|
5203 |
|
5204 | self._setEvn(item);
|
5205 |
|
5206 | children.push(item);
|
5207 | }
|
5208 |
|
5209 | return self;
|
5210 | },
|
5211 | _setEvn: function _setEvn(item) {
|
5212 | var self = this;
|
5213 | item._attrs.parent = self;
|
5214 | item._attrs.context = self._attrs.context;
|
5215 | item._attrs.canvas = self._attrs.canvas;
|
5216 | var clip = item._attrs.attrs.clip;
|
5217 |
|
5218 | if (clip) {
|
5219 | clip.set('parent', self);
|
5220 | clip.set('context', self.get('context'));
|
5221 | }
|
5222 |
|
5223 | if (item._attrs.isGroup) {
|
5224 | var children = item._attrs.children;
|
5225 |
|
5226 | for (var i = 0, len = children.length; i < len; i++) {
|
5227 | item._setEvn(children[i]);
|
5228 | }
|
5229 | }
|
5230 | }
|
5231 | };
|
5232 |
|
5233 | }),
|
5234 |
|
5235 | (function(module, exports, __webpack_require__) {
|
5236 |
|
5237 | function _inheritsLoose(subClass, superClass) {
|
5238 | subClass.prototype = Object.create(superClass.prototype);
|
5239 | subClass.prototype.constructor = subClass;
|
5240 | subClass.__proto__ = superClass;
|
5241 | }
|
5242 |
|
5243 | var Util = __webpack_require__(0);
|
5244 |
|
5245 | var Element = __webpack_require__(26);
|
5246 |
|
5247 | var Container = __webpack_require__(36);
|
5248 |
|
5249 | var Vector2 = __webpack_require__(7);
|
5250 |
|
5251 | var Group =
|
5252 |
|
5253 | function (_Element) {
|
5254 | _inheritsLoose(Group, _Element);
|
5255 |
|
5256 | function Group() {
|
5257 | return _Element.apply(this, arguments) || this;
|
5258 | }
|
5259 |
|
5260 | var _proto = Group.prototype;
|
5261 |
|
5262 | _proto._initProperties = function _initProperties() {
|
5263 | this._attrs = {
|
5264 | zIndex: 0,
|
5265 | visible: true,
|
5266 | destroyed: false,
|
5267 | isGroup: true,
|
5268 | children: []
|
5269 | };
|
5270 | };
|
5271 |
|
5272 | _proto.drawInner = function drawInner(context) {
|
5273 | var children = this.get('children');
|
5274 |
|
5275 | for (var i = 0, len = children.length; i < len; i++) {
|
5276 | var child = children[i];
|
5277 | child.draw(context);
|
5278 | }
|
5279 |
|
5280 | return this;
|
5281 | };
|
5282 |
|
5283 | _proto.getBBox = function getBBox() {
|
5284 | var self = this;
|
5285 | var minX = Infinity;
|
5286 | var maxX = -Infinity;
|
5287 | var minY = Infinity;
|
5288 | var maxY = -Infinity;
|
5289 | var children = self.get('children');
|
5290 |
|
5291 | for (var i = 0, length = children.length; i < length; i++) {
|
5292 | var child = children[i];
|
5293 |
|
5294 | if (child.get('visible')) {
|
5295 | var box = child.getBBox();
|
5296 |
|
5297 | if (!box) {
|
5298 | continue;
|
5299 | }
|
5300 |
|
5301 | var leftTop = [box.minX, box.minY];
|
5302 | var leftBottom = [box.minX, box.maxY];
|
5303 | var rightTop = [box.maxX, box.minY];
|
5304 | var rightBottom = [box.maxX, box.maxY];
|
5305 | var matrix = child.attr('matrix');
|
5306 | Vector2.transformMat2d(leftTop, leftTop, matrix);
|
5307 | Vector2.transformMat2d(leftBottom, leftBottom, matrix);
|
5308 | Vector2.transformMat2d(rightTop, rightTop, matrix);
|
5309 | Vector2.transformMat2d(rightBottom, rightBottom, matrix);
|
5310 | minX = Math.min(leftTop[0], leftBottom[0], rightTop[0], rightBottom[0], minX);
|
5311 | maxX = Math.max(leftTop[0], leftBottom[0], rightTop[0], rightBottom[0], maxX);
|
5312 | minY = Math.min(leftTop[1], leftBottom[1], rightTop[1], rightBottom[1], minY);
|
5313 | maxY = Math.max(leftTop[1], leftBottom[1], rightTop[1], rightBottom[1], maxY);
|
5314 | }
|
5315 | }
|
5316 |
|
5317 | return {
|
5318 | minX: minX,
|
5319 | minY: minY,
|
5320 | maxX: maxX,
|
5321 | maxY: maxY,
|
5322 | x: minX,
|
5323 | y: minY,
|
5324 | width: maxX - minX,
|
5325 | height: maxY - minY
|
5326 | };
|
5327 | };
|
5328 |
|
5329 | _proto.destroy = function destroy() {
|
5330 | if (this.get('destroyed')) {
|
5331 | return;
|
5332 | }
|
5333 |
|
5334 | this.clear();
|
5335 |
|
5336 | _Element.prototype.destroy.call(this);
|
5337 | };
|
5338 |
|
5339 | return Group;
|
5340 | }(Element);
|
5341 |
|
5342 | Util.mix(Group.prototype, Container, {
|
5343 | getGroupClass: function getGroupClass() {
|
5344 | return Group;
|
5345 | }
|
5346 | });
|
5347 | module.exports = Group;
|
5348 |
|
5349 | }),
|
5350 |
|
5351 | (function(module, exports) {
|
5352 |
|
5353 | module.exports = {
|
5354 | requestAnimationFrame: typeof window === 'object' && window.requestAnimationFrame ? window.requestAnimationFrame : function (fn) {
|
5355 | return setTimeout(fn, 16);
|
5356 | }
|
5357 | };
|
5358 |
|
5359 | }),
|
5360 |
|
5361 | (function(module, exports, __webpack_require__) {
|
5362 |
|
5363 |
|
5364 |
|
5365 |
|
5366 |
|
5367 | var Vector2 = __webpack_require__(7);
|
5368 |
|
5369 | function getPoint(v) {
|
5370 | return [v.x, v.y];
|
5371 | }
|
5372 |
|
5373 | function smoothBezier(points, smooth, isLoop, constraint) {
|
5374 | var cps = [];
|
5375 | var prevPoint;
|
5376 | var nextPoint;
|
5377 | var hasConstraint = !!constraint;
|
5378 | var min;
|
5379 | var max;
|
5380 | var point;
|
5381 | var len;
|
5382 | var l;
|
5383 | var i;
|
5384 |
|
5385 | if (hasConstraint) {
|
5386 | min = [Infinity, Infinity];
|
5387 | max = [-Infinity, -Infinity];
|
5388 |
|
5389 | for (i = 0, l = points.length; i < l; i++) {
|
5390 | point = getPoint(points[i]);
|
5391 | Vector2.min(min, min, point);
|
5392 | Vector2.max(max, max, point);
|
5393 | }
|
5394 |
|
5395 | Vector2.min(min, min, constraint[0]);
|
5396 | Vector2.max(max, max, constraint[1]);
|
5397 | }
|
5398 |
|
5399 | for (i = 0, len = points.length; i < len; i++) {
|
5400 | point = getPoint(points[i]);
|
5401 |
|
5402 | if (isLoop) {
|
5403 | prevPoint = getPoint(points[i ? i - 1 : len - 1]);
|
5404 | nextPoint = getPoint(points[(i + 1) % len]);
|
5405 | } else {
|
5406 | if (i === 0 || i === len - 1) {
|
5407 | cps.push([point[0], point[1]]);
|
5408 | continue;
|
5409 | } else {
|
5410 | prevPoint = getPoint(points[i - 1]);
|
5411 | nextPoint = getPoint(points[i + 1]);
|
5412 | }
|
5413 | }
|
5414 |
|
5415 | var v = Vector2.sub([], nextPoint, prevPoint);
|
5416 | Vector2.scale(v, v, smooth);
|
5417 | var d0 = Vector2.distance(point, prevPoint);
|
5418 | var d1 = Vector2.distance(point, nextPoint);
|
5419 | var sum = d0 + d1;
|
5420 |
|
5421 | if (sum !== 0) {
|
5422 | d0 /= sum;
|
5423 | d1 /= sum;
|
5424 | }
|
5425 |
|
5426 | var v1 = Vector2.scale([], v, -d0);
|
5427 | var v2 = Vector2.scale([], v, d1);
|
5428 | var cp0 = Vector2.add([], point, v1);
|
5429 | var cp1 = Vector2.add([], point, v2);
|
5430 |
|
5431 | if (hasConstraint) {
|
5432 | Vector2.max(cp0, cp0, min);
|
5433 | Vector2.min(cp0, cp0, max);
|
5434 | Vector2.max(cp1, cp1, min);
|
5435 | Vector2.min(cp1, cp1, max);
|
5436 | }
|
5437 |
|
5438 | cps.push([cp0[0], cp0[1]]);
|
5439 | cps.push([cp1[0], cp1[1]]);
|
5440 | }
|
5441 |
|
5442 | if (isLoop) {
|
5443 | cps.push(cps.shift());
|
5444 | }
|
5445 |
|
5446 | return cps;
|
5447 | }
|
5448 |
|
5449 | function catmullRom2bezier(pointList, z, constraint) {
|
5450 | var isLoop = !!z;
|
5451 | var controlPointList = smoothBezier(pointList, 0.4, isLoop, constraint);
|
5452 | var len = pointList.length;
|
5453 | var d1 = [];
|
5454 | var cp1;
|
5455 | var cp2;
|
5456 | var p;
|
5457 |
|
5458 | for (var i = 0; i < len - 1; i++) {
|
5459 | cp1 = controlPointList[i * 2];
|
5460 | cp2 = controlPointList[i * 2 + 1];
|
5461 | p = pointList[i + 1];
|
5462 | d1.push(['C', cp1[0], cp1[1], cp2[0], cp2[1], p.x, p.y]);
|
5463 | }
|
5464 |
|
5465 | if (isLoop) {
|
5466 | cp1 = controlPointList[len];
|
5467 | cp2 = controlPointList[len + 1];
|
5468 | p = pointList[0];
|
5469 | d1.push(['C', cp1[0], cp1[1], cp2[0], cp2[1], p.x, p.y]);
|
5470 | }
|
5471 |
|
5472 | return d1;
|
5473 | }
|
5474 |
|
5475 | module.exports = {
|
5476 | smooth: catmullRom2bezier
|
5477 | };
|
5478 |
|
5479 | }),
|
5480 |
|
5481 | (function(module, exports, __webpack_require__) {
|
5482 |
|
5483 | function _inheritsLoose(subClass, superClass) {
|
5484 | subClass.prototype = Object.create(superClass.prototype);
|
5485 | subClass.prototype.constructor = subClass;
|
5486 | subClass.__proto__ = superClass;
|
5487 | }
|
5488 |
|
5489 | var Geom = __webpack_require__(5);
|
5490 |
|
5491 | var ShapeUtil = __webpack_require__(21);
|
5492 |
|
5493 | var Util = __webpack_require__(0);
|
5494 |
|
5495 | __webpack_require__(41);
|
5496 |
|
5497 | var Path =
|
5498 |
|
5499 | function (_Geom) {
|
5500 | _inheritsLoose(Path, _Geom);
|
5501 |
|
5502 | function Path() {
|
5503 | return _Geom.apply(this, arguments) || this;
|
5504 | }
|
5505 |
|
5506 | var _proto = Path.prototype;
|
5507 |
|
5508 | _proto.getDefaultCfg = function getDefaultCfg() {
|
5509 | var cfg = _Geom.prototype.getDefaultCfg.call(this);
|
5510 |
|
5511 | cfg.type = 'path';
|
5512 | cfg.shapeType = 'line';
|
5513 | return cfg;
|
5514 | };
|
5515 |
|
5516 | _proto.getDrawCfg = function getDrawCfg(obj) {
|
5517 | var cfg = _Geom.prototype.getDrawCfg.call(this, obj);
|
5518 |
|
5519 | cfg.isStack = this.hasAdjust('stack');
|
5520 | return cfg;
|
5521 | };
|
5522 |
|
5523 | _proto.draw = function draw(data, shapeFactory) {
|
5524 | var self = this;
|
5525 | var container = self.get('container');
|
5526 | var yScale = self.getYScale();
|
5527 | var connectNulls = self.get('connectNulls');
|
5528 | var splitArray = ShapeUtil.splitArray(data, yScale.field, connectNulls);
|
5529 | var cfg = this.getDrawCfg(data[0]);
|
5530 | cfg.origin = data;
|
5531 | Util.each(splitArray, function (subData, splitedIndex) {
|
5532 | cfg.splitedIndex = splitedIndex;
|
5533 | cfg.points = subData;
|
5534 | self.drawShape(cfg.shape, data[0], cfg, container, shapeFactory);
|
5535 | });
|
5536 | };
|
5537 |
|
5538 | return Path;
|
5539 | }(Geom);
|
5540 |
|
5541 | Geom.Path = Path;
|
5542 | module.exports = Path;
|
5543 |
|
5544 | }),
|
5545 |
|
5546 | (function(module, exports, __webpack_require__) {
|
5547 |
|
5548 | var Util = __webpack_require__(0);
|
5549 |
|
5550 | var Shape = __webpack_require__(6);
|
5551 |
|
5552 | var ShapeUtil = __webpack_require__(21);
|
5553 |
|
5554 | var Global = __webpack_require__(1);
|
5555 |
|
5556 |
|
5557 | var Line = Shape.registerFactory('line', {
|
5558 | defaultShapeType: 'line'
|
5559 | });
|
5560 |
|
5561 | function getStyle(cfg) {
|
5562 | var style = {
|
5563 | strokeStyle: cfg.color
|
5564 | };
|
5565 |
|
5566 | if (cfg.size >= 0) {
|
5567 | style.lineWidth = cfg.size;
|
5568 | }
|
5569 |
|
5570 | Util.mix(style, cfg.style);
|
5571 | return Util.mix({}, Global.shape.line, style);
|
5572 | }
|
5573 |
|
5574 | function drawLines(cfg, container, style, smooth) {
|
5575 | var points = cfg.points;
|
5576 |
|
5577 | if (points.length && Util.isArray(points[0].y)) {
|
5578 | var topPoints = [];
|
5579 | var bottomPoints = [];
|
5580 |
|
5581 | for (var i = 0, len = points.length; i < len; i++) {
|
5582 | var point = points[i];
|
5583 | var tmp = ShapeUtil.splitPoints(point);
|
5584 | bottomPoints.push(tmp[0]);
|
5585 | topPoints.push(tmp[1]);
|
5586 | }
|
5587 |
|
5588 | if (cfg.isInCircle) {
|
5589 | topPoints.push(topPoints[0]);
|
5590 | bottomPoints.push(bottomPoints[0]);
|
5591 | }
|
5592 |
|
5593 | if (cfg.isStack) {
|
5594 | return container.addShape('Polyline', {
|
5595 | className: 'line',
|
5596 | attrs: Util.mix({
|
5597 | points: topPoints,
|
5598 | smooth: smooth
|
5599 | }, style)
|
5600 | });
|
5601 | }
|
5602 |
|
5603 | var topShape = container.addShape('Polyline', {
|
5604 | className: 'line',
|
5605 | attrs: Util.mix({
|
5606 | points: topPoints,
|
5607 | smooth: smooth
|
5608 | }, style)
|
5609 | });
|
5610 | var bottomShape = container.addShape('Polyline', {
|
5611 | className: 'line',
|
5612 | attrs: Util.mix({
|
5613 | points: bottomPoints,
|
5614 | smooth: smooth
|
5615 | }, style)
|
5616 | });
|
5617 | return [topShape, bottomShape];
|
5618 | }
|
5619 |
|
5620 | if (cfg.isInCircle) {
|
5621 | points.push(points[0]);
|
5622 | }
|
5623 |
|
5624 | return container.addShape('Polyline', {
|
5625 | className: 'line',
|
5626 | attrs: Util.mix({
|
5627 | points: points,
|
5628 | smooth: smooth
|
5629 | }, style)
|
5630 | });
|
5631 | }
|
5632 |
|
5633 | var SHAPES = ['line', 'smooth', 'dash'];
|
5634 | Util.each(SHAPES, function (shapeType) {
|
5635 | Shape.registerShape('line', shapeType, {
|
5636 | draw: function draw(cfg, container) {
|
5637 | var smooth = shapeType === 'smooth';
|
5638 | var style = getStyle(cfg);
|
5639 |
|
5640 | if (shapeType === 'dash') {
|
5641 | style.lineDash = Global.lineDash;
|
5642 | }
|
5643 |
|
5644 | return drawLines(cfg, container, style, smooth);
|
5645 | }
|
5646 | });
|
5647 | });
|
5648 | module.exports = Line;
|
5649 |
|
5650 | }),
|
5651 |
|
5652 | (function(module, exports, __webpack_require__) {
|
5653 |
|
5654 |
|
5655 |
|
5656 |
|
5657 |
|
5658 |
|
5659 | var Global = __webpack_require__(1);
|
5660 |
|
5661 | var Util = __webpack_require__(0);
|
5662 |
|
5663 | var SizeMixin = {
|
5664 | getDefalutSize: function getDefalutSize() {
|
5665 | var defaultSize = this.get('defaultSize');
|
5666 |
|
5667 | if (!defaultSize) {
|
5668 | var coord = this.get('coord');
|
5669 | var xScale = this.getXScale();
|
5670 | var dataArray = this.get('dataArray');
|
5671 | var count = xScale.values.length;
|
5672 | var range = xScale.range;
|
5673 | var normalizeSize = 1 / count;
|
5674 | var widthRatio = 1;
|
5675 |
|
5676 | if (coord && coord.isPolar) {
|
5677 | if (coord.transposed && count > 1) {
|
5678 | widthRatio = Global.widthRatio.multiplePie;
|
5679 | } else {
|
5680 | widthRatio = Global.widthRatio.rose;
|
5681 | }
|
5682 | } else {
|
5683 | if (xScale.isLinear) {
|
5684 | normalizeSize *= range[1] - range[0];
|
5685 | }
|
5686 |
|
5687 | widthRatio = Global.widthRatio.column;
|
5688 | }
|
5689 |
|
5690 | normalizeSize *= widthRatio;
|
5691 |
|
5692 | if (this.hasAdjust('dodge')) {
|
5693 | normalizeSize = normalizeSize / dataArray.length;
|
5694 | }
|
5695 |
|
5696 | defaultSize = normalizeSize;
|
5697 | this.set('defaultSize', defaultSize);
|
5698 | }
|
5699 |
|
5700 | return defaultSize;
|
5701 | },
|
5702 | getDimWidth: function getDimWidth(dimName) {
|
5703 | var coord = this.get('coord');
|
5704 | var start = coord.convertPoint({
|
5705 | x: 0,
|
5706 | y: 0
|
5707 | });
|
5708 | var end = coord.convertPoint({
|
5709 | x: dimName === 'x' ? 1 : 0,
|
5710 | y: dimName === 'x' ? 0 : 1
|
5711 | });
|
5712 | var width = 0;
|
5713 |
|
5714 | if (start && end) {
|
5715 | width = Math.sqrt(Math.pow(end.x - start.x, 2) + Math.pow(end.y - start.y, 2));
|
5716 | }
|
5717 |
|
5718 | return width;
|
5719 | },
|
5720 | _getWidth: function _getWidth() {
|
5721 | var width = this.get('_width');
|
5722 |
|
5723 | if (!width) {
|
5724 | var coord = this.get('coord');
|
5725 |
|
5726 | if (coord && coord.isPolar && !coord.transposed) {
|
5727 | width = (coord.endAngle - coord.startAngle) * coord.circleRadius;
|
5728 | } else {
|
5729 | width = this.getDimWidth('x');
|
5730 | }
|
5731 |
|
5732 | this.set('_width', width);
|
5733 | }
|
5734 |
|
5735 | return width;
|
5736 | },
|
5737 | _toNormalizedSize: function _toNormalizedSize(size) {
|
5738 | var width = this._getWidth();
|
5739 |
|
5740 | return size / width;
|
5741 | },
|
5742 | _toCoordSize: function _toCoordSize(normalizeSize) {
|
5743 | var width = this._getWidth();
|
5744 |
|
5745 | return width * normalizeSize;
|
5746 | },
|
5747 | getNormalizedSize: function getNormalizedSize(obj) {
|
5748 | var size = this.getAttrValue('size', obj);
|
5749 |
|
5750 | if (Util.isNil(size)) {
|
5751 | size = this.getDefalutSize();
|
5752 | } else {
|
5753 | size = this._toNormalizedSize(size);
|
5754 | }
|
5755 |
|
5756 | return size;
|
5757 | },
|
5758 | getSize: function getSize(obj) {
|
5759 | var size = this.getAttrValue('size', obj);
|
5760 |
|
5761 | if (Util.isNil(size)) {
|
5762 | var normalizeSize = this.getDefalutSize();
|
5763 | size = this._toCoordSize(normalizeSize);
|
5764 | }
|
5765 |
|
5766 | return size;
|
5767 | }
|
5768 | };
|
5769 | module.exports = SizeMixin;
|
5770 |
|
5771 | }),
|
5772 |
|
5773 | (function(module, exports, __webpack_require__) {
|
5774 |
|
5775 | function _inheritsLoose(subClass, superClass) {
|
5776 | subClass.prototype = Object.create(superClass.prototype);
|
5777 | subClass.prototype.constructor = subClass;
|
5778 | subClass.__proto__ = superClass;
|
5779 | }
|
5780 |
|
5781 |
|
5782 |
|
5783 |
|
5784 |
|
5785 | var Util = __webpack_require__(0);
|
5786 |
|
5787 | var _require = __webpack_require__(3),
|
5788 | Shape = _require.Shape;
|
5789 |
|
5790 | var SYMBOLS = {
|
5791 | circle: function circle(x, y, r, ctx) {
|
5792 | ctx.arc(x, y, r, 0, Math.PI * 2, false);
|
5793 | },
|
5794 | square: function square(x, y, r, ctx) {
|
5795 | ctx.moveTo(x - r, y - r);
|
5796 | ctx.lineTo(x + r, y - r);
|
5797 | ctx.lineTo(x + r, y + r);
|
5798 | ctx.lineTo(x - r, y + r);
|
5799 | ctx.closePath();
|
5800 | }
|
5801 | };
|
5802 |
|
5803 | var Marker =
|
5804 |
|
5805 | function (_Shape) {
|
5806 | _inheritsLoose(Marker, _Shape);
|
5807 |
|
5808 | function Marker() {
|
5809 | return _Shape.apply(this, arguments) || this;
|
5810 | }
|
5811 |
|
5812 | var _proto = Marker.prototype;
|
5813 |
|
5814 | _proto._initProperties = function _initProperties() {
|
5815 | _Shape.prototype._initProperties.call(this);
|
5816 |
|
5817 | this._attrs.canFill = true;
|
5818 | this._attrs.canStroke = true;
|
5819 | this._attrs.type = 'marker';
|
5820 | };
|
5821 |
|
5822 | _proto.getDefaultAttrs = function getDefaultAttrs() {
|
5823 | return {
|
5824 | x: 0,
|
5825 | y: 0,
|
5826 | lineWidth: 0
|
5827 | };
|
5828 | };
|
5829 |
|
5830 | _proto.createPath = function createPath(context) {
|
5831 | var attrs = this.get('attrs');
|
5832 | var x = attrs.x,
|
5833 | y = attrs.y,
|
5834 | radius = attrs.radius;
|
5835 | var symbol = attrs.symbol || 'circle';
|
5836 | var method;
|
5837 |
|
5838 | if (Util.isFunction(symbol)) {
|
5839 | method = symbol;
|
5840 | } else {
|
5841 | method = SYMBOLS[symbol];
|
5842 | }
|
5843 |
|
5844 | context.beginPath();
|
5845 | method(x, y, radius, context, this);
|
5846 | };
|
5847 |
|
5848 | _proto.calculateBox = function calculateBox() {
|
5849 | var attrs = this.get('attrs');
|
5850 | var x = attrs.x,
|
5851 | y = attrs.y,
|
5852 | radius = attrs.radius;
|
5853 | return {
|
5854 | minX: x - radius,
|
5855 | minY: y - radius,
|
5856 | maxX: x + radius,
|
5857 | maxY: y + radius
|
5858 | };
|
5859 | };
|
5860 |
|
5861 | return Marker;
|
5862 | }(Shape);
|
5863 |
|
5864 | module.exports = Marker;
|
5865 |
|
5866 | }),
|
5867 |
|
5868 | (function(module, exports, __webpack_require__) {
|
5869 |
|
5870 | var Util = __webpack_require__(0);
|
5871 |
|
5872 | var _require = __webpack_require__(3),
|
5873 | Group = _require.Group;
|
5874 |
|
5875 | var Marker = __webpack_require__(43);
|
5876 |
|
5877 | var MARKER_RADIUS = 3;
|
5878 |
|
5879 | var List =
|
5880 |
|
5881 | function () {
|
5882 | var _proto = List.prototype;
|
5883 |
|
5884 | _proto.getDefaultCfg = function getDefaultCfg() {
|
5885 | return {
|
5886 | showTitle: false,
|
5887 |
|
5888 | |
5889 |
|
5890 |
|
5891 |
|
5892 | title: null,
|
5893 |
|
5894 | |
5895 |
|
5896 |
|
5897 |
|
5898 | items: null,
|
5899 |
|
5900 | |
5901 |
|
5902 |
|
5903 |
|
5904 | titleGap: 12,
|
5905 |
|
5906 | |
5907 |
|
5908 |
|
5909 |
|
5910 | itemGap: 10,
|
5911 |
|
5912 | |
5913 |
|
5914 |
|
5915 |
|
5916 | itemMarginBottom: 12,
|
5917 |
|
5918 | |
5919 |
|
5920 |
|
5921 |
|
5922 | itemFormatter: null,
|
5923 | itemWidth: null,
|
5924 |
|
5925 | |
5926 |
|
5927 |
|
5928 |
|
5929 | wordSpace: 6,
|
5930 | x: 0,
|
5931 | y: 0,
|
5932 | layout: 'horizontal',
|
5933 |
|
5934 | |
5935 |
|
5936 |
|
5937 |
|
5938 | joinString: ': '
|
5939 | };
|
5940 | };
|
5941 |
|
5942 | function List(cfg) {
|
5943 | Util.deepMix(this, this.getDefaultCfg(), cfg);
|
5944 |
|
5945 | this._init();
|
5946 |
|
5947 | this._renderTitle();
|
5948 |
|
5949 | this._renderItems();
|
5950 | }
|
5951 |
|
5952 | _proto._init = function _init() {
|
5953 | var container = new Group({
|
5954 | zIndex: this.zIndex || 0
|
5955 | });
|
5956 | this.container = container;
|
5957 | var wrapper = container.addGroup();
|
5958 | this.wrapper = wrapper;
|
5959 | var itemsGroup = wrapper.addGroup({
|
5960 | className: 'itemsGroup'
|
5961 | });
|
5962 | this.itemsGroup = itemsGroup;
|
5963 |
|
5964 | if (this.parent) {
|
5965 | this.parent.add(container);
|
5966 | }
|
5967 | };
|
5968 |
|
5969 | _proto._renderTitle = function _renderTitle(title) {
|
5970 | title = title || this.title;
|
5971 | var titleShape = this.titleShape;
|
5972 | var titleHeight = 0;
|
5973 |
|
5974 | if (this.showTitle && title) {
|
5975 | if (titleShape && !titleShape.get('destroyed')) {
|
5976 | titleShape.attr('text', title);
|
5977 | } else {
|
5978 | var wrapper = this.wrapper,
|
5979 | titleStyle = this.titleStyle;
|
5980 | titleShape = wrapper.addShape('text', {
|
5981 | className: 'title',
|
5982 | attrs: Util.mix({
|
5983 | x: 0,
|
5984 | y: 0,
|
5985 | text: title
|
5986 | }, titleStyle)
|
5987 | });
|
5988 | this.titleShape = titleShape;
|
5989 | }
|
5990 |
|
5991 | titleHeight = titleShape.getBBox().height + this.titleGap;
|
5992 | }
|
5993 |
|
5994 | this._titleHeight = titleHeight;
|
5995 | };
|
5996 |
|
5997 | _proto._renderItems = function _renderItems(items) {
|
5998 | var self = this;
|
5999 | items = items || self.items;
|
6000 |
|
6001 | if (!items) {
|
6002 | return;
|
6003 | }
|
6004 |
|
6005 | if (self.reversed) {
|
6006 | items.reverse();
|
6007 | }
|
6008 |
|
6009 | Util.each(items, function (item, index) {
|
6010 | self._addItem(item, index);
|
6011 | });
|
6012 |
|
6013 | if (items.length > 1) {
|
6014 | this._adjustItems();
|
6015 | }
|
6016 |
|
6017 | this._renderBackground();
|
6018 | };
|
6019 |
|
6020 | _proto._renderBackground = function _renderBackground() {
|
6021 | var background = this.background;
|
6022 |
|
6023 | if (background) {
|
6024 | var container = this.container;
|
6025 | var wrapper = this.wrapper;
|
6026 |
|
6027 | var _wrapper$getBBox = wrapper.getBBox(),
|
6028 | minX = _wrapper$getBBox.minX,
|
6029 | minY = _wrapper$getBBox.minY,
|
6030 | width = _wrapper$getBBox.width,
|
6031 | height = _wrapper$getBBox.height;
|
6032 |
|
6033 | var padding = background.padding || [0, 0, 0, 0];
|
6034 | padding = Util.parsePadding(padding);
|
6035 | var attrs = Util.mix({
|
6036 | x: minX - padding[3],
|
6037 | y: minY - padding[0],
|
6038 | width: width + padding[1] + padding[3],
|
6039 | height: height + padding[0] + padding[2]
|
6040 | }, background);
|
6041 | var backShape = this.backShape;
|
6042 |
|
6043 | if (backShape) {
|
6044 | backShape.attr(attrs);
|
6045 | } else {
|
6046 | backShape = container.addShape('Rect', {
|
6047 | zIndex: -1,
|
6048 | attrs: attrs
|
6049 | });
|
6050 | }
|
6051 |
|
6052 | this.backShape = backShape;
|
6053 | container.sort();
|
6054 | }
|
6055 | };
|
6056 |
|
6057 | _proto._addItem = function _addItem(item) {
|
6058 | var itemsGroup = this.itemsGroup;
|
6059 | var itemGroup = itemsGroup.addGroup({
|
6060 | name: item.name,
|
6061 | value: item.value,
|
6062 | dataValue: item.dataValue,
|
6063 | checked: item.checked
|
6064 | });
|
6065 | var unCheckStyle = this.unCheckStyle,
|
6066 | unCheckColor = this.unCheckColor,
|
6067 | nameStyle = this.nameStyle,
|
6068 | valueStyle = this.valueStyle,
|
6069 | wordSpace = this.wordSpace;
|
6070 | var marker = item.marker,
|
6071 | value = item.value;
|
6072 | var startX = 0;
|
6073 |
|
6074 | if (unCheckColor) {
|
6075 | unCheckStyle.fill = unCheckColor;
|
6076 | }
|
6077 |
|
6078 | if (marker) {
|
6079 | var radius = marker.radius || MARKER_RADIUS;
|
6080 | var markerAttrs = Util.mix({
|
6081 | x: radius,
|
6082 | y: this._titleHeight
|
6083 | }, marker);
|
6084 |
|
6085 | if (item.checked === false) {
|
6086 | Util.mix(markerAttrs, unCheckStyle);
|
6087 | }
|
6088 |
|
6089 | var markerShape = new Marker({
|
6090 | className: 'item-marker',
|
6091 | attrs: markerAttrs
|
6092 | });
|
6093 | itemGroup.add(markerShape);
|
6094 | startX += markerShape.getBBox().width + wordSpace;
|
6095 | }
|
6096 |
|
6097 | var nameText;
|
6098 | var name = item.name;
|
6099 |
|
6100 | if (name) {
|
6101 | var joinString = this.joinString || '';
|
6102 | name = value ? name + joinString : name;
|
6103 | nameText = itemGroup.addShape('text', {
|
6104 | className: 'name',
|
6105 | attrs: Util.mix({
|
6106 | x: startX,
|
6107 | y: this._titleHeight,
|
6108 | text: this._formatItemValue(name)
|
6109 | }, nameStyle, item.checked === false ? unCheckStyle : null)
|
6110 | });
|
6111 | }
|
6112 |
|
6113 | if (value) {
|
6114 | var valueX = startX;
|
6115 |
|
6116 | if (nameText) {
|
6117 | valueX += nameText.getBBox().width;
|
6118 | }
|
6119 |
|
6120 | itemGroup.addShape('text', {
|
6121 | className: 'value',
|
6122 | attrs: Util.mix({
|
6123 | x: valueX,
|
6124 | y: this._titleHeight,
|
6125 | text: value
|
6126 | }, valueStyle, item.checked === false ? unCheckStyle : null)
|
6127 | });
|
6128 | }
|
6129 |
|
6130 | return itemGroup;
|
6131 | };
|
6132 |
|
6133 | _proto._formatItemValue = function _formatItemValue(value) {
|
6134 | var formatter = this.itemFormatter;
|
6135 |
|
6136 | if (formatter) {
|
6137 | value = formatter.call(this, value);
|
6138 | }
|
6139 |
|
6140 | return value;
|
6141 | };
|
6142 |
|
6143 | _proto._getMaxItemWidth = function _getMaxItemWidth() {
|
6144 | var width;
|
6145 | var itemWidth = this.itemWidth;
|
6146 |
|
6147 | if (Util.isNumber(itemWidth) || Util.isNil(itemWidth)) {
|
6148 | return itemWidth;
|
6149 | }
|
6150 |
|
6151 | if (itemWidth === 'auto') {
|
6152 | var itemsGroup = this.itemsGroup;
|
6153 | var children = itemsGroup.get('children');
|
6154 | var count = children.length;
|
6155 | var maxItemWidth = 0;
|
6156 |
|
6157 | for (var i = 0; i < count; i++) {
|
6158 | var _children$i$getBBox = children[i].getBBox(),
|
6159 | _width = _children$i$getBBox.width;
|
6160 |
|
6161 | maxItemWidth = Math.max(maxItemWidth, _width);
|
6162 | }
|
6163 |
|
6164 | var maxLength = this.maxLength;
|
6165 | var itemGap = this.itemGap;
|
6166 | var twoAvgWidth = (maxLength - itemGap) / 2;
|
6167 | var threeAvgWidth = (maxLength - itemGap * 2) / 3;
|
6168 |
|
6169 | if (count === 2) {
|
6170 | width = Math.max(maxItemWidth, twoAvgWidth);
|
6171 | } else {
|
6172 |
|
6173 |
|
6174 |
|
6175 | if (maxItemWidth <= threeAvgWidth) {
|
6176 | width = threeAvgWidth;
|
6177 | } else if (maxItemWidth <= twoAvgWidth) {
|
6178 | width = twoAvgWidth;
|
6179 | } else {
|
6180 | width = maxItemWidth;
|
6181 | }
|
6182 | }
|
6183 |
|
6184 | return width;
|
6185 | }
|
6186 | };
|
6187 |
|
6188 | _proto._adjustHorizontal = function _adjustHorizontal() {
|
6189 | var maxLength = this.maxLength,
|
6190 | itemsGroup = this.itemsGroup;
|
6191 | var children = itemsGroup.get('children');
|
6192 | var itemGap = this.itemGap,
|
6193 | itemMarginBottom = this.itemMarginBottom;
|
6194 | var titleHeight = this._titleHeight;
|
6195 | var row = 0;
|
6196 | var rowWidth = 0;
|
6197 | var width;
|
6198 | var height;
|
6199 |
|
6200 | var itemWidth = this._getMaxItemWidth();
|
6201 |
|
6202 | var legendHitBoxes = [];
|
6203 |
|
6204 | for (var i = 0, len = children.length; i < len; i++) {
|
6205 | var child = children[i];
|
6206 | var box = child.getBBox();
|
6207 | var childHeight = box.height;
|
6208 | var childWidth = box.width;
|
6209 | width = itemWidth || childWidth;
|
6210 | height = childHeight + itemMarginBottom;
|
6211 |
|
6212 | if (width - (maxLength - rowWidth) > 0.0001) {
|
6213 | row++;
|
6214 | rowWidth = 0;
|
6215 | }
|
6216 |
|
6217 | child.moveTo(rowWidth, row * height);
|
6218 | legendHitBoxes.push({
|
6219 | x: rowWidth,
|
6220 | y: row * height + titleHeight - childHeight / 2,
|
6221 | width: childWidth * 1.375,
|
6222 | height: childHeight * 1.375
|
6223 | });
|
6224 | rowWidth += width + itemGap;
|
6225 | }
|
6226 |
|
6227 | this.legendHitBoxes = legendHitBoxes;
|
6228 | return;
|
6229 | };
|
6230 |
|
6231 | _proto._adjustVertical = function _adjustVertical() {
|
6232 | var maxLength = this.maxLength,
|
6233 | itemsGroup = this.itemsGroup;
|
6234 | var itemGap = this.itemGap,
|
6235 | itemMarginBottom = this.itemMarginBottom,
|
6236 | itemWidth = this.itemWidth;
|
6237 | var titleHeight = this._titleHeight;
|
6238 | var children = itemsGroup.get('children');
|
6239 | var colHeight = 0;
|
6240 | var width;
|
6241 | var height;
|
6242 | var maxItemWidth = 0;
|
6243 | var totalWidth = 0;
|
6244 | var legendHitBoxes = [];
|
6245 |
|
6246 | for (var i = 0, length = children.length; i < length; i++) {
|
6247 | var child = children[i];
|
6248 | var bbox = child.getBBox();
|
6249 | width = bbox.width;
|
6250 | height = bbox.height;
|
6251 |
|
6252 | if (Util.isNumber(itemWidth)) {
|
6253 | maxItemWidth = itemWidth + itemGap;
|
6254 | } else if (width > maxItemWidth) {
|
6255 | maxItemWidth = width + itemGap;
|
6256 | }
|
6257 |
|
6258 | if (maxLength - colHeight < height) {
|
6259 | colHeight = 0;
|
6260 | totalWidth += maxItemWidth;
|
6261 | child.moveTo(totalWidth, 0);
|
6262 | legendHitBoxes.push({
|
6263 | x: totalWidth,
|
6264 | y: titleHeight - height / 2,
|
6265 | width: width * 1.375,
|
6266 | height: height * 1.375
|
6267 | });
|
6268 | } else {
|
6269 | child.moveTo(totalWidth, colHeight);
|
6270 | legendHitBoxes.push({
|
6271 | x: totalWidth,
|
6272 | y: colHeight - height / 2 + titleHeight,
|
6273 | width: width * 1.375,
|
6274 | height: height * 1.375
|
6275 | });
|
6276 | }
|
6277 |
|
6278 | colHeight += height + itemMarginBottom;
|
6279 | }
|
6280 |
|
6281 | this.legendHitBoxes = legendHitBoxes;
|
6282 | return;
|
6283 | };
|
6284 |
|
6285 | _proto._adjustItems = function _adjustItems() {
|
6286 | var layout = this.layout;
|
6287 |
|
6288 | if (layout === 'horizontal') {
|
6289 | this._adjustHorizontal();
|
6290 | } else {
|
6291 | this._adjustVertical();
|
6292 | }
|
6293 | };
|
6294 |
|
6295 | _proto.moveTo = function moveTo(x, y) {
|
6296 | this.x = x;
|
6297 | this.y = y;
|
6298 | var container = this.container;
|
6299 | container && container.moveTo(x, y);
|
6300 | return this;
|
6301 | };
|
6302 |
|
6303 | _proto.setItems = function setItems(items) {
|
6304 | this.clearItems();
|
6305 |
|
6306 | this._renderItems(items);
|
6307 | };
|
6308 |
|
6309 | _proto.setTitle = function setTitle(title) {
|
6310 | this._renderTitle(title);
|
6311 | };
|
6312 |
|
6313 | _proto.clearItems = function clearItems() {
|
6314 | var itemsGroup = this.itemsGroup;
|
6315 | itemsGroup.clear();
|
6316 | };
|
6317 |
|
6318 | _proto.getWidth = function getWidth() {
|
6319 | var container = this.container;
|
6320 | var bbox = container.getBBox();
|
6321 | return bbox.width;
|
6322 | };
|
6323 |
|
6324 | _proto.getHeight = function getHeight() {
|
6325 | var container = this.container;
|
6326 | var bbox = container.getBBox();
|
6327 | return bbox.height;
|
6328 | };
|
6329 |
|
6330 | _proto.show = function show() {
|
6331 | var container = this.container;
|
6332 | container.show();
|
6333 | };
|
6334 |
|
6335 | _proto.hide = function hide() {
|
6336 | var container = this.container;
|
6337 | container.hide();
|
6338 | };
|
6339 |
|
6340 | _proto.clear = function clear() {
|
6341 | var container = this.container;
|
6342 | container.clear();
|
6343 | container.remove(true);
|
6344 | };
|
6345 |
|
6346 | return List;
|
6347 | }();
|
6348 |
|
6349 | module.exports = List;
|
6350 |
|
6351 | }),
|
6352 |
|
6353 | (function(module, exports, __webpack_require__) {
|
6354 |
|
6355 |
|
6356 |
|
6357 |
|
6358 |
|
6359 | var Util = __webpack_require__(0);
|
6360 |
|
6361 | var defaultAnimationCfg = {
|
6362 | appear: {
|
6363 | duration: 450,
|
6364 | easing: 'quadraticOut'
|
6365 | },
|
6366 |
|
6367 | update: {
|
6368 | duration: 300,
|
6369 | easing: 'quadraticOut'
|
6370 | },
|
6371 |
|
6372 | enter: {
|
6373 | duration: 300,
|
6374 | easing: 'quadraticOut'
|
6375 | },
|
6376 |
|
6377 | leave: {
|
6378 | duration: 350,
|
6379 | easing: 'quadraticIn'
|
6380 |
|
6381 | }
|
6382 | };
|
6383 | var Animate = {
|
6384 | defaultCfg: {},
|
6385 | Action: {},
|
6386 | getAnimation: function getAnimation(geomType, coord, animationType) {
|
6387 | var geomAnimateCfg = this.defaultCfg[geomType];
|
6388 |
|
6389 | if (geomAnimateCfg) {
|
6390 | var animation = geomAnimateCfg[animationType];
|
6391 |
|
6392 | if (Util.isFunction(animation)) {
|
6393 | return animation(coord);
|
6394 | }
|
6395 | }
|
6396 |
|
6397 | return false;
|
6398 | },
|
6399 | getAnimateCfg: function getAnimateCfg(geomType, animationType) {
|
6400 | var defaultCfg = defaultAnimationCfg[animationType];
|
6401 | var geomConfig = this.defaultCfg[geomType];
|
6402 |
|
6403 | if (geomConfig && geomConfig.cfg && geomConfig.cfg[animationType]) {
|
6404 | return Util.deepMix({}, defaultCfg, geomConfig.cfg[animationType]);
|
6405 | }
|
6406 |
|
6407 | return defaultCfg;
|
6408 | },
|
6409 | registerAnimation: function registerAnimation(animationName, animationFun) {
|
6410 | if (!this.Action) {
|
6411 | this.Action = {};
|
6412 | }
|
6413 |
|
6414 | this.Action[animationName] = animationFun;
|
6415 | }
|
6416 | };
|
6417 | module.exports = Animate;
|
6418 |
|
6419 | }),
|
6420 |
|
6421 | (function(module, exports, __webpack_require__) {
|
6422 |
|
6423 |
|
6424 |
|
6425 |
|
6426 |
|
6427 | var _require = __webpack_require__(3),
|
6428 | Matrix = _require.Matrix;
|
6429 |
|
6430 | var Util = __webpack_require__(0);
|
6431 |
|
6432 | var Helpers = {
|
6433 | getCoordInfo: function getCoordInfo(coord) {
|
6434 | var start = coord.start;
|
6435 | var end = coord.end;
|
6436 | return {
|
6437 | start: start,
|
6438 | end: end,
|
6439 | width: end.x - start.x,
|
6440 | height: Math.abs(end.y - start.y)
|
6441 | };
|
6442 | },
|
6443 | getScaledMatrix: function getScaledMatrix(shape, v, direct) {
|
6444 | var scaledMatrix;
|
6445 | shape.apply(v);
|
6446 | var x = v[0];
|
6447 | var y = v[1];
|
6448 |
|
6449 | if (direct === 'x') {
|
6450 | shape.transform([['t', x, y], ['s', 0.01, 1], ['t', -x, -y]]);
|
6451 | var matrix = shape.getMatrix();
|
6452 | scaledMatrix = Matrix.transform(matrix, [['t', x, y], ['s', 100, 1], ['t', -x, -y]]);
|
6453 | } else if (direct === 'y') {
|
6454 | shape.transform([['t', x, y], ['s', 1, 0.01], ['t', -x, -y]]);
|
6455 |
|
6456 | var _matrix = shape.getMatrix();
|
6457 |
|
6458 | scaledMatrix = Matrix.transform(_matrix, [['t', x, y], ['s', 1, 100], ['t', -x, -y]]);
|
6459 | } else if (direct === 'xy') {
|
6460 | shape.transform([['t', x, y], ['s', 0.01, 0.01], ['t', -x, -y]]);
|
6461 |
|
6462 | var _matrix2 = shape.getMatrix();
|
6463 |
|
6464 | scaledMatrix = Matrix.transform(_matrix2, [['t', x, y], ['s', 100, 100], ['t', -x, -y]]);
|
6465 | }
|
6466 |
|
6467 | return scaledMatrix;
|
6468 | },
|
6469 | getAnimateParam: function getAnimateParam(animateCfg, index, id) {
|
6470 | var result = {};
|
6471 |
|
6472 | if (animateCfg.delay) {
|
6473 | result.delay = Util.isFunction(animateCfg.delay) ? animateCfg.delay(index, id) : animateCfg.delay;
|
6474 | }
|
6475 |
|
6476 | result.easing = animateCfg.easing;
|
6477 | result.duration = animateCfg.duration;
|
6478 | result.delay = animateCfg.delay;
|
6479 | return result;
|
6480 | },
|
6481 | doAnimation: function doAnimation(shape, endState, animateCfg, callback) {
|
6482 | var id = shape._id;
|
6483 | var index = shape.get('index');
|
6484 |
|
6485 | var _Helpers$getAnimatePa = Helpers.getAnimateParam(animateCfg, index, id),
|
6486 | easing = _Helpers$getAnimatePa.easing,
|
6487 | delay = _Helpers$getAnimatePa.delay,
|
6488 | duration = _Helpers$getAnimatePa.duration;
|
6489 |
|
6490 | var anim = shape.animate().to({
|
6491 | attrs: endState,
|
6492 | duration: duration,
|
6493 | delay: delay,
|
6494 | easing: easing
|
6495 | });
|
6496 |
|
6497 | if (callback) {
|
6498 | anim.onEnd(function () {
|
6499 | callback();
|
6500 | });
|
6501 | }
|
6502 | }
|
6503 | };
|
6504 | module.exports = Helpers;
|
6505 |
|
6506 | }),
|
6507 |
|
6508 | (function(module, exports, __webpack_require__) {
|
6509 |
|
6510 | var F2 = __webpack_require__(48);
|
6511 |
|
6512 | __webpack_require__(90);
|
6513 |
|
6514 | __webpack_require__(102);
|
6515 |
|
6516 | __webpack_require__(107);
|
6517 |
|
6518 |
|
6519 | __webpack_require__(108);
|
6520 |
|
6521 |
|
6522 | __webpack_require__(109);
|
6523 |
|
6524 |
|
6525 | __webpack_require__(112);
|
6526 |
|
6527 |
|
6528 | __webpack_require__(113);
|
6529 |
|
6530 |
|
6531 | __webpack_require__(114);
|
6532 |
|
6533 |
|
6534 | __webpack_require__(115);
|
6535 |
|
6536 |
|
6537 | __webpack_require__(116);
|
6538 |
|
6539 |
|
6540 | __webpack_require__(117);
|
6541 |
|
6542 |
|
6543 | __webpack_require__(118);
|
6544 |
|
6545 |
|
6546 | var Tooltip = __webpack_require__(119);
|
6547 |
|
6548 | var Guide = __webpack_require__(122);
|
6549 |
|
6550 | var Legend = __webpack_require__(123);
|
6551 |
|
6552 | var Animation = __webpack_require__(124);
|
6553 |
|
6554 | var ScrollBar = __webpack_require__(130);
|
6555 |
|
6556 | var PieLabel = __webpack_require__(131);
|
6557 |
|
6558 | F2.Animate = __webpack_require__(45);
|
6559 |
|
6560 | F2.Chart.plugins.register([Tooltip, Legend, Guide, Animation, ScrollBar, PieLabel]);
|
6561 |
|
6562 | __webpack_require__(132);
|
6563 |
|
6564 | __webpack_require__(134);
|
6565 |
|
6566 | __webpack_require__(135);
|
6567 |
|
6568 | F2.Interaction = __webpack_require__(22);
|
6569 | module.exports = F2;
|
6570 |
|
6571 | }),
|
6572 |
|
6573 | (function(module, exports, __webpack_require__) {
|
6574 |
|
6575 | var Renderer = __webpack_require__(49);
|
6576 |
|
6577 | var Core = __webpack_require__(51);
|
6578 |
|
6579 |
|
6580 | function strLen(str) {
|
6581 | var len = 0;
|
6582 |
|
6583 | for (var i = 0; i < str.length; i++) {
|
6584 | if (str.charCodeAt(i) > 0 && str.charCodeAt(i) < 128) {
|
6585 | len++;
|
6586 | } else {
|
6587 | len += 2;
|
6588 | }
|
6589 | }
|
6590 |
|
6591 | return len;
|
6592 | }
|
6593 |
|
6594 |
|
6595 |
|
6596 | Core.Util.measureText = function (text, font, ctx) {
|
6597 | if (!ctx || !ctx.measureText) {
|
6598 | var fontSize = 12;
|
6599 |
|
6600 | if (font) {
|
6601 | fontSize = parseInt(font.split(' ')[3], 10);
|
6602 | }
|
6603 |
|
6604 | fontSize /= 2;
|
6605 | return {
|
6606 | width: strLen(text) * fontSize
|
6607 | };
|
6608 | }
|
6609 |
|
6610 | ctx.font = font || '12px sans-serif';
|
6611 | return ctx.measureText(text);
|
6612 | };
|
6613 |
|
6614 |
|
6615 | Core.Util.addEventListener = function (source, type, listener) {
|
6616 | source.addListener(type, listener);
|
6617 | };
|
6618 |
|
6619 | Core.Util.removeEventListener = function (source, type, listener) {
|
6620 | source.removeListener(type, listener);
|
6621 | };
|
6622 |
|
6623 | Core.Util.createEvent = function (event, chart) {
|
6624 | var type = event.type;
|
6625 | var x = 0;
|
6626 | var y = 0;
|
6627 | var touches = event.touches;
|
6628 |
|
6629 | if (touches && touches.length > 0) {
|
6630 | x = touches[0].x;
|
6631 | y = touches[0].y;
|
6632 | }
|
6633 |
|
6634 | return {
|
6635 | type: type,
|
6636 | chart: chart,
|
6637 | x: x,
|
6638 | y: y
|
6639 | };
|
6640 | };
|
6641 |
|
6642 | Core.Renderer = Renderer;
|
6643 | module.exports = Core;
|
6644 |
|
6645 | }),
|
6646 |
|
6647 | (function(module, exports, __webpack_require__) {
|
6648 |
|
6649 | function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
|
6650 |
|
6651 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
6652 |
|
6653 |
|
6654 |
|
6655 |
|
6656 |
|
6657 |
|
6658 | var EventEmitter = __webpack_require__(50);
|
6659 |
|
6660 | var CAPITALIZED_ATTRS_MAP = {
|
6661 | fillStyle: 'FillStyle',
|
6662 | fontSize: 'FontSize',
|
6663 | globalAlpha: 'GlobalAlpha',
|
6664 | opacity: 'GlobalAlpha',
|
6665 | lineCap: 'LineCap',
|
6666 | lineJoin: 'LineJoin',
|
6667 | lineWidth: 'LineWidth',
|
6668 | miterLimit: 'MiterLimit',
|
6669 | strokeStyle: 'StrokeStyle',
|
6670 | textAlign: 'TextAlign',
|
6671 | textBaseline: 'TextBaseline'
|
6672 | };
|
6673 |
|
6674 | var Renderer =
|
6675 |
|
6676 | function (_EventEmitter) {
|
6677 | _inheritsLoose(Renderer, _EventEmitter);
|
6678 |
|
6679 | function Renderer(myCtx) {
|
6680 | var _this;
|
6681 |
|
6682 | _this = _EventEmitter.call(this) || this;
|
6683 |
|
6684 | var self = _assertThisInitialized(_assertThisInitialized(_this));
|
6685 |
|
6686 | self.ctx = myCtx;
|
6687 | self.style = {};
|
6688 |
|
6689 | self._initContext(myCtx);
|
6690 |
|
6691 | return _this;
|
6692 | }
|
6693 |
|
6694 | var _proto = Renderer.prototype;
|
6695 |
|
6696 | _proto.getContext = function getContext(type) {
|
6697 | if (type === '2d') {
|
6698 | return this.ctx;
|
6699 | }
|
6700 | };
|
6701 |
|
6702 | _proto._initContext = function _initContext(myCtx) {
|
6703 | Object.keys(CAPITALIZED_ATTRS_MAP).map(function (key) {
|
6704 | Object.defineProperty(myCtx, key, {
|
6705 | set: function set(value) {
|
6706 | var name = 'set' + CAPITALIZED_ATTRS_MAP[key];
|
6707 | myCtx[name](value);
|
6708 | }
|
6709 | });
|
6710 | return key;
|
6711 | });
|
6712 | };
|
6713 |
|
6714 | return Renderer;
|
6715 | }(EventEmitter);
|
6716 |
|
6717 | module.exports = Renderer;
|
6718 |
|
6719 | }),
|
6720 |
|
6721 | (function(module, exports, __webpack_require__) {
|
6722 |
|
6723 | var __WEBPACK_AMD_DEFINE_RESULT__; |
6724 |
|
6725 |
|
6726 |
|
6727 |
|
6728 |
|
6729 | ;
|
6730 |
|
6731 | (function (exports) {
|
6732 | 'use strict';
|
6733 | |
6734 |
|
6735 |
|
6736 |
|
6737 |
|
6738 |
|
6739 |
|
6740 | function EventEmitter() {}
|
6741 |
|
6742 |
|
6743 | var proto = EventEmitter.prototype;
|
6744 | var originalGlobalValue = exports.EventEmitter;
|
6745 | |
6746 |
|
6747 |
|
6748 |
|
6749 |
|
6750 |
|
6751 |
|
6752 |
|
6753 |
|
6754 | function indexOfListener(listeners, listener) {
|
6755 | var i = listeners.length;
|
6756 |
|
6757 | while (i--) {
|
6758 | if (listeners[i].listener === listener) {
|
6759 | return i;
|
6760 | }
|
6761 | }
|
6762 |
|
6763 | return -1;
|
6764 | }
|
6765 | |
6766 |
|
6767 |
|
6768 |
|
6769 |
|
6770 |
|
6771 |
|
6772 |
|
6773 |
|
6774 | function alias(name) {
|
6775 | return function aliasClosure() {
|
6776 | return this[name].apply(this, arguments);
|
6777 | };
|
6778 | }
|
6779 | |
6780 |
|
6781 |
|
6782 |
|
6783 |
|
6784 |
|
6785 |
|
6786 |
|
6787 |
|
6788 |
|
6789 |
|
6790 | proto.getListeners = function getListeners(evt) {
|
6791 | var events = this._getEvents();
|
6792 |
|
6793 | var response;
|
6794 | var key;
|
6795 |
|
6796 |
|
6797 | if (evt instanceof RegExp) {
|
6798 | response = {};
|
6799 |
|
6800 | for (key in events) {
|
6801 | if (events.hasOwnProperty(key) && evt.test(key)) {
|
6802 | response[key] = events[key];
|
6803 | }
|
6804 | }
|
6805 | } else {
|
6806 | response = events[evt] || (events[evt] = []);
|
6807 | }
|
6808 |
|
6809 | return response;
|
6810 | };
|
6811 | |
6812 |
|
6813 |
|
6814 |
|
6815 |
|
6816 |
|
6817 |
|
6818 |
|
6819 | proto.flattenListeners = function flattenListeners(listeners) {
|
6820 | var flatListeners = [];
|
6821 | var i;
|
6822 |
|
6823 | for (i = 0; i < listeners.length; i += 1) {
|
6824 | flatListeners.push(listeners[i].listener);
|
6825 | }
|
6826 |
|
6827 | return flatListeners;
|
6828 | };
|
6829 | |
6830 |
|
6831 |
|
6832 |
|
6833 |
|
6834 |
|
6835 |
|
6836 |
|
6837 | proto.getListenersAsObject = function getListenersAsObject(evt) {
|
6838 | var listeners = this.getListeners(evt);
|
6839 | var response;
|
6840 |
|
6841 | if (listeners instanceof Array) {
|
6842 | response = {};
|
6843 | response[evt] = listeners;
|
6844 | }
|
6845 |
|
6846 | return response || listeners;
|
6847 | };
|
6848 |
|
6849 | function isValidListener(listener) {
|
6850 | if (typeof listener === 'function' || listener instanceof RegExp) {
|
6851 | return true;
|
6852 | } else if (listener && typeof listener === 'object') {
|
6853 | return isValidListener(listener.listener);
|
6854 | } else {
|
6855 | return false;
|
6856 | }
|
6857 | }
|
6858 | |
6859 |
|
6860 |
|
6861 |
|
6862 |
|
6863 |
|
6864 |
|
6865 |
|
6866 |
|
6867 |
|
6868 |
|
6869 |
|
6870 | proto.addListener = function addListener(evt, listener) {
|
6871 | if (!isValidListener(listener)) {
|
6872 | throw new TypeError('listener must be a function');
|
6873 | }
|
6874 |
|
6875 | var listeners = this.getListenersAsObject(evt);
|
6876 | var listenerIsWrapped = typeof listener === 'object';
|
6877 | var key;
|
6878 |
|
6879 | for (key in listeners) {
|
6880 | if (listeners.hasOwnProperty(key) && indexOfListener(listeners[key], listener) === -1) {
|
6881 | listeners[key].push(listenerIsWrapped ? listener : {
|
6882 | listener: listener,
|
6883 | once: false
|
6884 | });
|
6885 | }
|
6886 | }
|
6887 |
|
6888 | return this;
|
6889 | };
|
6890 | |
6891 |
|
6892 |
|
6893 |
|
6894 |
|
6895 | proto.on = alias('addListener');
|
6896 | |
6897 |
|
6898 |
|
6899 |
|
6900 |
|
6901 |
|
6902 |
|
6903 |
|
6904 |
|
6905 | proto.addOnceListener = function addOnceListener(evt, listener) {
|
6906 | return this.addListener(evt, {
|
6907 | listener: listener,
|
6908 | once: true
|
6909 | });
|
6910 | };
|
6911 | |
6912 |
|
6913 |
|
6914 |
|
6915 |
|
6916 | proto.once = alias('addOnceListener');
|
6917 | |
6918 |
|
6919 |
|
6920 |
|
6921 |
|
6922 |
|
6923 |
|
6924 |
|
6925 | proto.defineEvent = function defineEvent(evt) {
|
6926 | this.getListeners(evt);
|
6927 | return this;
|
6928 | };
|
6929 | |
6930 |
|
6931 |
|
6932 |
|
6933 |
|
6934 |
|
6935 |
|
6936 |
|
6937 | proto.defineEvents = function defineEvents(evts) {
|
6938 | for (var i = 0; i < evts.length; i += 1) {
|
6939 | this.defineEvent(evts[i]);
|
6940 | }
|
6941 |
|
6942 | return this;
|
6943 | };
|
6944 | |
6945 |
|
6946 |
|
6947 |
|
6948 |
|
6949 |
|
6950 |
|
6951 |
|
6952 |
|
6953 |
|
6954 | proto.removeListener = function removeListener(evt, listener) {
|
6955 | var listeners = this.getListenersAsObject(evt);
|
6956 | var index;
|
6957 | var key;
|
6958 |
|
6959 | for (key in listeners) {
|
6960 | if (listeners.hasOwnProperty(key)) {
|
6961 | index = indexOfListener(listeners[key], listener);
|
6962 |
|
6963 | if (index !== -1) {
|
6964 | listeners[key].splice(index, 1);
|
6965 | }
|
6966 | }
|
6967 | }
|
6968 |
|
6969 | return this;
|
6970 | };
|
6971 | |
6972 |
|
6973 |
|
6974 |
|
6975 |
|
6976 | proto.off = alias('removeListener');
|
6977 | |
6978 |
|
6979 |
|
6980 |
|
6981 |
|
6982 |
|
6983 |
|
6984 |
|
6985 |
|
6986 |
|
6987 |
|
6988 | proto.addListeners = function addListeners(evt, listeners) {
|
6989 |
|
6990 | return this.manipulateListeners(false, evt, listeners);
|
6991 | };
|
6992 | |
6993 |
|
6994 |
|
6995 |
|
6996 |
|
6997 |
|
6998 |
|
6999 |
|
7000 |
|
7001 |
|
7002 |
|
7003 |
|
7004 | proto.removeListeners = function removeListeners(evt, listeners) {
|
7005 |
|
7006 | return this.manipulateListeners(true, evt, listeners);
|
7007 | };
|
7008 | |
7009 |
|
7010 |
|
7011 |
|
7012 |
|
7013 |
|
7014 |
|
7015 |
|
7016 |
|
7017 |
|
7018 |
|
7019 |
|
7020 |
|
7021 |
|
7022 | proto.manipulateListeners = function manipulateListeners(remove, evt, listeners) {
|
7023 | var i;
|
7024 | var value;
|
7025 | var single = remove ? this.removeListener : this.addListener;
|
7026 | var multiple = remove ? this.removeListeners : this.addListeners;
|
7027 |
|
7028 | if (typeof evt === 'object' && !(evt instanceof RegExp)) {
|
7029 | for (i in evt) {
|
7030 | if (evt.hasOwnProperty(i) && (value = evt[i])) {
|
7031 |
|
7032 | if (typeof value === 'function') {
|
7033 | single.call(this, i, value);
|
7034 | } else {
|
7035 |
|
7036 | multiple.call(this, i, value);
|
7037 | }
|
7038 | }
|
7039 | }
|
7040 | } else {
|
7041 |
|
7042 |
|
7043 |
|
7044 | i = listeners.length;
|
7045 |
|
7046 | while (i--) {
|
7047 | single.call(this, evt, listeners[i]);
|
7048 | }
|
7049 | }
|
7050 |
|
7051 | return this;
|
7052 | };
|
7053 | |
7054 |
|
7055 |
|
7056 |
|
7057 |
|
7058 |
|
7059 |
|
7060 |
|
7061 |
|
7062 |
|
7063 |
|
7064 | proto.removeEvent = function removeEvent(evt) {
|
7065 | var type = typeof evt;
|
7066 |
|
7067 | var events = this._getEvents();
|
7068 |
|
7069 | var key;
|
7070 |
|
7071 | if (type === 'string') {
|
7072 |
|
7073 | delete events[evt];
|
7074 | } else if (evt instanceof RegExp) {
|
7075 |
|
7076 | for (key in events) {
|
7077 | if (events.hasOwnProperty(key) && evt.test(key)) {
|
7078 | delete events[key];
|
7079 | }
|
7080 | }
|
7081 | } else {
|
7082 |
|
7083 | delete this._events;
|
7084 | }
|
7085 |
|
7086 | return this;
|
7087 | };
|
7088 | |
7089 |
|
7090 |
|
7091 |
|
7092 |
|
7093 |
|
7094 |
|
7095 | proto.removeAllListeners = alias('removeEvent');
|
7096 | |
7097 |
|
7098 |
|
7099 |
|
7100 |
|
7101 |
|
7102 |
|
7103 |
|
7104 |
|
7105 |
|
7106 |
|
7107 |
|
7108 |
|
7109 | proto.emitEvent = function emitEvent(evt, args) {
|
7110 | var listenersMap = this.getListenersAsObject(evt);
|
7111 | var listeners;
|
7112 | var listener;
|
7113 | var i;
|
7114 | var key;
|
7115 | var response;
|
7116 |
|
7117 | for (key in listenersMap) {
|
7118 | if (listenersMap.hasOwnProperty(key)) {
|
7119 | listeners = listenersMap[key].slice(0);
|
7120 |
|
7121 | for (i = 0; i < listeners.length; i++) {
|
7122 |
|
7123 |
|
7124 | listener = listeners[i];
|
7125 |
|
7126 | if (listener.once === true) {
|
7127 | this.removeListener(evt, listener.listener);
|
7128 | }
|
7129 |
|
7130 | response = listener.listener.apply(this, args || []);
|
7131 |
|
7132 | if (response === this._getOnceReturnValue()) {
|
7133 | this.removeListener(evt, listener.listener);
|
7134 | }
|
7135 | }
|
7136 | }
|
7137 | }
|
7138 |
|
7139 | return this;
|
7140 | };
|
7141 | |
7142 |
|
7143 |
|
7144 |
|
7145 |
|
7146 | proto.trigger = alias('emitEvent');
|
7147 | |
7148 |
|
7149 |
|
7150 |
|
7151 |
|
7152 |
|
7153 |
|
7154 |
|
7155 |
|
7156 | proto.emit = function emit(evt) {
|
7157 | var args = Array.prototype.slice.call(arguments, 1);
|
7158 | return this.emitEvent(evt, args);
|
7159 | };
|
7160 | |
7161 |
|
7162 |
|
7163 |
|
7164 |
|
7165 |
|
7166 |
|
7167 |
|
7168 |
|
7169 |
|
7170 | proto.setOnceReturnValue = function setOnceReturnValue(value) {
|
7171 | this._onceReturnValue = value;
|
7172 | return this;
|
7173 | };
|
7174 | |
7175 |
|
7176 |
|
7177 |
|
7178 |
|
7179 |
|
7180 |
|
7181 |
|
7182 |
|
7183 |
|
7184 | proto._getOnceReturnValue = function _getOnceReturnValue() {
|
7185 | if (this.hasOwnProperty('_onceReturnValue')) {
|
7186 | return this._onceReturnValue;
|
7187 | } else {
|
7188 | return true;
|
7189 | }
|
7190 | };
|
7191 | |
7192 |
|
7193 |
|
7194 |
|
7195 |
|
7196 |
|
7197 |
|
7198 |
|
7199 | proto._getEvents = function _getEvents() {
|
7200 | return this._events || (this._events = {});
|
7201 | };
|
7202 | |
7203 |
|
7204 |
|
7205 |
|
7206 |
|
7207 |
|
7208 |
|
7209 | EventEmitter.noConflict = function noConflict() {
|
7210 | exports.EventEmitter = originalGlobalValue;
|
7211 | return EventEmitter;
|
7212 | };
|
7213 |
|
7214 |
|
7215 | if (true) {
|
7216 | !(__WEBPACK_AMD_DEFINE_RESULT__ = (function () {
|
7217 | return EventEmitter;
|
7218 | }).call(exports, __webpack_require__, exports, module),
|
7219 | __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
7220 | } else if (typeof module === 'object' && module.exports) {
|
7221 | module.exports = EventEmitter;
|
7222 | } else {
|
7223 | exports.EventEmitter = EventEmitter;
|
7224 | }
|
7225 | })(typeof window !== 'undefined' ? window : this || {});
|
7226 |
|
7227 | }),
|
7228 |
|
7229 | (function(module, exports, __webpack_require__) {
|
7230 |
|
7231 | var Core = {};
|
7232 |
|
7233 | var Global = __webpack_require__(1);
|
7234 |
|
7235 | Core.Global = Global;
|
7236 | Core.version = Global.version;
|
7237 | Core.Chart = __webpack_require__(12);
|
7238 | Core.Shape = __webpack_require__(6);
|
7239 | Core.G = __webpack_require__(3);
|
7240 | Core.Util = __webpack_require__(0);
|
7241 |
|
7242 | Core.track = function (enable) {
|
7243 | Global.trackable = enable;
|
7244 | };
|
7245 |
|
7246 | __webpack_require__(89);
|
7247 |
|
7248 | module.exports = Core;
|
7249 |
|
7250 | }),
|
7251 |
|
7252 | (function(module, exports, __webpack_require__) {
|
7253 |
|
7254 |
|
7255 |
|
7256 |
|
7257 |
|
7258 | var Util = __webpack_require__(0);
|
7259 |
|
7260 | var color1 = '#E8E8E8';
|
7261 |
|
7262 | var color2 = '#808080';
|
7263 |
|
7264 | var defaultAxis = {
|
7265 | label: {
|
7266 | fill: color2,
|
7267 | fontSize: 10
|
7268 | },
|
7269 | line: {
|
7270 | stroke: color1,
|
7271 | lineWidth: 1
|
7272 | },
|
7273 | grid: {
|
7274 | type: 'line',
|
7275 | stroke: color1,
|
7276 | lineWidth: 1,
|
7277 | lineDash: [2]
|
7278 | },
|
7279 | tickLine: null,
|
7280 | labelOffset: 7.5
|
7281 | };
|
7282 | var Theme = {
|
7283 | fontFamily: '"Helvetica Neue", "San Francisco", Helvetica, Tahoma, Arial, "PingFang SC", "Hiragino Sans GB", "Heiti SC", "Microsoft YaHei", sans-serif',
|
7284 | defaultColor: '#1890FF',
|
7285 | pixelRatio: 1,
|
7286 | padding: 'auto',
|
7287 | appendPadding: 15,
|
7288 | colors: ['#1890FF', '#2FC25B', '#FACC14', '#223273', '#8543E0', '#13C2C2', '#3436C7', '#F04864'],
|
7289 | shapes: {
|
7290 | line: ['line', 'dash'],
|
7291 | point: ['circle', 'hollowCircle']
|
7292 | },
|
7293 | sizes: [4, 10],
|
7294 | axis: {
|
7295 | common: defaultAxis,
|
7296 |
|
7297 | bottom: Util.mix({}, defaultAxis, {
|
7298 | grid: null
|
7299 | }),
|
7300 | left: Util.mix({}, defaultAxis, {
|
7301 | line: null
|
7302 | }),
|
7303 | right: Util.mix({}, defaultAxis, {
|
7304 | line: null
|
7305 | }),
|
7306 | circle: Util.mix({}, defaultAxis, {
|
7307 | line: null
|
7308 | }),
|
7309 | radius: Util.mix({}, defaultAxis, {
|
7310 | labelOffset: 4
|
7311 | })
|
7312 | },
|
7313 | shape: {
|
7314 | line: {
|
7315 | lineWidth: 2,
|
7316 | lineJoin: 'round',
|
7317 | lineCap: 'round'
|
7318 | },
|
7319 | point: {
|
7320 | lineWidth: 0,
|
7321 | size: 3
|
7322 | },
|
7323 | area: {
|
7324 | fillOpacity: 0.1
|
7325 | }
|
7326 | },
|
7327 | _defaultAxis: defaultAxis
|
7328 | };
|
7329 | module.exports = Theme;
|
7330 |
|
7331 | }),
|
7332 |
|
7333 | (function(module, exports) {
|
7334 |
|
7335 | var DomUtil;
|
7336 |
|
7337 |
|
7338 |
|
7339 |
|
7340 |
|
7341 |
|
7342 | var supportsEventListenerOptions = function () {
|
7343 | var supports = false;
|
7344 |
|
7345 | try {
|
7346 | var options = Object.defineProperty({}, 'passive', {
|
7347 | get: function get() {
|
7348 | supports = true;
|
7349 | }
|
7350 | });
|
7351 | window.addEventListener('e', null, options);
|
7352 | } catch (e) {
|
7353 | }
|
7354 |
|
7355 | return supports;
|
7356 | }();
|
7357 |
|
7358 |
|
7359 |
|
7360 | var eventListenerOptions = supportsEventListenerOptions ? {
|
7361 | passive: true
|
7362 | } : false;
|
7363 |
|
7364 | function createEvent(type, chart, x, y, nativeEvent) {
|
7365 | return {
|
7366 | type: type,
|
7367 | chart: chart,
|
7368 | native: nativeEvent || null,
|
7369 | x: x !== undefined ? x : null,
|
7370 | y: y !== undefined ? y : null
|
7371 | };
|
7372 | }
|
7373 |
|
7374 | function fromNativeEvent(event, chart) {
|
7375 | var type = event.type;
|
7376 | var point = {};
|
7377 | var touches = event.targetTouches;
|
7378 |
|
7379 | if (touches && touches.length > 0) {
|
7380 | point.x = touches[0].clientX;
|
7381 | point.y = touches[0].clientY;
|
7382 | } else {
|
7383 | point.x = event.clientX;
|
7384 | point.y = event.clientY;
|
7385 | }
|
7386 |
|
7387 | var canvas = chart.get('canvas');
|
7388 | var pos = DomUtil.getRelativePosition(point, canvas);
|
7389 | return createEvent(type, chart, pos.x, pos.y, event);
|
7390 | }
|
7391 |
|
7392 | DomUtil = {
|
7393 |
|
7394 | isWx: typeof wx === 'object' && typeof wx.getSystemInfoSync === 'function',
|
7395 |
|
7396 | isMy: typeof my === 'object' && typeof my.getSystemInfoSync === 'function',
|
7397 |
|
7398 | isNode: typeof module !== 'undefined' && typeof module.exports !== 'undefined',
|
7399 |
|
7400 | isBrowser: typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.sessionStorage !== 'undefined',
|
7401 |
|
7402 | getPixelRatio: function getPixelRatio() {
|
7403 | return window && window.devicePixelRatio || 1;
|
7404 | },
|
7405 | getStyle: function getStyle(el, property) {
|
7406 | return el.currentStyle ? el.currentStyle[property] : document.defaultView.getComputedStyle(el, null).getPropertyValue(property);
|
7407 | },
|
7408 | getWidth: function getWidth(el) {
|
7409 | var width = this.getStyle(el, 'width');
|
7410 |
|
7411 | if (width === 'auto') {
|
7412 | width = el.offsetWidth;
|
7413 | }
|
7414 |
|
7415 | return parseFloat(width);
|
7416 | },
|
7417 | getHeight: function getHeight(el) {
|
7418 | var height = this.getStyle(el, 'height');
|
7419 |
|
7420 | if (height === 'auto') {
|
7421 | height = el.offsetHeight;
|
7422 | }
|
7423 |
|
7424 | return parseFloat(height);
|
7425 | },
|
7426 | getDomById: function getDomById(id) {
|
7427 | if (!id) {
|
7428 | return null;
|
7429 | }
|
7430 |
|
7431 | return document.getElementById(id);
|
7432 | },
|
7433 | getRelativePosition: function getRelativePosition(point, canvas) {
|
7434 | var canvasDom = canvas.get('el');
|
7435 |
|
7436 | var _canvasDom$getBoundin = canvasDom.getBoundingClientRect(),
|
7437 | top = _canvasDom$getBoundin.top,
|
7438 | right = _canvasDom$getBoundin.right,
|
7439 | bottom = _canvasDom$getBoundin.bottom,
|
7440 | left = _canvasDom$getBoundin.left;
|
7441 |
|
7442 | var paddingLeft = parseFloat(this.getStyle(canvasDom, 'padding-left'));
|
7443 | var paddingTop = parseFloat(this.getStyle(canvasDom, 'padding-top'));
|
7444 | var paddingRight = parseFloat(this.getStyle(canvasDom, 'padding-right'));
|
7445 | var paddingBottom = parseFloat(this.getStyle(canvasDom, 'padding-bottom'));
|
7446 | var width = right - left - paddingLeft - paddingRight;
|
7447 | var height = bottom - top - paddingTop - paddingBottom;
|
7448 | var pixelRatio = canvas.get('pixelRatio');
|
7449 | var mouseX = (point.x - left - paddingLeft) / width * canvasDom.width / pixelRatio;
|
7450 | var mouseY = (point.y - top - paddingTop) / height * canvasDom.height / pixelRatio;
|
7451 | return {
|
7452 | x: mouseX,
|
7453 | y: mouseY
|
7454 | };
|
7455 | },
|
7456 | addEventListener: function addEventListener(source, type, listener) {
|
7457 | DomUtil.isBrowser && source.addEventListener(type, listener, eventListenerOptions);
|
7458 | },
|
7459 | removeEventListener: function removeEventListener(source, type, listener) {
|
7460 | DomUtil.isBrowser && source.removeEventListener(type, listener, eventListenerOptions);
|
7461 | },
|
7462 | createEvent: function createEvent(event, chart) {
|
7463 | return fromNativeEvent(event, chart);
|
7464 | },
|
7465 | measureText: function measureText(text, font, ctx) {
|
7466 | if (!ctx) {
|
7467 | ctx = document.createElement('canvas').getContext('2d');
|
7468 | }
|
7469 |
|
7470 | ctx.font = font || '12px sans-serif';
|
7471 | return ctx.measureText(text);
|
7472 | }
|
7473 | };
|
7474 | module.exports = DomUtil;
|
7475 |
|
7476 | }),
|
7477 |
|
7478 | (function(module, exports, __webpack_require__) {
|
7479 |
|
7480 | var toString = __webpack_require__(30);
|
7481 |
|
7482 | var upperFirst = function upperFirst(value) {
|
7483 | var str = toString(value);
|
7484 | return str.charAt(0).toUpperCase() + str.substring(1);
|
7485 | };
|
7486 |
|
7487 | module.exports = upperFirst;
|
7488 |
|
7489 | }),
|
7490 |
|
7491 | (function(module, exports, __webpack_require__) {
|
7492 |
|
7493 | var toString = __webpack_require__(30);
|
7494 |
|
7495 | var lowerFirst = function lowerFirst(value) {
|
7496 | var str = toString(value);
|
7497 | return str.charAt(0).toLowerCase() + str.substring(1);
|
7498 | };
|
7499 |
|
7500 | module.exports = lowerFirst;
|
7501 |
|
7502 | }),
|
7503 |
|
7504 | (function(module, exports, __webpack_require__) {
|
7505 |
|
7506 |
|
7507 |
|
7508 |
|
7509 |
|
7510 |
|
7511 |
|
7512 | var isType = __webpack_require__(10);
|
7513 |
|
7514 | var isBoolean = function isBoolean(value) {
|
7515 | return isType(value, 'Boolean');
|
7516 | };
|
7517 |
|
7518 | module.exports = isBoolean;
|
7519 |
|
7520 | }),
|
7521 |
|
7522 | (function(module, exports, __webpack_require__) {
|
7523 |
|
7524 |
|
7525 |
|
7526 |
|
7527 |
|
7528 |
|
7529 | var isType = __webpack_require__(10);
|
7530 |
|
7531 | var isFunction = function isFunction(value) {
|
7532 | return isType(value, 'Function');
|
7533 | };
|
7534 |
|
7535 | module.exports = isFunction;
|
7536 |
|
7537 | }),
|
7538 |
|
7539 | (function(module, exports) {
|
7540 |
|
7541 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
|
7542 | return typeof obj;
|
7543 | } : function (obj) {
|
7544 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
7545 | };
|
7546 |
|
7547 | var isObjectLike = function isObjectLike(value) {
|
7548 | |
7549 |
|
7550 |
|
7551 |
|
7552 |
|
7553 |
|
7554 | return (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && value !== null;
|
7555 | };
|
7556 |
|
7557 | module.exports = isObjectLike;
|
7558 |
|
7559 | }),
|
7560 |
|
7561 | (function(module, exports, __webpack_require__) {
|
7562 |
|
7563 | var isPlainObject = __webpack_require__(32);
|
7564 |
|
7565 | var isArray = __webpack_require__(11);
|
7566 |
|
7567 | var MAX_MIX_LEVEL = 5;
|
7568 |
|
7569 | function _deepMix(dist, src, level, maxLevel) {
|
7570 | level = level || 0;
|
7571 | maxLevel = maxLevel || MAX_MIX_LEVEL;
|
7572 |
|
7573 | for (var key in src) {
|
7574 | if (src.hasOwnProperty(key)) {
|
7575 | var value = src[key];
|
7576 |
|
7577 | if (value !== null && isPlainObject(value)) {
|
7578 | if (!isPlainObject(dist[key])) {
|
7579 | dist[key] = {};
|
7580 | }
|
7581 |
|
7582 | if (level < maxLevel) {
|
7583 | _deepMix(dist[key], value, level + 1, maxLevel);
|
7584 | } else {
|
7585 | dist[key] = src[key];
|
7586 | }
|
7587 | } else if (isArray(value)) {
|
7588 | dist[key] = [];
|
7589 | dist[key] = dist[key].concat(value);
|
7590 | } else if (value !== undefined) {
|
7591 | dist[key] = value;
|
7592 | }
|
7593 | }
|
7594 | }
|
7595 | }
|
7596 |
|
7597 | var deepMix = function deepMix() {
|
7598 | var args = new Array(arguments.length);
|
7599 | var length = args.length;
|
7600 |
|
7601 | for (var i = 0; i < length; i++) {
|
7602 | args[i] = arguments[i];
|
7603 | }
|
7604 |
|
7605 | var rst = args[0];
|
7606 |
|
7607 | for (var _i = 1; _i < length; _i++) {
|
7608 | _deepMix(rst, args[_i]);
|
7609 | }
|
7610 |
|
7611 | return rst;
|
7612 | };
|
7613 |
|
7614 | module.exports = deepMix;
|
7615 |
|
7616 | }),
|
7617 |
|
7618 | (function(module, exports, __webpack_require__) {
|
7619 |
|
7620 | var Util = __webpack_require__(0);
|
7621 |
|
7622 | var Plot =
|
7623 |
|
7624 | function () {
|
7625 | function Plot(cfg) {
|
7626 | Util.mix(this, cfg);
|
7627 |
|
7628 | this._init();
|
7629 | }
|
7630 |
|
7631 | var _proto = Plot.prototype;
|
7632 |
|
7633 | _proto._init = function _init() {
|
7634 | var self = this;
|
7635 | var start = self.start;
|
7636 | var end = self.end;
|
7637 | var xMin = Math.min(start.x, end.x);
|
7638 | var xMax = Math.max(start.x, end.x);
|
7639 | var yMin = Math.min(start.y, end.y);
|
7640 | var yMax = Math.max(start.y, end.y);
|
7641 | this.tl = {
|
7642 | x: xMin,
|
7643 | y: yMin
|
7644 | };
|
7645 | this.tr = {
|
7646 | x: xMax,
|
7647 | y: yMin
|
7648 | };
|
7649 | this.bl = {
|
7650 | x: xMin,
|
7651 | y: yMax
|
7652 | };
|
7653 | this.br = {
|
7654 | x: xMax,
|
7655 | y: yMax
|
7656 | };
|
7657 | this.width = xMax - xMin;
|
7658 | this.height = yMax - yMin;
|
7659 | };
|
7660 | |
7661 |
|
7662 |
|
7663 |
|
7664 |
|
7665 |
|
7666 |
|
7667 | _proto.reset = function reset(start, end) {
|
7668 | this.start = start;
|
7669 | this.end = end;
|
7670 |
|
7671 | this._init();
|
7672 | };
|
7673 | |
7674 |
|
7675 |
|
7676 |
|
7677 |
|
7678 |
|
7679 |
|
7680 |
|
7681 | _proto.isInRange = function isInRange(x, y) {
|
7682 | if (Util.isObject(x)) {
|
7683 | y = x.y;
|
7684 | x = x.x;
|
7685 | }
|
7686 |
|
7687 | var tl = this.tl;
|
7688 | var br = this.br;
|
7689 | return tl.x <= x && x <= br.x && tl.y <= y && y <= br.y;
|
7690 | };
|
7691 |
|
7692 | return Plot;
|
7693 | }();
|
7694 |
|
7695 | module.exports = Plot;
|
7696 |
|
7697 | }),
|
7698 |
|
7699 | (function(module, exports, __webpack_require__) {
|
7700 |
|
7701 | var Coord = __webpack_require__(23);
|
7702 |
|
7703 | __webpack_require__(62);
|
7704 |
|
7705 | module.exports = Coord;
|
7706 |
|
7707 | }),
|
7708 |
|
7709 | (function(module, exports, __webpack_require__) {
|
7710 |
|
7711 | function _inheritsLoose(subClass, superClass) {
|
7712 | subClass.prototype = Object.create(superClass.prototype);
|
7713 | subClass.prototype.constructor = subClass;
|
7714 | subClass.__proto__ = superClass;
|
7715 | }
|
7716 |
|
7717 | var Base = __webpack_require__(23);
|
7718 |
|
7719 | var Cartesian =
|
7720 |
|
7721 | function (_Base) {
|
7722 | _inheritsLoose(Cartesian, _Base);
|
7723 |
|
7724 | function Cartesian() {
|
7725 | return _Base.apply(this, arguments) || this;
|
7726 | }
|
7727 |
|
7728 | var _proto = Cartesian.prototype;
|
7729 |
|
7730 | _proto._initDefaultCfg = function _initDefaultCfg() {
|
7731 | this.type = 'cartesian';
|
7732 | this.transposed = false;
|
7733 | this.isRect = true;
|
7734 | };
|
7735 |
|
7736 | _proto.init = function init(start, end) {
|
7737 | this.x = {
|
7738 | start: start.x,
|
7739 | end: end.x
|
7740 | };
|
7741 | this.y = {
|
7742 | start: start.y,
|
7743 | end: end.y
|
7744 | };
|
7745 | };
|
7746 |
|
7747 | _proto.convertPoint = function convertPoint(point) {
|
7748 | var self = this;
|
7749 | var transposed = self.transposed;
|
7750 | var xDim = transposed ? 'y' : 'x';
|
7751 | var yDim = transposed ? 'x' : 'y';
|
7752 | var x = self.x;
|
7753 | var y = self.y;
|
7754 | return {
|
7755 | x: x.start + (x.end - x.start) * point[xDim],
|
7756 | y: y.start + (y.end - y.start) * point[yDim]
|
7757 | };
|
7758 | };
|
7759 |
|
7760 | _proto.invertPoint = function invertPoint(point) {
|
7761 | var self = this;
|
7762 | var transposed = self.transposed;
|
7763 | var xDim = transposed ? 'y' : 'x';
|
7764 | var yDim = transposed ? 'x' : 'y';
|
7765 | var x = self.x;
|
7766 | var y = self.y;
|
7767 | var rst = {};
|
7768 | rst[xDim] = (point.x - x.start) / (x.end - x.start);
|
7769 | rst[yDim] = (point.y - y.start) / (y.end - y.start);
|
7770 | return rst;
|
7771 | };
|
7772 |
|
7773 | return Cartesian;
|
7774 | }(Base);
|
7775 |
|
7776 | Base.Cartesian = Cartesian;
|
7777 | Base.Rect = Cartesian;
|
7778 | module.exports = Cartesian;
|
7779 |
|
7780 | }),
|
7781 |
|
7782 | (function(module, exports, __webpack_require__) {
|
7783 |
|
7784 | module.exports = {
|
7785 | Position: __webpack_require__(64),
|
7786 | Shape: __webpack_require__(65),
|
7787 | Size: __webpack_require__(66),
|
7788 | Color: __webpack_require__(67)
|
7789 | };
|
7790 |
|
7791 | }),
|
7792 |
|
7793 | (function(module, exports, __webpack_require__) {
|
7794 |
|
7795 | function _inheritsLoose(subClass, superClass) {
|
7796 | subClass.prototype = Object.create(superClass.prototype);
|
7797 | subClass.prototype.constructor = subClass;
|
7798 | subClass.__proto__ = superClass;
|
7799 | }
|
7800 |
|
7801 | var isNil = __webpack_require__(9);
|
7802 |
|
7803 | var isArray = __webpack_require__(11);
|
7804 |
|
7805 | var each = __webpack_require__(4);
|
7806 |
|
7807 | var Base = __webpack_require__(19);
|
7808 |
|
7809 | var Position =
|
7810 |
|
7811 | function (_Base) {
|
7812 | _inheritsLoose(Position, _Base);
|
7813 |
|
7814 | function Position(cfg) {
|
7815 | var _this;
|
7816 |
|
7817 | _this = _Base.call(this, cfg) || this;
|
7818 | _this.names = ['x', 'y'];
|
7819 | _this.type = 'position';
|
7820 | return _this;
|
7821 | }
|
7822 |
|
7823 | var _proto = Position.prototype;
|
7824 |
|
7825 | _proto.mapping = function mapping(x, y) {
|
7826 | var scales = this.scales;
|
7827 | var coord = this.coord;
|
7828 | var scaleX = scales[0];
|
7829 | var scaleY = scales[1];
|
7830 | var rstX;
|
7831 | var rstY;
|
7832 | var obj;
|
7833 |
|
7834 | if (isNil(x) || isNil(y)) {
|
7835 | return [];
|
7836 | }
|
7837 |
|
7838 | if (isArray(y) && isArray(x)) {
|
7839 | rstX = [];
|
7840 | rstY = [];
|
7841 |
|
7842 | for (var i = 0, j = 0, xLen = x.length, yLen = y.length; i < xLen && j < yLen; i++, j++) {
|
7843 | obj = coord.convertPoint({
|
7844 | x: scaleX.scale(x[i]),
|
7845 | y: scaleY.scale(y[j])
|
7846 | });
|
7847 | rstX.push(obj.x);
|
7848 | rstY.push(obj.y);
|
7849 | }
|
7850 | } else if (isArray(y)) {
|
7851 | x = scaleX.scale(x);
|
7852 | rstY = [];
|
7853 | each(y, function (yVal) {
|
7854 | yVal = scaleY.scale(yVal);
|
7855 | obj = coord.convertPoint({
|
7856 | x: x,
|
7857 | y: yVal
|
7858 | });
|
7859 |
|
7860 | if (rstX && rstX !== obj.x) {
|
7861 | if (!isArray(rstX)) {
|
7862 | rstX = [rstX];
|
7863 | }
|
7864 |
|
7865 | rstX.push(obj.x);
|
7866 | } else {
|
7867 | rstX = obj.x;
|
7868 | }
|
7869 |
|
7870 | rstY.push(obj.y);
|
7871 | });
|
7872 | } else if (isArray(x)) {
|
7873 | y = scaleY.scale(y);
|
7874 | rstX = [];
|
7875 | each(x, function (xVal) {
|
7876 | xVal = scaleX.scale(xVal);
|
7877 | obj = coord.convertPoint({
|
7878 | x: xVal,
|
7879 | y: y
|
7880 | });
|
7881 |
|
7882 | if (rstY && rstY !== obj.y) {
|
7883 | if (!isArray(rstY)) {
|
7884 | rstY = [rstY];
|
7885 | }
|
7886 |
|
7887 | rstY.push(obj.y);
|
7888 | } else {
|
7889 | rstY = obj.y;
|
7890 | }
|
7891 |
|
7892 | rstX.push(obj.x);
|
7893 | });
|
7894 | } else {
|
7895 | x = scaleX.scale(x);
|
7896 | y = scaleY.scale(y);
|
7897 | var point = coord.convertPoint({
|
7898 | x: x,
|
7899 | y: y
|
7900 | });
|
7901 | rstX = point.x;
|
7902 | rstY = point.y;
|
7903 | }
|
7904 |
|
7905 | return [rstX, rstY];
|
7906 | };
|
7907 |
|
7908 | return Position;
|
7909 | }(Base);
|
7910 |
|
7911 | module.exports = Position;
|
7912 |
|
7913 | }),
|
7914 |
|
7915 | (function(module, exports, __webpack_require__) {
|
7916 |
|
7917 | function _inheritsLoose(subClass, superClass) {
|
7918 | subClass.prototype = Object.create(superClass.prototype);
|
7919 | subClass.prototype.constructor = subClass;
|
7920 | subClass.__proto__ = superClass;
|
7921 | }
|
7922 |
|
7923 | var Base = __webpack_require__(19);
|
7924 |
|
7925 | var Shape =
|
7926 |
|
7927 | function (_Base) {
|
7928 | _inheritsLoose(Shape, _Base);
|
7929 |
|
7930 | function Shape(cfg) {
|
7931 | var _this;
|
7932 |
|
7933 | _this = _Base.call(this, cfg) || this;
|
7934 | _this.names = ['shape'];
|
7935 | _this.type = 'shape';
|
7936 | _this.gradient = null;
|
7937 | return _this;
|
7938 | }
|
7939 | |
7940 |
|
7941 |
|
7942 |
|
7943 |
|
7944 | var _proto = Shape.prototype;
|
7945 |
|
7946 | _proto.getLinearValue = function getLinearValue(percent) {
|
7947 | var values = this.values;
|
7948 | var index = Math.round((values.length - 1) * percent);
|
7949 | return values[index];
|
7950 | };
|
7951 |
|
7952 | return Shape;
|
7953 | }(Base);
|
7954 |
|
7955 | module.exports = Shape;
|
7956 |
|
7957 | }),
|
7958 |
|
7959 | (function(module, exports, __webpack_require__) {
|
7960 |
|
7961 | function _inheritsLoose(subClass, superClass) {
|
7962 | subClass.prototype = Object.create(superClass.prototype);
|
7963 | subClass.prototype.constructor = subClass;
|
7964 | subClass.__proto__ = superClass;
|
7965 | }
|
7966 |
|
7967 | var Base = __webpack_require__(19);
|
7968 |
|
7969 | var Size =
|
7970 |
|
7971 | function (_Base) {
|
7972 | _inheritsLoose(Size, _Base);
|
7973 |
|
7974 | function Size(cfg) {
|
7975 | var _this;
|
7976 |
|
7977 | _this = _Base.call(this, cfg) || this;
|
7978 | _this.names = ['size'];
|
7979 | _this.type = 'size';
|
7980 | _this.gradient = null;
|
7981 | return _this;
|
7982 | }
|
7983 |
|
7984 | return Size;
|
7985 | }(Base);
|
7986 |
|
7987 | module.exports = Size;
|
7988 |
|
7989 | }),
|
7990 |
|
7991 | (function(module, exports, __webpack_require__) {
|
7992 |
|
7993 | function _inheritsLoose(subClass, superClass) {
|
7994 | subClass.prototype = Object.create(superClass.prototype);
|
7995 | subClass.prototype.constructor = subClass;
|
7996 | subClass.__proto__ = superClass;
|
7997 | }
|
7998 |
|
7999 | var Util = __webpack_require__(0);
|
8000 |
|
8001 | var ColorUtil = __webpack_require__(68);
|
8002 |
|
8003 | var Base = __webpack_require__(19);
|
8004 |
|
8005 | var Color =
|
8006 |
|
8007 | function (_Base) {
|
8008 | _inheritsLoose(Color, _Base);
|
8009 |
|
8010 | function Color(cfg) {
|
8011 | var _this;
|
8012 |
|
8013 | _this = _Base.call(this, cfg) || this;
|
8014 | _this.names = ['color'];
|
8015 | _this.type = 'color';
|
8016 | _this.gradient = null;
|
8017 |
|
8018 | if (Util.isString(_this.values)) {
|
8019 | _this.linear = true;
|
8020 | }
|
8021 |
|
8022 | return _this;
|
8023 | }
|
8024 | |
8025 |
|
8026 |
|
8027 |
|
8028 |
|
8029 | var _proto = Color.prototype;
|
8030 |
|
8031 | _proto.getLinearValue = function getLinearValue(percent) {
|
8032 | var gradient = this.gradient;
|
8033 |
|
8034 | if (!gradient) {
|
8035 | var values = this.values;
|
8036 | gradient = ColorUtil.gradient(values);
|
8037 | this.gradient = gradient;
|
8038 | }
|
8039 |
|
8040 | return gradient(percent);
|
8041 | };
|
8042 |
|
8043 | return Color;
|
8044 | }(Base);
|
8045 |
|
8046 | module.exports = Color;
|
8047 |
|
8048 | }),
|
8049 |
|
8050 | (function(module, exports, __webpack_require__) {
|
8051 |
|
8052 | var Util = __webpack_require__(0);
|
8053 |
|
8054 |
|
8055 | function getValue(start, end, percent, index) {
|
8056 | var value = start[index] + (end[index] - start[index]) * percent;
|
8057 | return value;
|
8058 | }
|
8059 |
|
8060 |
|
8061 | function arr2hex(arr) {
|
8062 | return '#' + toRGBValue(arr[0]) + toRGBValue(arr[1]) + toRGBValue(arr[2]);
|
8063 | }
|
8064 |
|
8065 | function toRGBValue(value) {
|
8066 | value = Math.round(value);
|
8067 | value = value.toString(16);
|
8068 |
|
8069 | if (value.length === 1) {
|
8070 | value = '0' + value;
|
8071 | }
|
8072 |
|
8073 | return value;
|
8074 | }
|
8075 |
|
8076 | function calColor(colors, percent) {
|
8077 | var steps = colors.length - 1;
|
8078 | var step = Math.floor(steps * percent);
|
8079 | var left = steps * percent - step;
|
8080 | var start = colors[step];
|
8081 | var end = step === steps ? start : colors[step + 1];
|
8082 | var rgb = arr2hex([getValue(start, end, left, 0), getValue(start, end, left, 1), getValue(start, end, left, 2)]);
|
8083 | return rgb;
|
8084 | }
|
8085 |
|
8086 | function hex2arr(str) {
|
8087 | var arr = [];
|
8088 | arr.push(parseInt(str.substr(1, 2), 16));
|
8089 | arr.push(parseInt(str.substr(3, 2), 16));
|
8090 | arr.push(parseInt(str.substr(5, 2), 16));
|
8091 | return arr;
|
8092 | }
|
8093 |
|
8094 | var colorCache = {
|
8095 | black: '#000000',
|
8096 | blue: '#0000ff',
|
8097 | grey: '#808080',
|
8098 | green: '#008000',
|
8099 | orange: '#ffa500',
|
8100 | pink: '#ffc0cb',
|
8101 | purple: '#800080',
|
8102 | red: '#ff0000',
|
8103 | white: '#ffffff',
|
8104 | yellow: '#ffff00'
|
8105 | };
|
8106 | var ColorUtil = {
|
8107 | |
8108 |
|
8109 |
|
8110 |
|
8111 |
|
8112 | toHex: function toHex(color) {
|
8113 | if (colorCache[color]) {
|
8114 | return colorCache[color];
|
8115 | }
|
8116 |
|
8117 | if (color[0] === '#') {
|
8118 | if (color.length === 7) {
|
8119 | return color;
|
8120 | }
|
8121 |
|
8122 | var hex = color.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, function (m, r, g, b) {
|
8123 | return '#' + r + r + g + g + b + b;
|
8124 | });
|
8125 |
|
8126 | colorCache[color] = hex;
|
8127 | return hex;
|
8128 | }
|
8129 |
|
8130 |
|
8131 | var rst = color.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
|
8132 | rst.shift();
|
8133 | rst = arr2hex(rst);
|
8134 | colorCache[color] = rst;
|
8135 | return rst;
|
8136 | },
|
8137 | hex2arr: hex2arr,
|
8138 |
|
8139 | |
8140 |
|
8141 |
|
8142 |
|
8143 |
|
8144 | gradient: function gradient(colors) {
|
8145 | var points = [];
|
8146 |
|
8147 | if (Util.isString(colors)) {
|
8148 | colors = colors.split('-');
|
8149 | }
|
8150 |
|
8151 | Util.each(colors, function (color) {
|
8152 | if (color.indexOf('#') === -1) {
|
8153 | color = ColorUtil.toHex(color);
|
8154 | }
|
8155 |
|
8156 | points.push(hex2arr(color));
|
8157 | });
|
8158 | return function (percent) {
|
8159 | return calColor(points, percent);
|
8160 | };
|
8161 | }
|
8162 | };
|
8163 | module.exports = ColorUtil;
|
8164 |
|
8165 | }),
|
8166 |
|
8167 | (function(module, exports, __webpack_require__) {
|
8168 |
|
8169 | var Util = __webpack_require__(0);
|
8170 |
|
8171 | var Global = __webpack_require__(1);
|
8172 |
|
8173 | var Scale = __webpack_require__(70);
|
8174 |
|
8175 | var SCALE_TYPES_MAP = {
|
8176 | linear: 'Linear',
|
8177 | cat: 'Cat',
|
8178 | timeCat: 'TimeCat',
|
8179 | identity: 'Identity'
|
8180 | };
|
8181 |
|
8182 | var ScaleController =
|
8183 |
|
8184 | function () {
|
8185 | function ScaleController(cfg) {
|
8186 |
|
8187 | this.defs = {};
|
8188 | Util.mix(this, cfg);
|
8189 | }
|
8190 |
|
8191 | var _proto = ScaleController.prototype;
|
8192 |
|
8193 | _proto._getDef = function _getDef(field) {
|
8194 | var defs = this.defs;
|
8195 | var def = null;
|
8196 |
|
8197 | if (Global.scales[field] || defs[field]) {
|
8198 | def = Util.mix({}, Global.scales[field]);
|
8199 | Util.each(defs[field], function (v, k) {
|
8200 | if (Util.isNil(v)) {
|
8201 | delete def[k];
|
8202 | } else {
|
8203 | def[k] = v;
|
8204 | }
|
8205 | });
|
8206 | }
|
8207 |
|
8208 | return def;
|
8209 | };
|
8210 |
|
8211 | _proto._getDefaultType = function _getDefaultType(field, data, def) {
|
8212 | if (def && def.type) {
|
8213 | return def.type;
|
8214 | }
|
8215 |
|
8216 | var type = 'linear';
|
8217 | var value = Util.Array.firstValue(data, field);
|
8218 |
|
8219 | if (Util.isArray(value)) {
|
8220 | value = value[0];
|
8221 | }
|
8222 |
|
8223 | if (Util.isString(value)) {
|
8224 | type = 'cat';
|
8225 | }
|
8226 |
|
8227 | return type;
|
8228 | };
|
8229 |
|
8230 | _proto._getScaleCfg = function _getScaleCfg(type, field, data, def) {
|
8231 | var values;
|
8232 |
|
8233 | if (def && def.values) {
|
8234 | values = def.values;
|
8235 | } else {
|
8236 | values = Util.Array.values(data, field);
|
8237 | }
|
8238 |
|
8239 | var cfg = {
|
8240 | field: field,
|
8241 | values: values
|
8242 | };
|
8243 |
|
8244 | if (type !== 'cat' && type !== 'timeCat') {
|
8245 | if (!def || !(def.min && def.max)) {
|
8246 | var _Util$Array$getRange = Util.Array.getRange(values),
|
8247 | min = _Util$Array$getRange.min,
|
8248 | max = _Util$Array$getRange.max;
|
8249 |
|
8250 | cfg.min = min;
|
8251 | cfg.max = max;
|
8252 | cfg.nice = true;
|
8253 | }
|
8254 | }
|
8255 |
|
8256 | if (type === 'cat' || type === 'timeCat') {
|
8257 | cfg.isRounding = false;
|
8258 | }
|
8259 |
|
8260 | return cfg;
|
8261 | };
|
8262 |
|
8263 | _proto.createScale = function createScale(field, data) {
|
8264 | var self = this;
|
8265 |
|
8266 | var def = self._getDef(field);
|
8267 |
|
8268 | var scale;
|
8269 |
|
8270 | if (!data || !data.length) {
|
8271 | if (def && def.type) {
|
8272 | scale = new Scale[SCALE_TYPES_MAP[def.type]](def);
|
8273 | } else {
|
8274 | scale = new Scale.Identity({
|
8275 | value: field,
|
8276 | field: field.toString(),
|
8277 | values: [field]
|
8278 | });
|
8279 | }
|
8280 |
|
8281 | return scale;
|
8282 | }
|
8283 |
|
8284 | var firstObj = data[0];
|
8285 | var firstValue = firstObj[field];
|
8286 |
|
8287 | if (firstValue === null) {
|
8288 | firstValue = Util.Array.firstValue(data, field);
|
8289 | }
|
8290 |
|
8291 | if (Util.isNumber(field) || Util.isNil(firstValue) && !def) {
|
8292 | scale = new Scale.Identity({
|
8293 | value: field,
|
8294 | field: field.toString(),
|
8295 | values: [field]
|
8296 | });
|
8297 | } else {
|
8298 | var type = self._getDefaultType(field, data, def);
|
8299 |
|
8300 | var cfg = self._getScaleCfg(type, field, data, def);
|
8301 |
|
8302 | def && Util.mix(cfg, def);
|
8303 | scale = new Scale[SCALE_TYPES_MAP[type]](cfg);
|
8304 | }
|
8305 |
|
8306 | return scale;
|
8307 | };
|
8308 |
|
8309 | return ScaleController;
|
8310 | }();
|
8311 |
|
8312 | module.exports = ScaleController;
|
8313 |
|
8314 | }),
|
8315 |
|
8316 | (function(module, exports, __webpack_require__) {
|
8317 |
|
8318 | var Scale = __webpack_require__(16);
|
8319 |
|
8320 | __webpack_require__(71);
|
8321 |
|
8322 | __webpack_require__(74);
|
8323 |
|
8324 | __webpack_require__(34);
|
8325 |
|
8326 | module.exports = Scale;
|
8327 |
|
8328 | }),
|
8329 |
|
8330 | (function(module, exports, __webpack_require__) {
|
8331 |
|
8332 | function _inheritsLoose(subClass, superClass) {
|
8333 | subClass.prototype = Object.create(superClass.prototype);
|
8334 | subClass.prototype.constructor = subClass;
|
8335 | subClass.__proto__ = superClass;
|
8336 | }
|
8337 |
|
8338 |
|
8339 |
|
8340 |
|
8341 |
|
8342 |
|
8343 | var isNil = __webpack_require__(9);
|
8344 |
|
8345 | var each = __webpack_require__(4);
|
8346 |
|
8347 | var Base = __webpack_require__(16);
|
8348 |
|
8349 | var numberAuto = __webpack_require__(72);
|
8350 |
|
8351 |
|
8352 |
|
8353 |
|
8354 |
|
8355 |
|
8356 | var Linear =
|
8357 |
|
8358 | function (_Base) {
|
8359 | _inheritsLoose(Linear, _Base);
|
8360 |
|
8361 | function Linear() {
|
8362 | return _Base.apply(this, arguments) || this;
|
8363 | }
|
8364 |
|
8365 | var _proto = Linear.prototype;
|
8366 |
|
8367 | _proto._initDefaultCfg = function _initDefaultCfg() {
|
8368 | _Base.prototype._initDefaultCfg.call(this);
|
8369 |
|
8370 | var self = this;
|
8371 | self.type = 'linear';
|
8372 | self.isLinear = true;
|
8373 | |
8374 |
|
8375 |
|
8376 |
|
8377 |
|
8378 |
|
8379 | self.nice = false;
|
8380 | |
8381 |
|
8382 |
|
8383 |
|
8384 |
|
8385 |
|
8386 | self.min = null;
|
8387 | |
8388 |
|
8389 |
|
8390 |
|
8391 |
|
8392 |
|
8393 | self.minLimit = null;
|
8394 | |
8395 |
|
8396 |
|
8397 |
|
8398 |
|
8399 |
|
8400 | self.max = null;
|
8401 | |
8402 |
|
8403 |
|
8404 |
|
8405 |
|
8406 |
|
8407 | self.maxLimit = null;
|
8408 | |
8409 |
|
8410 |
|
8411 |
|
8412 |
|
8413 |
|
8414 | self.tickCount = null;
|
8415 | |
8416 |
|
8417 |
|
8418 |
|
8419 |
|
8420 |
|
8421 | self.tickInterval = null;
|
8422 | |
8423 |
|
8424 |
|
8425 |
|
8426 |
|
8427 |
|
8428 | self.minTickInterval = null;
|
8429 | |
8430 |
|
8431 |
|
8432 |
|
8433 |
|
8434 | self.snapArray = null;
|
8435 | };
|
8436 | |
8437 |
|
8438 |
|
8439 |
|
8440 |
|
8441 |
|
8442 | _proto.init = function init() {
|
8443 | var self = this;
|
8444 |
|
8445 | if (!self.ticks) {
|
8446 | self.min = self.translate(self.min);
|
8447 | self.max = self.translate(self.max);
|
8448 | self.initTicks();
|
8449 | } else {
|
8450 | var ticks = self.ticks;
|
8451 | var firstValue = self.translate(ticks[0]);
|
8452 | var lastValue = self.translate(ticks[ticks.length - 1]);
|
8453 |
|
8454 | if (isNil(self.min) || self.min > firstValue) {
|
8455 | self.min = firstValue;
|
8456 | }
|
8457 |
|
8458 | if (isNil(self.max) || self.max < lastValue) {
|
8459 | self.max = lastValue;
|
8460 | }
|
8461 | }
|
8462 | };
|
8463 | |
8464 |
|
8465 |
|
8466 |
|
8467 |
|
8468 |
|
8469 |
|
8470 | _proto.calculateTicks = function calculateTicks() {
|
8471 | var min = this.min,
|
8472 | max = this.max,
|
8473 | minLimit = this.minLimit,
|
8474 | maxLimit = this.maxLimit,
|
8475 | tickCount = this.tickCount,
|
8476 | tickInterval = this.tickInterval,
|
8477 | minTickInterval = this.minTickInterval,
|
8478 | snapArray = this.snapArray;
|
8479 |
|
8480 | if (tickCount === 1) {
|
8481 | throw new Error('linear scale\'tickCount should not be 1');
|
8482 | }
|
8483 |
|
8484 | if (max < min) {
|
8485 | throw new Error("max: " + max + " should not be less than min: " + min);
|
8486 | }
|
8487 |
|
8488 | var tmp = numberAuto({
|
8489 | min: min,
|
8490 | max: max,
|
8491 | minLimit: minLimit,
|
8492 | maxLimit: maxLimit,
|
8493 | minCount: tickCount,
|
8494 | maxCount: tickCount,
|
8495 | interval: tickInterval,
|
8496 | minTickInterval: minTickInterval,
|
8497 | snapArray: snapArray
|
8498 | });
|
8499 | return tmp.ticks;
|
8500 | };
|
8501 |
|
8502 |
|
8503 | _proto.initTicks = function initTicks() {
|
8504 | var self = this;
|
8505 | var calTicks = self.calculateTicks();
|
8506 |
|
8507 | if (self.nice) {
|
8508 |
|
8509 | self.ticks = calTicks;
|
8510 | self.min = calTicks[0];
|
8511 | self.max = calTicks[calTicks.length - 1];
|
8512 | } else {
|
8513 | var ticks = [];
|
8514 | each(calTicks, function (tick) {
|
8515 | if (tick >= self.min && tick <= self.max) {
|
8516 | ticks.push(tick);
|
8517 | }
|
8518 | });
|
8519 |
|
8520 | if (!ticks.length) {
|
8521 | ticks.push(self.min);
|
8522 | ticks.push(self.max);
|
8523 | }
|
8524 |
|
8525 | self.ticks = ticks;
|
8526 | }
|
8527 | };
|
8528 | |
8529 |
|
8530 |
|
8531 |
|
8532 |
|
8533 | _proto.scale = function scale(value) {
|
8534 | if (isNil(value)) {
|
8535 | return NaN;
|
8536 | }
|
8537 |
|
8538 | var max = this.max;
|
8539 | var min = this.min;
|
8540 |
|
8541 | if (max === min) {
|
8542 | return 0;
|
8543 | }
|
8544 |
|
8545 | var percent = (value - min) / (max - min);
|
8546 | var rangeMin = this.rangeMin();
|
8547 | var rangeMax = this.rangeMax();
|
8548 | return rangeMin + percent * (rangeMax - rangeMin);
|
8549 | };
|
8550 | |
8551 |
|
8552 |
|
8553 |
|
8554 |
|
8555 | _proto.invert = function invert(value) {
|
8556 | var percent = (value - this.rangeMin()) / (this.rangeMax() - this.rangeMin());
|
8557 | return this.min + percent * (this.max - this.min);
|
8558 | };
|
8559 |
|
8560 | return Linear;
|
8561 | }(Base);
|
8562 |
|
8563 | Base.Linear = Linear;
|
8564 | module.exports = Linear;
|
8565 |
|
8566 | }),
|
8567 |
|
8568 | (function(module, exports, __webpack_require__) {
|
8569 |
|
8570 |
|
8571 |
|
8572 |
|
8573 |
|
8574 | var isNil = __webpack_require__(9);
|
8575 |
|
8576 | var isNumber = __webpack_require__(15);
|
8577 |
|
8578 | var AutoUtil = __webpack_require__(73);
|
8579 |
|
8580 | var MIN_COUNT = 5;
|
8581 | var MAX_COUNT = 7;
|
8582 | var 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];
|
8583 | var SNAP_ARRAY = [0, 1, 2, 4, 5, 10];
|
8584 |
|
8585 | module.exports = function (info) {
|
8586 | var min = info.min;
|
8587 | var max = info.max;
|
8588 | var interval = info.interval;
|
8589 | var minTickInterval = info.minTickInterval;
|
8590 | var ticks = [];
|
8591 | var minCount = info.minCount || MIN_COUNT;
|
8592 | var maxCount = info.maxCount || MAX_COUNT;
|
8593 | var isFixedCount = minCount === maxCount;
|
8594 |
|
8595 | var minLimit = isNil(info.minLimit) ? -Infinity : info.minLimit;
|
8596 |
|
8597 | var maxLimit = isNil(info.maxLimit) ? Infinity : info.maxLimit;
|
8598 |
|
8599 | var avgCount = (minCount + maxCount) / 2;
|
8600 | var count = avgCount;
|
8601 |
|
8602 | var snapArray = info.snapArray ? info.snapArray : isFixedCount ? SNAP_COUNT_ARRAY : SNAP_ARRAY;
|
8603 |
|
8604 | if (min === minLimit && max === maxLimit && isFixedCount) {
|
8605 | interval = (max - min) / (count - 1);
|
8606 | }
|
8607 |
|
8608 | if (isNil(min)) {
|
8609 | min = 0;
|
8610 | }
|
8611 |
|
8612 | if (isNil(max)) {
|
8613 | max = 0;
|
8614 | }
|
8615 |
|
8616 | if (max === min) {
|
8617 | if (min === 0) {
|
8618 | max = 1;
|
8619 | } else {
|
8620 | if (min > 0) {
|
8621 | min = 0;
|
8622 | } else {
|
8623 | max = 0;
|
8624 | }
|
8625 | }
|
8626 |
|
8627 | if (max - min < 5 && !interval && max - min >= 1) {
|
8628 | interval = 1;
|
8629 | }
|
8630 | }
|
8631 |
|
8632 | if (isNil(interval)) {
|
8633 |
|
8634 | var temp = (max - min) / (avgCount - 1);
|
8635 | interval = AutoUtil.snapFactorTo(temp, snapArray, 'ceil');
|
8636 |
|
8637 | if (maxCount !== minCount) {
|
8638 | count = parseInt((max - min) / interval, 10);
|
8639 |
|
8640 | if (count > maxCount) {
|
8641 | count = maxCount;
|
8642 | }
|
8643 |
|
8644 | if (count < minCount) {
|
8645 | count = minCount;
|
8646 | }
|
8647 |
|
8648 |
|
8649 | interval = AutoUtil.snapFactorTo((max - min) / (count - 1), snapArray, 'floor');
|
8650 | }
|
8651 | }
|
8652 |
|
8653 |
|
8654 | if (isNumber(minTickInterval) && interval < minTickInterval) {
|
8655 | interval = minTickInterval;
|
8656 | }
|
8657 |
|
8658 | if (info.interval || maxCount !== minCount) {
|
8659 |
|
8660 | max = Math.min(AutoUtil.snapMultiple(max, interval, 'ceil'), maxLimit);
|
8661 |
|
8662 | min = Math.max(AutoUtil.snapMultiple(min, interval, 'floor'), minLimit);
|
8663 |
|
8664 | count = Math.round((max - min) / interval);
|
8665 | min = AutoUtil.fixedBase(min, interval);
|
8666 | max = AutoUtil.fixedBase(max, interval);
|
8667 | } else {
|
8668 | avgCount = parseInt(avgCount, 10);
|
8669 |
|
8670 | var avg = (max + min) / 2;
|
8671 | var avgTick = AutoUtil.snapMultiple(avg, interval, 'ceil');
|
8672 | var sideCount = Math.floor((avgCount - 2) / 2);
|
8673 | var maxTick = avgTick + sideCount * interval;
|
8674 | var minTick;
|
8675 |
|
8676 | if (avgCount % 2 === 0) {
|
8677 | minTick = avgTick - sideCount * interval;
|
8678 | } else {
|
8679 | minTick = avgTick - (sideCount + 1) * interval;
|
8680 | }
|
8681 |
|
8682 | if (maxTick < max) {
|
8683 | maxTick = maxTick + interval;
|
8684 | }
|
8685 |
|
8686 | if (minTick > min) {
|
8687 | minTick = minTick - interval;
|
8688 | }
|
8689 |
|
8690 | max = AutoUtil.fixedBase(maxTick, interval);
|
8691 | min = AutoUtil.fixedBase(minTick, interval);
|
8692 | }
|
8693 |
|
8694 | max = Math.min(max, maxLimit);
|
8695 | min = Math.max(min, minLimit);
|
8696 | ticks.push(min);
|
8697 |
|
8698 | for (var i = 1; i < count; i++) {
|
8699 | var tickValue = AutoUtil.fixedBase(interval * i + min, interval);
|
8700 |
|
8701 | if (tickValue < max) {
|
8702 | ticks.push(tickValue);
|
8703 | }
|
8704 | }
|
8705 |
|
8706 | if (ticks[ticks.length - 1] < max) {
|
8707 | ticks.push(max);
|
8708 | }
|
8709 |
|
8710 | return {
|
8711 | min: min,
|
8712 | max: max,
|
8713 | interval: interval,
|
8714 | count: count,
|
8715 | ticks: ticks
|
8716 | };
|
8717 | };
|
8718 |
|
8719 | }),
|
8720 |
|
8721 | (function(module, exports) {
|
8722 |
|
8723 |
|
8724 |
|
8725 |
|
8726 |
|
8727 |
|
8728 | var DECIMAL_LENGTH = 12;
|
8729 |
|
8730 | function getFactor(v) {
|
8731 | var factor = 1;
|
8732 |
|
8733 | if (v === Infinity || v === -Infinity) {
|
8734 | throw new Error('Not support Infinity!');
|
8735 | }
|
8736 |
|
8737 | if (v < 1) {
|
8738 | var count = 0;
|
8739 |
|
8740 | while (v < 1) {
|
8741 | factor = factor / 10;
|
8742 | v = v * 10;
|
8743 | count++;
|
8744 | }
|
8745 |
|
8746 |
|
8747 | if (factor.toString().length > DECIMAL_LENGTH) {
|
8748 | factor = parseFloat(factor.toFixed(count));
|
8749 | }
|
8750 | } else {
|
8751 | while (v > 10) {
|
8752 | factor = factor * 10;
|
8753 | v = v / 10;
|
8754 | }
|
8755 | }
|
8756 |
|
8757 | return factor;
|
8758 | }
|
8759 |
|
8760 |
|
8761 | function arrayFloor(values, value) {
|
8762 | var length = values.length;
|
8763 |
|
8764 | if (length === 0) {
|
8765 | return NaN;
|
8766 | }
|
8767 |
|
8768 | var pre = values[0];
|
8769 |
|
8770 | if (value < values[0]) {
|
8771 | return NaN;
|
8772 | }
|
8773 |
|
8774 | if (value >= values[length - 1]) {
|
8775 | return values[length - 1];
|
8776 | }
|
8777 |
|
8778 | for (var i = 1; i < values.length; i++) {
|
8779 | if (value < values[i]) {
|
8780 | break;
|
8781 | }
|
8782 |
|
8783 | pre = values[i];
|
8784 | }
|
8785 |
|
8786 | return pre;
|
8787 | }
|
8788 |
|
8789 |
|
8790 | function arrayCeiling(values, value) {
|
8791 | var length = values.length;
|
8792 |
|
8793 | if (length === 0) {
|
8794 | return NaN;
|
8795 | }
|
8796 |
|
8797 |
|
8798 | var rst;
|
8799 |
|
8800 | if (value > values[length - 1]) {
|
8801 | return NaN;
|
8802 | }
|
8803 |
|
8804 | if (value < values[0]) {
|
8805 | return values[0];
|
8806 | }
|
8807 |
|
8808 | for (var i = 1; i < values.length; i++) {
|
8809 | if (value <= values[i]) {
|
8810 | rst = values[i];
|
8811 | break;
|
8812 | }
|
8813 | }
|
8814 |
|
8815 | return rst;
|
8816 | }
|
8817 |
|
8818 | var Util = {
|
8819 |
|
8820 | snapFactorTo: function snapFactorTo(v, arr, snapType) {
|
8821 |
|
8822 | if (isNaN(v)) {
|
8823 | return NaN;
|
8824 | }
|
8825 |
|
8826 | var factor = 1;
|
8827 |
|
8828 | if (v !== 0) {
|
8829 | if (v < 0) {
|
8830 | factor = -1;
|
8831 | }
|
8832 |
|
8833 | v = v * factor;
|
8834 |
|
8835 | var tmpFactor = getFactor(v);
|
8836 | factor = factor * tmpFactor;
|
8837 |
|
8838 | v = v / tmpFactor;
|
8839 | }
|
8840 |
|
8841 | if (snapType === 'floor') {
|
8842 | v = Util.snapFloor(arr, v);
|
8843 | } else if (snapType === 'ceil') {
|
8844 | v = Util.snapCeiling(arr, v);
|
8845 | } else {
|
8846 | v = Util.snapTo(arr, v);
|
8847 | }
|
8848 |
|
8849 | var rst = v * factor;
|
8850 |
|
8851 | if (Math.abs(factor) < 1 && rst.toString().length > DECIMAL_LENGTH) {
|
8852 | var decimalVal = parseInt(1 / factor);
|
8853 | var symbol = factor > 0 ? 1 : -1;
|
8854 | rst = v / decimalVal * symbol;
|
8855 | }
|
8856 |
|
8857 | return rst;
|
8858 | },
|
8859 |
|
8860 | snapMultiple: function snapMultiple(v, base, snapType) {
|
8861 | var div;
|
8862 |
|
8863 | if (snapType === 'ceil') {
|
8864 | div = Math.ceil(v / base);
|
8865 | } else if (snapType === 'floor') {
|
8866 | div = Math.floor(v / base);
|
8867 | } else {
|
8868 | div = Math.round(v / base);
|
8869 | }
|
8870 |
|
8871 | return div * base;
|
8872 | },
|
8873 |
|
8874 | |
8875 |
|
8876 |
|
8877 |
|
8878 |
|
8879 |
|
8880 | snapTo: function snapTo(values, value) {
|
8881 |
|
8882 | var floorVal = arrayFloor(values, value);
|
8883 | var ceilingVal = arrayCeiling(values, value);
|
8884 |
|
8885 | if (isNaN(floorVal) || isNaN(ceilingVal)) {
|
8886 | if (values[0] >= value) {
|
8887 | return values[0];
|
8888 | }
|
8889 |
|
8890 | var last = values[values.length - 1];
|
8891 |
|
8892 | if (last <= value) {
|
8893 | return last;
|
8894 | }
|
8895 | }
|
8896 |
|
8897 | if (Math.abs(value - floorVal) < Math.abs(ceilingVal - value)) {
|
8898 | return floorVal;
|
8899 | }
|
8900 |
|
8901 | return ceilingVal;
|
8902 | },
|
8903 |
|
8904 | |
8905 |
|
8906 |
|
8907 |
|
8908 |
|
8909 |
|
8910 | snapFloor: function snapFloor(values, value) {
|
8911 |
|
8912 | return arrayFloor(values, value);
|
8913 | },
|
8914 |
|
8915 | |
8916 |
|
8917 |
|
8918 |
|
8919 |
|
8920 |
|
8921 | snapCeiling: function snapCeiling(values, value) {
|
8922 |
|
8923 | return arrayCeiling(values, value);
|
8924 | },
|
8925 | fixedBase: function fixedBase(v, base) {
|
8926 | var str = base.toString();
|
8927 | var index = str.indexOf('.');
|
8928 |
|
8929 | if (index === -1) {
|
8930 | return Math.round(v);
|
8931 | }
|
8932 |
|
8933 | var length = str.substr(index + 1).length;
|
8934 |
|
8935 | if (length > 20) {
|
8936 | length = 20;
|
8937 | }
|
8938 |
|
8939 | return parseFloat(v.toFixed(length));
|
8940 | }
|
8941 | };
|
8942 | module.exports = Util;
|
8943 |
|
8944 | }),
|
8945 |
|
8946 | (function(module, exports, __webpack_require__) {
|
8947 |
|
8948 | function _inheritsLoose(subClass, superClass) {
|
8949 | subClass.prototype = Object.create(superClass.prototype);
|
8950 | subClass.prototype.constructor = subClass;
|
8951 | subClass.__proto__ = superClass;
|
8952 | }
|
8953 |
|
8954 | var Base = __webpack_require__(16);
|
8955 |
|
8956 | var isNumber = __webpack_require__(15);
|
8957 |
|
8958 | var Identity =
|
8959 |
|
8960 | function (_Base) {
|
8961 | _inheritsLoose(Identity, _Base);
|
8962 |
|
8963 | function Identity() {
|
8964 | return _Base.apply(this, arguments) || this;
|
8965 | }
|
8966 |
|
8967 | var _proto = Identity.prototype;
|
8968 |
|
8969 | _proto._initDefaultCfg = function _initDefaultCfg() {
|
8970 | _Base.prototype._initDefaultCfg.call(this);
|
8971 |
|
8972 | this.isIdentity = true;
|
8973 | this.type = 'identity';
|
8974 | |
8975 |
|
8976 |
|
8977 |
|
8978 |
|
8979 | this.value = null;
|
8980 | };
|
8981 | |
8982 |
|
8983 |
|
8984 |
|
8985 |
|
8986 | _proto.getText = function getText() {
|
8987 | return this.value.toString();
|
8988 | };
|
8989 | |
8990 |
|
8991 |
|
8992 |
|
8993 |
|
8994 | _proto.scale = function scale(value) {
|
8995 | if (this.value !== value && isNumber(value)) {
|
8996 | return value;
|
8997 | }
|
8998 |
|
8999 | return this.range[0];
|
9000 | };
|
9001 | |
9002 |
|
9003 |
|
9004 |
|
9005 |
|
9006 | _proto.invert = function invert() {
|
9007 | return this.value;
|
9008 | };
|
9009 |
|
9010 | return Identity;
|
9011 | }(Base);
|
9012 |
|
9013 | Base.Identity = Identity;
|
9014 | module.exports = Identity;
|
9015 |
|
9016 | }),
|
9017 |
|
9018 | (function(module, exports, __webpack_require__) {
|
9019 |
|
9020 | var Util = __webpack_require__(0);
|
9021 |
|
9022 | var Axis = __webpack_require__(76);
|
9023 |
|
9024 | var Global = __webpack_require__(1);
|
9025 |
|
9026 | var _require = __webpack_require__(3),
|
9027 | Shape = _require.Shape;
|
9028 |
|
9029 | function formatTicks(ticks) {
|
9030 | var tmp = ticks.slice(0);
|
9031 |
|
9032 | if (tmp.length > 0) {
|
9033 | var first = tmp[0];
|
9034 | var last = tmp[tmp.length - 1];
|
9035 |
|
9036 | if (first.value !== 0) {
|
9037 | tmp.unshift({
|
9038 | value: 0
|
9039 | });
|
9040 | }
|
9041 |
|
9042 | if (last.value !== 1) {
|
9043 | tmp.push({
|
9044 | value: 1
|
9045 | });
|
9046 | }
|
9047 | }
|
9048 |
|
9049 | return tmp;
|
9050 | }
|
9051 |
|
9052 | var AxisController =
|
9053 |
|
9054 | function () {
|
9055 | function AxisController(cfg) {
|
9056 | this.axisCfg = {};
|
9057 | this.frontPlot = null;
|
9058 | this.backPlot = null;
|
9059 | this.axes = {};
|
9060 |
|
9061 | Util.mix(this, cfg);
|
9062 | }
|
9063 |
|
9064 | var _proto = AxisController.prototype;
|
9065 |
|
9066 | _proto._isHide = function _isHide(field) {
|
9067 | var axisCfg = this.axisCfg;
|
9068 | return !axisCfg || axisCfg[field] === false;
|
9069 | };
|
9070 |
|
9071 | _proto._getLinePosition = function _getLinePosition(scale, dimType, index, transposed) {
|
9072 | var position = '';
|
9073 | var field = scale.field;
|
9074 | var axisCfg = this.axisCfg;
|
9075 |
|
9076 | if (axisCfg[field] && axisCfg[field].position) {
|
9077 | position = axisCfg[field].position;
|
9078 | } else if (dimType === 'x') {
|
9079 | position = transposed ? 'left' : 'bottom';
|
9080 | } else if (dimType === 'y') {
|
9081 | position = index ? 'right' : 'left';
|
9082 |
|
9083 | if (transposed) {
|
9084 | position = 'bottom';
|
9085 | }
|
9086 | }
|
9087 |
|
9088 | return position;
|
9089 | };
|
9090 |
|
9091 | _proto._getLineCfg = function _getLineCfg(coord, dimType, position) {
|
9092 | var start;
|
9093 | var end;
|
9094 | var factor = 1;
|
9095 |
|
9096 | if (dimType === 'x') {
|
9097 | start = {
|
9098 | x: 0,
|
9099 | y: 0
|
9100 | };
|
9101 | end = {
|
9102 | x: 1,
|
9103 | y: 0
|
9104 | };
|
9105 | } else {
|
9106 | if (position === 'right') {
|
9107 |
|
9108 | start = {
|
9109 | x: 1,
|
9110 | y: 0
|
9111 | };
|
9112 | end = {
|
9113 | x: 1,
|
9114 | y: 1
|
9115 | };
|
9116 | } else {
|
9117 | start = {
|
9118 | x: 0,
|
9119 | y: 0
|
9120 | };
|
9121 | end = {
|
9122 | x: 0,
|
9123 | y: 1
|
9124 | };
|
9125 | factor = -1;
|
9126 | }
|
9127 | }
|
9128 |
|
9129 | if (coord.transposed) {
|
9130 | factor *= -1;
|
9131 | }
|
9132 |
|
9133 | return {
|
9134 | offsetFactor: factor,
|
9135 | start: coord.convertPoint(start),
|
9136 | end: coord.convertPoint(end)
|
9137 | };
|
9138 | };
|
9139 |
|
9140 | _proto._getCircleCfg = function _getCircleCfg(coord) {
|
9141 | return {
|
9142 | startAngle: coord.startAngle,
|
9143 | endAngle: coord.endAngle,
|
9144 | center: coord.center,
|
9145 | radius: coord.circleRadius
|
9146 | };
|
9147 | };
|
9148 |
|
9149 | _proto._getRadiusCfg = function _getRadiusCfg(coord) {
|
9150 | var transposed = coord.transposed;
|
9151 | var start;
|
9152 | var end;
|
9153 |
|
9154 | if (transposed) {
|
9155 | start = {
|
9156 | x: 0,
|
9157 | y: 0
|
9158 | };
|
9159 | end = {
|
9160 | x: 1,
|
9161 | y: 0
|
9162 | };
|
9163 | } else {
|
9164 | start = {
|
9165 | x: 0,
|
9166 | y: 0
|
9167 | };
|
9168 | end = {
|
9169 | x: 0,
|
9170 | y: 1
|
9171 | };
|
9172 | }
|
9173 |
|
9174 | return {
|
9175 | offsetFactor: -1,
|
9176 | start: coord.convertPoint(start),
|
9177 | end: coord.convertPoint(end)
|
9178 | };
|
9179 | };
|
9180 |
|
9181 | _proto._getAxisCfg = function _getAxisCfg(coord, scale, verticalScale, dimType, defaultCfg) {
|
9182 | var self = this;
|
9183 | var axisCfg = this.axisCfg;
|
9184 | var ticks = scale.getTicks();
|
9185 | var cfg = Util.deepMix({
|
9186 | ticks: ticks,
|
9187 | frontContainer: this.frontPlot,
|
9188 | backContainer: this.backPlot
|
9189 | }, defaultCfg, axisCfg[scale.field]);
|
9190 | var labels = [];
|
9191 | var label = cfg.label;
|
9192 | var count = ticks.length;
|
9193 | var maxWidth = 0;
|
9194 | var maxHeight = 0;
|
9195 | var labelCfg = label;
|
9196 | Util.each(ticks, function (tick, index) {
|
9197 | if (Util.isFunction(label)) {
|
9198 | var executedLabel = label(tick.text, index, count);
|
9199 |
|
9200 | if (executedLabel) {
|
9201 | labelCfg = Util.mix({}, Global._defaultAxis.label, executedLabel);
|
9202 | } else {
|
9203 | labelCfg = null;
|
9204 | }
|
9205 | }
|
9206 |
|
9207 | if (labelCfg) {
|
9208 | var textStyle = {};
|
9209 |
|
9210 | if (labelCfg.textAlign) {
|
9211 | textStyle.textAlign = labelCfg.textAlign;
|
9212 | }
|
9213 |
|
9214 | if (labelCfg.textBaseline) {
|
9215 | textStyle.textBaseline = labelCfg.textBaseline;
|
9216 | }
|
9217 |
|
9218 | var axisLabel = new Shape.Text({
|
9219 | className: 'axis-label',
|
9220 | attrs: Util.mix({
|
9221 | x: 0,
|
9222 | y: 0,
|
9223 | text: tick.text,
|
9224 | fontFamily: self.chart.get('canvas').get('fontFamily')
|
9225 | }, labelCfg),
|
9226 | value: tick.value,
|
9227 | textStyle: textStyle,
|
9228 | top: labelCfg.top,
|
9229 | context: self.chart.get('canvas').get('context')
|
9230 | });
|
9231 | labels.push(axisLabel);
|
9232 |
|
9233 | var _axisLabel$getBBox = axisLabel.getBBox(),
|
9234 | width = _axisLabel$getBBox.width,
|
9235 | height = _axisLabel$getBBox.height;
|
9236 |
|
9237 | maxWidth = Math.max(maxWidth, width);
|
9238 | maxHeight = Math.max(maxHeight, height);
|
9239 | }
|
9240 | });
|
9241 | cfg.labels = labels;
|
9242 | cfg.maxWidth = maxWidth;
|
9243 | cfg.maxHeight = maxHeight;
|
9244 | return cfg;
|
9245 | };
|
9246 |
|
9247 | _proto._createAxis = function _createAxis(coord, scale, verticalScale, dimType, index) {
|
9248 | if (index === void 0) {
|
9249 | index = '';
|
9250 | }
|
9251 |
|
9252 | var self = this;
|
9253 | var coordType = coord.type;
|
9254 | var transposed = coord.transposed;
|
9255 | var type;
|
9256 | var key;
|
9257 | var defaultCfg;
|
9258 |
|
9259 | if (coordType === 'cartesian' || coordType === 'rect') {
|
9260 | var position = self._getLinePosition(scale, dimType, index, transposed);
|
9261 |
|
9262 | defaultCfg = Global.axis[position];
|
9263 | defaultCfg.position = position;
|
9264 | type = 'Line';
|
9265 | key = position;
|
9266 | } else {
|
9267 | if (dimType === 'x' && !transposed || dimType === 'y' && transposed) {
|
9268 | defaultCfg = Global.axis.circle;
|
9269 | type = 'Circle';
|
9270 | key = 'circle';
|
9271 | } else {
|
9272 | defaultCfg = Global.axis.radius;
|
9273 | type = 'Line';
|
9274 | key = 'radius';
|
9275 | }
|
9276 | }
|
9277 |
|
9278 | var cfg = self._getAxisCfg(coord, scale, verticalScale, dimType, defaultCfg);
|
9279 |
|
9280 | cfg.type = type;
|
9281 | cfg.dimType = dimType;
|
9282 | cfg.verticalScale = verticalScale;
|
9283 | cfg.index = index;
|
9284 | this.axes[key] = cfg;
|
9285 | };
|
9286 |
|
9287 | _proto.createAxis = function createAxis(coord, xScale, yScales) {
|
9288 | var self = this;
|
9289 |
|
9290 | if (xScale && !self._isHide(xScale.field)) {
|
9291 | self._createAxis(coord, xScale, yScales[0], 'x');
|
9292 | }
|
9293 |
|
9294 | Util.each(yScales, function (yScale, index) {
|
9295 | if (!self._isHide(yScale.field)) {
|
9296 | self._createAxis(coord, yScale, xScale, 'y', index);
|
9297 | }
|
9298 | });
|
9299 | var axes = this.axes;
|
9300 | var chart = self.chart;
|
9301 |
|
9302 | if (chart._isAutoPadding()) {
|
9303 | var userPadding = Util.parsePadding(chart.get('padding'));
|
9304 | var appendPadding = Util.parsePadding(chart.get('appendPadding'));
|
9305 | var legendRange = chart.get('legendRange') || {
|
9306 | top: 0,
|
9307 | right: 0,
|
9308 | bottom: 0,
|
9309 | left: 0
|
9310 | };
|
9311 | 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]];
|
9312 |
|
9313 | if (coord.isPolar) {
|
9314 | var circleAxis = axes.circle;
|
9315 |
|
9316 | if (circleAxis) {
|
9317 | var maxHeight = circleAxis.maxHeight,
|
9318 | maxWidth = circleAxis.maxWidth,
|
9319 | labelOffset = circleAxis.labelOffset;
|
9320 | padding[0] += maxHeight + labelOffset;
|
9321 | padding[1] += maxWidth + labelOffset;
|
9322 | padding[2] += maxHeight + labelOffset;
|
9323 | padding[3] += maxWidth + labelOffset;
|
9324 | }
|
9325 | } else {
|
9326 | if (axes.right && userPadding[1] === 'auto') {
|
9327 | var _axes$right = axes.right,
|
9328 | _maxWidth = _axes$right.maxWidth,
|
9329 | _labelOffset = _axes$right.labelOffset;
|
9330 | padding[1] += _maxWidth + _labelOffset;
|
9331 | }
|
9332 |
|
9333 | if (axes.left && userPadding[3] === 'auto') {
|
9334 | var _axes$left = axes.left,
|
9335 | _maxWidth2 = _axes$left.maxWidth,
|
9336 | _labelOffset2 = _axes$left.labelOffset;
|
9337 | padding[3] += _maxWidth2 + _labelOffset2;
|
9338 | }
|
9339 |
|
9340 | if (axes.bottom && userPadding[2] === 'auto') {
|
9341 | var _axes$bottom = axes.bottom,
|
9342 | _maxHeight = _axes$bottom.maxHeight,
|
9343 | _labelOffset3 = _axes$bottom.labelOffset;
|
9344 | padding[2] += _maxHeight + _labelOffset3;
|
9345 | }
|
9346 | }
|
9347 |
|
9348 | chart.set('_padding', padding);
|
9349 |
|
9350 | chart._updateLayout(padding);
|
9351 | }
|
9352 |
|
9353 | Util.each(axes, function (axis) {
|
9354 | var type = axis.type,
|
9355 | grid = axis.grid,
|
9356 | verticalScale = axis.verticalScale,
|
9357 | ticks = axis.ticks,
|
9358 | dimType = axis.dimType,
|
9359 | position = axis.position,
|
9360 | index = axis.index;
|
9361 | var appendCfg;
|
9362 |
|
9363 | if (coord.isPolar) {
|
9364 | if (type === 'Line') {
|
9365 | appendCfg = self._getRadiusCfg(coord);
|
9366 | } else if (type === 'Circle') {
|
9367 | appendCfg = self._getCircleCfg(coord);
|
9368 | }
|
9369 | } else {
|
9370 | appendCfg = self._getLineCfg(coord, dimType, position);
|
9371 | }
|
9372 |
|
9373 | if (grid && verticalScale) {
|
9374 | var gridPoints = [];
|
9375 | var verticalTicks = formatTicks(verticalScale.getTicks());
|
9376 | Util.each(ticks, function (tick) {
|
9377 | var subPoints = [];
|
9378 | Util.each(verticalTicks, function (verticalTick) {
|
9379 | var x = dimType === 'x' ? tick.value : verticalTick.value;
|
9380 | var y = dimType === 'x' ? verticalTick.value : tick.value;
|
9381 |
|
9382 | if (x >= 0 && x <= 1 && y >= 0 && y <= 1) {
|
9383 | var point = coord.convertPoint({
|
9384 | x: x,
|
9385 | y: y
|
9386 | });
|
9387 | subPoints.push(point);
|
9388 | }
|
9389 | });
|
9390 | gridPoints.push({
|
9391 | points: subPoints,
|
9392 | _id: 'axis-' + dimType + index + '-grid-' + tick.tickValue
|
9393 | });
|
9394 | });
|
9395 | axis.gridPoints = gridPoints;
|
9396 |
|
9397 | if (coord.isPolar) {
|
9398 | axis.center = coord.center;
|
9399 | axis.startAngle = coord.startAngle;
|
9400 | axis.endAngle = coord.endAngle;
|
9401 | }
|
9402 | }
|
9403 |
|
9404 | appendCfg._id = 'axis-' + dimType;
|
9405 |
|
9406 | if (!Util.isNil(index)) {
|
9407 | appendCfg._id = 'axis-' + dimType + index;
|
9408 | }
|
9409 |
|
9410 | new Axis[type](Util.mix(axis, appendCfg));
|
9411 | });
|
9412 | };
|
9413 |
|
9414 | _proto.clear = function clear() {
|
9415 | this.axes = {};
|
9416 | this.frontPlot.clear();
|
9417 | this.backPlot.clear();
|
9418 | };
|
9419 |
|
9420 | return AxisController;
|
9421 | }();
|
9422 |
|
9423 | module.exports = AxisController;
|
9424 |
|
9425 | }),
|
9426 |
|
9427 | (function(module, exports, __webpack_require__) {
|
9428 |
|
9429 | var Abstract = __webpack_require__(25);
|
9430 |
|
9431 | __webpack_require__(77);
|
9432 |
|
9433 | module.exports = Abstract;
|
9434 |
|
9435 | }),
|
9436 |
|
9437 | (function(module, exports, __webpack_require__) {
|
9438 |
|
9439 | function _inheritsLoose(subClass, superClass) {
|
9440 | subClass.prototype = Object.create(superClass.prototype);
|
9441 | subClass.prototype.constructor = subClass;
|
9442 | subClass.__proto__ = superClass;
|
9443 | }
|
9444 |
|
9445 | var Util = __webpack_require__(0);
|
9446 |
|
9447 | var Abstract = __webpack_require__(25);
|
9448 |
|
9449 | var Line =
|
9450 |
|
9451 | function (_Abstract) {
|
9452 | _inheritsLoose(Line, _Abstract);
|
9453 |
|
9454 | function Line() {
|
9455 | return _Abstract.apply(this, arguments) || this;
|
9456 | }
|
9457 |
|
9458 | var _proto = Line.prototype;
|
9459 |
|
9460 | _proto._initDefaultCfg = function _initDefaultCfg() {
|
9461 | _Abstract.prototype._initDefaultCfg.call(this);
|
9462 |
|
9463 | this.start = null;
|
9464 | this.end = null;
|
9465 | };
|
9466 |
|
9467 | _proto.getOffsetPoint = function getOffsetPoint(value) {
|
9468 | var start = this.start,
|
9469 | end = this.end;
|
9470 | return {
|
9471 | x: start.x + (end.x - start.x) * value,
|
9472 | y: start.y + (end.y - start.y) * value
|
9473 | };
|
9474 | };
|
9475 |
|
9476 | _proto.getAxisVector = function getAxisVector() {
|
9477 | var start = this.start,
|
9478 | end = this.end;
|
9479 | return [end.x - start.x, end.y - start.y];
|
9480 | };
|
9481 |
|
9482 | _proto.drawLine = function drawLine(lineCfg) {
|
9483 | var container = this.getContainer(lineCfg.top);
|
9484 | var start = this.start,
|
9485 | end = this.end;
|
9486 | container.addShape('line', {
|
9487 | className: 'axis-line',
|
9488 | attrs: Util.mix({
|
9489 | x1: start.x,
|
9490 | y1: start.y,
|
9491 | x2: end.x,
|
9492 | y2: end.y
|
9493 | }, lineCfg)
|
9494 | });
|
9495 | };
|
9496 |
|
9497 | return Line;
|
9498 | }(Abstract);
|
9499 |
|
9500 | Abstract.Line = Line;
|
9501 | module.exports = Line;
|
9502 |
|
9503 | }),
|
9504 |
|
9505 | (function(module, exports, __webpack_require__) {
|
9506 |
|
9507 | var Util = __webpack_require__(0);
|
9508 |
|
9509 | var Container = __webpack_require__(36);
|
9510 |
|
9511 | var Group = __webpack_require__(37);
|
9512 |
|
9513 | var _require = __webpack_require__(38),
|
9514 | requestAnimationFrame = _require.requestAnimationFrame;
|
9515 |
|
9516 | var Canvas =
|
9517 |
|
9518 | function () {
|
9519 | var _proto = Canvas.prototype;
|
9520 |
|
9521 | _proto.get = function get(name) {
|
9522 | return this._attrs[name];
|
9523 | };
|
9524 |
|
9525 | _proto.set = function set(name, value) {
|
9526 | this._attrs[name] = value;
|
9527 | };
|
9528 |
|
9529 | function Canvas(cfg) {
|
9530 | this._attrs = Util.mix({
|
9531 | type: 'canvas',
|
9532 | children: []
|
9533 | }, cfg);
|
9534 |
|
9535 | this._initPixelRatio();
|
9536 |
|
9537 | this._initCanvas();
|
9538 | }
|
9539 |
|
9540 | _proto._initPixelRatio = function _initPixelRatio() {
|
9541 | var pixelRatio = this.get('pixelRatio');
|
9542 |
|
9543 | if (!pixelRatio) {
|
9544 | this.set('pixelRatio', Util.getPixelRatio());
|
9545 | }
|
9546 | };
|
9547 |
|
9548 | _proto.beforeDraw = function beforeDraw() {
|
9549 | var context = this._attrs.context;
|
9550 | var el = this._attrs.el;
|
9551 | !Util.isWx && !Util.isMy && context && context.clearRect(0, 0, el.width, el.height);
|
9552 | };
|
9553 |
|
9554 | _proto._initCanvas = function _initCanvas() {
|
9555 | var self = this;
|
9556 | var el = self.get('el');
|
9557 | var context = self.get('context');
|
9558 | var canvas;
|
9559 |
|
9560 | if (context) {
|
9561 |
|
9562 | canvas = context.canvas;
|
9563 | } else if (Util.isString(el)) {
|
9564 |
|
9565 | canvas = Util.getDomById(el);
|
9566 | } else {
|
9567 |
|
9568 | canvas = el;
|
9569 | }
|
9570 |
|
9571 | if (!canvas) {
|
9572 | throw new Error('Please specify the id or el of the chart!');
|
9573 | }
|
9574 |
|
9575 | if (context && canvas && !canvas.getContext) {
|
9576 | canvas.getContext = function () {
|
9577 | return context;
|
9578 | };
|
9579 | }
|
9580 |
|
9581 | var width = self.get('width');
|
9582 |
|
9583 | if (!width) {
|
9584 | width = Util.getWidth(canvas);
|
9585 | }
|
9586 |
|
9587 | var height = self.get('height');
|
9588 |
|
9589 | if (!height) {
|
9590 | height = Util.getHeight(canvas);
|
9591 | }
|
9592 |
|
9593 | self.set('canvas', this);
|
9594 | self.set('el', canvas);
|
9595 | self.set('context', context || canvas.getContext('2d'));
|
9596 | self.changeSize(width, height);
|
9597 | };
|
9598 |
|
9599 | _proto.changeSize = function changeSize(width, height) {
|
9600 | var pixelRatio = this.get('pixelRatio');
|
9601 | var canvasDOM = this.get('el');
|
9602 |
|
9603 | if (Util.isBrowser) {
|
9604 | canvasDOM.style.width = width + 'px';
|
9605 | canvasDOM.style.height = height + 'px';
|
9606 | }
|
9607 |
|
9608 | if (!Util.isWx && !Util.isMy) {
|
9609 | canvasDOM.width = width * pixelRatio;
|
9610 | canvasDOM.height = height * pixelRatio;
|
9611 |
|
9612 | if (pixelRatio !== 1) {
|
9613 | var ctx = this.get('context');
|
9614 | ctx.scale(pixelRatio, pixelRatio);
|
9615 | }
|
9616 | }
|
9617 |
|
9618 | this.set('width', width);
|
9619 | this.set('height', height);
|
9620 | };
|
9621 |
|
9622 | _proto.getWidth = function getWidth() {
|
9623 | var pixelRatio = this.get('pixelRatio');
|
9624 | var width = this.get('width');
|
9625 | return width * pixelRatio;
|
9626 | };
|
9627 |
|
9628 | _proto.getHeight = function getHeight() {
|
9629 | var pixelRatio = this.get('pixelRatio');
|
9630 | var height = this.get('height');
|
9631 | return height * pixelRatio;
|
9632 | };
|
9633 |
|
9634 | _proto.getPointByClient = function getPointByClient(clientX, clientY) {
|
9635 | var el = this.get('el');
|
9636 | var bbox = el.getBoundingClientRect();
|
9637 | var width = bbox.right - bbox.left;
|
9638 | var height = bbox.bottom - bbox.top;
|
9639 | return {
|
9640 | x: (clientX - bbox.left) * (el.width / width),
|
9641 | y: (clientY - bbox.top) * (el.height / height)
|
9642 | };
|
9643 | };
|
9644 |
|
9645 | _proto._beginDraw = function _beginDraw() {
|
9646 | this._attrs.toDraw = true;
|
9647 | };
|
9648 |
|
9649 | _proto._endDraw = function _endDraw() {
|
9650 | this._attrs.toDraw = false;
|
9651 | };
|
9652 |
|
9653 | _proto.draw = function draw() {
|
9654 | var self = this;
|
9655 |
|
9656 | function drawInner() {
|
9657 | self.set('animateHandler', requestAnimationFrame(function () {
|
9658 | self.set('animateHandler', undefined);
|
9659 |
|
9660 | if (self.get('toDraw')) {
|
9661 | drawInner();
|
9662 | }
|
9663 | }));
|
9664 | self.beforeDraw();
|
9665 |
|
9666 | try {
|
9667 | var context = self._attrs.context;
|
9668 | var children = self._attrs.children;
|
9669 |
|
9670 | for (var i = 0, len = children.length; i < len; i++) {
|
9671 | var child = children[i];
|
9672 | child.draw(context);
|
9673 | }
|
9674 |
|
9675 | if (Util.isWx || Util.isMy) {
|
9676 | context.draw();
|
9677 | }
|
9678 | } catch (ev) {
|
9679 | console.warn('error in draw canvas, detail as:');
|
9680 | console.warn(ev);
|
9681 |
|
9682 | self._endDraw();
|
9683 | }
|
9684 |
|
9685 | self._endDraw();
|
9686 | }
|
9687 |
|
9688 | if (self.get('destroyed')) {
|
9689 | return;
|
9690 | }
|
9691 |
|
9692 | if (self.get('animateHandler')) {
|
9693 | this._beginDraw();
|
9694 | } else {
|
9695 | drawInner();
|
9696 | }
|
9697 | };
|
9698 |
|
9699 | _proto.destroy = function destroy() {
|
9700 | if (this.get('destroyed')) {
|
9701 | return;
|
9702 | }
|
9703 |
|
9704 | this.clear();
|
9705 | this._attrs = {};
|
9706 | this.set('destroyed', true);
|
9707 | };
|
9708 |
|
9709 | _proto.isDestroyed = function isDestroyed() {
|
9710 | return this.get('destroyed');
|
9711 | };
|
9712 |
|
9713 | return Canvas;
|
9714 | }();
|
9715 |
|
9716 | Util.mix(Canvas.prototype, Container, {
|
9717 | getGroupClass: function getGroupClass() {
|
9718 | return Group;
|
9719 | }
|
9720 | });
|
9721 | module.exports = Canvas;
|
9722 |
|
9723 | }),
|
9724 |
|
9725 | (function(module, exports, __webpack_require__) {
|
9726 |
|
9727 | var Util = __webpack_require__(0);
|
9728 |
|
9729 | function _mod(n, m) {
|
9730 | return (n % m + m) % m;
|
9731 | }
|
9732 |
|
9733 | function _addStop(steps, gradient) {
|
9734 | Util.each(steps, function (item) {
|
9735 | item = item.split(':');
|
9736 | gradient.addColorStop(Number(item[0]), item[1]);
|
9737 | });
|
9738 | }
|
9739 |
|
9740 |
|
9741 | function _parseLineGradient(color, shape, context) {
|
9742 | var arr = color.split(' ');
|
9743 | var angle = arr[0].slice(2, arr[0].length - 1);
|
9744 | angle = _mod(parseFloat(angle) * Math.PI / 180, Math.PI * 2);
|
9745 | var steps = arr.slice(1);
|
9746 |
|
9747 | var _shape$getBBox = shape.getBBox(),
|
9748 | minX = _shape$getBBox.minX,
|
9749 | minY = _shape$getBBox.minY,
|
9750 | maxX = _shape$getBBox.maxX,
|
9751 | maxY = _shape$getBBox.maxY;
|
9752 |
|
9753 | var start;
|
9754 | var end;
|
9755 |
|
9756 | if (angle >= 0 && angle < 0.5 * Math.PI) {
|
9757 | start = {
|
9758 | x: minX,
|
9759 | y: minY
|
9760 | };
|
9761 | end = {
|
9762 | x: maxX,
|
9763 | y: maxY
|
9764 | };
|
9765 | } else if (0.5 * Math.PI <= angle && angle < Math.PI) {
|
9766 | start = {
|
9767 | x: maxX,
|
9768 | y: minY
|
9769 | };
|
9770 | end = {
|
9771 | x: minX,
|
9772 | y: maxY
|
9773 | };
|
9774 | } else if (Math.PI <= angle && angle < 1.5 * Math.PI) {
|
9775 | start = {
|
9776 | x: maxX,
|
9777 | y: maxY
|
9778 | };
|
9779 | end = {
|
9780 | x: minX,
|
9781 | y: minY
|
9782 | };
|
9783 | } else {
|
9784 | start = {
|
9785 | x: minX,
|
9786 | y: maxY
|
9787 | };
|
9788 | end = {
|
9789 | x: maxX,
|
9790 | y: minY
|
9791 | };
|
9792 | }
|
9793 |
|
9794 | var tanTheta = Math.tan(angle);
|
9795 | var tanTheta2 = tanTheta * tanTheta;
|
9796 | var x = (end.x - start.x + tanTheta * (end.y - start.y)) / (tanTheta2 + 1) + start.x;
|
9797 | var y = tanTheta * (end.x - start.x + tanTheta * (end.y - start.y)) / (tanTheta2 + 1) + start.y;
|
9798 | var gradient = context.createLinearGradient(start.x, start.y, x, y);
|
9799 |
|
9800 | _addStop(steps, gradient);
|
9801 |
|
9802 | return gradient;
|
9803 | }
|
9804 |
|
9805 |
|
9806 | function _parseRadialGradient(color, shape, context) {
|
9807 | var arr = color.split(' ');
|
9808 | var circleCfg = arr[0].slice(2, arr[0].length - 1);
|
9809 | circleCfg = circleCfg.split(',');
|
9810 | var fx = parseFloat(circleCfg[0]);
|
9811 | var fy = parseFloat(circleCfg[1]);
|
9812 | var fr = parseFloat(circleCfg[2]);
|
9813 | var steps = arr.slice(1);
|
9814 |
|
9815 | if (fr === 0) {
|
9816 | var _color = steps[steps.length - 1];
|
9817 | return _color.split(':')[1];
|
9818 | }
|
9819 |
|
9820 | var _shape$getBBox2 = shape.getBBox(),
|
9821 | width = _shape$getBBox2.width,
|
9822 | height = _shape$getBBox2.height,
|
9823 | minX = _shape$getBBox2.minX,
|
9824 | minY = _shape$getBBox2.minY;
|
9825 |
|
9826 | var r = Math.sqrt(width * width + height * height) / 2;
|
9827 | var gradient = context.createRadialGradient(minX + width * fx, minY + height * fy, fr * r, minX + width / 2, minY + height / 2, r);
|
9828 |
|
9829 | _addStop(steps, gradient);
|
9830 |
|
9831 | return gradient;
|
9832 | }
|
9833 |
|
9834 | module.exports = {
|
9835 | parseStyle: function parseStyle(color, shape, context) {
|
9836 | if (color[1] === '(') {
|
9837 | try {
|
9838 | var firstCode = color[0];
|
9839 |
|
9840 | if (firstCode === 'l') {
|
9841 | return _parseLineGradient(color, shape, context);
|
9842 | } else if (firstCode === 'r') {
|
9843 | return _parseRadialGradient(color, shape, context);
|
9844 | }
|
9845 | } catch (ev) {
|
9846 | console.error('error in parsing gradient string, please check if there are any extra whitespaces.');
|
9847 | console.error(ev);
|
9848 | }
|
9849 | }
|
9850 |
|
9851 | return color;
|
9852 | }
|
9853 | };
|
9854 |
|
9855 | }),
|
9856 |
|
9857 | (function(module, exports, __webpack_require__) {
|
9858 |
|
9859 | function _inheritsLoose(subClass, superClass) {
|
9860 | subClass.prototype = Object.create(superClass.prototype);
|
9861 | subClass.prototype.constructor = subClass;
|
9862 | subClass.__proto__ = superClass;
|
9863 | }
|
9864 |
|
9865 | var Util = __webpack_require__(0);
|
9866 |
|
9867 | var Shape = __webpack_require__(2);
|
9868 |
|
9869 | var Rect =
|
9870 |
|
9871 | function (_Shape) {
|
9872 | _inheritsLoose(Rect, _Shape);
|
9873 |
|
9874 | function Rect() {
|
9875 | return _Shape.apply(this, arguments) || this;
|
9876 | }
|
9877 |
|
9878 | var _proto = Rect.prototype;
|
9879 |
|
9880 | _proto._initProperties = function _initProperties() {
|
9881 | _Shape.prototype._initProperties.call(this);
|
9882 |
|
9883 | this._attrs.canFill = true;
|
9884 | this._attrs.canStroke = true;
|
9885 | this._attrs.type = 'rect';
|
9886 | };
|
9887 |
|
9888 | _proto.getDefaultAttrs = function getDefaultAttrs() {
|
9889 | return {
|
9890 | x: 0,
|
9891 | y: 0,
|
9892 | width: 0,
|
9893 | height: 0,
|
9894 | radius: 0,
|
9895 | lineWidth: 0
|
9896 | };
|
9897 | };
|
9898 |
|
9899 | _proto.createPath = function createPath(context) {
|
9900 | var self = this;
|
9901 | var attrs = self.get('attrs');
|
9902 | var x = attrs.x,
|
9903 | y = attrs.y,
|
9904 | width = attrs.width,
|
9905 | height = attrs.height;
|
9906 | context.beginPath();
|
9907 | var radius = attrs.radius;
|
9908 |
|
9909 | if (!radius || !(width * height)) {
|
9910 | context.rect(x, y, width, height);
|
9911 | } else {
|
9912 | radius = Util.parsePadding(radius);
|
9913 | context.moveTo(x + radius[0], y);
|
9914 | context.lineTo(x + width - radius[1], y);
|
9915 | context.arc(x + width - radius[1], y + radius[1], radius[1], -Math.PI / 2, 0, false);
|
9916 | context.lineTo(x + width, y + height - radius[2]);
|
9917 | context.arc(x + width - radius[2], y + height - radius[2], radius[2], 0, Math.PI / 2, false);
|
9918 | context.lineTo(x + radius[3], y + height);
|
9919 | context.arc(x + radius[3], y + height - radius[3], radius[3], Math.PI / 2, Math.PI, false);
|
9920 | context.lineTo(x, y + radius[0]);
|
9921 | context.arc(x + radius[0], y + radius[0], radius[0], Math.PI, Math.PI * 3 / 2, false);
|
9922 | context.closePath();
|
9923 | }
|
9924 | };
|
9925 |
|
9926 | _proto.calculateBox = function calculateBox() {
|
9927 | var attrs = this.get('attrs');
|
9928 | var x = attrs.x,
|
9929 | y = attrs.y,
|
9930 | width = attrs.width,
|
9931 | height = attrs.height;
|
9932 | return {
|
9933 | minX: x,
|
9934 | minY: y,
|
9935 | maxX: x + width,
|
9936 | maxY: y + height
|
9937 | };
|
9938 | };
|
9939 |
|
9940 | return Rect;
|
9941 | }(Shape);
|
9942 |
|
9943 | Shape.Rect = Rect;
|
9944 | module.exports = Rect;
|
9945 |
|
9946 | }),
|
9947 |
|
9948 | (function(module, exports, __webpack_require__) {
|
9949 |
|
9950 | function _inheritsLoose(subClass, superClass) {
|
9951 | subClass.prototype = Object.create(superClass.prototype);
|
9952 | subClass.prototype.constructor = subClass;
|
9953 | subClass.__proto__ = superClass;
|
9954 | }
|
9955 |
|
9956 | var Shape = __webpack_require__(2);
|
9957 |
|
9958 | var Circle =
|
9959 |
|
9960 | function (_Shape) {
|
9961 | _inheritsLoose(Circle, _Shape);
|
9962 |
|
9963 | function Circle() {
|
9964 | return _Shape.apply(this, arguments) || this;
|
9965 | }
|
9966 |
|
9967 | var _proto = Circle.prototype;
|
9968 |
|
9969 | _proto._initProperties = function _initProperties() {
|
9970 | _Shape.prototype._initProperties.call(this);
|
9971 |
|
9972 | this._attrs.canFill = true;
|
9973 | this._attrs.canStroke = true;
|
9974 | this._attrs.type = 'circle';
|
9975 | };
|
9976 |
|
9977 | _proto.getDefaultAttrs = function getDefaultAttrs() {
|
9978 | return {
|
9979 | x: 0,
|
9980 | y: 0,
|
9981 | r: 0,
|
9982 | lineWidth: 0
|
9983 | };
|
9984 | };
|
9985 |
|
9986 | _proto.createPath = function createPath(context) {
|
9987 | var attrs = this.get('attrs');
|
9988 | var x = attrs.x,
|
9989 | y = attrs.y,
|
9990 | r = attrs.r;
|
9991 | context.beginPath();
|
9992 | context.arc(x, y, r, 0, Math.PI * 2, false);
|
9993 | context.closePath();
|
9994 | };
|
9995 |
|
9996 | _proto.calculateBox = function calculateBox() {
|
9997 | var attrs = this.get('attrs');
|
9998 | var x = attrs.x,
|
9999 | y = attrs.y,
|
10000 | r = attrs.r;
|
10001 | return {
|
10002 | minX: x - r,
|
10003 | maxX: x + r,
|
10004 | minY: y - r,
|
10005 | maxY: y + r
|
10006 | };
|
10007 | };
|
10008 |
|
10009 | return Circle;
|
10010 | }(Shape);
|
10011 |
|
10012 | Shape.Circle = Circle;
|
10013 | module.exports = Circle;
|
10014 |
|
10015 | }),
|
10016 |
|
10017 | (function(module, exports, __webpack_require__) {
|
10018 |
|
10019 | function _inheritsLoose(subClass, superClass) {
|
10020 | subClass.prototype = Object.create(superClass.prototype);
|
10021 | subClass.prototype.constructor = subClass;
|
10022 | subClass.__proto__ = superClass;
|
10023 | }
|
10024 |
|
10025 | var Shape = __webpack_require__(2);
|
10026 |
|
10027 | var bbox = __webpack_require__(13);
|
10028 |
|
10029 | var Line =
|
10030 |
|
10031 | function (_Shape) {
|
10032 | _inheritsLoose(Line, _Shape);
|
10033 |
|
10034 | function Line() {
|
10035 | return _Shape.apply(this, arguments) || this;
|
10036 | }
|
10037 |
|
10038 | var _proto = Line.prototype;
|
10039 |
|
10040 | _proto._initProperties = function _initProperties() {
|
10041 | _Shape.prototype._initProperties.call(this);
|
10042 |
|
10043 | this._attrs.canStroke = true;
|
10044 | this._attrs.type = 'line';
|
10045 | };
|
10046 |
|
10047 | _proto.getDefaultAttrs = function getDefaultAttrs() {
|
10048 | return {
|
10049 | x1: 0,
|
10050 | y1: 0,
|
10051 | x2: 0,
|
10052 | y2: 0,
|
10053 | lineWidth: 1
|
10054 | };
|
10055 | };
|
10056 |
|
10057 | _proto.createPath = function createPath(context) {
|
10058 | var attrs = this.get('attrs');
|
10059 | var x1 = attrs.x1,
|
10060 | y1 = attrs.y1,
|
10061 | x2 = attrs.x2,
|
10062 | y2 = attrs.y2;
|
10063 | context.beginPath();
|
10064 | context.moveTo(x1, y1);
|
10065 | context.lineTo(x2, y2);
|
10066 | };
|
10067 |
|
10068 | _proto.calculateBox = function calculateBox() {
|
10069 | var attrs = this.get('attrs');
|
10070 | var x1 = attrs.x1,
|
10071 | y1 = attrs.y1,
|
10072 | x2 = attrs.x2,
|
10073 | y2 = attrs.y2,
|
10074 | lineWidth = attrs.lineWidth;
|
10075 | return bbox.getBBoxFromLine(x1, y1, x2, y2, lineWidth);
|
10076 | };
|
10077 |
|
10078 | return Line;
|
10079 | }(Shape);
|
10080 |
|
10081 | Shape.Line = Line;
|
10082 | module.exports = Line;
|
10083 |
|
10084 | }),
|
10085 |
|
10086 | (function(module, exports, __webpack_require__) {
|
10087 |
|
10088 | function _inheritsLoose(subClass, superClass) {
|
10089 | subClass.prototype = Object.create(superClass.prototype);
|
10090 | subClass.prototype.constructor = subClass;
|
10091 | subClass.__proto__ = superClass;
|
10092 | }
|
10093 |
|
10094 | var Shape = __webpack_require__(2);
|
10095 |
|
10096 | var bbox = __webpack_require__(13);
|
10097 |
|
10098 | var Polygon =
|
10099 |
|
10100 | function (_Shape) {
|
10101 | _inheritsLoose(Polygon, _Shape);
|
10102 |
|
10103 | function Polygon() {
|
10104 | return _Shape.apply(this, arguments) || this;
|
10105 | }
|
10106 |
|
10107 | var _proto = Polygon.prototype;
|
10108 |
|
10109 | _proto._initProperties = function _initProperties() {
|
10110 | _Shape.prototype._initProperties.call(this);
|
10111 |
|
10112 | this._attrs.canFill = true;
|
10113 | this._attrs.canStroke = true;
|
10114 | this._attrs.type = 'polygon';
|
10115 | };
|
10116 |
|
10117 | _proto.getDefaultAttrs = function getDefaultAttrs() {
|
10118 | return {
|
10119 | points: null,
|
10120 | lineWidth: 0
|
10121 | };
|
10122 | };
|
10123 |
|
10124 | _proto.createPath = function createPath(context) {
|
10125 | var self = this;
|
10126 | var attrs = self.get('attrs');
|
10127 | var points = attrs.points;
|
10128 | context.beginPath();
|
10129 |
|
10130 | for (var i = 0, len = points.length; i < len; i++) {
|
10131 | var point = points[i];
|
10132 |
|
10133 | if (i === 0) {
|
10134 | context.moveTo(point.x, point.y);
|
10135 | } else {
|
10136 | context.lineTo(point.x, point.y);
|
10137 | }
|
10138 | }
|
10139 |
|
10140 | context.closePath();
|
10141 | };
|
10142 |
|
10143 | _proto.calculateBox = function calculateBox() {
|
10144 | var attrs = this.get('attrs');
|
10145 | var points = attrs.points;
|
10146 | return bbox.getBBoxFromPoints(points);
|
10147 | };
|
10148 |
|
10149 | return Polygon;
|
10150 | }(Shape);
|
10151 |
|
10152 | Shape.Polygon = Polygon;
|
10153 | module.exports = Polygon;
|
10154 |
|
10155 | }),
|
10156 |
|
10157 | (function(module, exports, __webpack_require__) {
|
10158 |
|
10159 | function _inheritsLoose(subClass, superClass) {
|
10160 | subClass.prototype = Object.create(superClass.prototype);
|
10161 | subClass.prototype.constructor = subClass;
|
10162 | subClass.__proto__ = superClass;
|
10163 | }
|
10164 |
|
10165 | var Shape = __webpack_require__(2);
|
10166 |
|
10167 | var Smooth = __webpack_require__(39);
|
10168 |
|
10169 | var bbox = __webpack_require__(13);
|
10170 |
|
10171 | var Polyline =
|
10172 |
|
10173 | function (_Shape) {
|
10174 | _inheritsLoose(Polyline, _Shape);
|
10175 |
|
10176 | function Polyline() {
|
10177 | return _Shape.apply(this, arguments) || this;
|
10178 | }
|
10179 |
|
10180 | var _proto = Polyline.prototype;
|
10181 |
|
10182 | _proto._initProperties = function _initProperties() {
|
10183 | _Shape.prototype._initProperties.call(this);
|
10184 |
|
10185 | this._attrs.canFill = true;
|
10186 | this._attrs.canStroke = true;
|
10187 | this._attrs.type = 'polyline';
|
10188 | };
|
10189 |
|
10190 | _proto.getDefaultAttrs = function getDefaultAttrs() {
|
10191 | return {
|
10192 | points: null,
|
10193 | lineWidth: 1,
|
10194 | smooth: false
|
10195 | };
|
10196 | };
|
10197 |
|
10198 | _proto.createPath = function createPath(context) {
|
10199 | var self = this;
|
10200 | var attrs = self.get('attrs');
|
10201 | var points = attrs.points,
|
10202 | smooth = attrs.smooth;
|
10203 | var filteredPoints = [];
|
10204 |
|
10205 | for (var i = 0, len = points.length; i < len; i++) {
|
10206 | var point = points[i];
|
10207 |
|
10208 | if (!isNaN(point.x) && !isNaN(point.y)) {
|
10209 | filteredPoints.push(point);
|
10210 | }
|
10211 | }
|
10212 |
|
10213 | context.beginPath();
|
10214 |
|
10215 | if (filteredPoints.length) {
|
10216 | context.moveTo(filteredPoints[0].x, filteredPoints[0].y);
|
10217 |
|
10218 | if (smooth) {
|
10219 | var constaint = [[0, 0], [1, 1]];
|
10220 | var sps = Smooth.smooth(filteredPoints, false, constaint);
|
10221 |
|
10222 | for (var _i = 0, n = sps.length; _i < n; _i++) {
|
10223 | var sp = sps[_i];
|
10224 | context.bezierCurveTo(sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]);
|
10225 | }
|
10226 | } else {
|
10227 | var _i2;
|
10228 |
|
10229 | var l;
|
10230 |
|
10231 | for (_i2 = 1, l = filteredPoints.length - 1; _i2 < l; _i2++) {
|
10232 | context.lineTo(filteredPoints[_i2].x, filteredPoints[_i2].y);
|
10233 | }
|
10234 |
|
10235 | context.lineTo(filteredPoints[l].x, filteredPoints[l].y);
|
10236 | }
|
10237 | }
|
10238 | };
|
10239 |
|
10240 | _proto.calculateBox = function calculateBox() {
|
10241 | var attrs = this.get('attrs');
|
10242 | var points = attrs.points,
|
10243 | smooth = attrs.smooth,
|
10244 | lineWidth = attrs.lineWidth;
|
10245 |
|
10246 | if (smooth) {
|
10247 | var newPoints = [];
|
10248 | var constaint = [[0, 0], [1, 1]];
|
10249 | var sps = Smooth.smooth(points, false, constaint);
|
10250 |
|
10251 | for (var i = 0, n = sps.length; i < n; i++) {
|
10252 | var sp = sps[i];
|
10253 |
|
10254 | if (i === 0) {
|
10255 | newPoints.push([points[0].x, points[0].y, sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]]);
|
10256 | } else {
|
10257 | var lastPoint = sps[i - 1];
|
10258 | newPoints.push([lastPoint[5], lastPoint[6], sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]]);
|
10259 | }
|
10260 | }
|
10261 |
|
10262 | return bbox.getBBoxFromBezierGroup(newPoints, lineWidth);
|
10263 | }
|
10264 |
|
10265 | return bbox.getBBoxFromPoints(points, lineWidth);
|
10266 | };
|
10267 |
|
10268 | return Polyline;
|
10269 | }(Shape);
|
10270 |
|
10271 | Shape.Polyline = Polyline;
|
10272 | module.exports = Polyline;
|
10273 |
|
10274 | }),
|
10275 |
|
10276 | (function(module, exports, __webpack_require__) {
|
10277 |
|
10278 | function _inheritsLoose(subClass, superClass) {
|
10279 | subClass.prototype = Object.create(superClass.prototype);
|
10280 | subClass.prototype.constructor = subClass;
|
10281 | subClass.__proto__ = superClass;
|
10282 | }
|
10283 |
|
10284 | var Shape = __webpack_require__(2);
|
10285 |
|
10286 | var bbox = __webpack_require__(13);
|
10287 |
|
10288 | var Arc =
|
10289 |
|
10290 | function (_Shape) {
|
10291 | _inheritsLoose(Arc, _Shape);
|
10292 |
|
10293 | function Arc() {
|
10294 | return _Shape.apply(this, arguments) || this;
|
10295 | }
|
10296 |
|
10297 | var _proto = Arc.prototype;
|
10298 |
|
10299 | _proto._initProperties = function _initProperties() {
|
10300 | _Shape.prototype._initProperties.call(this);
|
10301 |
|
10302 | this._attrs.canStroke = true;
|
10303 | this._attrs.canFill = true;
|
10304 | this._attrs.type = 'arc';
|
10305 | };
|
10306 |
|
10307 | _proto.getDefaultAttrs = function getDefaultAttrs() {
|
10308 | return {
|
10309 | x: 0,
|
10310 | y: 0,
|
10311 | r: 0,
|
10312 | startAngle: 0,
|
10313 | endAngle: Math.PI * 2,
|
10314 | clockwise: false,
|
10315 | lineWidth: 1
|
10316 | };
|
10317 | };
|
10318 |
|
10319 | _proto.createPath = function createPath(context) {
|
10320 | var attrs = this.get('attrs');
|
10321 | var x = attrs.x,
|
10322 | y = attrs.y,
|
10323 | r = attrs.r,
|
10324 | startAngle = attrs.startAngle,
|
10325 | endAngle = attrs.endAngle,
|
10326 | clockwise = attrs.clockwise;
|
10327 | context.beginPath();
|
10328 | context.arc(x, y, r, startAngle, endAngle, clockwise);
|
10329 | };
|
10330 |
|
10331 | _proto.calculateBox = function calculateBox() {
|
10332 | var attrs = this.get('attrs');
|
10333 | var x = attrs.x,
|
10334 | y = attrs.y,
|
10335 | r = attrs.r,
|
10336 | startAngle = attrs.startAngle,
|
10337 | endAngle = attrs.endAngle,
|
10338 | clockwise = attrs.clockwise;
|
10339 | return bbox.getBBoxFromArc(x, y, r, startAngle, endAngle, clockwise);
|
10340 | };
|
10341 |
|
10342 | return Arc;
|
10343 | }(Shape);
|
10344 |
|
10345 | Shape.Arc = Arc;
|
10346 | module.exports = Arc;
|
10347 |
|
10348 | }),
|
10349 |
|
10350 | (function(module, exports, __webpack_require__) {
|
10351 |
|
10352 | function _inheritsLoose(subClass, superClass) {
|
10353 | subClass.prototype = Object.create(superClass.prototype);
|
10354 | subClass.prototype.constructor = subClass;
|
10355 | subClass.__proto__ = superClass;
|
10356 | }
|
10357 |
|
10358 | var Shape = __webpack_require__(2);
|
10359 |
|
10360 | var bbox = __webpack_require__(13);
|
10361 |
|
10362 | var Sector =
|
10363 |
|
10364 | function (_Shape) {
|
10365 | _inheritsLoose(Sector, _Shape);
|
10366 |
|
10367 | function Sector() {
|
10368 | return _Shape.apply(this, arguments) || this;
|
10369 | }
|
10370 |
|
10371 | var _proto = Sector.prototype;
|
10372 |
|
10373 | _proto._initProperties = function _initProperties() {
|
10374 | _Shape.prototype._initProperties.call(this);
|
10375 |
|
10376 | this._attrs.canFill = true;
|
10377 | this._attrs.canStroke = true;
|
10378 | this._attrs.type = 'sector';
|
10379 | };
|
10380 |
|
10381 | _proto.getDefaultAttrs = function getDefaultAttrs() {
|
10382 | return {
|
10383 | x: 0,
|
10384 | y: 0,
|
10385 | lineWidth: 0,
|
10386 | r: 0,
|
10387 | r0: 0,
|
10388 | startAngle: 0,
|
10389 | endAngle: Math.PI * 2,
|
10390 | clockwise: false
|
10391 | };
|
10392 | };
|
10393 |
|
10394 | _proto.createPath = function createPath(context) {
|
10395 | var attrs = this.get('attrs');
|
10396 | var x = attrs.x,
|
10397 | y = attrs.y,
|
10398 | startAngle = attrs.startAngle,
|
10399 | endAngle = attrs.endAngle,
|
10400 | r = attrs.r,
|
10401 | r0 = attrs.r0,
|
10402 | clockwise = attrs.clockwise;
|
10403 | context.beginPath();
|
10404 | var unitX = Math.cos(startAngle);
|
10405 | var unitY = Math.sin(startAngle);
|
10406 | context.moveTo(unitX * r0 + x, unitY * r0 + y);
|
10407 | context.lineTo(unitX * r + x, unitY * r + y);
|
10408 | context.arc(x, y, r, startAngle, endAngle, clockwise);
|
10409 | context.lineTo(Math.cos(endAngle) * r0 + x, Math.sin(endAngle) * r0 + y);
|
10410 |
|
10411 | if (r0 !== 0) {
|
10412 | context.arc(x, y, r0, endAngle, startAngle, !clockwise);
|
10413 | }
|
10414 |
|
10415 | context.closePath();
|
10416 | };
|
10417 |
|
10418 | _proto.calculateBox = function calculateBox() {
|
10419 | var attrs = this.get('attrs');
|
10420 | var x = attrs.x,
|
10421 | y = attrs.y,
|
10422 | r = attrs.r,
|
10423 | r0 = attrs.r0,
|
10424 | startAngle = attrs.startAngle,
|
10425 | endAngle = attrs.endAngle,
|
10426 | clockwise = attrs.clockwise;
|
10427 | var outerBBox = bbox.getBBoxFromArc(x, y, r, startAngle, endAngle, clockwise);
|
10428 | var innerBBox = bbox.getBBoxFromArc(x, y, r0, startAngle, endAngle, clockwise);
|
10429 | return {
|
10430 | minX: Math.min(outerBBox.minX, innerBBox.minX),
|
10431 | minY: Math.min(outerBBox.minY, innerBBox.minY),
|
10432 | maxX: Math.max(outerBBox.maxX, innerBBox.maxX),
|
10433 | maxY: Math.max(outerBBox.maxY, innerBBox.maxY)
|
10434 | };
|
10435 | };
|
10436 |
|
10437 | return Sector;
|
10438 | }(Shape);
|
10439 |
|
10440 | Shape.Sector = Sector;
|
10441 | module.exports = Sector;
|
10442 |
|
10443 | }),
|
10444 |
|
10445 | (function(module, exports, __webpack_require__) {
|
10446 |
|
10447 | function _inheritsLoose(subClass, superClass) {
|
10448 | subClass.prototype = Object.create(superClass.prototype);
|
10449 | subClass.prototype.constructor = subClass;
|
10450 | subClass.__proto__ = superClass;
|
10451 | }
|
10452 |
|
10453 | var Util = __webpack_require__(0);
|
10454 |
|
10455 | var Shape = __webpack_require__(2);
|
10456 |
|
10457 | var textWidthCacheCounter = 0;
|
10458 | var textWidthCache = {};
|
10459 | var TEXT_CACHE_MAX = 5000;
|
10460 |
|
10461 | var Text =
|
10462 |
|
10463 | function (_Shape) {
|
10464 | _inheritsLoose(Text, _Shape);
|
10465 |
|
10466 | function Text() {
|
10467 | return _Shape.apply(this, arguments) || this;
|
10468 | }
|
10469 |
|
10470 | var _proto = Text.prototype;
|
10471 |
|
10472 | _proto._initProperties = function _initProperties() {
|
10473 | _Shape.prototype._initProperties.call(this);
|
10474 |
|
10475 | this._attrs.canFill = true;
|
10476 | this._attrs.canStroke = true;
|
10477 | this._attrs.type = 'text';
|
10478 | };
|
10479 |
|
10480 | _proto.getDefaultAttrs = function getDefaultAttrs() {
|
10481 | return {
|
10482 | lineWidth: 0,
|
10483 | lineCount: 1,
|
10484 | fontSize: 12,
|
10485 | fontFamily: 'sans-serif',
|
10486 | fontStyle: 'normal',
|
10487 | fontWeight: 'normal',
|
10488 | fontVariant: 'normal',
|
10489 | textAlign: 'start',
|
10490 | textBaseline: 'bottom',
|
10491 | lineHeight: null,
|
10492 | textArr: null
|
10493 | };
|
10494 | };
|
10495 |
|
10496 | _proto._getFontStyle = function _getFontStyle() {
|
10497 | var attrs = this._attrs.attrs;
|
10498 | var fontSize = attrs.fontSize,
|
10499 | fontFamily = attrs.fontFamily,
|
10500 | fontWeight = attrs.fontWeight,
|
10501 | fontStyle = attrs.fontStyle,
|
10502 | fontVariant = attrs.fontVariant;
|
10503 | return fontStyle + " " + fontVariant + " " + fontWeight + " " + fontSize + "px " + fontFamily;
|
10504 | };
|
10505 |
|
10506 | _proto._afterAttrsSet = function _afterAttrsSet() {
|
10507 | var attrs = this._attrs.attrs;
|
10508 | attrs.font = this._getFontStyle();
|
10509 |
|
10510 | if (attrs.text) {
|
10511 | var text = attrs.text;
|
10512 | var textArr = null;
|
10513 | var lineCount = 1;
|
10514 |
|
10515 | if (Util.isString(text) && text.indexOf('\n') !== -1) {
|
10516 | textArr = text.split('\n');
|
10517 | lineCount = textArr.length;
|
10518 | }
|
10519 |
|
10520 | attrs.lineCount = lineCount;
|
10521 | attrs.textArr = textArr;
|
10522 | }
|
10523 |
|
10524 | this.set('attrs', attrs);
|
10525 | };
|
10526 |
|
10527 | _proto._getTextHeight = function _getTextHeight() {
|
10528 | var attrs = this._attrs.attrs;
|
10529 |
|
10530 | if (attrs.height) {
|
10531 | return attrs.height;
|
10532 | }
|
10533 |
|
10534 | var lineCount = attrs.lineCount;
|
10535 | var fontSize = attrs.fontSize * 1;
|
10536 |
|
10537 | if (lineCount > 1) {
|
10538 | var spaceingY = this._getSpaceingY();
|
10539 |
|
10540 | return fontSize * lineCount + spaceingY * (lineCount - 1);
|
10541 | }
|
10542 |
|
10543 | return fontSize;
|
10544 | };
|
10545 |
|
10546 | _proto._getSpaceingY = function _getSpaceingY() {
|
10547 | var attrs = this._attrs.attrs;
|
10548 | var lineHeight = attrs.lineHeight;
|
10549 | var fontSize = attrs.fontSize * 1;
|
10550 | return lineHeight ? lineHeight - fontSize : fontSize * 0.14;
|
10551 | };
|
10552 |
|
10553 | _proto.drawInner = function drawInner(context) {
|
10554 | var self = this;
|
10555 | var attrs = self._attrs.attrs;
|
10556 | var text = attrs.text;
|
10557 | var x = attrs.x;
|
10558 | var y = attrs.y;
|
10559 |
|
10560 | if (Util.isNil(text) || isNaN(x) || isNaN(y)) {
|
10561 |
|
10562 | return;
|
10563 | }
|
10564 |
|
10565 | var textArr = attrs.textArr;
|
10566 | var fontSize = attrs.fontSize * 1;
|
10567 |
|
10568 | var spaceingY = self._getSpaceingY();
|
10569 |
|
10570 | if (attrs.rotate) {
|
10571 |
|
10572 | context.translate(x, y);
|
10573 | context.rotate(attrs.rotate);
|
10574 | x = 0;
|
10575 | y = 0;
|
10576 | }
|
10577 |
|
10578 | var textBaseline = attrs.textBaseline;
|
10579 | var height;
|
10580 |
|
10581 | if (textArr) {
|
10582 | height = self._getTextHeight();
|
10583 | }
|
10584 |
|
10585 | var subY;
|
10586 |
|
10587 | if (self.hasFill()) {
|
10588 | var fillOpacity = attrs.fillOpacity;
|
10589 |
|
10590 | if (!Util.isNil(fillOpacity) && fillOpacity !== 1) {
|
10591 | context.globalAlpha = fillOpacity;
|
10592 | }
|
10593 |
|
10594 | if (textArr) {
|
10595 | for (var i = 0, len = textArr.length; i < len; i++) {
|
10596 | var subText = textArr[i];
|
10597 | subY = y + i * (spaceingY + fontSize) - height + fontSize;
|
10598 |
|
10599 | if (textBaseline === 'middle') {
|
10600 | subY += height - fontSize - (height - fontSize) / 2;
|
10601 | }
|
10602 |
|
10603 | if (textBaseline === 'top') {
|
10604 | subY += height - fontSize;
|
10605 | }
|
10606 |
|
10607 | context.fillText(subText, x, subY);
|
10608 | }
|
10609 | } else {
|
10610 | context.fillText(text, x, y);
|
10611 | }
|
10612 | }
|
10613 |
|
10614 | if (self.hasStroke()) {
|
10615 | if (textArr) {
|
10616 | for (var _i = 0, _len = textArr.length; _i < _len; _i++) {
|
10617 | var _subText = textArr[_i];
|
10618 | subY = y + _i * (spaceingY + fontSize) - height + fontSize;
|
10619 |
|
10620 | if (textBaseline === 'middle') {
|
10621 | subY += height - fontSize - (height - fontSize) / 2;
|
10622 | }
|
10623 |
|
10624 | if (textBaseline === 'top') {
|
10625 | subY += height - fontSize;
|
10626 | }
|
10627 |
|
10628 | context.strokeText(_subText, x, subY);
|
10629 | }
|
10630 | } else {
|
10631 | context.strokeText(text, x, y);
|
10632 | }
|
10633 | }
|
10634 | };
|
10635 |
|
10636 | _proto.calculateBox = function calculateBox() {
|
10637 | var self = this;
|
10638 | var attrs = self._attrs.attrs;
|
10639 | var x = attrs.x,
|
10640 | y = attrs.y,
|
10641 | textAlign = attrs.textAlign,
|
10642 | textBaseline = attrs.textBaseline;
|
10643 |
|
10644 | var width = self._getTextWidth();
|
10645 |
|
10646 |
|
10647 | if (!width) {
|
10648 | return {
|
10649 | minX: x,
|
10650 | minY: y,
|
10651 | maxX: x,
|
10652 | maxY: y
|
10653 | };
|
10654 | }
|
10655 |
|
10656 | var height = self._getTextHeight();
|
10657 |
|
10658 |
|
10659 | var point = {
|
10660 | x: x,
|
10661 | y: y - height
|
10662 | };
|
10663 |
|
10664 | if (textAlign) {
|
10665 | if (textAlign === 'end' || textAlign === 'right') {
|
10666 | point.x -= width;
|
10667 | } else if (textAlign === 'center') {
|
10668 | point.x -= width / 2;
|
10669 | }
|
10670 | }
|
10671 |
|
10672 | if (textBaseline) {
|
10673 | if (textBaseline === 'top') {
|
10674 | point.y += height;
|
10675 | } else if (textBaseline === 'middle') {
|
10676 | point.y += height / 2;
|
10677 | }
|
10678 | }
|
10679 |
|
10680 | return {
|
10681 | minX: point.x,
|
10682 | minY: point.y,
|
10683 | maxX: point.x + width,
|
10684 | maxY: point.y + height
|
10685 | };
|
10686 | };
|
10687 |
|
10688 | _proto._getTextWidth = function _getTextWidth() {
|
10689 | var attrs = this._attrs.attrs;
|
10690 |
|
10691 | if (attrs.width) {
|
10692 | return attrs.width;
|
10693 | }
|
10694 |
|
10695 | var text = attrs.text;
|
10696 | var context = this.get('context');
|
10697 | if (Util.isNil(text)) return undefined;
|
10698 | var font = attrs.font;
|
10699 | var textArr = attrs.textArr;
|
10700 | var key = text + '' + font;
|
10701 |
|
10702 | if (textWidthCache[key]) {
|
10703 | return textWidthCache[key];
|
10704 | }
|
10705 |
|
10706 | var width = 0;
|
10707 |
|
10708 | if (textArr) {
|
10709 | for (var i = 0, length = textArr.length; i < length; i++) {
|
10710 | var subText = textArr[i];
|
10711 | width = Math.max(width, Util.measureText(subText, font, context).width);
|
10712 | }
|
10713 | } else {
|
10714 | width = Util.measureText(text, font, context).width;
|
10715 | }
|
10716 |
|
10717 | if (textWidthCacheCounter > TEXT_CACHE_MAX) {
|
10718 | textWidthCacheCounter = 0;
|
10719 | textWidthCache = {};
|
10720 | }
|
10721 |
|
10722 | textWidthCacheCounter++;
|
10723 | textWidthCache[key] = width;
|
10724 | return width;
|
10725 | };
|
10726 |
|
10727 | return Text;
|
10728 | }(Shape);
|
10729 |
|
10730 | Shape.Text = Text;
|
10731 | module.exports = Text;
|
10732 |
|
10733 | }),
|
10734 |
|
10735 | (function(module, exports, __webpack_require__) {
|
10736 |
|
10737 | function _inheritsLoose(subClass, superClass) {
|
10738 | subClass.prototype = Object.create(superClass.prototype);
|
10739 | subClass.prototype.constructor = subClass;
|
10740 | subClass.__proto__ = superClass;
|
10741 | }
|
10742 |
|
10743 | var Shape = __webpack_require__(2);
|
10744 |
|
10745 | var Custom =
|
10746 |
|
10747 | function (_Shape) {
|
10748 | _inheritsLoose(Custom, _Shape);
|
10749 |
|
10750 | function Custom() {
|
10751 | return _Shape.apply(this, arguments) || this;
|
10752 | }
|
10753 |
|
10754 | var _proto = Custom.prototype;
|
10755 |
|
10756 | _proto._initProperties = function _initProperties() {
|
10757 | _Shape.prototype._initProperties.call(this);
|
10758 |
|
10759 | this._attrs.canFill = true;
|
10760 | this._attrs.canStroke = true;
|
10761 | this._attrs.createPath = null;
|
10762 | this._attrs.type = 'custom';
|
10763 | };
|
10764 |
|
10765 | _proto.createPath = function createPath(context) {
|
10766 | var createPath = this.get('createPath');
|
10767 | createPath && createPath.call(this, context);
|
10768 | };
|
10769 |
|
10770 | _proto.calculateBox = function calculateBox() {
|
10771 | var calculateBox = this.get('calculateBox');
|
10772 | return calculateBox && calculateBox.call(this);
|
10773 | };
|
10774 |
|
10775 | return Custom;
|
10776 | }(Shape);
|
10777 |
|
10778 | Shape.Custom = Custom;
|
10779 | module.exports = Custom;
|
10780 |
|
10781 | }),
|
10782 |
|
10783 | (function(module, exports, __webpack_require__) {
|
10784 |
|
10785 |
|
10786 |
|
10787 |
|
10788 |
|
10789 | var Global = __webpack_require__(1);
|
10790 |
|
10791 | var Util = __webpack_require__(0);
|
10792 |
|
10793 | var SERVER_URL = 'https://kcart.alipay.com/web/bi.do';
|
10794 | setTimeout(function () {
|
10795 | if (Global.trackable && Util.isBrowser) {
|
10796 |
|
10797 | var image = new Image();
|
10798 | var newObj = {
|
10799 | pg: document.URL,
|
10800 | r: new Date().getTime(),
|
10801 | f2: true,
|
10802 | version: Global.version,
|
10803 | page_type: 'syslog'
|
10804 | };
|
10805 | var d = encodeURIComponent(JSON.stringify([newObj]));
|
10806 | image.src = SERVER_URL + "?BIProfile=merge&d=" + d;
|
10807 | }
|
10808 | }, 3000);
|
10809 |
|
10810 | }),
|
10811 |
|
10812 | (function(module, exports, __webpack_require__) {
|
10813 |
|
10814 | var Geom = __webpack_require__(5);
|
10815 |
|
10816 | __webpack_require__(91);
|
10817 |
|
10818 | __webpack_require__(40);
|
10819 |
|
10820 | __webpack_require__(93);
|
10821 |
|
10822 | __webpack_require__(94);
|
10823 |
|
10824 | __webpack_require__(96);
|
10825 |
|
10826 | __webpack_require__(98);
|
10827 |
|
10828 | __webpack_require__(100);
|
10829 |
|
10830 | module.exports = Geom;
|
10831 |
|
10832 | }),
|
10833 |
|
10834 | (function(module, exports, __webpack_require__) {
|
10835 |
|
10836 | function _inheritsLoose(subClass, superClass) {
|
10837 | subClass.prototype = Object.create(superClass.prototype);
|
10838 | subClass.prototype.constructor = subClass;
|
10839 | subClass.__proto__ = superClass;
|
10840 | }
|
10841 |
|
10842 | var Util = __webpack_require__(0);
|
10843 |
|
10844 | var Geom = __webpack_require__(5);
|
10845 |
|
10846 | __webpack_require__(92);
|
10847 |
|
10848 | var Point =
|
10849 |
|
10850 | function (_Geom) {
|
10851 | _inheritsLoose(Point, _Geom);
|
10852 |
|
10853 | function Point() {
|
10854 | return _Geom.apply(this, arguments) || this;
|
10855 | }
|
10856 |
|
10857 | var _proto = Point.prototype;
|
10858 |
|
10859 | _proto.getDefaultCfg = function getDefaultCfg() {
|
10860 | var cfg = _Geom.prototype.getDefaultCfg.call(this);
|
10861 |
|
10862 | cfg.type = 'point';
|
10863 | cfg.shapeType = 'point';
|
10864 | cfg.generatePoints = true;
|
10865 | return cfg;
|
10866 | };
|
10867 |
|
10868 | _proto.draw = function draw(data, shapeFactory) {
|
10869 | var self = this;
|
10870 | var container = self.get('container');
|
10871 | Util.each(data, function (obj) {
|
10872 | var shape = obj.shape;
|
10873 | var cfg = self.getDrawCfg(obj);
|
10874 |
|
10875 | if (Util.isArray(obj.y)) {
|
10876 | var hasStack = self.hasAdjust('stack');
|
10877 | Util.each(obj.y, function (y, idx) {
|
10878 | cfg.y = y;
|
10879 |
|
10880 | if (!hasStack || idx !== 0) {
|
10881 | self.drawShape(shape, obj, cfg, container, shapeFactory);
|
10882 | }
|
10883 | });
|
10884 | } else if (!Util.isNil(obj.y)) {
|
10885 | self.drawShape(shape, obj, cfg, container, shapeFactory);
|
10886 | }
|
10887 | });
|
10888 | };
|
10889 |
|
10890 | return Point;
|
10891 | }(Geom);
|
10892 |
|
10893 | Geom.Point = Point;
|
10894 | module.exports = Point;
|
10895 |
|
10896 | }),
|
10897 |
|
10898 | (function(module, exports, __webpack_require__) {
|
10899 |
|
10900 | var Util = __webpack_require__(0);
|
10901 |
|
10902 | var Global = __webpack_require__(1);
|
10903 |
|
10904 | var ShapeUtil = __webpack_require__(21);
|
10905 |
|
10906 | var Shape = __webpack_require__(6);
|
10907 |
|
10908 | var SHAPES = ['circle', 'hollowCircle', 'rect'];
|
10909 | var Point = Shape.registerFactory('point', {
|
10910 | defaultShapeType: 'circle',
|
10911 | getDefaultPoints: function getDefaultPoints(pointInfo) {
|
10912 | return ShapeUtil.splitPoints(pointInfo);
|
10913 | }
|
10914 | });
|
10915 |
|
10916 | function getPointsCfg(cfg) {
|
10917 | var style = {
|
10918 | lineWidth: 0,
|
10919 | stroke: cfg.color,
|
10920 | fill: cfg.color
|
10921 | };
|
10922 |
|
10923 | if (cfg.size) {
|
10924 | style.size = cfg.size;
|
10925 | }
|
10926 |
|
10927 | Util.mix(style, cfg.style);
|
10928 | return Util.mix({}, Global.shape.point, style);
|
10929 | }
|
10930 |
|
10931 | function drawShape(cfg, container, shape) {
|
10932 | if (cfg.size === 0) return;
|
10933 | var pointCfg = getPointsCfg(cfg);
|
10934 | var size = pointCfg.r || pointCfg.size;
|
10935 | var x = cfg.x;
|
10936 | var y = !Util.isArray(cfg.y) ? [cfg.y] : cfg.y;
|
10937 |
|
10938 | if (shape === 'hollowCircle') {
|
10939 | pointCfg.lineWidth = 1;
|
10940 | pointCfg.fill = null;
|
10941 | }
|
10942 |
|
10943 | for (var i = 0, len = y.length; i < len; i++) {
|
10944 | if (shape === 'rect') {
|
10945 | return container.addShape('Rect', {
|
10946 | className: 'point',
|
10947 | attrs: Util.mix({
|
10948 | x: x - size,
|
10949 | y: y[i] - size,
|
10950 | width: size * 2,
|
10951 | height: size * 2
|
10952 | }, pointCfg)
|
10953 | });
|
10954 | }
|
10955 |
|
10956 | return container.addShape('Circle', {
|
10957 | className: 'point',
|
10958 | attrs: Util.mix({
|
10959 | x: x,
|
10960 | y: y[i],
|
10961 | r: size
|
10962 | }, pointCfg)
|
10963 | });
|
10964 | }
|
10965 | }
|
10966 |
|
10967 | Util.each(SHAPES, function (shapeType) {
|
10968 | Shape.registerShape('point', shapeType, {
|
10969 | draw: function draw(cfg, container) {
|
10970 | return drawShape(cfg, container, shapeType);
|
10971 | }
|
10972 | });
|
10973 | });
|
10974 | module.exports = Point;
|
10975 |
|
10976 | }),
|
10977 |
|
10978 | (function(module, exports, __webpack_require__) {
|
10979 |
|
10980 | function _inheritsLoose(subClass, superClass) {
|
10981 | subClass.prototype = Object.create(superClass.prototype);
|
10982 | subClass.prototype.constructor = subClass;
|
10983 | subClass.__proto__ = superClass;
|
10984 | }
|
10985 |
|
10986 | var Path = __webpack_require__(40);
|
10987 |
|
10988 | var Geom = __webpack_require__(5);
|
10989 |
|
10990 | __webpack_require__(41);
|
10991 |
|
10992 | var Line =
|
10993 |
|
10994 | function (_Path) {
|
10995 | _inheritsLoose(Line, _Path);
|
10996 |
|
10997 | function Line() {
|
10998 | return _Path.apply(this, arguments) || this;
|
10999 | }
|
11000 |
|
11001 | var _proto = Line.prototype;
|
11002 |
|
11003 | _proto.getDefaultCfg = function getDefaultCfg() {
|
11004 | var cfg = _Path.prototype.getDefaultCfg.call(this);
|
11005 |
|
11006 | cfg.type = 'line';
|
11007 | cfg.sortable = true;
|
11008 | return cfg;
|
11009 | };
|
11010 |
|
11011 | return Line;
|
11012 | }(Path);
|
11013 |
|
11014 | Geom.Line = Line;
|
11015 | module.exports = Line;
|
11016 |
|
11017 | }),
|
11018 |
|
11019 | (function(module, exports, __webpack_require__) {
|
11020 |
|
11021 | function _inheritsLoose(subClass, superClass) {
|
11022 | subClass.prototype = Object.create(superClass.prototype);
|
11023 | subClass.prototype.constructor = subClass;
|
11024 | subClass.__proto__ = superClass;
|
11025 | }
|
11026 |
|
11027 |
|
11028 |
|
11029 |
|
11030 |
|
11031 |
|
11032 |
|
11033 | var Geom = __webpack_require__(5);
|
11034 |
|
11035 | var ShapeUtil = __webpack_require__(21);
|
11036 |
|
11037 | var Util = __webpack_require__(0);
|
11038 |
|
11039 | __webpack_require__(95);
|
11040 |
|
11041 | var Area =
|
11042 |
|
11043 | function (_Geom) {
|
11044 | _inheritsLoose(Area, _Geom);
|
11045 |
|
11046 | function Area() {
|
11047 | return _Geom.apply(this, arguments) || this;
|
11048 | }
|
11049 |
|
11050 | var _proto = Area.prototype;
|
11051 | |
11052 |
|
11053 |
|
11054 |
|
11055 |
|
11056 |
|
11057 | _proto.getDefaultCfg = function getDefaultCfg() {
|
11058 | var cfg = _Geom.prototype.getDefaultCfg.call(this);
|
11059 |
|
11060 | cfg.type = 'area';
|
11061 | cfg.shapeType = 'area';
|
11062 | cfg.generatePoints = true;
|
11063 | cfg.sortable = true;
|
11064 | return cfg;
|
11065 | };
|
11066 |
|
11067 | _proto.draw = function draw(data, shapeFactory) {
|
11068 | var self = this;
|
11069 | var container = self.get('container');
|
11070 | var cfg = this.getDrawCfg(data[0]);
|
11071 | var yScale = self.getYScale();
|
11072 | var connectNulls = self.get('connectNulls');
|
11073 | var splitArray = ShapeUtil.splitArray(data, yScale.field, connectNulls);
|
11074 | cfg.origin = data;
|
11075 | Util.each(splitArray, function (subData, splitedIndex) {
|
11076 | cfg.splitedIndex = splitedIndex;
|
11077 | var points = subData.map(function (obj) {
|
11078 | return obj.points;
|
11079 | });
|
11080 | cfg.points = points;
|
11081 | self.drawShape(cfg.shape, data[0], cfg, container, shapeFactory);
|
11082 | });
|
11083 | };
|
11084 |
|
11085 | return Area;
|
11086 | }(Geom);
|
11087 |
|
11088 | Geom.Area = Area;
|
11089 | module.exports = Area;
|
11090 |
|
11091 | }),
|
11092 |
|
11093 | (function(module, exports, __webpack_require__) {
|
11094 |
|
11095 | var Util = __webpack_require__(0);
|
11096 |
|
11097 | var Shape = __webpack_require__(6);
|
11098 |
|
11099 | var Smooth = __webpack_require__(39);
|
11100 |
|
11101 | var bbox = __webpack_require__(13);
|
11102 |
|
11103 | var Global = __webpack_require__(1);
|
11104 |
|
11105 | function equals(v1, v2) {
|
11106 | return Math.abs(v1 - v2) < 0.00001;
|
11107 | }
|
11108 |
|
11109 | function notEmpty(value) {
|
11110 | return !isNaN(value) && !Util.isNil(value);
|
11111 | }
|
11112 |
|
11113 | function filterPoints(points) {
|
11114 | var filteredPoints = [];
|
11115 |
|
11116 | for (var i = 0, len = points.length; i < len; i++) {
|
11117 | var point = points[i];
|
11118 |
|
11119 | if (notEmpty(point.x) && notEmpty(point.y)) {
|
11120 | filteredPoints.push(point);
|
11121 | }
|
11122 | }
|
11123 |
|
11124 | return filteredPoints;
|
11125 | }
|
11126 |
|
11127 | function equalsCenter(points, center) {
|
11128 | var eqls = true;
|
11129 | Util.each(points, function (point) {
|
11130 | if (!equals(point.x, center.x) || !equals(point.y, center.y)) {
|
11131 | eqls = false;
|
11132 | return false;
|
11133 | }
|
11134 | });
|
11135 | return eqls;
|
11136 | }
|
11137 |
|
11138 | function drawRectShape(topPoints, bottomPoints, container, style, isSmooth) {
|
11139 | var shape;
|
11140 | var points = topPoints.concat(bottomPoints);
|
11141 |
|
11142 | if (isSmooth) {
|
11143 | shape = container.addShape('Custom', {
|
11144 | className: 'area',
|
11145 | attrs: Util.mix({
|
11146 | points: points
|
11147 | }, style),
|
11148 | createPath: function createPath(context) {
|
11149 | var constaint = [[0, 0], [1, 1]];
|
11150 | var points = filterPoints(this._attrs.attrs.points);
|
11151 | var pointsLen = points.length;
|
11152 | var topPoints = points.slice(0, pointsLen / 2);
|
11153 | var bottomPoints = points.slice(pointsLen / 2, pointsLen);
|
11154 | var topSps = Smooth.smooth(topPoints, false, constaint);
|
11155 | context.beginPath();
|
11156 | context.moveTo(topPoints[0].x, topPoints[0].y);
|
11157 |
|
11158 | for (var i = 0, n = topSps.length; i < n; i++) {
|
11159 | var sp = topSps[i];
|
11160 | context.bezierCurveTo(sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]);
|
11161 | }
|
11162 |
|
11163 | if (bottomPoints.length) {
|
11164 | var bottomSps = Smooth.smooth(bottomPoints, false, constaint);
|
11165 | context.lineTo(bottomPoints[0].x, bottomPoints[0].y);
|
11166 |
|
11167 | for (var _i = 0, _n = bottomSps.length; _i < _n; _i++) {
|
11168 | var _sp = bottomSps[_i];
|
11169 | context.bezierCurveTo(_sp[1], _sp[2], _sp[3], _sp[4], _sp[5], _sp[6]);
|
11170 | }
|
11171 | }
|
11172 |
|
11173 | context.closePath();
|
11174 | },
|
11175 | calculateBox: function calculateBox() {
|
11176 | var points = filterPoints(this._attrs.attrs.points);
|
11177 | return bbox.getBBoxFromPoints(points);
|
11178 | }
|
11179 | });
|
11180 | } else {
|
11181 | shape = container.addShape('Polyline', {
|
11182 | className: 'area',
|
11183 | attrs: Util.mix({
|
11184 | points: points
|
11185 | }, style)
|
11186 | });
|
11187 | }
|
11188 |
|
11189 | return shape;
|
11190 | }
|
11191 |
|
11192 | function drawShape(cfg, container, isSmooth) {
|
11193 | var self = this;
|
11194 | var points = cfg.points;
|
11195 | var topPoints = [];
|
11196 | var bottomPoints = [];
|
11197 | Util.each(points, function (point) {
|
11198 | bottomPoints.push(point[0]);
|
11199 | topPoints.push(point[1]);
|
11200 | });
|
11201 | var style = Util.mix({
|
11202 | fillStyle: cfg.color
|
11203 | }, Global.shape.area, cfg.style);
|
11204 | bottomPoints.reverse();
|
11205 | topPoints = self.parsePoints(topPoints);
|
11206 | bottomPoints = self.parsePoints(bottomPoints);
|
11207 |
|
11208 | if (cfg.isInCircle) {
|
11209 | topPoints.push(topPoints[0]);
|
11210 | bottomPoints.unshift(bottomPoints[bottomPoints.length - 1]);
|
11211 |
|
11212 | if (equalsCenter(bottomPoints, cfg.center)) {
|
11213 | bottomPoints = [];
|
11214 | }
|
11215 | }
|
11216 |
|
11217 | return drawRectShape(topPoints, bottomPoints, container, style, isSmooth);
|
11218 | }
|
11219 |
|
11220 | var Area = Shape.registerFactory('area', {
|
11221 | defaultShapeType: 'area',
|
11222 | getDefaultPoints: function getDefaultPoints(obj) {
|
11223 | var x = obj.x;
|
11224 | var y = obj.y;
|
11225 | var y0 = obj.y0;
|
11226 | y = Util.isArray(y) ? y : [y0, y];
|
11227 | var points = [];
|
11228 | points.push({
|
11229 | x: x,
|
11230 | y: y[0]
|
11231 | }, {
|
11232 | x: x,
|
11233 | y: y[1]
|
11234 | });
|
11235 | return points;
|
11236 | }
|
11237 | });
|
11238 | var SHAPES = ['area', 'smooth'];
|
11239 | Util.each(SHAPES, function (shapeType) {
|
11240 | Shape.registerShape('area', shapeType, {
|
11241 | draw: function draw(cfg, container) {
|
11242 | var smooth = shapeType === 'smooth';
|
11243 | return drawShape.call(this, cfg, container, smooth);
|
11244 | }
|
11245 | });
|
11246 | });
|
11247 | module.exports = Area;
|
11248 |
|
11249 | }),
|
11250 |
|
11251 | (function(module, exports, __webpack_require__) {
|
11252 |
|
11253 | function _inheritsLoose(subClass, superClass) {
|
11254 | subClass.prototype = Object.create(superClass.prototype);
|
11255 | subClass.prototype.constructor = subClass;
|
11256 | subClass.__proto__ = superClass;
|
11257 | }
|
11258 |
|
11259 | function _assertThisInitialized(self) {
|
11260 | if (self === void 0) {
|
11261 | throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
11262 | }
|
11263 |
|
11264 | return self;
|
11265 | }
|
11266 |
|
11267 | var Geom = __webpack_require__(5);
|
11268 |
|
11269 | var Util = __webpack_require__(0);
|
11270 |
|
11271 | var SizeMixin = __webpack_require__(42);
|
11272 |
|
11273 | __webpack_require__(97);
|
11274 |
|
11275 | var Interval =
|
11276 |
|
11277 | function (_Geom) {
|
11278 | _inheritsLoose(Interval, _Geom);
|
11279 |
|
11280 | var _proto = Interval.prototype;
|
11281 |
|
11282 | _proto.getDefaultCfg = function getDefaultCfg() {
|
11283 | var cfg = _Geom.prototype.getDefaultCfg.call(this);
|
11284 |
|
11285 | cfg.type = 'interval';
|
11286 | cfg.shapeType = 'interval';
|
11287 | cfg.generatePoints = true;
|
11288 | return cfg;
|
11289 | };
|
11290 |
|
11291 | function Interval(cfg) {
|
11292 | var _this;
|
11293 |
|
11294 | _this = _Geom.call(this, cfg) || this;
|
11295 | Util.mix(_assertThisInitialized(_assertThisInitialized(_this)), SizeMixin);
|
11296 | return _this;
|
11297 | }
|
11298 |
|
11299 | _proto.createShapePointsCfg = function createShapePointsCfg(obj) {
|
11300 | var cfg = _Geom.prototype.createShapePointsCfg.call(this, obj);
|
11301 |
|
11302 | cfg.size = this.getNormalizedSize(obj);
|
11303 | return cfg;
|
11304 | };
|
11305 |
|
11306 | _proto.clearInner = function clearInner() {
|
11307 | _Geom.prototype.clearInner.call(this);
|
11308 |
|
11309 | this.set('defaultSize', null);
|
11310 | };
|
11311 |
|
11312 | return Interval;
|
11313 | }(Geom);
|
11314 |
|
11315 | Geom.Interval = Interval;
|
11316 | module.exports = Interval;
|
11317 |
|
11318 | }),
|
11319 |
|
11320 | (function(module, exports, __webpack_require__) {
|
11321 |
|
11322 | var Util = __webpack_require__(0);
|
11323 |
|
11324 | var Shape = __webpack_require__(6);
|
11325 |
|
11326 | var Vector2 = __webpack_require__(7);
|
11327 |
|
11328 | var Global = __webpack_require__(1);
|
11329 |
|
11330 | function getRectPoints(cfg) {
|
11331 | var x = cfg.x,
|
11332 | y = cfg.y,
|
11333 | y0 = cfg.y0,
|
11334 | size = cfg.size;
|
11335 | var ymin = y0;
|
11336 | var ymax = y;
|
11337 |
|
11338 | if (Util.isArray(y)) {
|
11339 | ymax = y[1];
|
11340 | ymin = y[0];
|
11341 | }
|
11342 |
|
11343 | var xmin;
|
11344 | var xmax;
|
11345 |
|
11346 | if (Util.isArray(x)) {
|
11347 | xmin = x[0];
|
11348 | xmax = x[1];
|
11349 | } else {
|
11350 | xmin = x - size / 2;
|
11351 | xmax = x + size / 2;
|
11352 | }
|
11353 |
|
11354 | return [{
|
11355 | x: xmin,
|
11356 | y: ymin
|
11357 | }, {
|
11358 | x: xmin,
|
11359 | y: ymax
|
11360 | }, {
|
11361 | x: xmax,
|
11362 | y: ymax
|
11363 | }, {
|
11364 | x: xmax,
|
11365 | y: ymin
|
11366 | }];
|
11367 | }
|
11368 |
|
11369 | function getRectRange(points) {
|
11370 | var xValues = [];
|
11371 | var yValues = [];
|
11372 |
|
11373 | for (var i = 0, len = points.length; i < len; i++) {
|
11374 | var point = points[i];
|
11375 | xValues.push(point.x);
|
11376 | yValues.push(point.y);
|
11377 | }
|
11378 |
|
11379 | var xMin = Math.min.apply(null, xValues);
|
11380 | var yMin = Math.min.apply(null, yValues);
|
11381 | var xMax = Math.max.apply(null, xValues);
|
11382 | var yMax = Math.max.apply(null, yValues);
|
11383 | return {
|
11384 | x: xMin,
|
11385 | y: yMin,
|
11386 | width: xMax - xMin,
|
11387 | height: yMax - yMin
|
11388 | };
|
11389 | }
|
11390 |
|
11391 | var Interval = Shape.registerFactory('interval', {
|
11392 | defaultShapeType: 'rect',
|
11393 | getDefaultPoints: function getDefaultPoints(cfg) {
|
11394 | return getRectPoints(cfg);
|
11395 | }
|
11396 | });
|
11397 | Shape.registerShape('interval', 'rect', {
|
11398 | draw: function draw(cfg, container) {
|
11399 | var points = this.parsePoints(cfg.points);
|
11400 | var style = Util.mix({
|
11401 | fill: cfg.color
|
11402 | }, Global.shape.interval, cfg.style);
|
11403 |
|
11404 | if (cfg.isInCircle) {
|
11405 | var newPoints = points.slice(0);
|
11406 |
|
11407 | if (this._coord.transposed) {
|
11408 | newPoints = [points[0], points[3], points[2], points[1]];
|
11409 | }
|
11410 |
|
11411 | var _cfg$center = cfg.center,
|
11412 | x = _cfg$center.x,
|
11413 | y = _cfg$center.y;
|
11414 | var v = [1, 0];
|
11415 | var v0 = [newPoints[0].x - x, newPoints[0].y - y];
|
11416 | var v1 = [newPoints[1].x - x, newPoints[1].y - y];
|
11417 | var v2 = [newPoints[2].x - x, newPoints[2].y - y];
|
11418 | var startAngle = Vector2.angleTo(v, v1);
|
11419 | var endAngle = Vector2.angleTo(v, v2);
|
11420 | var r0 = Vector2.length(v0);
|
11421 | var r = Vector2.length(v1);
|
11422 |
|
11423 | if (startAngle >= 1.5 * Math.PI) {
|
11424 | startAngle = startAngle - 2 * Math.PI;
|
11425 | }
|
11426 |
|
11427 | if (endAngle >= 1.5 * Math.PI) {
|
11428 | endAngle = endAngle - 2 * Math.PI;
|
11429 | }
|
11430 |
|
11431 | return container.addShape('Sector', {
|
11432 | className: 'interval',
|
11433 | attrs: Util.mix({
|
11434 | x: x,
|
11435 | y: y,
|
11436 | r: r,
|
11437 | r0: r0,
|
11438 | startAngle: startAngle,
|
11439 | endAngle: endAngle
|
11440 | }, style)
|
11441 | });
|
11442 | }
|
11443 |
|
11444 | var rectCfg = getRectRange(points);
|
11445 | return container.addShape('rect', {
|
11446 | className: 'interval',
|
11447 | attrs: Util.mix(rectCfg, style)
|
11448 | });
|
11449 | }
|
11450 | });
|
11451 | module.exports = Interval;
|
11452 |
|
11453 | }),
|
11454 |
|
11455 | (function(module, exports, __webpack_require__) {
|
11456 |
|
11457 | function _inheritsLoose(subClass, superClass) {
|
11458 | subClass.prototype = Object.create(superClass.prototype);
|
11459 | subClass.prototype.constructor = subClass;
|
11460 | subClass.__proto__ = superClass;
|
11461 | }
|
11462 |
|
11463 | var Geom = __webpack_require__(5);
|
11464 |
|
11465 | var Util = __webpack_require__(0);
|
11466 |
|
11467 | __webpack_require__(99);
|
11468 |
|
11469 | var Polygon =
|
11470 |
|
11471 | function (_Geom) {
|
11472 | _inheritsLoose(Polygon, _Geom);
|
11473 |
|
11474 | function Polygon() {
|
11475 | return _Geom.apply(this, arguments) || this;
|
11476 | }
|
11477 |
|
11478 | var _proto = Polygon.prototype;
|
11479 |
|
11480 | _proto.getDefaultCfg = function getDefaultCfg() {
|
11481 | var cfg = _Geom.prototype.getDefaultCfg.call(this);
|
11482 |
|
11483 | cfg.type = 'polygon';
|
11484 | cfg.shapeType = 'polygon';
|
11485 | cfg.generatePoints = true;
|
11486 | return cfg;
|
11487 | };
|
11488 |
|
11489 | _proto.createShapePointsCfg = function createShapePointsCfg(obj) {
|
11490 | var cfg = _Geom.prototype.createShapePointsCfg.call(this, obj);
|
11491 |
|
11492 | var self = this;
|
11493 | var x = cfg.x;
|
11494 | var y = cfg.y;
|
11495 | var temp;
|
11496 |
|
11497 | if (!(Util.isArray(x) && Util.isArray(y))) {
|
11498 | var xScale = self.getXScale();
|
11499 | var yScale = self.getYScale();
|
11500 | var xCount = xScale.values ? xScale.values.length : xScale.ticks.length;
|
11501 | var yCount = yScale.values ? yScale.values.length : yScale.ticks.length;
|
11502 | var xOffset = 0.5 * 1 / xCount;
|
11503 | var yOffset = 0.5 * 1 / yCount;
|
11504 |
|
11505 | if (xScale.isCategory && yScale.isCategory) {
|
11506 | x = [x - xOffset, x - xOffset, x + xOffset, x + xOffset];
|
11507 | y = [y - yOffset, y + yOffset, y + yOffset, y - yOffset];
|
11508 | } else if (Util.isArray(x)) {
|
11509 | temp = x;
|
11510 | x = [temp[0], temp[0], temp[1], temp[1]];
|
11511 | y = [y - yOffset / 2, y + yOffset / 2, y + yOffset / 2, y - yOffset / 2];
|
11512 | } else if (Util.isArray(y)) {
|
11513 | temp = y;
|
11514 | y = [temp[0], temp[1], temp[1], temp[0]];
|
11515 | x = [x - xOffset / 2, x - xOffset / 2, x + xOffset / 2, x + xOffset / 2];
|
11516 | }
|
11517 |
|
11518 | cfg.x = x;
|
11519 | cfg.y = y;
|
11520 | }
|
11521 |
|
11522 | return cfg;
|
11523 | };
|
11524 |
|
11525 | return Polygon;
|
11526 | }(Geom);
|
11527 |
|
11528 | Geom.Polygon = Polygon;
|
11529 | module.exports = Polygon;
|
11530 |
|
11531 | }),
|
11532 |
|
11533 | (function(module, exports, __webpack_require__) {
|
11534 |
|
11535 | var Shape = __webpack_require__(6);
|
11536 |
|
11537 | var Util = __webpack_require__(0);
|
11538 |
|
11539 | var Polygon = Shape.registerFactory('polygon', {
|
11540 | defaultShapeType: 'polygon',
|
11541 | getDefaultPoints: function getDefaultPoints(pointInfo) {
|
11542 | var points = [];
|
11543 | var x = pointInfo.x,
|
11544 | y = pointInfo.y;
|
11545 |
|
11546 | for (var i = 0, len = x.length; i < len; i++) {
|
11547 | points.push({
|
11548 | x: x[i],
|
11549 | y: y[i]
|
11550 | });
|
11551 | }
|
11552 |
|
11553 | return points;
|
11554 | }
|
11555 | });
|
11556 | Shape.registerShape('polygon', 'polygon', {
|
11557 | draw: function draw(cfg, container) {
|
11558 | var points = this.parsePoints(cfg.points);
|
11559 | var style = Util.mix({
|
11560 | fill: cfg.color,
|
11561 | points: points
|
11562 | }, cfg.style);
|
11563 | return container.addShape('Polygon', {
|
11564 | className: 'polygon',
|
11565 | attrs: style
|
11566 | });
|
11567 | }
|
11568 | });
|
11569 | module.exports = Polygon;
|
11570 |
|
11571 | }),
|
11572 |
|
11573 | (function(module, exports, __webpack_require__) {
|
11574 |
|
11575 | function _inheritsLoose(subClass, superClass) {
|
11576 | subClass.prototype = Object.create(superClass.prototype);
|
11577 | subClass.prototype.constructor = subClass;
|
11578 | subClass.__proto__ = superClass;
|
11579 | }
|
11580 |
|
11581 | function _assertThisInitialized(self) {
|
11582 | if (self === void 0) {
|
11583 | throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
11584 | }
|
11585 |
|
11586 | return self;
|
11587 | }
|
11588 |
|
11589 | var Geom = __webpack_require__(5);
|
11590 |
|
11591 | var Util = __webpack_require__(0);
|
11592 |
|
11593 | var SizeMixin = __webpack_require__(42);
|
11594 |
|
11595 | __webpack_require__(101);
|
11596 |
|
11597 | var Schema =
|
11598 |
|
11599 | function (_Geom) {
|
11600 | _inheritsLoose(Schema, _Geom);
|
11601 |
|
11602 | var _proto = Schema.prototype;
|
11603 |
|
11604 | _proto.getDefaultCfg = function getDefaultCfg() {
|
11605 | var cfg = _Geom.prototype.getDefaultCfg.call(this);
|
11606 |
|
11607 | cfg.type = 'schema';
|
11608 | cfg.shapeType = 'schema';
|
11609 | cfg.generatePoints = true;
|
11610 | return cfg;
|
11611 | };
|
11612 |
|
11613 | function Schema(cfg) {
|
11614 | var _this;
|
11615 |
|
11616 | _this = _Geom.call(this, cfg) || this;
|
11617 | Util.mix(_assertThisInitialized(_assertThisInitialized(_this)), SizeMixin);
|
11618 | return _this;
|
11619 | }
|
11620 |
|
11621 | _proto.createShapePointsCfg = function createShapePointsCfg(obj) {
|
11622 | var cfg = _Geom.prototype.createShapePointsCfg.call(this, obj);
|
11623 |
|
11624 | cfg.size = this.getNormalizedSize(obj);
|
11625 | return cfg;
|
11626 | };
|
11627 |
|
11628 | _proto.clearInner = function clearInner() {
|
11629 | _Geom.prototype.clearInner.call(this);
|
11630 |
|
11631 | this.set('defaultSize', null);
|
11632 | };
|
11633 |
|
11634 | return Schema;
|
11635 | }(Geom);
|
11636 |
|
11637 | Geom.Schema = Schema;
|
11638 | module.exports = Schema;
|
11639 |
|
11640 | }),
|
11641 |
|
11642 | (function(module, exports, __webpack_require__) {
|
11643 |
|
11644 | var Shape = __webpack_require__(6);
|
11645 |
|
11646 | var Util = __webpack_require__(0);
|
11647 |
|
11648 | function _sortValue(value) {
|
11649 | var sorted = value.sort(function (a, b) {
|
11650 | return a < b ? 1 : -1;
|
11651 | });
|
11652 | var length = sorted.length;
|
11653 |
|
11654 | if (length < 4) {
|
11655 | var min = sorted[length - 1];
|
11656 |
|
11657 | for (var i = 0; i < 4 - length; i++) {
|
11658 | sorted.push(min);
|
11659 | }
|
11660 | }
|
11661 |
|
11662 | return sorted;
|
11663 | }
|
11664 |
|
11665 |
|
11666 | function getCandlePoints(x, y, width) {
|
11667 | var yValues = _sortValue(y);
|
11668 |
|
11669 | var points = [{
|
11670 | x: x,
|
11671 | y: yValues[0]
|
11672 | }, {
|
11673 | x: x,
|
11674 | y: yValues[1]
|
11675 | }, {
|
11676 | x: x - width / 2,
|
11677 | y: yValues[2]
|
11678 | }, {
|
11679 | x: x - width / 2,
|
11680 | y: yValues[1]
|
11681 | }, {
|
11682 | x: x + width / 2,
|
11683 | y: yValues[1]
|
11684 | }, {
|
11685 | x: x + width / 2,
|
11686 | y: yValues[2]
|
11687 | }, {
|
11688 | x: x,
|
11689 | y: yValues[2]
|
11690 | }, {
|
11691 | x: x,
|
11692 | y: yValues[3]
|
11693 | }];
|
11694 | return points;
|
11695 | }
|
11696 |
|
11697 | var Schema = Shape.registerFactory('schema', {});
|
11698 | Shape.registerShape('schema', 'candle', {
|
11699 | getPoints: function getPoints(cfg) {
|
11700 | return getCandlePoints(cfg.x, cfg.y, cfg.size);
|
11701 | },
|
11702 | draw: function draw(cfg, container) {
|
11703 | var points = this.parsePoints(cfg.points);
|
11704 | var style = Util.mix({
|
11705 | stroke: cfg.color,
|
11706 | fill: cfg.color,
|
11707 | lineWidth: 1
|
11708 | }, cfg.style);
|
11709 | return container.addShape('Custom', {
|
11710 | className: 'schema',
|
11711 | attrs: style,
|
11712 | createPath: function createPath(ctx) {
|
11713 | ctx.beginPath();
|
11714 | ctx.moveTo(points[0].x, points[0].y);
|
11715 | ctx.lineTo(points[1].x, points[1].y);
|
11716 | ctx.moveTo(points[2].x, points[2].y);
|
11717 |
|
11718 | for (var i = 3; i < 6; i++) {
|
11719 | ctx.lineTo(points[i].x, points[i].y);
|
11720 | }
|
11721 |
|
11722 | ctx.closePath();
|
11723 | ctx.moveTo(points[6].x, points[6].y);
|
11724 | ctx.lineTo(points[7].x, points[7].y);
|
11725 | }
|
11726 | });
|
11727 | }
|
11728 | });
|
11729 | module.exports = Schema;
|
11730 |
|
11731 | }),
|
11732 |
|
11733 | (function(module, exports, __webpack_require__) {
|
11734 |
|
11735 | module.exports = {
|
11736 | Stack: __webpack_require__(103),
|
11737 | Dodge: __webpack_require__(105)
|
11738 | };
|
11739 |
|
11740 | }),
|
11741 |
|
11742 | (function(module, exports, __webpack_require__) {
|
11743 |
|
11744 | var Stack = __webpack_require__(104);
|
11745 |
|
11746 | module.exports = Stack;
|
11747 |
|
11748 | }),
|
11749 |
|
11750 | (function(module, exports, __webpack_require__) {
|
11751 |
|
11752 | function _inheritsLoose(subClass, superClass) {
|
11753 | subClass.prototype = Object.create(superClass.prototype);
|
11754 | subClass.prototype.constructor = subClass;
|
11755 | subClass.__proto__ = superClass;
|
11756 | }
|
11757 |
|
11758 | var isArray = __webpack_require__(11);
|
11759 |
|
11760 | var isNil = __webpack_require__(9);
|
11761 |
|
11762 | var Adjust = __webpack_require__(24);
|
11763 |
|
11764 | var Stack =
|
11765 |
|
11766 | function (_Adjust) {
|
11767 | _inheritsLoose(Stack, _Adjust);
|
11768 |
|
11769 | function Stack() {
|
11770 | return _Adjust.apply(this, arguments) || this;
|
11771 | }
|
11772 |
|
11773 | var _proto = Stack.prototype;
|
11774 |
|
11775 | _proto._initDefaultCfg = function _initDefaultCfg() {
|
11776 | this.xField = null;
|
11777 |
|
11778 | this.yField = null;
|
11779 | };
|
11780 |
|
11781 | _proto.processAdjust = function processAdjust(dataArray) {
|
11782 | this.processStack(dataArray);
|
11783 | };
|
11784 |
|
11785 | _proto.processStack = function processStack(dataArray) {
|
11786 | var self = this;
|
11787 | var xField = self.xField;
|
11788 | var yField = self.yField;
|
11789 | var count = dataArray.length;
|
11790 | var stackCache = {
|
11791 | positive: {},
|
11792 | negative: {}
|
11793 | };
|
11794 |
|
11795 | if (self.reverseOrder) {
|
11796 | dataArray = dataArray.slice(0).reverse();
|
11797 | }
|
11798 |
|
11799 | for (var i = 0; i < count; i++) {
|
11800 | var data = dataArray[i];
|
11801 |
|
11802 | for (var j = 0, len = data.length; j < len; j++) {
|
11803 | var item = data[j];
|
11804 | var x = item[xField] || 0;
|
11805 | var y = item[yField];
|
11806 | var xkey = x.toString();
|
11807 | y = isArray(y) ? y[1] : y;
|
11808 |
|
11809 | if (!isNil(y)) {
|
11810 | var direction = y >= 0 ? 'positive' : 'negative';
|
11811 |
|
11812 | if (!stackCache[direction][xkey]) {
|
11813 | stackCache[direction][xkey] = 0;
|
11814 | }
|
11815 |
|
11816 | item[yField] = [stackCache[direction][xkey], y + stackCache[direction][xkey]];
|
11817 | stackCache[direction][xkey] += y;
|
11818 | }
|
11819 | }
|
11820 | }
|
11821 | };
|
11822 |
|
11823 | return Stack;
|
11824 | }(Adjust);
|
11825 |
|
11826 | Adjust.Stack = Stack;
|
11827 | module.exports = Stack;
|
11828 |
|
11829 | }),
|
11830 |
|
11831 | (function(module, exports, __webpack_require__) {
|
11832 |
|
11833 | var Dodge = __webpack_require__(106);
|
11834 |
|
11835 | module.exports = Dodge;
|
11836 |
|
11837 | }),
|
11838 |
|
11839 | (function(module, exports, __webpack_require__) {
|
11840 |
|
11841 | function _inheritsLoose(subClass, superClass) {
|
11842 | subClass.prototype = Object.create(superClass.prototype);
|
11843 | subClass.prototype.constructor = subClass;
|
11844 | subClass.__proto__ = superClass;
|
11845 | }
|
11846 |
|
11847 | var Adjust = __webpack_require__(24);
|
11848 |
|
11849 | var each = __webpack_require__(4);
|
11850 |
|
11851 | var MARGIN_RATIO = 1 / 2;
|
11852 | var DODGE_RATIO = 1 / 2;
|
11853 |
|
11854 | var Dodge =
|
11855 |
|
11856 | function (_Adjust) {
|
11857 | _inheritsLoose(Dodge, _Adjust);
|
11858 |
|
11859 | function Dodge() {
|
11860 | return _Adjust.apply(this, arguments) || this;
|
11861 | }
|
11862 |
|
11863 | var _proto = Dodge.prototype;
|
11864 |
|
11865 | _proto._initDefaultCfg = function _initDefaultCfg() {
|
11866 | |
11867 |
|
11868 |
|
11869 |
|
11870 | this.marginRatio = MARGIN_RATIO;
|
11871 | |
11872 |
|
11873 |
|
11874 |
|
11875 |
|
11876 | this.dodgeRatio = DODGE_RATIO;
|
11877 | this.adjustNames = ['x', 'y'];
|
11878 | };
|
11879 |
|
11880 | _proto.getDodgeOffset = function getDodgeOffset(range, index, count) {
|
11881 | var self = this;
|
11882 | var pre = range.pre;
|
11883 | var next = range.next;
|
11884 | var tickLength = next - pre;
|
11885 | var width = tickLength * self.dodgeRatio / count;
|
11886 | var margin = self.marginRatio * width;
|
11887 | var offset = 1 / 2 * (tickLength - count * width - (count - 1) * margin) + ((index + 1) * width + index * margin) - 1 / 2 * width - 1 / 2 * tickLength;
|
11888 | return (pre + next) / 2 + offset;
|
11889 | };
|
11890 |
|
11891 | _proto.processAdjust = function processAdjust(dataArray) {
|
11892 | var self = this;
|
11893 | var count = dataArray.length;
|
11894 | var xField = self.xField;
|
11895 | each(dataArray, function (data, index) {
|
11896 | for (var i = 0, len = data.length; i < len; i++) {
|
11897 | var obj = data[i];
|
11898 | var value = obj[xField];
|
11899 | var range = {
|
11900 | pre: value - 0.5,
|
11901 | next: value + 0.5
|
11902 | };
|
11903 | var dodgeValue = self.getDodgeOffset(range, index, count);
|
11904 | obj[xField] = dodgeValue;
|
11905 | }
|
11906 | });
|
11907 | };
|
11908 |
|
11909 | return Dodge;
|
11910 | }(Adjust);
|
11911 |
|
11912 | Adjust.Dodge = Dodge;
|
11913 | module.exports = Dodge;
|
11914 |
|
11915 | }),
|
11916 |
|
11917 | (function(module, exports, __webpack_require__) {
|
11918 |
|
11919 | function _inheritsLoose(subClass, superClass) {
|
11920 | subClass.prototype = Object.create(superClass.prototype);
|
11921 | subClass.prototype.constructor = subClass;
|
11922 | subClass.__proto__ = superClass;
|
11923 | }
|
11924 |
|
11925 | var Base = __webpack_require__(23);
|
11926 |
|
11927 | var Vector2 = __webpack_require__(7);
|
11928 |
|
11929 | var Matrix = __webpack_require__(27);
|
11930 |
|
11931 | var Polar =
|
11932 |
|
11933 | function (_Base) {
|
11934 | _inheritsLoose(Polar, _Base);
|
11935 |
|
11936 | function Polar() {
|
11937 | return _Base.apply(this, arguments) || this;
|
11938 | }
|
11939 |
|
11940 | var _proto = Polar.prototype;
|
11941 |
|
11942 | _proto._initDefaultCfg = function _initDefaultCfg() {
|
11943 | this.type = 'polar';
|
11944 | this.startAngle = -Math.PI / 2;
|
11945 | this.endAngle = Math.PI * 3 / 2;
|
11946 | this.inner = 0;
|
11947 | this.innerRadius = 0;
|
11948 |
|
11949 | this.isPolar = true;
|
11950 | this.transposed = false;
|
11951 | this.center = null;
|
11952 | this.radius = null;
|
11953 | };
|
11954 |
|
11955 | _proto.init = function init(start, end) {
|
11956 | var self = this;
|
11957 | var inner = self.inner || self.innerRadius;
|
11958 | var width = Math.abs(end.x - start.x);
|
11959 | var height = Math.abs(end.y - start.y);
|
11960 | var maxRadius;
|
11961 | var center;
|
11962 |
|
11963 | if (self.startAngle === -Math.PI && self.endAngle === 0) {
|
11964 | maxRadius = Math.min(width / 2, height);
|
11965 | center = {
|
11966 | x: (start.x + end.x) / 2,
|
11967 | y: start.y
|
11968 | };
|
11969 | } else {
|
11970 | maxRadius = Math.min(width, height) / 2;
|
11971 | center = {
|
11972 | x: (start.x + end.x) / 2,
|
11973 | y: (start.y + end.y) / 2
|
11974 | };
|
11975 | }
|
11976 |
|
11977 | var radius = self.radius;
|
11978 |
|
11979 | if (radius > 0 && radius <= 1) {
|
11980 | maxRadius = maxRadius * radius;
|
11981 | }
|
11982 |
|
11983 | this.x = {
|
11984 | start: self.startAngle,
|
11985 | end: self.endAngle
|
11986 | };
|
11987 | this.y = {
|
11988 | start: maxRadius * inner,
|
11989 | end: maxRadius
|
11990 | };
|
11991 | this.center = center;
|
11992 | this.circleRadius = maxRadius;
|
11993 | };
|
11994 |
|
11995 | _proto.convertPoint = function convertPoint(point) {
|
11996 | var self = this;
|
11997 | var center = self.center;
|
11998 | var transposed = self.transposed;
|
11999 | var xDim = transposed ? 'y' : 'x';
|
12000 | var yDim = transposed ? 'x' : 'y';
|
12001 | var x = self.x;
|
12002 | var y = self.y;
|
12003 | var angle = x.start + (x.end - x.start) * point[xDim];
|
12004 | var radius = y.start + (y.end - y.start) * point[yDim];
|
12005 | return {
|
12006 | x: center.x + Math.cos(angle) * radius,
|
12007 | y: center.y + Math.sin(angle) * radius
|
12008 | };
|
12009 | };
|
12010 |
|
12011 | _proto.invertPoint = function invertPoint(point) {
|
12012 | var self = this;
|
12013 | var center = self.center,
|
12014 | transposed = self.transposed,
|
12015 | x = self.x,
|
12016 | y = self.y;
|
12017 | var xDim = transposed ? 'y' : 'x';
|
12018 | var yDim = transposed ? 'x' : 'y';
|
12019 | var m = [1, 0, 0, 1, 0, 0];
|
12020 | Matrix.rotate(m, m, x.start);
|
12021 | var startV = [1, 0];
|
12022 | Vector2.transformMat2d(startV, startV, m);
|
12023 | startV = [startV[0], startV[1]];
|
12024 | var pointV = [point.x - center.x, point.y - center.y];
|
12025 |
|
12026 | if (Vector2.zero(pointV)) {
|
12027 | return {
|
12028 | x: 0,
|
12029 | y: 0
|
12030 | };
|
12031 | }
|
12032 |
|
12033 | var theta = Vector2.angleTo(startV, pointV, x.end < x.start);
|
12034 |
|
12035 | if (Math.abs(theta - Math.PI * 2) < 0.001) {
|
12036 | theta = 0;
|
12037 | }
|
12038 |
|
12039 | var l = Vector2.length(pointV);
|
12040 | var percentX = theta / (x.end - x.start);
|
12041 | percentX = x.end - x.start > 0 ? percentX : -percentX;
|
12042 | var percentY = (l - y.start) / (y.end - y.start);
|
12043 | var rst = {};
|
12044 | rst[xDim] = percentX;
|
12045 | rst[yDim] = percentY;
|
12046 | return rst;
|
12047 | };
|
12048 |
|
12049 | return Polar;
|
12050 | }(Base);
|
12051 |
|
12052 | Base.Polar = Polar;
|
12053 | module.exports = Polar;
|
12054 |
|
12055 | }),
|
12056 |
|
12057 | (function(module, exports, __webpack_require__) {
|
12058 |
|
12059 | function _inheritsLoose(subClass, superClass) {
|
12060 | subClass.prototype = Object.create(superClass.prototype);
|
12061 | subClass.prototype.constructor = subClass;
|
12062 | subClass.__proto__ = superClass;
|
12063 | }
|
12064 |
|
12065 | var Util = __webpack_require__(0);
|
12066 |
|
12067 | var Abstract = __webpack_require__(25);
|
12068 |
|
12069 | var Circle =
|
12070 |
|
12071 | function (_Abstract) {
|
12072 | _inheritsLoose(Circle, _Abstract);
|
12073 |
|
12074 | function Circle() {
|
12075 | return _Abstract.apply(this, arguments) || this;
|
12076 | }
|
12077 |
|
12078 | var _proto = Circle.prototype;
|
12079 |
|
12080 | _proto._initDefaultCfg = function _initDefaultCfg() {
|
12081 | _Abstract.prototype._initDefaultCfg.call(this);
|
12082 |
|
12083 | this.startAngle = -Math.PI / 2;
|
12084 |
|
12085 | this.endAngle = Math.PI * 3 / 2;
|
12086 |
|
12087 | this.radius = null;
|
12088 |
|
12089 | this.center = null;
|
12090 | };
|
12091 |
|
12092 | _proto.getOffsetPoint = function getOffsetPoint(value) {
|
12093 | var startAngle = this.startAngle,
|
12094 | endAngle = this.endAngle;
|
12095 | var angle = startAngle + (endAngle - startAngle) * value;
|
12096 | return this._getCirclePoint(angle);
|
12097 | };
|
12098 |
|
12099 | _proto._getCirclePoint = function _getCirclePoint(angle, radius) {
|
12100 | var self = this;
|
12101 | var center = self.center;
|
12102 | radius = radius || self.radius;
|
12103 | return {
|
12104 | x: center.x + Math.cos(angle) * radius,
|
12105 | y: center.y + Math.sin(angle) * radius
|
12106 | };
|
12107 | };
|
12108 |
|
12109 | _proto.getTextAlignInfo = function getTextAlignInfo(point, offset) {
|
12110 | var self = this;
|
12111 | var offsetVector = self.getOffsetVector(point, offset);
|
12112 | var align;
|
12113 | var baseLine = 'middle';
|
12114 |
|
12115 | if (offsetVector[0] > 0) {
|
12116 | align = 'left';
|
12117 | } else if (offsetVector[0] < 0) {
|
12118 | align = 'right';
|
12119 | } else {
|
12120 | align = 'center';
|
12121 |
|
12122 | if (offsetVector[1] > 0) {
|
12123 | baseLine = 'top';
|
12124 | } else if (offsetVector[1] < 0) {
|
12125 | baseLine = 'bottom';
|
12126 | }
|
12127 | }
|
12128 |
|
12129 | return {
|
12130 | textAlign: align,
|
12131 | textBaseline: baseLine
|
12132 | };
|
12133 | };
|
12134 |
|
12135 | _proto.getAxisVector = function getAxisVector(point) {
|
12136 | var center = this.center;
|
12137 | var factor = this.offsetFactor;
|
12138 | return [(point.y - center.y) * factor, (point.x - center.x) * -1 * factor];
|
12139 | };
|
12140 |
|
12141 | _proto.drawLine = function drawLine(lineCfg) {
|
12142 | var center = this.center,
|
12143 | radius = this.radius,
|
12144 | startAngle = this.startAngle,
|
12145 | endAngle = this.endAngle;
|
12146 | var container = this.getContainer(lineCfg.top);
|
12147 | container.addShape('arc', {
|
12148 | className: 'axis-line',
|
12149 | attrs: Util.mix({
|
12150 | x: center.x,
|
12151 | y: center.y,
|
12152 | r: radius,
|
12153 | startAngle: startAngle,
|
12154 | endAngle: endAngle
|
12155 | }, lineCfg)
|
12156 | });
|
12157 | };
|
12158 |
|
12159 | return Circle;
|
12160 | }(Abstract);
|
12161 |
|
12162 | Abstract.Circle = Circle;
|
12163 | module.exports = Circle;
|
12164 |
|
12165 | }),
|
12166 |
|
12167 | (function(module, exports, __webpack_require__) {
|
12168 |
|
12169 | var TimeCat = __webpack_require__(110);
|
12170 |
|
12171 | module.exports = TimeCat;
|
12172 |
|
12173 | }),
|
12174 |
|
12175 | (function(module, exports, __webpack_require__) {
|
12176 |
|
12177 | function _inheritsLoose(subClass, superClass) {
|
12178 | subClass.prototype = Object.create(superClass.prototype);
|
12179 | subClass.prototype.constructor = subClass;
|
12180 | subClass.__proto__ = superClass;
|
12181 | }
|
12182 |
|
12183 |
|
12184 |
|
12185 |
|
12186 |
|
12187 |
|
12188 | var Base = __webpack_require__(16);
|
12189 |
|
12190 | var Category = __webpack_require__(34);
|
12191 |
|
12192 | var fecha = __webpack_require__(111);
|
12193 |
|
12194 | var catAuto = __webpack_require__(35);
|
12195 |
|
12196 | var TimeUtil = __webpack_require__(28);
|
12197 |
|
12198 | var each = __webpack_require__(4);
|
12199 |
|
12200 | var isNumber = __webpack_require__(15);
|
12201 |
|
12202 | var isObject = __webpack_require__(17);
|
12203 |
|
12204 | var isString = __webpack_require__(14);
|
12205 |
|
12206 |
|
12207 |
|
12208 |
|
12209 |
|
12210 |
|
12211 | var TimeCategory =
|
12212 |
|
12213 | function (_Category) {
|
12214 | _inheritsLoose(TimeCategory, _Category);
|
12215 |
|
12216 | function TimeCategory() {
|
12217 | return _Category.apply(this, arguments) || this;
|
12218 | }
|
12219 |
|
12220 | var _proto = TimeCategory.prototype;
|
12221 |
|
12222 | _proto._initDefaultCfg = function _initDefaultCfg() {
|
12223 | _Category.prototype._initDefaultCfg.call(this);
|
12224 |
|
12225 | this.type = 'timeCat';
|
12226 | |
12227 |
|
12228 |
|
12229 |
|
12230 |
|
12231 | this.sortable = true;
|
12232 | this.tickCount = 5;
|
12233 | |
12234 |
|
12235 |
|
12236 |
|
12237 |
|
12238 | this.mask = 'YYYY-MM-DD';
|
12239 | };
|
12240 |
|
12241 | _proto.init = function init() {
|
12242 | var self = this;
|
12243 | var values = this.values;
|
12244 |
|
12245 | each(values, function (v, i) {
|
12246 | values[i] = self._toTimeStamp(v);
|
12247 | });
|
12248 |
|
12249 | if (this.sortable) {
|
12250 |
|
12251 | values.sort(function (v1, v2) {
|
12252 | return v1 - v2;
|
12253 | });
|
12254 | }
|
12255 |
|
12256 | if (!self.ticks) {
|
12257 | self.ticks = this.calculateTicks();
|
12258 | }
|
12259 | };
|
12260 | |
12261 |
|
12262 |
|
12263 |
|
12264 |
|
12265 |
|
12266 | _proto.calculateTicks = function calculateTicks() {
|
12267 | var self = this;
|
12268 | var count = self.tickCount;
|
12269 | var ticks;
|
12270 |
|
12271 | if (count) {
|
12272 | var temp = catAuto({
|
12273 | maxCount: count,
|
12274 | data: self.values,
|
12275 | isRounding: self.isRounding
|
12276 | });
|
12277 | ticks = temp.ticks;
|
12278 | } else {
|
12279 | ticks = self.values;
|
12280 | }
|
12281 |
|
12282 | return ticks;
|
12283 | };
|
12284 | |
12285 |
|
12286 |
|
12287 |
|
12288 |
|
12289 | _proto.translate = function translate(value) {
|
12290 | value = this._toTimeStamp(value);
|
12291 | var index = this.values.indexOf(value);
|
12292 |
|
12293 | if (index === -1) {
|
12294 | if (isNumber(value) && value < this.values.length) {
|
12295 | index = value;
|
12296 | } else {
|
12297 | index = NaN;
|
12298 | }
|
12299 | }
|
12300 |
|
12301 | return index;
|
12302 | };
|
12303 | |
12304 |
|
12305 |
|
12306 |
|
12307 |
|
12308 | _proto.scale = function scale(value) {
|
12309 | var rangeMin = this.rangeMin();
|
12310 | var rangeMax = this.rangeMax();
|
12311 | var index = this.translate(value);
|
12312 | var percent;
|
12313 |
|
12314 | if (this.values.length === 1 || isNaN(index)) {
|
12315 |
|
12316 | percent = index;
|
12317 | } else if (index > -1) {
|
12318 | percent = index / (this.values.length - 1);
|
12319 | } else {
|
12320 | percent = 0;
|
12321 | }
|
12322 |
|
12323 | return rangeMin + percent * (rangeMax - rangeMin);
|
12324 | };
|
12325 | |
12326 |
|
12327 |
|
12328 |
|
12329 |
|
12330 | _proto.getText = function getText(value) {
|
12331 | var result = '';
|
12332 | var index = this.translate(value);
|
12333 |
|
12334 | if (index > -1) {
|
12335 | result = this.values[index];
|
12336 | } else {
|
12337 | result = value;
|
12338 | }
|
12339 |
|
12340 | var formatter = this.formatter;
|
12341 | result = parseInt(result, 10);
|
12342 | result = formatter ? formatter(result) : fecha.format(result, this.mask);
|
12343 | return result;
|
12344 | };
|
12345 | |
12346 |
|
12347 |
|
12348 |
|
12349 |
|
12350 | _proto.getTicks = function getTicks() {
|
12351 | var self = this;
|
12352 | var ticks = this.ticks;
|
12353 | var rst = [];
|
12354 | each(ticks, function (tick) {
|
12355 | var obj;
|
12356 |
|
12357 | if (isObject(tick)) {
|
12358 | obj = tick;
|
12359 | } else {
|
12360 | obj = {
|
12361 | text: isString(tick) ? tick : self.getText(tick),
|
12362 | value: self.scale(tick),
|
12363 | tickValue: tick
|
12364 |
|
12365 | };
|
12366 | }
|
12367 |
|
12368 | rst.push(obj);
|
12369 | });
|
12370 | return rst;
|
12371 | };
|
12372 |
|
12373 |
|
12374 | _proto._toTimeStamp = function _toTimeStamp(value) {
|
12375 | return TimeUtil.toTimeStamp(value);
|
12376 | };
|
12377 |
|
12378 | return TimeCategory;
|
12379 | }(Category);
|
12380 |
|
12381 | Base.TimeCat = TimeCategory;
|
12382 | module.exports = TimeCategory;
|
12383 |
|
12384 | }),
|
12385 |
|
12386 | (function(module, exports, __webpack_require__) {
|
12387 |
|
12388 | var __WEBPACK_AMD_DEFINE_RESULT__;(function (main) {
|
12389 | 'use strict';
|
12390 | |
12391 |
|
12392 |
|
12393 |
|
12394 |
|
12395 | var fecha = {};
|
12396 | var token = /d{1,4}|M{1,4}|YY(?:YY)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
|
12397 | var twoDigits = /\d\d?/;
|
12398 | var threeDigits = /\d{3}/;
|
12399 | var fourDigits = /\d{4}/;
|
12400 | var word = /[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i;
|
12401 | var literal = /\[([^]*?)\]/gm;
|
12402 |
|
12403 | var noop = function () {};
|
12404 |
|
12405 | function shorten(arr, sLen) {
|
12406 | var newArr = [];
|
12407 |
|
12408 | for (var i = 0, len = arr.length; i < len; i++) {
|
12409 | newArr.push(arr[i].substr(0, sLen));
|
12410 | }
|
12411 |
|
12412 | return newArr;
|
12413 | }
|
12414 |
|
12415 | function monthUpdate(arrName) {
|
12416 | return function (d, v, i18n) {
|
12417 | var index = i18n[arrName].indexOf(v.charAt(0).toUpperCase() + v.substr(1).toLowerCase());
|
12418 |
|
12419 | if (~index) {
|
12420 | d.month = index;
|
12421 | }
|
12422 | };
|
12423 | }
|
12424 |
|
12425 | function pad(val, len) {
|
12426 | val = String(val);
|
12427 | len = len || 2;
|
12428 |
|
12429 | while (val.length < len) {
|
12430 | val = '0' + val;
|
12431 | }
|
12432 |
|
12433 | return val;
|
12434 | }
|
12435 |
|
12436 | var dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
12437 | var monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
12438 | var monthNamesShort = shorten(monthNames, 3);
|
12439 | var dayNamesShort = shorten(dayNames, 3);
|
12440 | fecha.i18n = {
|
12441 | dayNamesShort: dayNamesShort,
|
12442 | dayNames: dayNames,
|
12443 | monthNamesShort: monthNamesShort,
|
12444 | monthNames: monthNames,
|
12445 | amPm: ['am', 'pm'],
|
12446 | DoFn: function DoFn(D) {
|
12447 | return D + ['th', 'st', 'nd', 'rd'][D % 10 > 3 ? 0 : (D - D % 10 !== 10) * D % 10];
|
12448 | }
|
12449 | };
|
12450 | var formatFlags = {
|
12451 | D: function (dateObj) {
|
12452 | return dateObj.getDate();
|
12453 | },
|
12454 | DD: function (dateObj) {
|
12455 | return pad(dateObj.getDate());
|
12456 | },
|
12457 | Do: function (dateObj, i18n) {
|
12458 | return i18n.DoFn(dateObj.getDate());
|
12459 | },
|
12460 | d: function (dateObj) {
|
12461 | return dateObj.getDay();
|
12462 | },
|
12463 | dd: function (dateObj) {
|
12464 | return pad(dateObj.getDay());
|
12465 | },
|
12466 | ddd: function (dateObj, i18n) {
|
12467 | return i18n.dayNamesShort[dateObj.getDay()];
|
12468 | },
|
12469 | dddd: function (dateObj, i18n) {
|
12470 | return i18n.dayNames[dateObj.getDay()];
|
12471 | },
|
12472 | M: function (dateObj) {
|
12473 | return dateObj.getMonth() + 1;
|
12474 | },
|
12475 | MM: function (dateObj) {
|
12476 | return pad(dateObj.getMonth() + 1);
|
12477 | },
|
12478 | MMM: function (dateObj, i18n) {
|
12479 | return i18n.monthNamesShort[dateObj.getMonth()];
|
12480 | },
|
12481 | MMMM: function (dateObj, i18n) {
|
12482 | return i18n.monthNames[dateObj.getMonth()];
|
12483 | },
|
12484 | YY: function (dateObj) {
|
12485 | return String(dateObj.getFullYear()).substr(2);
|
12486 | },
|
12487 | YYYY: function (dateObj) {
|
12488 | return pad(dateObj.getFullYear(), 4);
|
12489 | },
|
12490 | h: function (dateObj) {
|
12491 | return dateObj.getHours() % 12 || 12;
|
12492 | },
|
12493 | hh: function (dateObj) {
|
12494 | return pad(dateObj.getHours() % 12 || 12);
|
12495 | },
|
12496 | H: function (dateObj) {
|
12497 | return dateObj.getHours();
|
12498 | },
|
12499 | HH: function (dateObj) {
|
12500 | return pad(dateObj.getHours());
|
12501 | },
|
12502 | m: function (dateObj) {
|
12503 | return dateObj.getMinutes();
|
12504 | },
|
12505 | mm: function (dateObj) {
|
12506 | return pad(dateObj.getMinutes());
|
12507 | },
|
12508 | s: function (dateObj) {
|
12509 | return dateObj.getSeconds();
|
12510 | },
|
12511 | ss: function (dateObj) {
|
12512 | return pad(dateObj.getSeconds());
|
12513 | },
|
12514 | S: function (dateObj) {
|
12515 | return Math.round(dateObj.getMilliseconds() / 100);
|
12516 | },
|
12517 | SS: function (dateObj) {
|
12518 | return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
|
12519 | },
|
12520 | SSS: function (dateObj) {
|
12521 | return pad(dateObj.getMilliseconds(), 3);
|
12522 | },
|
12523 | a: function (dateObj, i18n) {
|
12524 | return dateObj.getHours() < 12 ? i18n.amPm[0] : i18n.amPm[1];
|
12525 | },
|
12526 | A: function (dateObj, i18n) {
|
12527 | return dateObj.getHours() < 12 ? i18n.amPm[0].toUpperCase() : i18n.amPm[1].toUpperCase();
|
12528 | },
|
12529 | ZZ: function (dateObj) {
|
12530 | var o = dateObj.getTimezoneOffset();
|
12531 | return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
|
12532 | }
|
12533 | };
|
12534 | var parseFlags = {
|
12535 | D: [twoDigits, function (d, v) {
|
12536 | d.day = v;
|
12537 | }],
|
12538 | Do: [new RegExp(twoDigits.source + word.source), function (d, v) {
|
12539 | d.day = parseInt(v, 10);
|
12540 | }],
|
12541 | M: [twoDigits, function (d, v) {
|
12542 | d.month = v - 1;
|
12543 | }],
|
12544 | YY: [twoDigits, function (d, v) {
|
12545 | var da = new Date(),
|
12546 | cent = +('' + da.getFullYear()).substr(0, 2);
|
12547 | d.year = '' + (v > 68 ? cent - 1 : cent) + v;
|
12548 | }],
|
12549 | h: [twoDigits, function (d, v) {
|
12550 | d.hour = v;
|
12551 | }],
|
12552 | m: [twoDigits, function (d, v) {
|
12553 | d.minute = v;
|
12554 | }],
|
12555 | s: [twoDigits, function (d, v) {
|
12556 | d.second = v;
|
12557 | }],
|
12558 | YYYY: [fourDigits, function (d, v) {
|
12559 | d.year = v;
|
12560 | }],
|
12561 | S: [/\d/, function (d, v) {
|
12562 | d.millisecond = v * 100;
|
12563 | }],
|
12564 | SS: [/\d{2}/, function (d, v) {
|
12565 | d.millisecond = v * 10;
|
12566 | }],
|
12567 | SSS: [threeDigits, function (d, v) {
|
12568 | d.millisecond = v;
|
12569 | }],
|
12570 | d: [twoDigits, noop],
|
12571 | ddd: [word, noop],
|
12572 | MMM: [word, monthUpdate('monthNamesShort')],
|
12573 | MMMM: [word, monthUpdate('monthNames')],
|
12574 | a: [word, function (d, v, i18n) {
|
12575 | var val = v.toLowerCase();
|
12576 |
|
12577 | if (val === i18n.amPm[0]) {
|
12578 | d.isPm = false;
|
12579 | } else if (val === i18n.amPm[1]) {
|
12580 | d.isPm = true;
|
12581 | }
|
12582 | }],
|
12583 | ZZ: [/([\+\-]\d\d:?\d\d|Z)/, function (d, v) {
|
12584 | if (v === 'Z') v = '+00:00';
|
12585 | var parts = (v + '').match(/([\+\-]|\d\d)/gi),
|
12586 | minutes;
|
12587 |
|
12588 | if (parts) {
|
12589 | minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
|
12590 | d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
|
12591 | }
|
12592 | }]
|
12593 | };
|
12594 | parseFlags.dd = parseFlags.d;
|
12595 | parseFlags.dddd = parseFlags.ddd;
|
12596 | parseFlags.DD = parseFlags.D;
|
12597 | parseFlags.mm = parseFlags.m;
|
12598 | parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
|
12599 | parseFlags.MM = parseFlags.M;
|
12600 | parseFlags.ss = parseFlags.s;
|
12601 | parseFlags.A = parseFlags.a;
|
12602 |
|
12603 | fecha.masks = {
|
12604 | default: 'ddd MMM DD YYYY HH:mm:ss',
|
12605 | shortDate: 'M/D/YY',
|
12606 | mediumDate: 'MMM D, YYYY',
|
12607 | longDate: 'MMMM D, YYYY',
|
12608 | fullDate: 'dddd, MMMM D, YYYY',
|
12609 | shortTime: 'HH:mm',
|
12610 | mediumTime: 'HH:mm:ss',
|
12611 | longTime: 'HH:mm:ss.SSS'
|
12612 | };
|
12613 | |
12614 |
|
12615 |
|
12616 |
|
12617 |
|
12618 |
|
12619 |
|
12620 | fecha.format = function (dateObj, mask, i18nSettings) {
|
12621 | var i18n = i18nSettings || fecha.i18n;
|
12622 |
|
12623 | if (typeof dateObj === 'number') {
|
12624 | dateObj = new Date(dateObj);
|
12625 | }
|
12626 |
|
12627 | if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
|
12628 | throw new Error('Invalid Date in fecha.format');
|
12629 | }
|
12630 |
|
12631 | mask = fecha.masks[mask] || mask || fecha.masks['default'];
|
12632 | var literals = [];
|
12633 |
|
12634 | mask = mask.replace(literal, function ($0, $1) {
|
12635 | literals.push($1);
|
12636 | return '??';
|
12637 | });
|
12638 |
|
12639 | mask = mask.replace(token, function ($0) {
|
12640 | return $0 in formatFlags ? formatFlags[$0](dateObj, i18n) : $0.slice(1, $0.length - 1);
|
12641 | });
|
12642 |
|
12643 | return mask.replace(/\?\?/g, function () {
|
12644 | return literals.shift();
|
12645 | });
|
12646 | };
|
12647 | |
12648 |
|
12649 |
|
12650 |
|
12651 |
|
12652 |
|
12653 |
|
12654 |
|
12655 |
|
12656 | fecha.parse = function (dateStr, format, i18nSettings) {
|
12657 | var i18n = i18nSettings || fecha.i18n;
|
12658 |
|
12659 | if (typeof format !== 'string') {
|
12660 | throw new Error('Invalid format in fecha.parse');
|
12661 | }
|
12662 |
|
12663 | format = fecha.masks[format] || format;
|
12664 |
|
12665 |
|
12666 | if (dateStr.length > 1000) {
|
12667 | return false;
|
12668 | }
|
12669 |
|
12670 | var isValid = true;
|
12671 | var dateInfo = {};
|
12672 | format.replace(token, function ($0) {
|
12673 | if (parseFlags[$0]) {
|
12674 | var info = parseFlags[$0];
|
12675 | var index = dateStr.search(info[0]);
|
12676 |
|
12677 | if (!~index) {
|
12678 | isValid = false;
|
12679 | } else {
|
12680 | dateStr.replace(info[0], function (result) {
|
12681 | info[1](dateInfo, result, i18n);
|
12682 | dateStr = dateStr.substr(index + result.length);
|
12683 | return result;
|
12684 | });
|
12685 | }
|
12686 | }
|
12687 |
|
12688 | return parseFlags[$0] ? '' : $0.slice(1, $0.length - 1);
|
12689 | });
|
12690 |
|
12691 | if (!isValid) {
|
12692 | return false;
|
12693 | }
|
12694 |
|
12695 | var today = new Date();
|
12696 |
|
12697 | if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
|
12698 | dateInfo.hour = +dateInfo.hour + 12;
|
12699 | } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
|
12700 | dateInfo.hour = 0;
|
12701 | }
|
12702 |
|
12703 | var date;
|
12704 |
|
12705 | if (dateInfo.timezoneOffset != null) {
|
12706 | dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
|
12707 | 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));
|
12708 | } else {
|
12709 | 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);
|
12710 | }
|
12711 |
|
12712 | return date;
|
12713 | };
|
12714 |
|
12715 |
|
12716 |
|
12717 | if (typeof module !== 'undefined' && module.exports) {
|
12718 | module.exports = fecha;
|
12719 | } else if (true) {
|
12720 | !(__WEBPACK_AMD_DEFINE_RESULT__ = (function () {
|
12721 | return fecha;
|
12722 | }).call(exports, __webpack_require__, exports, module),
|
12723 | __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
12724 | } else {
|
12725 | main.fecha = fecha;
|
12726 | }
|
12727 | })(this);
|
12728 |
|
12729 | }),
|
12730 |
|
12731 | (function(module, exports, __webpack_require__) {
|
12732 |
|
12733 | function _inheritsLoose(subClass, superClass) {
|
12734 | subClass.prototype = Object.create(superClass.prototype);
|
12735 | subClass.prototype.constructor = subClass;
|
12736 | subClass.__proto__ = superClass;
|
12737 | }
|
12738 |
|
12739 | var Util = __webpack_require__(0);
|
12740 |
|
12741 | var GuideBase = __webpack_require__(8);
|
12742 |
|
12743 | var Arc =
|
12744 |
|
12745 | function (_GuideBase) {
|
12746 | _inheritsLoose(Arc, _GuideBase);
|
12747 |
|
12748 | function Arc() {
|
12749 | return _GuideBase.apply(this, arguments) || this;
|
12750 | }
|
12751 |
|
12752 | var _proto = Arc.prototype;
|
12753 |
|
12754 | _proto._initDefaultCfg = function _initDefaultCfg() {
|
12755 | this.type = 'arc';
|
12756 | |
12757 |
|
12758 |
|
12759 |
|
12760 |
|
12761 | this.start = [];
|
12762 | |
12763 |
|
12764 |
|
12765 |
|
12766 |
|
12767 | this.end = [];
|
12768 | |
12769 |
|
12770 |
|
12771 |
|
12772 |
|
12773 | this.style = {
|
12774 | stroke: '#999',
|
12775 | lineWidth: 1
|
12776 | };
|
12777 | };
|
12778 |
|
12779 | _proto.render = function render(coord, container) {
|
12780 | var self = this;
|
12781 | var start = self.parsePoint(coord, self.start);
|
12782 | var end = self.parsePoint(coord, self.end);
|
12783 |
|
12784 | if (!start || !end) {
|
12785 | return;
|
12786 | }
|
12787 |
|
12788 | var coordCenter = coord.center;
|
12789 | var radius = Math.sqrt((start.x - coordCenter.x) * (start.x - coordCenter.x) + (start.y - coordCenter.y) * (start.y - coordCenter.y));
|
12790 | var startAngle = Math.atan2(start.y - coordCenter.y, start.x - coordCenter.x);
|
12791 | var endAngle = Math.atan2(end.y - coordCenter.y, end.x - coordCenter.x);
|
12792 | var shape = container.addShape('arc', {
|
12793 | className: 'guide-arc',
|
12794 | attrs: Util.mix({
|
12795 | x: coordCenter.x,
|
12796 | y: coordCenter.y,
|
12797 | r: radius,
|
12798 | startAngle: startAngle,
|
12799 | endAngle: endAngle
|
12800 | }, self.style)
|
12801 | });
|
12802 | self.element = shape;
|
12803 | return shape;
|
12804 | };
|
12805 |
|
12806 | return Arc;
|
12807 | }(GuideBase);
|
12808 |
|
12809 | GuideBase.Arc = Arc;
|
12810 | module.exports = Arc;
|
12811 |
|
12812 | }),
|
12813 |
|
12814 | (function(module, exports, __webpack_require__) {
|
12815 |
|
12816 | function _inheritsLoose(subClass, superClass) {
|
12817 | subClass.prototype = Object.create(superClass.prototype);
|
12818 | subClass.prototype.constructor = subClass;
|
12819 | subClass.__proto__ = superClass;
|
12820 | }
|
12821 |
|
12822 | var Util = __webpack_require__(0);
|
12823 |
|
12824 | var GuideBase = __webpack_require__(8);
|
12825 |
|
12826 | var Line =
|
12827 |
|
12828 | function (_GuideBase) {
|
12829 | _inheritsLoose(Line, _GuideBase);
|
12830 |
|
12831 | function Line() {
|
12832 | return _GuideBase.apply(this, arguments) || this;
|
12833 | }
|
12834 |
|
12835 | var _proto = Line.prototype;
|
12836 |
|
12837 | _proto._initDefaultCfg = function _initDefaultCfg() {
|
12838 | this.type = 'line';
|
12839 | this.start = [];
|
12840 | this.end = [];
|
12841 | this.style = {
|
12842 | stroke: '#000',
|
12843 | lineWidth: 1
|
12844 | };
|
12845 | };
|
12846 |
|
12847 | _proto.render = function render(coord, container) {
|
12848 | var points = [];
|
12849 | points[0] = this.parsePoint(coord, this.start);
|
12850 | points[1] = this.parsePoint(coord, this.end);
|
12851 |
|
12852 | if (!points[0] || !points[1]) {
|
12853 | return;
|
12854 | }
|
12855 |
|
12856 | var shape = container.addShape('Line', {
|
12857 | className: 'guide-line',
|
12858 | attrs: Util.mix({
|
12859 | x1: points[0].x,
|
12860 | y1: points[0].y,
|
12861 | x2: points[1].x,
|
12862 | y2: points[1].y
|
12863 | }, this.style)
|
12864 | });
|
12865 | this.element = shape;
|
12866 | return shape;
|
12867 | };
|
12868 |
|
12869 | return Line;
|
12870 | }(GuideBase);
|
12871 |
|
12872 | GuideBase.Line = Line;
|
12873 | module.exports = Line;
|
12874 |
|
12875 | }),
|
12876 |
|
12877 | (function(module, exports, __webpack_require__) {
|
12878 |
|
12879 | function _inheritsLoose(subClass, superClass) {
|
12880 | subClass.prototype = Object.create(superClass.prototype);
|
12881 | subClass.prototype.constructor = subClass;
|
12882 | subClass.__proto__ = superClass;
|
12883 | }
|
12884 |
|
12885 | var Util = __webpack_require__(0);
|
12886 |
|
12887 | var GuideBase = __webpack_require__(8);
|
12888 |
|
12889 | var Text =
|
12890 |
|
12891 | function (_GuideBase) {
|
12892 | _inheritsLoose(Text, _GuideBase);
|
12893 |
|
12894 | function Text() {
|
12895 | return _GuideBase.apply(this, arguments) || this;
|
12896 | }
|
12897 |
|
12898 | var _proto = Text.prototype;
|
12899 |
|
12900 | _proto._initDefaultCfg = function _initDefaultCfg() {
|
12901 | this.type = 'text';
|
12902 | |
12903 |
|
12904 |
|
12905 |
|
12906 |
|
12907 | this.position = null;
|
12908 | |
12909 |
|
12910 |
|
12911 |
|
12912 |
|
12913 | this.content = null;
|
12914 | |
12915 |
|
12916 |
|
12917 |
|
12918 |
|
12919 | this.style = {
|
12920 | fill: '#000'
|
12921 | };
|
12922 | |
12923 |
|
12924 |
|
12925 |
|
12926 |
|
12927 | this.offsetX = 0;
|
12928 | |
12929 |
|
12930 |
|
12931 |
|
12932 |
|
12933 | this.offsetY = 0;
|
12934 | };
|
12935 |
|
12936 | _proto.render = function render(coord, container) {
|
12937 | var position = this.position;
|
12938 | var point = this.parsePoint(coord, position);
|
12939 |
|
12940 | if (!point) {
|
12941 | return;
|
12942 | }
|
12943 |
|
12944 | var content = this.content,
|
12945 | style = this.style,
|
12946 | offsetX = this.offsetX,
|
12947 | offsetY = this.offsetY;
|
12948 |
|
12949 | if (offsetX) {
|
12950 | point.x += offsetX;
|
12951 | }
|
12952 |
|
12953 | if (offsetY) {
|
12954 | point.y += offsetY;
|
12955 | }
|
12956 |
|
12957 | var shape = container.addShape('text', {
|
12958 | className: 'guide-text',
|
12959 | attrs: Util.mix({
|
12960 | x: point.x,
|
12961 | y: point.y,
|
12962 | text: content
|
12963 | }, style)
|
12964 | });
|
12965 | this.element = shape;
|
12966 | return shape;
|
12967 | };
|
12968 |
|
12969 | return Text;
|
12970 | }(GuideBase);
|
12971 |
|
12972 | GuideBase.Text = Text;
|
12973 | module.exports = Text;
|
12974 |
|
12975 | }),
|
12976 |
|
12977 | (function(module, exports, __webpack_require__) {
|
12978 |
|
12979 | function _inheritsLoose(subClass, superClass) {
|
12980 | subClass.prototype = Object.create(superClass.prototype);
|
12981 | subClass.prototype.constructor = subClass;
|
12982 | subClass.__proto__ = superClass;
|
12983 | }
|
12984 |
|
12985 | var Util = __webpack_require__(0);
|
12986 |
|
12987 | var GuideBase = __webpack_require__(8);
|
12988 |
|
12989 | var Tag =
|
12990 |
|
12991 | function (_GuideBase) {
|
12992 | _inheritsLoose(Tag, _GuideBase);
|
12993 |
|
12994 | function Tag() {
|
12995 | return _GuideBase.apply(this, arguments) || this;
|
12996 | }
|
12997 |
|
12998 | var _proto = Tag.prototype;
|
12999 |
|
13000 | _proto._initDefaultCfg = function _initDefaultCfg() {
|
13001 | this.type = 'tag';
|
13002 | this.position = null;
|
13003 | this.content = null;
|
13004 | this.direct = 'tl';
|
13005 | this.autoAdjust = true;
|
13006 | this.offsetX = 0;
|
13007 | this.offsetY = 0;
|
13008 | this.side = 4;
|
13009 | this.background = {
|
13010 | padding: 5,
|
13011 | radius: 2,
|
13012 | fill: '#1890FF'
|
13013 | };
|
13014 | this.textStyle = {
|
13015 | fontSize: 12,
|
13016 | fill: '#fff',
|
13017 | textAlign: 'center',
|
13018 | textBaseline: 'middle'
|
13019 | };
|
13020 | this.withPoint = true;
|
13021 | this.pointStyle = {
|
13022 | fill: '#1890FF',
|
13023 | r: 3,
|
13024 | lineWidth: 1,
|
13025 | stroke: '#fff'
|
13026 | };
|
13027 | };
|
13028 |
|
13029 | _proto._getDirect = function _getDirect(container, point, tagWidth, tagHeight) {
|
13030 | var direct = this.direct;
|
13031 | var side = this.side;
|
13032 | var canvas = container.get('canvas');
|
13033 | var clientWidth = canvas.get('width');
|
13034 | var clientHeight = canvas.get('height');
|
13035 | var x = point.x,
|
13036 | y = point.y;
|
13037 | var vertical = direct[0];
|
13038 | var horizontal = direct[1];
|
13039 |
|
13040 | if (vertical === 't' && y - side - tagHeight < 0) {
|
13041 | vertical = 'b';
|
13042 | } else if (vertical === 'b' && y + side + tagHeight > clientHeight) {
|
13043 | vertical = 't';
|
13044 | }
|
13045 |
|
13046 |
|
13047 | var diff = vertical === 'c' ? side : 0;
|
13048 |
|
13049 | if (horizontal === 'l' && x - diff - tagWidth < 0) {
|
13050 | horizontal = 'r';
|
13051 | } else if (horizontal === 'r' && x + diff + tagWidth > clientWidth) {
|
13052 | horizontal = 'l';
|
13053 | } else if (horizontal === 'c') {
|
13054 | if (tagWidth / 2 + x + diff > clientWidth) {
|
13055 | horizontal = 'l';
|
13056 | } else if (x - tagWidth / 2 - diff < 0) {
|
13057 | horizontal = 'r';
|
13058 | }
|
13059 | }
|
13060 |
|
13061 | direct = vertical + horizontal;
|
13062 | return direct;
|
13063 | };
|
13064 |
|
13065 | _proto.render = function render(coord, container) {
|
13066 | var position = this.parsePoint(coord, this.position);
|
13067 |
|
13068 | if (!position) {
|
13069 | return;
|
13070 | }
|
13071 |
|
13072 | var content = this.content,
|
13073 | background = this.background,
|
13074 | textStyle = this.textStyle;
|
13075 | var shapes = [];
|
13076 | var wrapperContainer = container.addGroup({
|
13077 | className: 'guide-tag'
|
13078 | });
|
13079 |
|
13080 | if (this.withPoint) {
|
13081 | var pointShape = wrapperContainer.addShape('Circle', {
|
13082 | className: 'guide-tag-point',
|
13083 | attrs: Util.mix({
|
13084 | x: position.x,
|
13085 | y: position.y
|
13086 | }, this.pointStyle)
|
13087 | });
|
13088 | shapes.push(pointShape);
|
13089 | }
|
13090 |
|
13091 | var tagContainer = wrapperContainer.addGroup();
|
13092 |
|
13093 | var tagText = tagContainer.addShape('text', {
|
13094 | className: 'guide-tag-text',
|
13095 | zIndex: 1,
|
13096 | attrs: Util.mix({
|
13097 | x: 0,
|
13098 | y: 0,
|
13099 | text: content
|
13100 | }, textStyle)
|
13101 | });
|
13102 | shapes.push(tagText);
|
13103 |
|
13104 | var textBBox = tagText.getBBox();
|
13105 | var padding = Util.parsePadding(background.padding);
|
13106 | var tagWidth = textBBox.width + padding[1] + padding[3];
|
13107 | var tagHeight = textBBox.height + padding[0] + padding[2];
|
13108 | var yMin = textBBox.minY - padding[0];
|
13109 | var xMin = textBBox.minX - padding[3];
|
13110 | var tagBg = tagContainer.addShape('rect', {
|
13111 | className: 'guide-tag-bg',
|
13112 | zIndex: -1,
|
13113 | attrs: Util.mix({
|
13114 | x: xMin,
|
13115 | y: yMin,
|
13116 | width: tagWidth,
|
13117 | height: tagHeight
|
13118 | }, background)
|
13119 | });
|
13120 | shapes.push(tagBg);
|
13121 | var direct = this.autoAdjust ? this._getDirect(container, position, tagWidth, tagHeight) : this.direct;
|
13122 | var side = this.side;
|
13123 | var x = position.x + this.offsetX;
|
13124 | var y = position.y + this.offsetY;
|
13125 | var arrowPoints;
|
13126 | var radius = Util.parsePadding(background.radius);
|
13127 |
|
13128 | if (direct === 'tl') {
|
13129 | arrowPoints = [{
|
13130 | x: tagWidth + xMin - side - 1,
|
13131 | y: tagHeight + yMin - 1
|
13132 | },
|
13133 | {
|
13134 | x: tagWidth + xMin,
|
13135 | y: tagHeight + yMin - 1
|
13136 | }, {
|
13137 | x: tagWidth + xMin,
|
13138 | y: tagHeight + side + yMin
|
13139 | }];
|
13140 | radius[2] = 0;
|
13141 | x = x - tagWidth;
|
13142 | y = y - side - tagHeight;
|
13143 | } else if (direct === 'cl') {
|
13144 | arrowPoints = [{
|
13145 | x: tagWidth + xMin - 1,
|
13146 | y: (tagHeight - side) / 2 + yMin - 1
|
13147 | }, {
|
13148 | x: tagWidth + xMin - 1,
|
13149 | y: (tagHeight + side) / 2 + yMin + 1
|
13150 | }, {
|
13151 | x: tagWidth + side + xMin,
|
13152 | y: tagHeight / 2 + yMin
|
13153 | }];
|
13154 | x = x - tagWidth - side;
|
13155 | y = y - tagHeight / 2;
|
13156 | } else if (direct === 'bl') {
|
13157 | arrowPoints = [{
|
13158 | x: tagWidth + xMin,
|
13159 | y: -side + yMin
|
13160 | }, {
|
13161 | x: tagWidth + xMin - side - 1,
|
13162 | y: yMin + 1
|
13163 | }, {
|
13164 | x: tagWidth + xMin,
|
13165 | y: yMin + 1
|
13166 | }];
|
13167 | radius[1] = 0;
|
13168 | x = x - tagWidth;
|
13169 | y = y + side;
|
13170 | } else if (direct === 'bc') {
|
13171 | arrowPoints = [{
|
13172 | x: tagWidth / 2 + xMin,
|
13173 | y: -side + yMin
|
13174 | }, {
|
13175 | x: (tagWidth - side) / 2 + xMin - 1,
|
13176 | y: yMin + 1
|
13177 | }, {
|
13178 | x: (tagWidth + side) / 2 + xMin + 1,
|
13179 | y: yMin + 1
|
13180 | }];
|
13181 | x = x - tagWidth / 2;
|
13182 | y = y + side;
|
13183 | } else if (direct === 'br') {
|
13184 | arrowPoints = [{
|
13185 | x: xMin,
|
13186 | y: yMin - side
|
13187 | }, {
|
13188 | x: xMin,
|
13189 | y: yMin + 1
|
13190 | }, {
|
13191 | x: xMin + side + 1,
|
13192 | y: yMin + 1
|
13193 | }];
|
13194 | radius[0] = 0;
|
13195 | y = y + side;
|
13196 | } else if (direct === 'cr') {
|
13197 | arrowPoints = [{
|
13198 | x: xMin - side,
|
13199 | y: tagHeight / 2 + yMin
|
13200 | }, {
|
13201 | x: xMin + 1,
|
13202 | y: (tagHeight - side) / 2 + yMin - 1
|
13203 | }, {
|
13204 | x: xMin + 1,
|
13205 | y: (tagHeight + side) / 2 + yMin + 1
|
13206 | }];
|
13207 | x = x + side;
|
13208 | y = y - tagHeight / 2;
|
13209 | } else if (direct === 'tr') {
|
13210 | arrowPoints = [{
|
13211 | x: xMin,
|
13212 | y: tagHeight + side + yMin
|
13213 | }, {
|
13214 | x: xMin,
|
13215 | y: tagHeight + yMin - 1
|
13216 | }, {
|
13217 | x: side + xMin + 1,
|
13218 | y: tagHeight + yMin - 1
|
13219 | }];
|
13220 | radius[3] = 0;
|
13221 | y = y - tagHeight - side;
|
13222 | } else if (direct === 'tc') {
|
13223 | arrowPoints = [{
|
13224 | x: (tagWidth - side) / 2 + xMin - 1,
|
13225 | y: tagHeight + yMin - 1
|
13226 | }, {
|
13227 | x: (tagWidth + side) / 2 + xMin + 1,
|
13228 | y: tagHeight + yMin - 1
|
13229 | }, {
|
13230 | x: tagWidth / 2 + xMin,
|
13231 | y: tagHeight + side + yMin
|
13232 | }];
|
13233 | x = x - tagWidth / 2;
|
13234 | y = y - tagHeight - side;
|
13235 | }
|
13236 |
|
13237 | var sideShape = tagContainer.addShape('Polygon', {
|
13238 | className: 'guide-tag-side',
|
13239 | zIndex: 0,
|
13240 | attrs: {
|
13241 | points: arrowPoints,
|
13242 | fill: background.fill
|
13243 | }
|
13244 | });
|
13245 | shapes.push(sideShape);
|
13246 | tagBg.attr('radius', radius);
|
13247 | tagContainer.moveTo(x - xMin, y - yMin);
|
13248 | tagContainer.sort();
|
13249 | this.element = wrapperContainer;
|
13250 | return shapes;
|
13251 | };
|
13252 |
|
13253 | return Tag;
|
13254 | }(GuideBase);
|
13255 |
|
13256 | GuideBase.Tag = Tag;
|
13257 | module.exports = Tag;
|
13258 |
|
13259 | }),
|
13260 |
|
13261 | (function(module, exports, __webpack_require__) {
|
13262 |
|
13263 | function _inheritsLoose(subClass, superClass) {
|
13264 | subClass.prototype = Object.create(superClass.prototype);
|
13265 | subClass.prototype.constructor = subClass;
|
13266 | subClass.__proto__ = superClass;
|
13267 | }
|
13268 |
|
13269 | var Util = __webpack_require__(0);
|
13270 |
|
13271 | var GuideBase = __webpack_require__(8);
|
13272 |
|
13273 | var Rect =
|
13274 |
|
13275 | function (_GuideBase) {
|
13276 | _inheritsLoose(Rect, _GuideBase);
|
13277 |
|
13278 | function Rect() {
|
13279 | return _GuideBase.apply(this, arguments) || this;
|
13280 | }
|
13281 |
|
13282 | var _proto = Rect.prototype;
|
13283 |
|
13284 | _proto._initDefaultCfg = function _initDefaultCfg() {
|
13285 | this.type = 'rect';
|
13286 | this.start = [];
|
13287 | this.end = [];
|
13288 | this.style = {
|
13289 | fill: '#CCD7EB',
|
13290 | opacity: 0.4
|
13291 | };
|
13292 | };
|
13293 |
|
13294 | _proto.render = function render(coord, container) {
|
13295 | var start = this.parsePoint(coord, this.start);
|
13296 | var end = this.parsePoint(coord, this.end);
|
13297 |
|
13298 | if (!start || !end) {
|
13299 | return;
|
13300 | }
|
13301 |
|
13302 | var shape = container.addShape('rect', {
|
13303 | className: 'guide-rect',
|
13304 | attrs: Util.mix({
|
13305 | x: Math.min(start.x, end.x),
|
13306 | y: Math.min(start.y, end.y),
|
13307 | width: Math.abs(end.x - start.x),
|
13308 | height: Math.abs(start.y - end.y)
|
13309 | }, this.style)
|
13310 | });
|
13311 | this.element = shape;
|
13312 | return shape;
|
13313 | };
|
13314 |
|
13315 | return Rect;
|
13316 | }(GuideBase);
|
13317 |
|
13318 | GuideBase.Rect = Rect;
|
13319 | module.exports = Rect;
|
13320 |
|
13321 | }),
|
13322 |
|
13323 | (function(module, exports, __webpack_require__) {
|
13324 |
|
13325 | function _inheritsLoose(subClass, superClass) {
|
13326 | subClass.prototype = Object.create(superClass.prototype);
|
13327 | subClass.prototype.constructor = subClass;
|
13328 | subClass.__proto__ = superClass;
|
13329 | }
|
13330 |
|
13331 | var Util = __webpack_require__(0);
|
13332 |
|
13333 | var GuideBase = __webpack_require__(8);
|
13334 |
|
13335 | var _require = __webpack_require__(2),
|
13336 | Rect = _require.Rect;
|
13337 |
|
13338 | var RegionFilter =
|
13339 |
|
13340 | function (_GuideBase) {
|
13341 | _inheritsLoose(RegionFilter, _GuideBase);
|
13342 |
|
13343 | function RegionFilter() {
|
13344 | return _GuideBase.apply(this, arguments) || this;
|
13345 | }
|
13346 |
|
13347 | var _proto = RegionFilter.prototype;
|
13348 |
|
13349 | _proto._initDefaultCfg = function _initDefaultCfg() {
|
13350 | this.type = 'regionFilter';
|
13351 | this.start = [];
|
13352 | this.end = [];
|
13353 | this.color = null;
|
13354 | this.style = null;
|
13355 | };
|
13356 |
|
13357 | _proto.render = function render(coord) {
|
13358 | var start = this.parsePoint(coord, this.start);
|
13359 | var end = this.parsePoint(coord, this.end);
|
13360 |
|
13361 | if (!start || !end) {
|
13362 | return;
|
13363 | }
|
13364 |
|
13365 | var clip = new Rect({
|
13366 | attrs: {
|
13367 | x: Math.min(start.x, end.x),
|
13368 | y: Math.min(start.y, end.y),
|
13369 | width: Math.abs(end.x - start.x),
|
13370 | height: Math.abs(end.y - start.y)
|
13371 | }
|
13372 | });
|
13373 |
|
13374 | this.clip = clip;
|
13375 | var chart = this.chart;
|
13376 | var color = this.color;
|
13377 | var style = this.style || {};
|
13378 | var regionElements = [];
|
13379 | var geoms = chart.get('geoms');
|
13380 | geoms.map(function (geom) {
|
13381 | var geomContainer = geom.get('container');
|
13382 | var children = geomContainer.get('children');
|
13383 | var group = geomContainer.addGroup({
|
13384 | zIndex: 10,
|
13385 | className: 'guide-region-filter'
|
13386 | });
|
13387 | children.map(function (c) {
|
13388 | if (c.get('isShape')) {
|
13389 | var type = c.get('type');
|
13390 | var attrs = Util.mix({}, c.get('attrs'), style);
|
13391 |
|
13392 | if (color && (attrs.fill || attrs.fillStyle)) {
|
13393 | attrs.fill = attrs.fillStyle = color;
|
13394 | }
|
13395 |
|
13396 | if (color && (attrs.stroke || attrs.strokeStyle)) {
|
13397 | attrs.stroke = attrs.strokeStyle = color;
|
13398 | }
|
13399 |
|
13400 | var cfg = {
|
13401 | attrs: attrs
|
13402 | };
|
13403 |
|
13404 | if (type === 'custom' || type === 'Custom') {
|
13405 |
|
13406 | cfg.createPath = c.get('createPath');
|
13407 | cfg.calculateBox = c.get('calculateBox');
|
13408 | }
|
13409 |
|
13410 | group.addShape(type, cfg);
|
13411 | }
|
13412 |
|
13413 | return c;
|
13414 | });
|
13415 | group.attr('clip', clip);
|
13416 | geomContainer.sort();
|
13417 | regionElements.push(group);
|
13418 | return geom;
|
13419 | });
|
13420 | this.element = regionElements;
|
13421 | };
|
13422 |
|
13423 | _proto.remove = function remove() {
|
13424 | var element = this.element;
|
13425 | Util.each(element, function (group) {
|
13426 | group && group.remove(true);
|
13427 | });
|
13428 | this.clip && this.clip.remove(true);
|
13429 | };
|
13430 |
|
13431 | return RegionFilter;
|
13432 | }(GuideBase);
|
13433 |
|
13434 | GuideBase.RegionFilter = RegionFilter;
|
13435 | module.exports = RegionFilter;
|
13436 |
|
13437 | }),
|
13438 |
|
13439 | (function(module, exports, __webpack_require__) {
|
13440 |
|
13441 | function _inheritsLoose(subClass, superClass) {
|
13442 | subClass.prototype = Object.create(superClass.prototype);
|
13443 | subClass.prototype.constructor = subClass;
|
13444 | subClass.__proto__ = superClass;
|
13445 | }
|
13446 |
|
13447 | var Util = __webpack_require__(0);
|
13448 |
|
13449 | var GuideBase = __webpack_require__(8);
|
13450 |
|
13451 | var Point =
|
13452 |
|
13453 | function (_GuideBase) {
|
13454 | _inheritsLoose(Point, _GuideBase);
|
13455 |
|
13456 | function Point() {
|
13457 | return _GuideBase.apply(this, arguments) || this;
|
13458 | }
|
13459 |
|
13460 | var _proto = Point.prototype;
|
13461 |
|
13462 | _proto._initDefaultCfg = function _initDefaultCfg() {
|
13463 | this.type = 'point';
|
13464 | this.position = null;
|
13465 | this.offsetX = 0;
|
13466 | this.offsetY = 0;
|
13467 | this.style = {
|
13468 | fill: '#1890FF',
|
13469 | r: 3,
|
13470 | lineWidth: 1,
|
13471 | stroke: '#fff'
|
13472 | };
|
13473 | };
|
13474 |
|
13475 | _proto.render = function render(coord, container) {
|
13476 | var position = this.parsePoint(coord, this.position);
|
13477 | var shape = container.addShape('Circle', {
|
13478 | className: 'guide-point',
|
13479 | attrs: Util.mix({
|
13480 | x: position.x + this.offsetX,
|
13481 | y: position.y + this.offsetY
|
13482 | }, this.style)
|
13483 | });
|
13484 | this.element = shape;
|
13485 | return shape;
|
13486 | };
|
13487 |
|
13488 | return Point;
|
13489 | }(GuideBase);
|
13490 |
|
13491 | GuideBase.Point = Point;
|
13492 | module.exports = Point;
|
13493 |
|
13494 | }),
|
13495 |
|
13496 | (function(module, exports, __webpack_require__) {
|
13497 |
|
13498 | var Util = __webpack_require__(0);
|
13499 |
|
13500 | var Global = __webpack_require__(1);
|
13501 |
|
13502 | var Tooltip = __webpack_require__(120);
|
13503 |
|
13504 | var Helper = __webpack_require__(20);
|
13505 |
|
13506 |
|
13507 | Global.tooltip = Util.deepMix({
|
13508 | triggerOn: ['touchstart', 'touchmove'],
|
13509 |
|
13510 | alwaysShow: false,
|
13511 | showTitle: false,
|
13512 | showCrosshairs: false,
|
13513 | crosshairsStyle: {
|
13514 | stroke: 'rgba(0, 0, 0, 0.25)',
|
13515 | lineWidth: 1
|
13516 | },
|
13517 | showTooltipMarker: true,
|
13518 | background: {
|
13519 | radius: 1,
|
13520 | fill: 'rgba(0, 0, 0, 0.65)',
|
13521 | padding: [3, 5]
|
13522 | },
|
13523 | titleStyle: {
|
13524 | fontSize: 12,
|
13525 | fill: '#fff',
|
13526 | textAlign: 'start',
|
13527 | textBaseline: 'top'
|
13528 | },
|
13529 | nameStyle: {
|
13530 | fontSize: 12,
|
13531 | fill: 'rgba(255, 255, 255, 0.65)',
|
13532 | textAlign: 'start',
|
13533 | textBaseline: 'middle'
|
13534 | },
|
13535 | valueStyle: {
|
13536 | fontSize: 12,
|
13537 | fill: '#fff',
|
13538 | textAlign: 'start',
|
13539 | textBaseline: 'middle'
|
13540 | },
|
13541 | showItemMarker: true,
|
13542 | itemMarkerStyle: {
|
13543 | radius: 3,
|
13544 | symbol: 'circle',
|
13545 | lineWidth: 1,
|
13546 | stroke: '#fff'
|
13547 | },
|
13548 | layout: 'horizontal',
|
13549 | snap: false
|
13550 | }, Global.tooltip || {});
|
13551 |
|
13552 | function _getTooltipValueScale(geom) {
|
13553 | var colorAttr = geom.getAttr('color');
|
13554 |
|
13555 | if (colorAttr) {
|
13556 | var colorScale = colorAttr.getScale(colorAttr.type);
|
13557 |
|
13558 | if (colorScale.isLinear) {
|
13559 | return colorScale;
|
13560 | }
|
13561 | }
|
13562 |
|
13563 | var xScale = geom.getXScale();
|
13564 | var yScale = geom.getYScale();
|
13565 |
|
13566 | if (yScale) {
|
13567 | return yScale;
|
13568 | }
|
13569 |
|
13570 | return xScale;
|
13571 | }
|
13572 |
|
13573 | function getTooltipName(geom, origin) {
|
13574 | var name;
|
13575 | var nameScale;
|
13576 |
|
13577 | var groupScales = geom._getGroupScales();
|
13578 |
|
13579 | if (groupScales.length) {
|
13580 | Util.each(groupScales, function (scale) {
|
13581 | nameScale = scale;
|
13582 | return false;
|
13583 | });
|
13584 | }
|
13585 |
|
13586 | if (nameScale) {
|
13587 | var field = nameScale.field;
|
13588 | name = nameScale.getText(origin[field]);
|
13589 | } else {
|
13590 | var valueScale = _getTooltipValueScale(geom);
|
13591 |
|
13592 | name = valueScale.alias || valueScale.field;
|
13593 | }
|
13594 |
|
13595 | return name;
|
13596 | }
|
13597 |
|
13598 | function getTooltipValue(geom, origin) {
|
13599 | var scale = _getTooltipValueScale(geom);
|
13600 |
|
13601 | return scale.getText(origin[scale.field]);
|
13602 | }
|
13603 |
|
13604 | function getTooltipTitle(geom, origin) {
|
13605 | var position = geom.getAttr('position');
|
13606 | var field = position.getFields()[0];
|
13607 | var scale = geom.get('scales')[field];
|
13608 | return scale.getText(origin[scale.field]);
|
13609 | }
|
13610 |
|
13611 | function _indexOfArray(items, item) {
|
13612 | var rst = -1;
|
13613 | Util.each(items, function (sub, index) {
|
13614 | if (sub.title === item.title && sub.name === item.name && sub.value === item.value && sub.color === item.color) {
|
13615 | rst = index;
|
13616 | return false;
|
13617 | }
|
13618 | });
|
13619 | return rst;
|
13620 | }
|
13621 |
|
13622 | function _uniqItems(items) {
|
13623 | var tmp = [];
|
13624 | Util.each(items, function (item) {
|
13625 | var index = _indexOfArray(tmp, item);
|
13626 |
|
13627 | if (index === -1) {
|
13628 | tmp.push(item);
|
13629 | } else {
|
13630 | tmp[index] = item;
|
13631 | }
|
13632 | });
|
13633 | return tmp;
|
13634 | }
|
13635 |
|
13636 | function isEqual(arr1, arr2) {
|
13637 | return JSON.stringify(arr1) === JSON.stringify(arr2);
|
13638 | }
|
13639 |
|
13640 | var TooltipController =
|
13641 |
|
13642 | function () {
|
13643 | function TooltipController(cfg) {
|
13644 | this.enable = true;
|
13645 | this.cfg = {};
|
13646 | this.tooltip = null;
|
13647 | this.chart = null;
|
13648 | this.timeStamp = 0;
|
13649 | Util.mix(this, cfg);
|
13650 | var chart = this.chart;
|
13651 | this.canvasDom = chart.get('canvas').get('el');
|
13652 | }
|
13653 |
|
13654 | var _proto = TooltipController.prototype;
|
13655 |
|
13656 | _proto._setCrosshairsCfg = function _setCrosshairsCfg() {
|
13657 | var self = this;
|
13658 | var chart = self.chart;
|
13659 | var defaultCfg = Util.mix({}, Global.tooltip);
|
13660 | var geoms = chart.get('geoms');
|
13661 | var shapes = [];
|
13662 | Util.each(geoms, function (geom) {
|
13663 | var type = geom.get('type');
|
13664 |
|
13665 | if (shapes.indexOf(type) === -1) {
|
13666 | shapes.push(type);
|
13667 | }
|
13668 | });
|
13669 | var coordType = chart.get('coord').type;
|
13670 |
|
13671 | if (geoms.length && (coordType === 'cartesian' || coordType === 'rect')) {
|
13672 | if (shapes.length === 1 && ['line', 'area', 'path', 'point'].indexOf(shapes[0]) !== -1) {
|
13673 | Util.mix(defaultCfg, {
|
13674 | showCrosshairs: true
|
13675 | });
|
13676 | }
|
13677 | }
|
13678 |
|
13679 | return defaultCfg;
|
13680 | };
|
13681 |
|
13682 | _proto._getMaxLength = function _getMaxLength(cfg) {
|
13683 | if (cfg === void 0) {
|
13684 | cfg = {};
|
13685 | }
|
13686 |
|
13687 | var _cfg = cfg,
|
13688 | layout = _cfg.layout,
|
13689 | plotRange = _cfg.plotRange;
|
13690 | return layout === 'horizontal' ? plotRange.br.x - plotRange.bl.x : plotRange.bl.y - plotRange.tr.y;
|
13691 | };
|
13692 |
|
13693 | _proto.render = function render() {
|
13694 | var self = this;
|
13695 |
|
13696 | if (self.tooltip) {
|
13697 | return;
|
13698 | }
|
13699 |
|
13700 | var chart = self.chart;
|
13701 | var canvas = chart.get('canvas');
|
13702 | var frontPlot = chart.get('frontPlot').addGroup({
|
13703 | className: 'tooltipContainer',
|
13704 | zIndex: 10
|
13705 | });
|
13706 | var backPlot = chart.get('backPlot').addGroup({
|
13707 | className: 'tooltipContainer'
|
13708 | });
|
13709 | var plotRange = chart.get('plotRange');
|
13710 | var coord = chart.get('coord');
|
13711 |
|
13712 | var defaultCfg = self._setCrosshairsCfg();
|
13713 |
|
13714 | var cfg = self.cfg;
|
13715 | cfg = Util.deepMix({
|
13716 | plotRange: plotRange,
|
13717 | frontPlot: frontPlot,
|
13718 | backPlot: backPlot,
|
13719 | canvas: canvas,
|
13720 | fixed: coord.transposed || coord.isPolar
|
13721 | }, defaultCfg, cfg);
|
13722 | cfg.maxLength = self._getMaxLength(cfg);
|
13723 | this.cfg = cfg;
|
13724 | var tooltip = new Tooltip(cfg);
|
13725 | self.tooltip = tooltip;
|
13726 | self.bindEvents();
|
13727 | };
|
13728 |
|
13729 | _proto.clear = function clear() {
|
13730 | var tooltip = this.tooltip;
|
13731 | tooltip && tooltip.destroy();
|
13732 | this.tooltip = null;
|
13733 | this.prePoint = null;
|
13734 | this._lastActive = null;
|
13735 | this.unBindEvents();
|
13736 | };
|
13737 |
|
13738 | _proto._getTooltipMarkerStyle = function _getTooltipMarkerStyle(cfg) {
|
13739 | if (cfg === void 0) {
|
13740 | cfg = {};
|
13741 | }
|
13742 |
|
13743 | var _cfg2 = cfg,
|
13744 | type = _cfg2.type,
|
13745 | items = _cfg2.items;
|
13746 | var tooltipCfg = this.cfg;
|
13747 |
|
13748 | if (type === 'rect') {
|
13749 | var x;
|
13750 | var y;
|
13751 | var width;
|
13752 | var height;
|
13753 | var chart = this.chart;
|
13754 |
|
13755 | var _chart$get = chart.get('plotRange'),
|
13756 | tl = _chart$get.tl,
|
13757 | br = _chart$get.br;
|
13758 |
|
13759 | var coord = chart.get('coord');
|
13760 | var firstItem = items[0];
|
13761 | var lastItem = items[items.length - 1];
|
13762 | var intervalWidth = firstItem.width;
|
13763 |
|
13764 | if (coord.transposed) {
|
13765 | x = tl.x;
|
13766 | y = lastItem.y - intervalWidth * 0.75;
|
13767 | width = br.x - tl.x;
|
13768 | height = firstItem.y - lastItem.y + 1.5 * intervalWidth;
|
13769 | } else {
|
13770 | x = firstItem.x - intervalWidth * 0.75;
|
13771 | y = tl.y;
|
13772 | width = lastItem.x - firstItem.x + 1.5 * intervalWidth;
|
13773 | height = br.y - tl.y;
|
13774 | }
|
13775 |
|
13776 | cfg.style = Util.mix({
|
13777 | x: x,
|
13778 | y: y,
|
13779 | width: width,
|
13780 | height: height,
|
13781 | fill: '#CCD6EC',
|
13782 | opacity: 0.3
|
13783 | }, tooltipCfg.tooltipMarkerStyle);
|
13784 | } else {
|
13785 | cfg.style = Util.mix({
|
13786 | radius: 4,
|
13787 | fill: '#fff',
|
13788 | lineWidth: 2
|
13789 | }, tooltipCfg.tooltipMarkerStyle);
|
13790 | }
|
13791 |
|
13792 | return cfg;
|
13793 | };
|
13794 |
|
13795 | _proto._setTooltip = function _setTooltip(point, items, tooltipMarkerCfg) {
|
13796 | if (tooltipMarkerCfg === void 0) {
|
13797 | tooltipMarkerCfg = {};
|
13798 | }
|
13799 |
|
13800 | var lastActive = this._lastActive;
|
13801 | var tooltip = this.tooltip;
|
13802 | var cfg = this.cfg;
|
13803 | items = _uniqItems(items);
|
13804 | var chart = this.chart;
|
13805 | var coord = chart.get('coord');
|
13806 | var yScale = chart.getYScales()[0];
|
13807 | var snap = cfg.snap;
|
13808 |
|
13809 | if (snap === false && yScale.isLinear) {
|
13810 | var invertPoint = coord.invertPoint(point);
|
13811 | var plot = chart.get('plotRange');
|
13812 | var tip;
|
13813 | var pos;
|
13814 |
|
13815 | if (Helper.isPointInPlot(point, plot)) {
|
13816 | if (coord.transposed) {
|
13817 | tip = yScale.invert(invertPoint.x);
|
13818 | pos = point.x;
|
13819 | tooltip.setXTipContent(tip);
|
13820 | tooltip.setXTipPosition(pos);
|
13821 | tooltip.setYCrosshairPosition(pos);
|
13822 | } else {
|
13823 | tip = yScale.invert(invertPoint.y);
|
13824 | pos = point.y;
|
13825 | tooltip.setYTipContent(tip);
|
13826 | tooltip.setYTipPosition(pos);
|
13827 | tooltip.setXCrosshairPosition(pos);
|
13828 | }
|
13829 | }
|
13830 | }
|
13831 |
|
13832 | if (cfg.onShow) {
|
13833 | cfg.onShow({
|
13834 | x: point.x,
|
13835 | y: point.y,
|
13836 | tooltip: tooltip,
|
13837 | items: items,
|
13838 | tooltipMarkerCfg: tooltipMarkerCfg
|
13839 | });
|
13840 | }
|
13841 |
|
13842 | if (isEqual(lastActive, items)) {
|
13843 | if (snap === false && (Util.directionEnabled(cfg.crosshairsType, 'y') || cfg.showYTip)) {
|
13844 | var canvas = this.chart.get('canvas');
|
13845 | canvas.draw();
|
13846 | }
|
13847 |
|
13848 | return;
|
13849 | }
|
13850 |
|
13851 | this._lastActive = items;
|
13852 | var onChange = cfg.onChange;
|
13853 |
|
13854 | if (onChange) {
|
13855 | onChange({
|
13856 | x: point.x,
|
13857 | y: point.y,
|
13858 | tooltip: tooltip,
|
13859 | items: items,
|
13860 | tooltipMarkerCfg: tooltipMarkerCfg
|
13861 | });
|
13862 | }
|
13863 |
|
13864 | var first = items[0];
|
13865 | var title = first.title || first.name;
|
13866 | var xTipPosX = first.x;
|
13867 |
|
13868 | if (items.length > 1) {
|
13869 | xTipPosX = (items[0].x + items[items.length - 1].x) / 2;
|
13870 | }
|
13871 |
|
13872 | tooltip.setContent(title, items, coord.transposed);
|
13873 | tooltip.setPosition(items, point);
|
13874 |
|
13875 | if (coord.transposed) {
|
13876 | var yTipPosY = first.y;
|
13877 |
|
13878 | if (items.length > 1) {
|
13879 | yTipPosY = (items[0].y + items[items.length - 1].y) / 2;
|
13880 | }
|
13881 |
|
13882 | tooltip.setYTipContent(title);
|
13883 | tooltip.setYTipPosition(yTipPosY);
|
13884 | tooltip.setXCrosshairPosition(yTipPosY);
|
13885 |
|
13886 | if (snap) {
|
13887 | tooltip.setXTipContent(first.value);
|
13888 | tooltip.setXTipPosition(xTipPosX);
|
13889 | tooltip.setYCrosshairPosition(xTipPosX);
|
13890 | }
|
13891 | } else {
|
13892 | tooltip.setXTipContent(title);
|
13893 | tooltip.setXTipPosition(xTipPosX);
|
13894 | tooltip.setYCrosshairPosition(xTipPosX);
|
13895 |
|
13896 | if (snap) {
|
13897 | tooltip.setYTipContent(first.value);
|
13898 | tooltip.setYTipPosition(first.y);
|
13899 | tooltip.setXCrosshairPosition(first.y);
|
13900 | }
|
13901 | }
|
13902 |
|
13903 | var markerItems = tooltipMarkerCfg.items;
|
13904 |
|
13905 | if (cfg.showTooltipMarker && markerItems.length) {
|
13906 | tooltipMarkerCfg = this._getTooltipMarkerStyle(tooltipMarkerCfg);
|
13907 | tooltip.setMarkers(tooltipMarkerCfg);
|
13908 | } else {
|
13909 | tooltip.clearMarkers();
|
13910 | }
|
13911 |
|
13912 | tooltip.show();
|
13913 | };
|
13914 |
|
13915 | _proto.showTooltip = function showTooltip(point) {
|
13916 | var self = this;
|
13917 | var chart = self.chart;
|
13918 | var tooltipMarkerType;
|
13919 | var tooltipMarkerItems = [];
|
13920 | var items = [];
|
13921 | var cfg = self.cfg;
|
13922 | var marker;
|
13923 |
|
13924 | if (cfg.showItemMarker) {
|
13925 | marker = cfg.itemMarkerStyle;
|
13926 | }
|
13927 |
|
13928 | var geoms = chart.get('geoms');
|
13929 | var coord = chart.get('coord');
|
13930 | Util.each(geoms, function (geom) {
|
13931 | if (geom.get('visible')) {
|
13932 | var type = geom.get('type');
|
13933 | var records = geom.getSnapRecords(point);
|
13934 | Util.each(records, function (record) {
|
13935 | if (record.x && record.y) {
|
13936 | var x = record.x,
|
13937 | y = record.y,
|
13938 | _origin = record._origin,
|
13939 | color = record.color;
|
13940 | var tooltipItem = {
|
13941 | x: x,
|
13942 | y: Util.isArray(y) ? y[1] : y,
|
13943 | color: color || Global.defaultColor,
|
13944 | origin: _origin,
|
13945 | name: getTooltipName(geom, _origin),
|
13946 | value: getTooltipValue(geom, _origin),
|
13947 | title: getTooltipTitle(geom, _origin)
|
13948 | };
|
13949 |
|
13950 | if (marker) {
|
13951 | tooltipItem.marker = Util.mix({
|
13952 | fill: color || Global.defaultColor
|
13953 | }, marker);
|
13954 | }
|
13955 |
|
13956 | items.push(tooltipItem);
|
13957 |
|
13958 | if (['line', 'area', 'path'].indexOf(type) !== -1) {
|
13959 | tooltipMarkerType = 'circle';
|
13960 | tooltipMarkerItems.push(tooltipItem);
|
13961 | } else if (type === 'interval' && (coord.type === 'cartesian' || coord.type === 'rect')) {
|
13962 | tooltipMarkerType = 'rect';
|
13963 | tooltipItem.width = geom.getSize(record._origin);
|
13964 | tooltipMarkerItems.push(tooltipItem);
|
13965 | }
|
13966 | }
|
13967 | });
|
13968 | }
|
13969 | });
|
13970 |
|
13971 | if (items.length) {
|
13972 | var tooltipMarkerCfg = {
|
13973 | items: tooltipMarkerItems,
|
13974 | type: tooltipMarkerType
|
13975 | };
|
13976 |
|
13977 | self._setTooltip(point, items, tooltipMarkerCfg);
|
13978 | } else {
|
13979 | self.hideTooltip();
|
13980 | }
|
13981 | };
|
13982 |
|
13983 | _proto.hideTooltip = function hideTooltip() {
|
13984 | var cfg = this.cfg;
|
13985 | this._lastActive = null;
|
13986 | var tooltip = this.tooltip;
|
13987 |
|
13988 | if (tooltip) {
|
13989 | tooltip.hide();
|
13990 |
|
13991 | if (cfg.onHide) {
|
13992 | cfg.onHide({
|
13993 | tooltip: tooltip
|
13994 | });
|
13995 | }
|
13996 |
|
13997 | var canvas = this.chart.get('canvas');
|
13998 | canvas.draw();
|
13999 | }
|
14000 | };
|
14001 |
|
14002 | _proto.handleShowEvent = function handleShowEvent(ev) {
|
14003 | var chart = this.chart;
|
14004 | if (!this.enable || chart.get('_closeTooltip')) return;
|
14005 | var plot = chart.get('plotRange');
|
14006 | var point = Util.createEvent(ev, chart);
|
14007 |
|
14008 | if (!Helper.isPointInPlot(point, plot) && !this.cfg.alwaysShow) {
|
14009 |
|
14010 | this.hideTooltip();
|
14011 | return;
|
14012 | }
|
14013 |
|
14014 | var lastTimeStamp = this.timeStamp;
|
14015 | var timeStamp = +new Date();
|
14016 |
|
14017 | if (timeStamp - lastTimeStamp > 16) {
|
14018 | this.showTooltip(point);
|
14019 | this.timeStamp = timeStamp;
|
14020 | }
|
14021 | };
|
14022 |
|
14023 | _proto.handleHideEvent = function handleHideEvent() {
|
14024 | var chart = this.chart;
|
14025 | if (!this.enable || chart.get('_closeTooltip')) return;
|
14026 | this.hideTooltip();
|
14027 | };
|
14028 |
|
14029 | _proto.handleDocEvent = function handleDocEvent(ev) {
|
14030 | var chart = this.chart;
|
14031 | if (!this.enable || chart.get('_closeTooltip')) return;
|
14032 | var canvasDom = this.canvasDom;
|
14033 |
|
14034 | if (ev.target !== canvasDom) {
|
14035 | this.hideTooltip();
|
14036 | }
|
14037 | };
|
14038 |
|
14039 | _proto._handleEvent = function _handleEvent(methodName, method, action) {
|
14040 | var canvasDom = this.canvasDom;
|
14041 | Util.each([].concat(methodName), function (aMethod) {
|
14042 | if (action === 'bind') {
|
14043 | Util.addEventListener(canvasDom, aMethod, method);
|
14044 | } else {
|
14045 | Util.removeEventListener(canvasDom, aMethod, method);
|
14046 | }
|
14047 | });
|
14048 | };
|
14049 |
|
14050 | _proto.bindEvents = function bindEvents() {
|
14051 | var cfg = this.cfg;
|
14052 | var triggerOn = cfg.triggerOn,
|
14053 | triggerOff = cfg.triggerOff,
|
14054 | alwaysShow = cfg.alwaysShow;
|
14055 | var showMethod = Util.wrapBehavior(this, 'handleShowEvent');
|
14056 | var hideMethod = Util.wrapBehavior(this, 'handleHideEvent');
|
14057 | triggerOn && this._handleEvent(triggerOn, showMethod, 'bind');
|
14058 | triggerOff && this._handleEvent(triggerOff, hideMethod, 'bind');
|
14059 |
|
14060 | if (!alwaysShow) {
|
14061 | var docMethod = Util.wrapBehavior(this, 'handleDocEvent');
|
14062 | Util.isBrowser && Util.addEventListener(document, 'touchstart', docMethod);
|
14063 | }
|
14064 | };
|
14065 |
|
14066 | _proto.unBindEvents = function unBindEvents() {
|
14067 | var cfg = this.cfg;
|
14068 | var triggerOn = cfg.triggerOn,
|
14069 | triggerOff = cfg.triggerOff,
|
14070 | alwaysShow = cfg.alwaysShow;
|
14071 | var showMethod = Util.getWrapBehavior(this, 'handleShowEvent');
|
14072 | var hideMethod = Util.getWrapBehavior(this, 'handleHideEvent');
|
14073 | triggerOn && this._handleEvent(triggerOn, showMethod, 'unBind');
|
14074 | triggerOff && this._handleEvent(triggerOff, hideMethod, 'unBind');
|
14075 |
|
14076 | if (!alwaysShow) {
|
14077 | var docMethod = Util.getWrapBehavior(this, 'handleDocEvent');
|
14078 | Util.isBrowser && Util.removeEventListener(document, 'touchstart', docMethod);
|
14079 | }
|
14080 | };
|
14081 |
|
14082 | return TooltipController;
|
14083 | }();
|
14084 |
|
14085 | module.exports = {
|
14086 | init: function init(chart) {
|
14087 | var tooltipController = new TooltipController({
|
14088 | chart: chart
|
14089 | });
|
14090 | chart.set('tooltipController', tooltipController);
|
14091 |
|
14092 | chart.tooltip = function (enable, cfg) {
|
14093 | if (Util.isObject(enable)) {
|
14094 | cfg = enable;
|
14095 | enable = true;
|
14096 | }
|
14097 |
|
14098 | tooltipController.enable = enable;
|
14099 |
|
14100 | if (cfg) {
|
14101 | tooltipController.cfg = cfg;
|
14102 | }
|
14103 |
|
14104 | return this;
|
14105 | };
|
14106 | },
|
14107 | afterGeomDraw: function afterGeomDraw(chart) {
|
14108 | var tooltipController = chart.get('tooltipController');
|
14109 | tooltipController.render();
|
14110 |
|
14111 | chart.showTooltip = function (point) {
|
14112 | tooltipController.showTooltip(point);
|
14113 | return this;
|
14114 | };
|
14115 |
|
14116 | chart.hideTooltip = function () {
|
14117 | tooltipController.hideTooltip();
|
14118 | return this;
|
14119 | };
|
14120 | },
|
14121 | clearInner: function clearInner(chart) {
|
14122 | var tooltipController = chart.get('tooltipController');
|
14123 | tooltipController.clear();
|
14124 | }
|
14125 | };
|
14126 |
|
14127 | }),
|
14128 |
|
14129 | (function(module, exports, __webpack_require__) {
|
14130 |
|
14131 | var Util = __webpack_require__(0);
|
14132 |
|
14133 | var Marker = __webpack_require__(43);
|
14134 |
|
14135 | var Container = __webpack_require__(44);
|
14136 |
|
14137 | var TextBox = __webpack_require__(121);
|
14138 |
|
14139 | var GAP = 4;
|
14140 |
|
14141 |
|
14142 |
|
14143 |
|
14144 |
|
14145 | var Tooltip =
|
14146 |
|
14147 | function () {
|
14148 | var _proto = Tooltip.prototype;
|
14149 |
|
14150 | _proto.getDefaultCfg = function getDefaultCfg() {
|
14151 | return {
|
14152 | |
14153 |
|
14154 |
|
14155 |
|
14156 | showCrosshairs: false,
|
14157 |
|
14158 | |
14159 |
|
14160 |
|
14161 |
|
14162 | crosshairsStyle: {
|
14163 | stroke: 'rgba(0, 0, 0, 0.25)',
|
14164 | lineWidth: 1
|
14165 | },
|
14166 |
|
14167 | |
14168 |
|
14169 |
|
14170 | crosshairsType: 'y',
|
14171 |
|
14172 | |
14173 |
|
14174 |
|
14175 | showXTip: false,
|
14176 |
|
14177 | |
14178 |
|
14179 |
|
14180 | showYTip: false,
|
14181 | xTip: null,
|
14182 | xTipBackground: {
|
14183 | radius: 1,
|
14184 | fill: 'rgba(0, 0, 0, 0.65)',
|
14185 | padding: [3, 5]
|
14186 | },
|
14187 | yTip: null,
|
14188 | yTipBackground: {
|
14189 | radius: 1,
|
14190 | fill: 'rgba(0, 0, 0, 0.65)',
|
14191 | padding: [3, 5]
|
14192 | },
|
14193 |
|
14194 | |
14195 |
|
14196 |
|
14197 |
|
14198 | background: null,
|
14199 |
|
14200 | |
14201 |
|
14202 |
|
14203 |
|
14204 | layout: 'horizontal',
|
14205 | offsetX: 0,
|
14206 | offsetY: 0
|
14207 | };
|
14208 | };
|
14209 |
|
14210 | function Tooltip(cfg) {
|
14211 | Util.deepMix(this, this.getDefaultCfg(), cfg);
|
14212 | var frontPlot = this.frontPlot,
|
14213 | custom = this.custom;
|
14214 |
|
14215 | if (!custom) {
|
14216 |
|
14217 | var container = new Container(Util.mix({
|
14218 | parent: frontPlot,
|
14219 | zIndex: 3
|
14220 | }, cfg));
|
14221 | this.container = container;
|
14222 | var fixed = this.fixed,
|
14223 | background = this.background;
|
14224 |
|
14225 | if (!fixed) {
|
14226 | this.tooltipArrow = frontPlot.addShape('Polygon', {
|
14227 | className: 'tooltip-arrow',
|
14228 | visible: false,
|
14229 | zIndex: 2,
|
14230 | attrs: Util.mix({
|
14231 | points: []
|
14232 | }, background)
|
14233 | });
|
14234 | }
|
14235 | }
|
14236 |
|
14237 | if (this.showXTip) {
|
14238 | var xTipBackground = this.xTipBackground;
|
14239 | var xTipBox = new TextBox({
|
14240 | className: 'xTip',
|
14241 | background: xTipBackground,
|
14242 | visible: false
|
14243 | });
|
14244 | frontPlot.add(xTipBox.container);
|
14245 | this.xTipBox = xTipBox;
|
14246 | }
|
14247 |
|
14248 | if (this.showYTip) {
|
14249 | var yTipBackground = this.yTipBackground;
|
14250 | var yTipBox = new TextBox({
|
14251 | className: 'yTip',
|
14252 | background: yTipBackground,
|
14253 | visible: false
|
14254 | });
|
14255 | frontPlot.add(yTipBox.container);
|
14256 | this.yTipBox = yTipBox;
|
14257 | }
|
14258 |
|
14259 | if (this.showCrosshairs) {
|
14260 | this._renderCrosshairs();
|
14261 | }
|
14262 |
|
14263 | frontPlot.sort();
|
14264 | }
|
14265 |
|
14266 | _proto.setContent = function setContent(title, items) {
|
14267 | this.title = title;
|
14268 | this.items = items;
|
14269 |
|
14270 | if (!this.custom) {
|
14271 | var container = this.container;
|
14272 | container.setTitle(title);
|
14273 | container.setItems(items);
|
14274 | }
|
14275 | };
|
14276 |
|
14277 | _proto.setYTipContent = function setYTipContent(val) {
|
14278 | var yTip = this.yTip;
|
14279 |
|
14280 | if (Util.isFunction(yTip)) {
|
14281 | val = yTip(val);
|
14282 | } else {
|
14283 | val = Util.mix({
|
14284 | text: val
|
14285 | }, yTip);
|
14286 | }
|
14287 |
|
14288 | this.yTipBox && this.yTipBox.updateContent(val);
|
14289 | };
|
14290 |
|
14291 | _proto.setYTipPosition = function setYTipPosition(pos) {
|
14292 | var plotRange = this.plotRange;
|
14293 | var crosshairsShapeX = this.crosshairsShapeX;
|
14294 |
|
14295 | if (this.showYTip) {
|
14296 | var yTipBox = this.yTipBox;
|
14297 | var yTipHeight = yTipBox.getHeight();
|
14298 | var yTipWidth = yTipBox.getWidth();
|
14299 | var posX = plotRange.tl.x - yTipWidth;
|
14300 | var posY = pos - yTipHeight / 2;
|
14301 |
|
14302 | if (posY <= plotRange.tl.y) {
|
14303 | posY = plotRange.tl.y;
|
14304 | }
|
14305 |
|
14306 | if (posY + yTipHeight >= plotRange.br.y) {
|
14307 | posY = plotRange.br.y - yTipHeight;
|
14308 | }
|
14309 |
|
14310 | if (posX < 0) {
|
14311 | posX = plotRange.tl.x;
|
14312 | crosshairsShapeX && crosshairsShapeX.attr('x1', plotRange.tl.x + yTipWidth);
|
14313 | }
|
14314 |
|
14315 | yTipBox.updatePosition(posX, posY);
|
14316 | }
|
14317 | };
|
14318 |
|
14319 | _proto.setXTipContent = function setXTipContent(val) {
|
14320 | var xTip = this.xTip;
|
14321 |
|
14322 | if (Util.isFunction(xTip)) {
|
14323 | val = xTip(val);
|
14324 | } else {
|
14325 | val = Util.mix({
|
14326 | text: val
|
14327 | }, xTip);
|
14328 | }
|
14329 |
|
14330 | this.xTipBox && this.xTipBox.updateContent(val);
|
14331 | };
|
14332 |
|
14333 | _proto.setXTipPosition = function setXTipPosition(pos) {
|
14334 | var showXTip = this.showXTip,
|
14335 | canvas = this.canvas,
|
14336 | plotRange = this.plotRange,
|
14337 | xTipBox = this.xTipBox,
|
14338 | crosshairsShapeY = this.crosshairsShapeY;
|
14339 |
|
14340 | if (showXTip) {
|
14341 | var el = canvas.get('el');
|
14342 | var canvasHeight = Util.getHeight(el);
|
14343 | var xTipWidth = xTipBox.getWidth();
|
14344 | var xTipHeight = xTipBox.getHeight();
|
14345 | var posX = pos - xTipWidth / 2;
|
14346 | var posY = plotRange.br.y;
|
14347 |
|
14348 | if (posX <= plotRange.tl.x) {
|
14349 | posX = plotRange.tl.x;
|
14350 | }
|
14351 |
|
14352 | if (posX + xTipWidth >= plotRange.tr.x) {
|
14353 | posX = plotRange.tr.x - xTipWidth;
|
14354 | }
|
14355 |
|
14356 | if (canvasHeight - posY < xTipHeight) {
|
14357 | posY -= xTipHeight;
|
14358 | }
|
14359 |
|
14360 | xTipBox.updatePosition(posX, posY);
|
14361 | crosshairsShapeY && crosshairsShapeY.attr('y1', posY);
|
14362 | }
|
14363 | };
|
14364 |
|
14365 | _proto.setXCrosshairPosition = function setXCrosshairPosition(pos) {
|
14366 | this.crosshairsShapeX && this.crosshairsShapeX.moveTo(0, pos);
|
14367 | };
|
14368 |
|
14369 | _proto.setYCrosshairPosition = function setYCrosshairPosition(pos) {
|
14370 | this.crosshairsShapeY && this.crosshairsShapeY.moveTo(pos, 0);
|
14371 | };
|
14372 |
|
14373 | _proto.setPosition = function setPosition(items) {
|
14374 | var container = this.container,
|
14375 | plotRange = this.plotRange,
|
14376 | offsetX = this.offsetX,
|
14377 | offsetY = this.offsetY,
|
14378 | fixed = this.fixed,
|
14379 | tooltipArrow = this.tooltipArrow;
|
14380 |
|
14381 | if (!container) {
|
14382 | return;
|
14383 | }
|
14384 |
|
14385 | var containerBBox = container.container.getBBox();
|
14386 | var minX = containerBBox.minX,
|
14387 | minY = containerBBox.minY,
|
14388 | width = containerBBox.width,
|
14389 | height = containerBBox.height;
|
14390 | var tl = plotRange.tl,
|
14391 | tr = plotRange.tr;
|
14392 | var posX = 0;
|
14393 | var posY = tl.y - height - GAP + offsetY;
|
14394 |
|
14395 | if (fixed) {
|
14396 | var x = (tl.x + tr.x) / 2;
|
14397 | posX = x - width / 2 + offsetX;
|
14398 | } else {
|
14399 | var _x;
|
14400 |
|
14401 | if (items.length > 1) {
|
14402 | _x = (items[0].x + items[items.length - 1].x) / 2;
|
14403 | } else {
|
14404 | _x = items[0].x;
|
14405 | }
|
14406 |
|
14407 | posX = _x - width / 2 + offsetX;
|
14408 |
|
14409 | if (posX < tl.x) {
|
14410 | posX = tl.x;
|
14411 | }
|
14412 |
|
14413 | if (posX + width > tr.x) {
|
14414 | posX = tr.x - width;
|
14415 | }
|
14416 |
|
14417 | if (tooltipArrow) {
|
14418 | tooltipArrow.attr('points', [{
|
14419 | x: _x - 3,
|
14420 | y: tl.y - GAP + offsetY
|
14421 | }, {
|
14422 | x: _x + 3,
|
14423 | y: tl.y - GAP + offsetY
|
14424 | }, {
|
14425 | x: _x,
|
14426 | y: tl.y + offsetY
|
14427 | }]);
|
14428 | var backShape = container.backShape;
|
14429 | var radius = Util.parsePadding(backShape.attr('radius'));
|
14430 |
|
14431 | if (_x === tl.x) {
|
14432 | radius[3] = 0;
|
14433 | tooltipArrow.attr('points', [{
|
14434 | x: tl.x,
|
14435 | y: tl.y + offsetY
|
14436 | }, {
|
14437 | x: tl.x,
|
14438 | y: tl.y - GAP + offsetY
|
14439 | }, {
|
14440 | x: tl.x + GAP,
|
14441 | y: tl.y - GAP + offsetY
|
14442 | }]);
|
14443 | } else if (_x === tr.x) {
|
14444 | radius[2] = 0;
|
14445 | tooltipArrow.attr('points', [{
|
14446 | x: tr.x,
|
14447 | y: tl.y + offsetY
|
14448 | }, {
|
14449 | x: tr.x - GAP,
|
14450 | y: tl.y - GAP + offsetY
|
14451 | }, {
|
14452 | x: tr.x,
|
14453 | y: tl.y - GAP + offsetY
|
14454 | }]);
|
14455 | }
|
14456 |
|
14457 | backShape.attr('radius', radius);
|
14458 | }
|
14459 | }
|
14460 |
|
14461 | container.moveTo(posX - minX, posY - minY);
|
14462 | };
|
14463 |
|
14464 | _proto.setMarkers = function setMarkers(cfg) {
|
14465 | if (cfg === void 0) {
|
14466 | cfg = {};
|
14467 | }
|
14468 |
|
14469 | var self = this;
|
14470 | var _cfg = cfg,
|
14471 | items = _cfg.items,
|
14472 | style = _cfg.style,
|
14473 | type = _cfg.type;
|
14474 |
|
14475 | var markerGroup = self._getMarkerGroup(type);
|
14476 |
|
14477 | if (type === 'circle') {
|
14478 | for (var i = 0, length = items.length; i < length; i++) {
|
14479 | var item = items[i];
|
14480 | var marker = new Marker({
|
14481 | className: 'tooltip-circle-marker',
|
14482 | attrs: Util.mix({
|
14483 | x: item.x,
|
14484 | y: item.y,
|
14485 | stroke: item.color
|
14486 | }, style)
|
14487 | });
|
14488 | markerGroup.add(marker);
|
14489 | }
|
14490 | } else {
|
14491 | markerGroup.addShape('rect', {
|
14492 | className: 'tooltip-rect-marker',
|
14493 | attrs: style
|
14494 | });
|
14495 | }
|
14496 | };
|
14497 |
|
14498 | _proto.clearMarkers = function clearMarkers() {
|
14499 | var markerGroup = this.markerGroup;
|
14500 | markerGroup && markerGroup.clear();
|
14501 | };
|
14502 |
|
14503 | _proto.show = function show() {
|
14504 | var crosshairsShapeX = this.crosshairsShapeX;
|
14505 | var crosshairsShapeY = this.crosshairsShapeY;
|
14506 | var markerGroup = this.markerGroup;
|
14507 | var container = this.container;
|
14508 | var tooltipArrow = this.tooltipArrow;
|
14509 | var xTipBox = this.xTipBox;
|
14510 | var yTipBox = this.yTipBox;
|
14511 | var canvas = this.canvas;
|
14512 | crosshairsShapeX && crosshairsShapeX.show();
|
14513 | crosshairsShapeY && crosshairsShapeY.show();
|
14514 | markerGroup && markerGroup.show();
|
14515 | container && container.show();
|
14516 | tooltipArrow && tooltipArrow.show();
|
14517 | xTipBox && xTipBox.show();
|
14518 | yTipBox && yTipBox.show();
|
14519 | canvas.draw();
|
14520 | };
|
14521 |
|
14522 | _proto.hide = function hide() {
|
14523 | var crosshairsShapeX = this.crosshairsShapeX;
|
14524 | var crosshairsShapeY = this.crosshairsShapeY;
|
14525 | var markerGroup = this.markerGroup;
|
14526 | var container = this.container;
|
14527 | var tooltipArrow = this.tooltipArrow;
|
14528 | var xTipBox = this.xTipBox;
|
14529 | var yTipBox = this.yTipBox;
|
14530 | crosshairsShapeX && crosshairsShapeX.hide();
|
14531 | crosshairsShapeY && crosshairsShapeY.hide();
|
14532 | markerGroup && markerGroup.hide();
|
14533 | container && container.hide();
|
14534 | tooltipArrow && tooltipArrow.hide();
|
14535 | xTipBox && xTipBox.hide();
|
14536 | yTipBox && yTipBox.hide();
|
14537 | };
|
14538 |
|
14539 | _proto.destroy = function destroy() {
|
14540 | var crosshairsShapeX = this.crosshairsShapeX;
|
14541 | var crosshairsShapeY = this.crosshairsShapeY;
|
14542 | var markerGroup = this.markerGroup;
|
14543 | var container = this.container;
|
14544 | var tooltipArrow = this.tooltipArrow;
|
14545 | var xTipBox = this.xTipBox;
|
14546 | var yTipBox = this.yTipBox;
|
14547 | crosshairsShapeX && crosshairsShapeX.remove(true);
|
14548 | crosshairsShapeY && crosshairsShapeY.remove(true);
|
14549 | markerGroup && markerGroup.remove(true);
|
14550 | tooltipArrow && tooltipArrow.remove(true);
|
14551 | container && container.clear();
|
14552 | xTipBox && xTipBox.clear();
|
14553 | yTipBox && yTipBox.clear();
|
14554 | this.destroyed = true;
|
14555 | };
|
14556 |
|
14557 | _proto._getMarkerGroup = function _getMarkerGroup(type) {
|
14558 | var markerGroup = this.markerGroup;
|
14559 |
|
14560 | if (!markerGroup) {
|
14561 | if (type === 'circle') {
|
14562 | markerGroup = this.frontPlot.addGroup({
|
14563 | zIndex: 1
|
14564 | });
|
14565 | this.frontPlot.sort();
|
14566 | } else {
|
14567 | markerGroup = this.backPlot.addGroup();
|
14568 | }
|
14569 |
|
14570 | this.markerGroup = markerGroup;
|
14571 | } else {
|
14572 | markerGroup.clear();
|
14573 | }
|
14574 |
|
14575 | return markerGroup;
|
14576 | };
|
14577 |
|
14578 | _proto._renderCrosshairs = function _renderCrosshairs() {
|
14579 | var crosshairsType = this.crosshairsType,
|
14580 | crosshairsStyle = this.crosshairsStyle,
|
14581 | frontPlot = this.frontPlot,
|
14582 | plotRange = this.plotRange;
|
14583 | var tl = plotRange.tl,
|
14584 | br = plotRange.br;
|
14585 |
|
14586 | if (Util.directionEnabled(crosshairsType, 'x')) {
|
14587 | this.crosshairsShapeX = frontPlot.addShape('Line', {
|
14588 | className: 'tooltip-crosshairs-x',
|
14589 | zIndex: 0,
|
14590 | visible: false,
|
14591 | attrs: Util.mix({
|
14592 | x1: tl.x,
|
14593 | y1: 0,
|
14594 | x2: br.x,
|
14595 | y2: 0
|
14596 | }, crosshairsStyle)
|
14597 | });
|
14598 | }
|
14599 |
|
14600 | if (Util.directionEnabled(crosshairsType, 'y')) {
|
14601 | this.crosshairsShapeY = frontPlot.addShape('Line', {
|
14602 | className: 'tooltip-crosshairs-y',
|
14603 | zIndex: 0,
|
14604 | visible: false,
|
14605 | attrs: Util.mix({
|
14606 | x1: 0,
|
14607 | y1: br.y,
|
14608 | x2: 0,
|
14609 | y2: tl.y
|
14610 | }, crosshairsStyle)
|
14611 | });
|
14612 | }
|
14613 | };
|
14614 |
|
14615 | return Tooltip;
|
14616 | }();
|
14617 |
|
14618 | module.exports = Tooltip;
|
14619 |
|
14620 | }),
|
14621 |
|
14622 | (function(module, exports, __webpack_require__) {
|
14623 |
|
14624 | var Util = __webpack_require__(0);
|
14625 |
|
14626 | var _require = __webpack_require__(3),
|
14627 | Group = _require.Group;
|
14628 |
|
14629 | var TextBox =
|
14630 |
|
14631 | function () {
|
14632 | var _proto = TextBox.prototype;
|
14633 |
|
14634 | _proto.getDefaultCfg = function getDefaultCfg() {
|
14635 | return {
|
14636 | x: 0,
|
14637 | y: 0,
|
14638 | content: '',
|
14639 | textStyle: {
|
14640 | fontSize: 12,
|
14641 | fill: '#fff',
|
14642 | textAlign: 'center',
|
14643 | textBaseline: 'middle'
|
14644 | },
|
14645 | background: {
|
14646 | radius: 1,
|
14647 | fill: 'rgba(0, 0, 0, 0.65)',
|
14648 | padding: [3, 5]
|
14649 | },
|
14650 | width: 0,
|
14651 | height: 0,
|
14652 | className: ''
|
14653 | };
|
14654 | };
|
14655 |
|
14656 | function TextBox(cfg) {
|
14657 | Util.deepMix(this, this.getDefaultCfg(), cfg);
|
14658 |
|
14659 | this._init();
|
14660 |
|
14661 | var content = this.content,
|
14662 | x = this.x,
|
14663 | y = this.y;
|
14664 |
|
14665 | if (!Util.isNil(content)) {
|
14666 | this.updateContent(content);
|
14667 | }
|
14668 |
|
14669 | this.updatePosition(x, y);
|
14670 | }
|
14671 |
|
14672 | _proto._init = function _init() {
|
14673 | var content = this.content,
|
14674 | textStyle = this.textStyle,
|
14675 | background = this.background,
|
14676 | className = this.className,
|
14677 | visible = this.visible;
|
14678 | var container = new Group({
|
14679 | className: className,
|
14680 | zIndex: 0,
|
14681 | visible: visible
|
14682 | });
|
14683 | var text = container.addShape('Text', {
|
14684 | className: className + '-text',
|
14685 | zIndex: 1,
|
14686 | attrs: Util.mix({
|
14687 | text: content,
|
14688 | x: 0,
|
14689 | y: 0
|
14690 | }, textStyle)
|
14691 | });
|
14692 | var backgroundShape = container.addShape('Rect', {
|
14693 | className: className + '-bg',
|
14694 | zIndex: -1,
|
14695 | attrs: Util.mix({
|
14696 | x: 0,
|
14697 | y: 0,
|
14698 | width: 0,
|
14699 | height: 0
|
14700 | }, background)
|
14701 | });
|
14702 | container.sort();
|
14703 | this.container = container;
|
14704 | this.textShape = text;
|
14705 | this.backgroundShape = backgroundShape;
|
14706 | };
|
14707 |
|
14708 | _proto._getBBox = function _getBBox() {
|
14709 | var textShape = this.textShape;
|
14710 | var background = this.background;
|
14711 | var textBBox = textShape.getBBox();
|
14712 | var padding = Util.parsePadding(background.padding);
|
14713 | var width = textBBox.width + padding[1] + padding[3];
|
14714 | var height = textBBox.height + padding[0] + padding[2];
|
14715 | var x = textBBox.minX - padding[3];
|
14716 | var y = textBBox.minY - padding[0];
|
14717 | return {
|
14718 | x: x,
|
14719 | y: y,
|
14720 | width: width,
|
14721 | height: height
|
14722 | };
|
14723 | };
|
14724 |
|
14725 | _proto.updateContent = function updateContent(text) {
|
14726 | var textShape = this.textShape,
|
14727 | backgroundShape = this.backgroundShape;
|
14728 |
|
14729 | if (!Util.isNil(text)) {
|
14730 | if (!Util.isObject(text)) {
|
14731 | text = {
|
14732 | text: text
|
14733 | };
|
14734 | }
|
14735 |
|
14736 | textShape.attr(text);
|
14737 |
|
14738 | var _this$_getBBox = this._getBBox(),
|
14739 | x = _this$_getBBox.x,
|
14740 | y = _this$_getBBox.y,
|
14741 | tipWidth = _this$_getBBox.width,
|
14742 | tipHeight = _this$_getBBox.height;
|
14743 |
|
14744 | var width = this.width || tipWidth;
|
14745 | var height = this.height || tipHeight;
|
14746 | backgroundShape.attr({
|
14747 | x: x,
|
14748 | y: y,
|
14749 | width: width,
|
14750 | height: height
|
14751 | });
|
14752 | this._width = width;
|
14753 | this._height = height;
|
14754 | this.content = text.text;
|
14755 | }
|
14756 | };
|
14757 |
|
14758 | _proto.updatePosition = function updatePosition(x, y) {
|
14759 | var container = this.container;
|
14760 |
|
14761 | var _this$_getBBox2 = this._getBBox(),
|
14762 | xMin = _this$_getBBox2.x,
|
14763 | yMin = _this$_getBBox2.y;
|
14764 |
|
14765 | container.moveTo(x - xMin, y - yMin);
|
14766 | this.x = x - xMin;
|
14767 | this.y = y - yMin;
|
14768 | };
|
14769 |
|
14770 | _proto.getWidth = function getWidth() {
|
14771 | return this._width;
|
14772 | };
|
14773 |
|
14774 | _proto.getHeight = function getHeight() {
|
14775 | return this._height;
|
14776 | };
|
14777 |
|
14778 | _proto.show = function show() {
|
14779 | this.container.show();
|
14780 | };
|
14781 |
|
14782 | _proto.hide = function hide() {
|
14783 | this.container.hide();
|
14784 | };
|
14785 |
|
14786 | _proto.clear = function clear() {
|
14787 | var container = this.container;
|
14788 | container.clear();
|
14789 | container.remove(true);
|
14790 | this.container = null;
|
14791 | this.textShape = null;
|
14792 | this.backgroundShape = null;
|
14793 | };
|
14794 |
|
14795 | return TextBox;
|
14796 | }();
|
14797 |
|
14798 | module.exports = TextBox;
|
14799 |
|
14800 | }),
|
14801 |
|
14802 | (function(module, exports, __webpack_require__) {
|
14803 |
|
14804 | var Util = __webpack_require__(0);
|
14805 |
|
14806 | var Guide = __webpack_require__(8);
|
14807 |
|
14808 | var Global = __webpack_require__(1);
|
14809 |
|
14810 |
|
14811 | Global.guide = Util.deepMix({
|
14812 | line: {
|
14813 | style: {
|
14814 | stroke: '#a3a3a3',
|
14815 | lineWidth: 1
|
14816 | },
|
14817 | top: true
|
14818 | },
|
14819 | text: {
|
14820 | style: {
|
14821 | fill: '#787878',
|
14822 | textAlign: 'center',
|
14823 | textBaseline: 'middle'
|
14824 | },
|
14825 | offsetX: 0,
|
14826 | offsetY: 0,
|
14827 | top: true
|
14828 | },
|
14829 | rect: {
|
14830 | style: {
|
14831 | fill: '#fafafa'
|
14832 | },
|
14833 | top: false
|
14834 | },
|
14835 | arc: {
|
14836 | style: {
|
14837 | stroke: '#a3a3a3'
|
14838 | },
|
14839 | top: true
|
14840 | },
|
14841 | html: {
|
14842 | offsetX: 0,
|
14843 | offsetY: 0,
|
14844 | alignX: 'center',
|
14845 | alignY: 'middle'
|
14846 | },
|
14847 | tag: {
|
14848 | top: true,
|
14849 | offsetX: 0,
|
14850 | offsetY: 0,
|
14851 | side: 4,
|
14852 | background: {
|
14853 | padding: 5,
|
14854 | radius: 2,
|
14855 | fill: '#1890FF'
|
14856 | },
|
14857 | textStyle: {
|
14858 | fontSize: 12,
|
14859 | fill: '#fff',
|
14860 | textAlign: 'center',
|
14861 | textBaseline: 'middle'
|
14862 | }
|
14863 | },
|
14864 | point: {
|
14865 | top: true,
|
14866 | offsetX: 0,
|
14867 | offsetY: 0,
|
14868 | style: {
|
14869 | fill: '#fff',
|
14870 | r: 3,
|
14871 | lineWidth: 2,
|
14872 | stroke: '#1890ff'
|
14873 | }
|
14874 | }
|
14875 | }, Global.guide || {});
|
14876 |
|
14877 | var GuideController =
|
14878 |
|
14879 | function () {
|
14880 | function GuideController(cfg) {
|
14881 | this.guides = [];
|
14882 | this.xScale = null;
|
14883 | this.yScales = null;
|
14884 | this.guideShapes = [];
|
14885 | Util.mix(this, cfg);
|
14886 | }
|
14887 |
|
14888 | var _proto = GuideController.prototype;
|
14889 |
|
14890 | _proto._toString = function _toString(position) {
|
14891 | if (Util.isFunction(position)) {
|
14892 | position = position(this.xScale, this.yScales);
|
14893 | }
|
14894 |
|
14895 | position = position.toString();
|
14896 | return position;
|
14897 | };
|
14898 |
|
14899 | _proto._getId = function _getId(shape, guide) {
|
14900 | var id = guide.id;
|
14901 |
|
14902 | if (!id) {
|
14903 | var type = guide.type;
|
14904 |
|
14905 | if (type === 'arc' || type === 'line' || type === 'rect') {
|
14906 | id = this._toString(guide.start) + '-' + this._toString(guide.end);
|
14907 | } else {
|
14908 | id = this._toString(guide.position);
|
14909 | }
|
14910 | }
|
14911 |
|
14912 | return id;
|
14913 | };
|
14914 |
|
14915 | _proto.paint = function paint(coord) {
|
14916 | var self = this;
|
14917 | var chart = self.chart,
|
14918 | guides = self.guides,
|
14919 | xScale = self.xScale,
|
14920 | yScales = self.yScales;
|
14921 | var guideShapes = [];
|
14922 | Util.each(guides, function (guide, idx) {
|
14923 | guide.xScale = xScale;
|
14924 | guide.yScales = yScales;
|
14925 | var container;
|
14926 |
|
14927 | if (guide.type === 'regionFilter') {
|
14928 |
|
14929 | guide.chart = chart;
|
14930 | } else {
|
14931 | container = guide.top ? self.frontPlot : self.backPlot;
|
14932 | }
|
14933 |
|
14934 | guide.coord = coord;
|
14935 | guide.container = container;
|
14936 | guide.canvas = chart.get('canvas');
|
14937 | var shape = guide.render(coord, container);
|
14938 |
|
14939 | if (shape) {
|
14940 | var id = self._getId(shape, guide);
|
14941 |
|
14942 | [].concat(shape).forEach(function (s) {
|
14943 | s._id = s.get('className') + '-' + id;
|
14944 | s.set('index', idx);
|
14945 | guideShapes.push(s);
|
14946 | });
|
14947 | }
|
14948 | });
|
14949 | self.guideShapes = guideShapes;
|
14950 | };
|
14951 |
|
14952 | _proto.clear = function clear() {
|
14953 | this.reset();
|
14954 | this.guides = [];
|
14955 | return this;
|
14956 | };
|
14957 |
|
14958 | _proto.reset = function reset() {
|
14959 | var guides = this.guides;
|
14960 | Util.each(guides, function (guide) {
|
14961 | guide.remove();
|
14962 | });
|
14963 | };
|
14964 |
|
14965 | _proto._createGuide = function _createGuide(type, cfg) {
|
14966 | var ClassName = Util.upperFirst(type);
|
14967 | var guide = new Guide[ClassName](Util.deepMix({}, Global.guide[type], cfg));
|
14968 | this.guides.push(guide);
|
14969 | return guide;
|
14970 | };
|
14971 |
|
14972 | _proto.line = function line(cfg) {
|
14973 | if (cfg === void 0) {
|
14974 | cfg = {};
|
14975 | }
|
14976 |
|
14977 | return this._createGuide('line', cfg);
|
14978 | };
|
14979 |
|
14980 | _proto.text = function text(cfg) {
|
14981 | if (cfg === void 0) {
|
14982 | cfg = {};
|
14983 | }
|
14984 |
|
14985 | return this._createGuide('text', cfg);
|
14986 | };
|
14987 |
|
14988 | _proto.arc = function arc(cfg) {
|
14989 | if (cfg === void 0) {
|
14990 | cfg = {};
|
14991 | }
|
14992 |
|
14993 | return this._createGuide('arc', cfg);
|
14994 | };
|
14995 |
|
14996 | _proto.html = function html(cfg) {
|
14997 | if (cfg === void 0) {
|
14998 | cfg = {};
|
14999 | }
|
15000 |
|
15001 | return this._createGuide('html', cfg);
|
15002 | };
|
15003 |
|
15004 | _proto.rect = function rect(cfg) {
|
15005 | if (cfg === void 0) {
|
15006 | cfg = {};
|
15007 | }
|
15008 |
|
15009 | return this._createGuide('rect', cfg);
|
15010 | };
|
15011 |
|
15012 | _proto.tag = function tag(cfg) {
|
15013 | if (cfg === void 0) {
|
15014 | cfg = {};
|
15015 | }
|
15016 |
|
15017 | return this._createGuide('tag', cfg);
|
15018 | };
|
15019 |
|
15020 | _proto.point = function point(cfg) {
|
15021 | if (cfg === void 0) {
|
15022 | cfg = {};
|
15023 | }
|
15024 |
|
15025 | return this._createGuide('point', cfg);
|
15026 | };
|
15027 |
|
15028 | _proto.regionFilter = function regionFilter(cfg) {
|
15029 | if (cfg === void 0) {
|
15030 | cfg = {};
|
15031 | }
|
15032 |
|
15033 | return this._createGuide('regionFilter', cfg);
|
15034 | };
|
15035 |
|
15036 | return GuideController;
|
15037 | }();
|
15038 |
|
15039 | module.exports = {
|
15040 | init: function init(chart) {
|
15041 | var guideController = new GuideController({
|
15042 | frontPlot: chart.get('frontPlot').addGroup({
|
15043 | zIndex: 20,
|
15044 | className: 'guideContainer'
|
15045 | }),
|
15046 | backPlot: chart.get('backPlot').addGroup({
|
15047 | className: 'guideContainer'
|
15048 | })
|
15049 | });
|
15050 | chart.set('guideController', guideController);
|
15051 | |
15052 |
|
15053 |
|
15054 |
|
15055 |
|
15056 | chart.guide = function () {
|
15057 | return guideController;
|
15058 | };
|
15059 | },
|
15060 | afterGeomDraw: function afterGeomDraw(chart) {
|
15061 | var guideController = chart.get('guideController');
|
15062 |
|
15063 | if (!guideController.guides.length) {
|
15064 | return;
|
15065 | }
|
15066 |
|
15067 | var xScale = chart.getXScale();
|
15068 | var yScales = chart.getYScales();
|
15069 | var coord = chart.get('coord');
|
15070 | guideController.xScale = xScale;
|
15071 | guideController.yScales = yScales;
|
15072 | guideController.chart = chart;
|
15073 |
|
15074 | guideController.paint(coord);
|
15075 | },
|
15076 | clear: function clear(chart) {
|
15077 | chart.get('guideController').clear();
|
15078 | },
|
15079 | repaint: function repaint(chart) {
|
15080 | chart.get('guideController').reset();
|
15081 | }
|
15082 | };
|
15083 |
|
15084 | }),
|
15085 |
|
15086 | (function(module, exports, __webpack_require__) {
|
15087 |
|
15088 | var Util = __webpack_require__(0);
|
15089 |
|
15090 | var List = __webpack_require__(44);
|
15091 |
|
15092 | var Global = __webpack_require__(1);
|
15093 |
|
15094 | var LEGEND_GAP = 12;
|
15095 | var MARKER_SIZE = 3;
|
15096 | var DEFAULT_CFG = {
|
15097 | itemMarginBottom: 12,
|
15098 | itemGap: 10,
|
15099 | showTitle: false,
|
15100 | titleStyle: {
|
15101 | fontSize: 12,
|
15102 | fill: '#808080',
|
15103 | textAlign: 'start',
|
15104 | textBaseline: 'top'
|
15105 | },
|
15106 | nameStyle: {
|
15107 | fill: '#808080',
|
15108 | fontSize: 12,
|
15109 | textAlign: 'start',
|
15110 | textBaseline: 'middle'
|
15111 | },
|
15112 | valueStyle: {
|
15113 | fill: '#000000',
|
15114 | fontSize: 12,
|
15115 | textAlign: 'start',
|
15116 | textBaseline: 'middle'
|
15117 | },
|
15118 | unCheckStyle: {
|
15119 | fill: '#bfbfbf'
|
15120 | },
|
15121 | itemWidth: 'auto',
|
15122 | wordSpace: 6,
|
15123 | selectedMode: 'multiple'
|
15124 |
|
15125 | };
|
15126 |
|
15127 | Global.legend = Util.deepMix({
|
15128 | common: DEFAULT_CFG,
|
15129 |
|
15130 | right: Util.mix({
|
15131 | position: 'right',
|
15132 | layout: 'vertical'
|
15133 | }, DEFAULT_CFG),
|
15134 | left: Util.mix({
|
15135 | position: 'left',
|
15136 | layout: 'vertical'
|
15137 | }, DEFAULT_CFG),
|
15138 | top: Util.mix({
|
15139 | position: 'top',
|
15140 | layout: 'horizontal'
|
15141 | }, DEFAULT_CFG),
|
15142 | bottom: Util.mix({
|
15143 | position: 'bottom',
|
15144 | layout: 'horizontal'
|
15145 | }, DEFAULT_CFG)
|
15146 | }, Global.legend || {});
|
15147 |
|
15148 | function getPaddingByPos(pos, appendPadding) {
|
15149 | var padding = 0;
|
15150 | appendPadding = Util.parsePadding(appendPadding);
|
15151 |
|
15152 | switch (pos) {
|
15153 | case 'top':
|
15154 | padding = appendPadding[0];
|
15155 | break;
|
15156 |
|
15157 | case 'right':
|
15158 | padding = appendPadding[1];
|
15159 | break;
|
15160 |
|
15161 | case 'bottom':
|
15162 | padding = appendPadding[2];
|
15163 | break;
|
15164 |
|
15165 | case 'left':
|
15166 | padding = appendPadding[3];
|
15167 | break;
|
15168 |
|
15169 | default:
|
15170 | break;
|
15171 | }
|
15172 |
|
15173 | return padding;
|
15174 | }
|
15175 |
|
15176 | var LegendController =
|
15177 |
|
15178 | function () {
|
15179 | function LegendController(cfg) {
|
15180 | this.legendCfg = {};
|
15181 | this.enable = true;
|
15182 | this.position = 'top';
|
15183 | Util.mix(this, cfg);
|
15184 | var chart = this.chart;
|
15185 | this.canvasDom = chart.get('canvas').get('el');
|
15186 | this.clear();
|
15187 | }
|
15188 |
|
15189 | var _proto = LegendController.prototype;
|
15190 |
|
15191 | _proto.addLegend = function addLegend(scale, items, filterVals) {
|
15192 | var self = this;
|
15193 | var legendCfg = self.legendCfg;
|
15194 | var field = scale.field;
|
15195 | var fieldCfg = legendCfg[field];
|
15196 |
|
15197 | if (fieldCfg === false) {
|
15198 | return null;
|
15199 | }
|
15200 |
|
15201 | if (fieldCfg && fieldCfg.custom) {
|
15202 | self.addCustomLegend(field);
|
15203 | } else {
|
15204 | var position = legendCfg.position || self.position;
|
15205 |
|
15206 | if (fieldCfg && fieldCfg.position) {
|
15207 | position = fieldCfg.position;
|
15208 | }
|
15209 |
|
15210 | if (scale.isCategory) {
|
15211 | self._addCategoryLegend(scale, items, position, filterVals);
|
15212 | }
|
15213 | }
|
15214 | };
|
15215 |
|
15216 | _proto.addCustomLegend = function addCustomLegend(field) {
|
15217 | var self = this;
|
15218 | var legendCfg = self.legendCfg;
|
15219 |
|
15220 | if (field && legendCfg[field]) {
|
15221 | legendCfg = legendCfg[field];
|
15222 | }
|
15223 |
|
15224 | var position = legendCfg.position || self.position;
|
15225 | var legends = self.legends;
|
15226 | legends[position] = legends[position] || [];
|
15227 | var items = legendCfg.items;
|
15228 |
|
15229 | if (!items) {
|
15230 | return null;
|
15231 | }
|
15232 |
|
15233 | var container = self.container;
|
15234 | Util.each(items, function (item) {
|
15235 | if (!Util.isPlainObject(item.marker)) {
|
15236 | item.marker = {
|
15237 | symbol: item.marker || 'circle',
|
15238 | fill: item.fill,
|
15239 | radius: MARKER_SIZE
|
15240 | };
|
15241 | } else {
|
15242 | item.marker.radius = item.marker.radius || MARKER_SIZE;
|
15243 | }
|
15244 |
|
15245 | item.checked = Util.isNil(item.checked) ? true : item.checked;
|
15246 | item.name = item.name || item.value;
|
15247 | });
|
15248 | var legend = new List(Util.deepMix({}, Global.legend[position], legendCfg, {
|
15249 | maxLength: self._getMaxLength(position),
|
15250 | items: items,
|
15251 | parent: container
|
15252 | }));
|
15253 | legends[position].push(legend);
|
15254 | };
|
15255 |
|
15256 | _proto.clear = function clear() {
|
15257 | var legends = this.legends;
|
15258 | Util.each(legends, function (legendItems) {
|
15259 | Util.each(legendItems, function (legend) {
|
15260 | legend.clear();
|
15261 | });
|
15262 | });
|
15263 | this.legends = {};
|
15264 | this.unBindEvents();
|
15265 | };
|
15266 |
|
15267 | _proto._isFiltered = function _isFiltered(scale, values, value) {
|
15268 | var rst = false;
|
15269 | Util.each(values, function (val) {
|
15270 | rst = rst || scale.getText(val) === scale.getText(value);
|
15271 |
|
15272 | if (rst) {
|
15273 | return false;
|
15274 | }
|
15275 | });
|
15276 | return rst;
|
15277 | };
|
15278 |
|
15279 | _proto._getMaxLength = function _getMaxLength(position) {
|
15280 | var chart = this.chart;
|
15281 | var appendPadding = Util.parsePadding(chart.get('appendPadding'));
|
15282 | return position === 'right' || position === 'left' ? chart.get('height') - (appendPadding[0] + appendPadding[2]) : chart.get('width') - (appendPadding[1] + appendPadding[3]);
|
15283 | };
|
15284 |
|
15285 | _proto._addCategoryLegend = function _addCategoryLegend(scale, items, position, filterVals) {
|
15286 | var self = this;
|
15287 | var legendCfg = self.legendCfg,
|
15288 | legends = self.legends,
|
15289 | container = self.container,
|
15290 | chart = self.chart;
|
15291 | var field = scale.field;
|
15292 | legends[position] = legends[position] || [];
|
15293 | var symbol = 'circle';
|
15294 |
|
15295 | if (legendCfg[field] && legendCfg[field].marker) {
|
15296 | symbol = legendCfg[field].marker;
|
15297 | } else if (legendCfg.marker) {
|
15298 | symbol = legendCfg.marker;
|
15299 | }
|
15300 |
|
15301 | Util.each(items, function (item) {
|
15302 | if (Util.isPlainObject(symbol)) {
|
15303 | Util.mix(item.marker, symbol);
|
15304 | } else {
|
15305 | item.marker.symbol = symbol;
|
15306 | }
|
15307 |
|
15308 | if (filterVals) {
|
15309 | item.checked = self._isFiltered(scale, filterVals, item.dataValue);
|
15310 | }
|
15311 | });
|
15312 | var legendItems = chart.get('legendItems');
|
15313 | legendItems[field] = items;
|
15314 | var lastCfg = Util.deepMix({}, Global.legend[position], legendCfg[field] || legendCfg, {
|
15315 | maxLength: self._getMaxLength(position),
|
15316 | items: items,
|
15317 | field: field,
|
15318 | filterVals: filterVals,
|
15319 | parent: container
|
15320 | });
|
15321 |
|
15322 | if (lastCfg.showTitle) {
|
15323 | Util.deepMix(lastCfg, {
|
15324 | title: scale.alias || scale.field
|
15325 | });
|
15326 | }
|
15327 |
|
15328 | var legend = new List(lastCfg);
|
15329 | legends[position].push(legend);
|
15330 | return legend;
|
15331 | };
|
15332 |
|
15333 | _proto._alignLegend = function _alignLegend(legend, pre, position) {
|
15334 | var self = this;
|
15335 | var _self$plotRange = self.plotRange,
|
15336 | tl = _self$plotRange.tl,
|
15337 | bl = _self$plotRange.bl;
|
15338 | var chart = self.chart;
|
15339 | var offsetX = legend.offsetX || 0;
|
15340 | var offsetY = legend.offsetY || 0;
|
15341 | var chartWidth = chart.get('width');
|
15342 | var chartHeight = chart.get('height');
|
15343 | var appendPadding = Util.parsePadding(chart.get('appendPadding'));
|
15344 | var legendHeight = legend.getHeight();
|
15345 | var legendWidth = legend.getWidth();
|
15346 | var x = 0;
|
15347 | var y = 0;
|
15348 |
|
15349 | if (position === 'left' || position === 'right') {
|
15350 | var verticalAlign = legend.verticalAlign || 'middle';
|
15351 | var height = Math.abs(tl.y - bl.y);
|
15352 | x = position === 'left' ? appendPadding[3] : chartWidth - legendWidth - appendPadding[1];
|
15353 | y = (height - legendHeight) / 2 + tl.y;
|
15354 |
|
15355 | if (verticalAlign === 'top') {
|
15356 | y = tl.y;
|
15357 | } else if (verticalAlign === 'bottom') {
|
15358 | y = bl.y - legendHeight;
|
15359 | }
|
15360 |
|
15361 | if (pre) {
|
15362 | y = pre.get('y') - legendHeight - LEGEND_GAP;
|
15363 | }
|
15364 | } else {
|
15365 | var align = legend.align || 'left';
|
15366 | x = appendPadding[3];
|
15367 |
|
15368 | if (align === 'center') {
|
15369 | x = chartWidth / 2 - legendWidth / 2;
|
15370 | } else if (align === 'right') {
|
15371 | x = chartWidth - (legendWidth + appendPadding[1]);
|
15372 | }
|
15373 |
|
15374 | y = position === 'top' ? appendPadding[0] + Math.abs(legend.container.getBBox().minY) : chartHeight - legendHeight;
|
15375 |
|
15376 | if (pre) {
|
15377 | var preWidth = pre.getWidth();
|
15378 | x = pre.x + preWidth + LEGEND_GAP;
|
15379 | }
|
15380 | }
|
15381 |
|
15382 | if (position === 'bottom' && offsetY > 0) {
|
15383 | offsetY = 0;
|
15384 | }
|
15385 |
|
15386 | if (position === 'right' && offsetX > 0) {
|
15387 | offsetX = 0;
|
15388 | }
|
15389 |
|
15390 | legend.moveTo(x + offsetX, y + offsetY);
|
15391 | };
|
15392 |
|
15393 | _proto.alignLegends = function alignLegends() {
|
15394 | var self = this;
|
15395 | var legends = self.legends;
|
15396 | Util.each(legends, function (legendItems, position) {
|
15397 | Util.each(legendItems, function (legend, index) {
|
15398 | var pre = legendItems[index - 1];
|
15399 |
|
15400 | self._alignLegend(legend, pre, position);
|
15401 | });
|
15402 | });
|
15403 | return self;
|
15404 | };
|
15405 |
|
15406 | _proto.handleEvent = function handleEvent(ev) {
|
15407 | var self = this;
|
15408 |
|
15409 | function findItem(x, y) {
|
15410 | var result = null;
|
15411 | var legends = self.legends;
|
15412 | Util.each(legends, function (legendItems) {
|
15413 | Util.each(legendItems, function (legend) {
|
15414 | var itemsGroup = legend.itemsGroup,
|
15415 | legendHitBoxes = legend.legendHitBoxes;
|
15416 | var children = itemsGroup.get('children');
|
15417 |
|
15418 | if (children.length) {
|
15419 | var legendPosX = legend.x;
|
15420 | var legendPosY = legend.y;
|
15421 | Util.each(legendHitBoxes, function (box, index) {
|
15422 | if (x >= box.x + legendPosX && x <= box.x + box.width + legendPosX && y >= box.y + legendPosY && y <= box.height + box.y + legendPosY) {
|
15423 |
|
15424 | result = {
|
15425 | clickedItem: children[index],
|
15426 | clickedLegend: legend
|
15427 | };
|
15428 | return false;
|
15429 | }
|
15430 | });
|
15431 | }
|
15432 | });
|
15433 | });
|
15434 | return result;
|
15435 | }
|
15436 |
|
15437 | var chart = self.chart;
|
15438 |
|
15439 | var _Util$createEvent = Util.createEvent(ev, chart),
|
15440 | x = _Util$createEvent.x,
|
15441 | y = _Util$createEvent.y;
|
15442 |
|
15443 | var clicked = findItem(x, y);
|
15444 |
|
15445 | if (clicked && clicked.clickedLegend.clickable !== false) {
|
15446 | var clickedItem = clicked.clickedItem,
|
15447 | clickedLegend = clicked.clickedLegend;
|
15448 |
|
15449 | if (clickedLegend.onClick) {
|
15450 | ev.clickedItem = clickedItem;
|
15451 | clickedLegend.onClick(ev);
|
15452 | } else if (!clickedLegend.custom) {
|
15453 | var checked = clickedItem.get('checked');
|
15454 | var value = clickedItem.get('dataValue');
|
15455 | var filterVals = clickedLegend.filterVals,
|
15456 | field = clickedLegend.field,
|
15457 | selectedMode = clickedLegend.selectedMode;
|
15458 | var isSingeSelected = selectedMode === 'single';
|
15459 |
|
15460 | if (isSingeSelected) {
|
15461 | chart.filter(field, function (val) {
|
15462 | return val === value;
|
15463 | });
|
15464 | } else {
|
15465 | if (!checked) {
|
15466 | filterVals.push(value);
|
15467 | } else {
|
15468 | Util.Array.remove(filterVals, value);
|
15469 | }
|
15470 |
|
15471 | chart.filter(field, function (val) {
|
15472 | return filterVals.indexOf(val) !== -1;
|
15473 | });
|
15474 | }
|
15475 |
|
15476 | chart.repaint();
|
15477 | }
|
15478 | }
|
15479 | };
|
15480 |
|
15481 | _proto.bindEvents = function bindEvents() {
|
15482 | var legendCfg = this.legendCfg;
|
15483 | var triggerOn = legendCfg.triggerOn || 'touchstart';
|
15484 | var method = Util.wrapBehavior(this, 'handleEvent');
|
15485 | Util.addEventListener(this.canvasDom, triggerOn, method);
|
15486 | };
|
15487 |
|
15488 | _proto.unBindEvents = function unBindEvents() {
|
15489 | var legendCfg = this.legendCfg;
|
15490 | var triggerOn = legendCfg.triggerOn || 'touchstart';
|
15491 | var method = Util.getWrapBehavior(this, 'handleEvent');
|
15492 | Util.removeEventListener(this.canvasDom, triggerOn, method);
|
15493 | };
|
15494 |
|
15495 | return LegendController;
|
15496 | }();
|
15497 |
|
15498 | module.exports = {
|
15499 | init: function init(chart) {
|
15500 | var legendController = new LegendController({
|
15501 | container: chart.get('backPlot'),
|
15502 | plotRange: chart.get('plotRange'),
|
15503 | chart: chart
|
15504 | });
|
15505 | chart.set('legendController', legendController);
|
15506 |
|
15507 | chart.legend = function (field, cfg) {
|
15508 | var legendCfg = legendController.legendCfg;
|
15509 | legendController.enable = true;
|
15510 |
|
15511 | if (Util.isBoolean(field)) {
|
15512 | legendController.enable = field;
|
15513 | legendCfg = cfg || {};
|
15514 | } else if (Util.isObject(field)) {
|
15515 | legendCfg = field;
|
15516 | } else {
|
15517 | legendCfg[field] = cfg;
|
15518 | }
|
15519 |
|
15520 | legendController.legendCfg = legendCfg;
|
15521 | return this;
|
15522 | };
|
15523 | },
|
15524 | beforeGeomDraw: function beforeGeomDraw(chart) {
|
15525 | var legendController = chart.get('legendController');
|
15526 | if (!legendController.enable) return null;
|
15527 |
|
15528 | var legendCfg = legendController.legendCfg;
|
15529 |
|
15530 | if (legendCfg && legendCfg.custom) {
|
15531 | legendController.addCustomLegend();
|
15532 | } else {
|
15533 | var legendItems = chart.getLegendItems();
|
15534 | var scales = chart.get('scales');
|
15535 | var filters = chart.get('filters');
|
15536 | Util.each(legendItems, function (items, field) {
|
15537 | var scale = scales[field];
|
15538 | var values = scale.values;
|
15539 | var filterVals;
|
15540 |
|
15541 | if (filters && filters[field]) {
|
15542 | filterVals = values.filter(filters[field]);
|
15543 | } else {
|
15544 | filterVals = values.slice(0);
|
15545 | }
|
15546 |
|
15547 | legendController.addLegend(scale, items, filterVals);
|
15548 | });
|
15549 | }
|
15550 |
|
15551 | if (legendCfg && legendCfg.clickable !== false) {
|
15552 | legendController.bindEvents();
|
15553 | }
|
15554 |
|
15555 | var legends = legendController.legends;
|
15556 | var legendRange = {
|
15557 | top: 0,
|
15558 | right: 0,
|
15559 | bottom: 0,
|
15560 | left: 0
|
15561 | };
|
15562 | Util.each(legends, function (legendItems, position) {
|
15563 | var padding = 0;
|
15564 | Util.each(legendItems, function (legend) {
|
15565 | var width = legend.getWidth();
|
15566 | var height = legend.getHeight();
|
15567 |
|
15568 | if (position === 'top' || position === 'bottom') {
|
15569 | padding = Math.max(padding, height);
|
15570 |
|
15571 | if (legend.offsetY > 0) {
|
15572 | padding += legend.offsetY;
|
15573 | }
|
15574 | } else {
|
15575 | padding = Math.max(padding, width);
|
15576 |
|
15577 | if (legend.offsetX > 0) {
|
15578 | padding += legend.offsetX;
|
15579 | }
|
15580 | }
|
15581 | });
|
15582 | legendRange[position] = padding + getPaddingByPos(position, chart.get('appendPadding'));
|
15583 | });
|
15584 | chart.set('legendRange', legendRange);
|
15585 | },
|
15586 | afterGeomDraw: function afterGeomDraw(chart) {
|
15587 | var legendController = chart.get('legendController');
|
15588 | legendController.alignLegends();
|
15589 | },
|
15590 | clearInner: function clearInner(chart) {
|
15591 | var legendController = chart.get('legendController');
|
15592 | legendController.clear();
|
15593 | chart.set('legendRange', null);
|
15594 | }
|
15595 | };
|
15596 |
|
15597 | }),
|
15598 |
|
15599 | (function(module, exports, __webpack_require__) {
|
15600 |
|
15601 |
|
15602 |
|
15603 |
|
15604 |
|
15605 | var Util = __webpack_require__(0);
|
15606 |
|
15607 | var Element = __webpack_require__(26);
|
15608 |
|
15609 | var Timeline = __webpack_require__(125);
|
15610 |
|
15611 | var Animator = __webpack_require__(126);
|
15612 |
|
15613 | var Animate = __webpack_require__(45);
|
15614 |
|
15615 | var ShapeAction = __webpack_require__(128);
|
15616 |
|
15617 | var GroupAction = __webpack_require__(129);
|
15618 |
|
15619 | var Chart = __webpack_require__(12);
|
15620 |
|
15621 | var timeline;
|
15622 |
|
15623 | Element.prototype.animate = function () {
|
15624 | var attrs = Util.mix({}, this.get('attrs'));
|
15625 | return new Animator(this, attrs, timeline);
|
15626 | };
|
15627 |
|
15628 | Chart.prototype.animate = function (cfg) {
|
15629 | this.set('animate', cfg);
|
15630 | return this;
|
15631 | };
|
15632 |
|
15633 | Animate.Action = ShapeAction;
|
15634 | Animate.defaultCfg = {
|
15635 | interval: {
|
15636 | enter: function enter(coord) {
|
15637 | if (coord.isPolar && coord.transposed) {
|
15638 |
|
15639 | return function (shape) {
|
15640 | shape.set('zIndex', -1);
|
15641 | var container = shape.get('parent');
|
15642 | container.sort();
|
15643 | };
|
15644 | }
|
15645 |
|
15646 | return ShapeAction.fadeIn;
|
15647 | }
|
15648 | },
|
15649 | area: {
|
15650 | enter: function enter(coord) {
|
15651 | if (coord.isPolar) return null;
|
15652 | return ShapeAction.fadeIn;
|
15653 | }
|
15654 | },
|
15655 | line: {
|
15656 | enter: function enter(coord) {
|
15657 | if (coord.isPolar) return null;
|
15658 | return ShapeAction.fadeIn;
|
15659 | }
|
15660 | },
|
15661 | path: {
|
15662 | enter: function enter(coord) {
|
15663 | if (coord.isPolar) return null;
|
15664 | return ShapeAction.fadeIn;
|
15665 | }
|
15666 | }
|
15667 | };
|
15668 | var GROUP_ANIMATION = {
|
15669 | line: function line(coord) {
|
15670 | if (coord.isPolar) {
|
15671 | return GroupAction.groupScaleInXY;
|
15672 | }
|
15673 |
|
15674 | return GroupAction.groupWaveIn;
|
15675 | },
|
15676 | area: function area(coord) {
|
15677 | if (coord.isPolar) {
|
15678 | return GroupAction.groupScaleInXY;
|
15679 | }
|
15680 |
|
15681 | return GroupAction.groupWaveIn;
|
15682 | },
|
15683 | path: function path(coord) {
|
15684 | if (coord.isPolar) {
|
15685 | return GroupAction.groupScaleInXY;
|
15686 | }
|
15687 |
|
15688 | return GroupAction.groupWaveIn;
|
15689 | },
|
15690 | point: function point() {
|
15691 | return GroupAction.shapesScaleInXY;
|
15692 | },
|
15693 | interval: function interval(coord) {
|
15694 | var result;
|
15695 |
|
15696 | if (coord.isPolar) {
|
15697 |
|
15698 | result = GroupAction.groupScaleInXY;
|
15699 |
|
15700 | if (coord.transposed) {
|
15701 |
|
15702 | result = GroupAction.groupWaveIn;
|
15703 | }
|
15704 | } else {
|
15705 | result = coord.transposed ? GroupAction.groupScaleInX : GroupAction.groupScaleInY;
|
15706 | }
|
15707 |
|
15708 | return result;
|
15709 | },
|
15710 | schema: function schema() {
|
15711 | return GroupAction.groupWaveIn;
|
15712 | }
|
15713 | };
|
15714 |
|
15715 | function diff(fromAttrs, toAttrs) {
|
15716 | var endState = {};
|
15717 |
|
15718 | for (var k in toAttrs) {
|
15719 | if (Util.isNumber(fromAttrs[k]) && fromAttrs[k] !== toAttrs[k]) {
|
15720 | endState[k] = toAttrs[k];
|
15721 | } else if (Util.isArray(fromAttrs[k]) && JSON.stringify(fromAttrs[k]) !== JSON.stringify(toAttrs[k])) {
|
15722 | endState[k] = toAttrs[k];
|
15723 | }
|
15724 | }
|
15725 |
|
15726 | return endState;
|
15727 | }
|
15728 |
|
15729 |
|
15730 | function _getShapeId(geom, dataObj, geomIdx) {
|
15731 | var type = geom.get('type');
|
15732 | var id = 'geom' + geomIdx + '-' + type;
|
15733 | var xScale = geom.getXScale();
|
15734 | var yScale = geom.getYScale();
|
15735 | var xField = xScale.field || 'x';
|
15736 | var yField = yScale.field || 'y';
|
15737 | var yVal = dataObj[yField];
|
15738 | var xVal;
|
15739 |
|
15740 | if (xScale.isIdentity) {
|
15741 | xVal = xScale.value;
|
15742 | } else {
|
15743 | xVal = dataObj[xField];
|
15744 | }
|
15745 |
|
15746 | if (type === 'interval' || type === 'schema') {
|
15747 | id += '-' + xVal;
|
15748 | } else if (type === 'line' || type === 'area' || type === 'path') {
|
15749 | id += '-' + type;
|
15750 | } else {
|
15751 | id += xScale.isCategory ? '-' + xVal : '-' + xVal + '-' + yVal;
|
15752 | }
|
15753 |
|
15754 | var groupScales = geom._getGroupScales();
|
15755 |
|
15756 | Util.each(groupScales, function (groupScale) {
|
15757 | var field = groupScale.field;
|
15758 |
|
15759 | if (groupScale.type !== 'identity') {
|
15760 | id += '-' + dataObj[field];
|
15761 | }
|
15762 | });
|
15763 | return id;
|
15764 | }
|
15765 |
|
15766 |
|
15767 | function getShapes(geoms, chart, coord) {
|
15768 | var shapes = [];
|
15769 | Util.each(geoms, function (geom, geomIdx) {
|
15770 | var geomContainer = geom.get('container');
|
15771 | var geomShapes = geomContainer.get('children');
|
15772 | var type = geom.get('type');
|
15773 | var animateCfg = Util.isNil(geom.get('animateCfg')) ? _getAnimateCfgByShapeType(type, chart) : geom.get('animateCfg');
|
15774 |
|
15775 | if (animateCfg !== false) {
|
15776 | Util.each(geomShapes, function (shape, index) {
|
15777 | if (shape.get('className') === type) {
|
15778 | shape._id = _getShapeId(geom, shape.get('origin')._origin, geomIdx);
|
15779 | shape.set('coord', coord);
|
15780 | shape.set('animateCfg', animateCfg);
|
15781 | shape.set('index', index);
|
15782 | shapes.push(shape);
|
15783 | }
|
15784 | });
|
15785 | }
|
15786 |
|
15787 | geom.set('shapes', geomShapes);
|
15788 | });
|
15789 | return shapes;
|
15790 | }
|
15791 |
|
15792 | function cache(shapes) {
|
15793 | var rst = {};
|
15794 |
|
15795 | for (var i = 0, len = shapes.length; i < len; i++) {
|
15796 | var shape = shapes[i];
|
15797 | if (!shape._id || shape.isClip) continue;
|
15798 | var id = shape._id;
|
15799 | rst[id] = {
|
15800 | _id: id,
|
15801 | type: shape.get('type'),
|
15802 |
|
15803 | attrs: Util.mix({}, shape._attrs.attrs),
|
15804 |
|
15805 | className: shape.get('className'),
|
15806 | geomType: shape.get('className'),
|
15807 | index: shape.get('index'),
|
15808 | coord: shape.get('coord'),
|
15809 | animateCfg: shape.get('animateCfg')
|
15810 | };
|
15811 | }
|
15812 |
|
15813 | return rst;
|
15814 | }
|
15815 |
|
15816 | function getAnimate(geomType, coord, animationType, animationName) {
|
15817 | var result;
|
15818 |
|
15819 | if (Util.isFunction(animationName)) {
|
15820 | result = animationName;
|
15821 | } else if (Util.isString(animationName)) {
|
15822 | result = Animate.Action[animationName];
|
15823 | } else {
|
15824 | result = Animate.getAnimation(geomType, coord, animationType);
|
15825 | }
|
15826 |
|
15827 | return result;
|
15828 | }
|
15829 |
|
15830 | function getAnimateCfg(geomType, animationType, animateCfg) {
|
15831 | if (animateCfg === false || Util.isObject(animateCfg) && animateCfg[animationType] === false) {
|
15832 | return false;
|
15833 | }
|
15834 |
|
15835 | var defaultCfg = Animate.getAnimateCfg(geomType, animationType);
|
15836 |
|
15837 | if (animateCfg && animateCfg[animationType]) {
|
15838 | return Util.deepMix({}, defaultCfg, animateCfg[animationType]);
|
15839 | }
|
15840 |
|
15841 | return defaultCfg;
|
15842 | }
|
15843 |
|
15844 | function addAnimate(cache, shapes, canvas) {
|
15845 | var animate;
|
15846 | var animateCfg;
|
15847 |
|
15848 | var updateShapes = [];
|
15849 | var newShapes = [];
|
15850 | Util.each(shapes, function (shape) {
|
15851 | var result = cache[shape._id];
|
15852 |
|
15853 | if (!result) {
|
15854 | newShapes.push(shape);
|
15855 | } else {
|
15856 | shape.set('cacheShape', result);
|
15857 | updateShapes.push(shape);
|
15858 | delete cache[shape._id];
|
15859 | }
|
15860 | });
|
15861 |
|
15862 | Util.each(cache, function (deletedShape) {
|
15863 | var className = deletedShape.className,
|
15864 | coord = deletedShape.coord,
|
15865 | _id = deletedShape._id,
|
15866 | attrs = deletedShape.attrs,
|
15867 | index = deletedShape.index,
|
15868 | type = deletedShape.type;
|
15869 | animateCfg = getAnimateCfg(className, 'leave', deletedShape.animateCfg);
|
15870 | if (animateCfg === false) return true;
|
15871 | animate = getAnimate(className, coord, 'leave', animateCfg.animation);
|
15872 |
|
15873 | if (Util.isFunction(animate)) {
|
15874 | var tempShape = canvas.addShape(type, {
|
15875 | attrs: attrs,
|
15876 | index: index,
|
15877 | canvas: canvas,
|
15878 | className: className
|
15879 | });
|
15880 | tempShape._id = _id;
|
15881 | animate(tempShape, animateCfg, coord);
|
15882 | }
|
15883 | });
|
15884 |
|
15885 | Util.each(updateShapes, function (updateShape) {
|
15886 | var className = updateShape.get('className');
|
15887 | animateCfg = getAnimateCfg(className, 'update', updateShape.get('animateCfg'));
|
15888 | if (animateCfg === false) return true;
|
15889 | var coord = updateShape.get('coord');
|
15890 | var cacheAttrs = updateShape.get('cacheShape').attrs;
|
15891 | var endState = diff(cacheAttrs, updateShape._attrs.attrs);
|
15892 |
|
15893 | if (Object.keys(endState).length) {
|
15894 | animate = getAnimate(className, coord, 'update', animateCfg.animation);
|
15895 |
|
15896 | if (Util.isFunction(animate)) {
|
15897 | animate(updateShape, animateCfg, coord);
|
15898 | } else {
|
15899 | updateShape.attr(cacheAttrs);
|
15900 | updateShape.animate().to({
|
15901 | attrs: endState,
|
15902 | duration: animateCfg.duration,
|
15903 | easing: animateCfg.easing,
|
15904 | delay: animateCfg.delay
|
15905 | }).onEnd(function () {
|
15906 | updateShape.set('cacheShape', null);
|
15907 | });
|
15908 | }
|
15909 | }
|
15910 | });
|
15911 |
|
15912 | Util.each(newShapes, function (newShape) {
|
15913 |
|
15914 | var className = newShape.get('className');
|
15915 | var coord = newShape.get('coord');
|
15916 | animateCfg = getAnimateCfg(className, 'enter', newShape.get('animateCfg'));
|
15917 | if (animateCfg === false) return true;
|
15918 | animate = getAnimate(className, coord, 'enter', animateCfg.animation);
|
15919 |
|
15920 | if (Util.isFunction(animate)) {
|
15921 | if (className === 'interval' && coord.isPolar && coord.transposed) {
|
15922 | var index = newShape.get('index');
|
15923 | var lastShape = updateShapes[index - 1];
|
15924 | animate(newShape, animateCfg, lastShape);
|
15925 | } else {
|
15926 | animate(newShape, animateCfg, coord);
|
15927 | }
|
15928 | }
|
15929 | });
|
15930 | }
|
15931 |
|
15932 | function _getAnimateCfgByShapeType(type, chart) {
|
15933 | if (!type) {
|
15934 | return null;
|
15935 | }
|
15936 |
|
15937 | var animateCfg = chart.get('animate');
|
15938 |
|
15939 | if (type.indexOf('guide-tag') > -1) {
|
15940 | type = 'guide-tag';
|
15941 | }
|
15942 |
|
15943 | if (Util.isObject(animateCfg)) {
|
15944 | return animateCfg[type];
|
15945 | }
|
15946 |
|
15947 | if (animateCfg === false) {
|
15948 | return false;
|
15949 | }
|
15950 |
|
15951 | return null;
|
15952 | }
|
15953 |
|
15954 | module.exports = {
|
15955 | afterCanvasInit: function afterCanvasInit()
|
15956 | /* chart */
|
15957 | {
|
15958 | timeline = new Timeline();
|
15959 | timeline.play();
|
15960 | },
|
15961 | beforeCanvasDraw: function beforeCanvasDraw(chart) {
|
15962 | if (chart.get('animate') === false) {
|
15963 | return;
|
15964 | }
|
15965 |
|
15966 | var isUpdate = chart.get('isUpdate');
|
15967 | var canvas = chart.get('canvas');
|
15968 | var coord = chart.get('coord');
|
15969 | var geoms = chart.get('geoms');
|
15970 | var caches = canvas.get('caches') || [];
|
15971 |
|
15972 | if (caches.length === 0) {
|
15973 | isUpdate = false;
|
15974 | }
|
15975 |
|
15976 | var cacheShapes = getShapes(geoms, chart, coord);
|
15977 |
|
15978 | var _chart$get = chart.get('axisController'),
|
15979 | frontPlot = _chart$get.frontPlot,
|
15980 | backPlot = _chart$get.backPlot;
|
15981 |
|
15982 | var axisShapes = frontPlot.get('children').concat(backPlot.get('children'));
|
15983 | var guideShapes = [];
|
15984 |
|
15985 | if (chart.get('guideController')) {
|
15986 | guideShapes = chart.get('guideController').guideShapes;
|
15987 | }
|
15988 |
|
15989 | var componentShapes = [];
|
15990 | axisShapes.concat(guideShapes).forEach(function (s) {
|
15991 | var className = s.get('className');
|
15992 |
|
15993 | var animateCfg = _getAnimateCfgByShapeType(className, chart);
|
15994 |
|
15995 | s.set('coord', coord);
|
15996 | s.set('animateCfg', animateCfg);
|
15997 | componentShapes.push(s);
|
15998 | cacheShapes.push(s);
|
15999 | });
|
16000 | canvas.set('caches', cache(cacheShapes));
|
16001 |
|
16002 | if (isUpdate) {
|
16003 | addAnimate(caches, cacheShapes, canvas);
|
16004 | } else {
|
16005 |
|
16006 | var animateCfg;
|
16007 | var animate;
|
16008 | Util.each(geoms, function (geom) {
|
16009 | var type = geom.get('type');
|
16010 | var geomCfg = Util.isNil(geom.get('animateCfg')) ? _getAnimateCfgByShapeType(type, chart) : geom.get('animateCfg');
|
16011 |
|
16012 | if (geomCfg !== false) {
|
16013 | animateCfg = getAnimateCfg(type, 'appear', geomCfg);
|
16014 | animate = getAnimate(type, coord, 'appear', animateCfg.animation);
|
16015 |
|
16016 | if (Util.isFunction(animate)) {
|
16017 | var shapes = geom.get('shapes');
|
16018 | Util.each(shapes, function (shape) {
|
16019 | animate(shape, animateCfg, coord);
|
16020 | });
|
16021 | } else if (GROUP_ANIMATION[type]) {
|
16022 |
|
16023 | animate = GroupAction[animateCfg.animation] || GROUP_ANIMATION[type](coord);
|
16024 | var yScale = geom.getYScale();
|
16025 | var zeroY = coord.convertPoint({
|
16026 | x: 0,
|
16027 | y: yScale.scale(geom.getYMinValue())
|
16028 | });
|
16029 | var container = geom.get('container');
|
16030 | animate && animate(container, animateCfg, coord, zeroY);
|
16031 | }
|
16032 | }
|
16033 | });
|
16034 |
|
16035 | Util.each(componentShapes, function (shape) {
|
16036 | var animateCfg = shape.get('animateCfg');
|
16037 | var className = shape.get('className');
|
16038 |
|
16039 | if (animateCfg && animateCfg.appear) {
|
16040 |
|
16041 | var defaultCfg = Animate.getAnimateCfg(className, 'appear');
|
16042 | var appearCfg = Util.deepMix({}, defaultCfg, animateCfg.appear);
|
16043 |
|
16044 | var _animate = getAnimate(className, coord, 'appear', appearCfg.animation);
|
16045 |
|
16046 | if (Util.isFunction(_animate)) {
|
16047 | _animate(shape, appearCfg, coord);
|
16048 | }
|
16049 | }
|
16050 | });
|
16051 | }
|
16052 | },
|
16053 | afterCanvasDestroyed: function afterCanvasDestroyed()
|
16054 | /* chart */
|
16055 | {
|
16056 | timeline.stop();
|
16057 | }
|
16058 | };
|
16059 |
|
16060 | }),
|
16061 |
|
16062 | (function(module, exports, __webpack_require__) {
|
16063 |
|
16064 | var _require = __webpack_require__(38),
|
16065 | requestAnimationFrame = _require.requestAnimationFrame;
|
16066 |
|
16067 | var clock = typeof performance === 'object' && performance.now ? performance : Date;
|
16068 |
|
16069 | var Timeline =
|
16070 |
|
16071 | function () {
|
16072 | function Timeline() {
|
16073 | this.anims = [];
|
16074 | this.time = null;
|
16075 | this.playing = false;
|
16076 | this.canvas = [];
|
16077 | }
|
16078 |
|
16079 | var _proto = Timeline.prototype;
|
16080 |
|
16081 | _proto.play = function play() {
|
16082 | var self = this;
|
16083 | self.time = clock.now();
|
16084 | self.playing = true;
|
16085 |
|
16086 | function step() {
|
16087 | if (self.playing) {
|
16088 | requestAnimationFrame(step);
|
16089 | self.update();
|
16090 | }
|
16091 | }
|
16092 |
|
16093 | requestAnimationFrame(step);
|
16094 | };
|
16095 |
|
16096 | _proto.stop = function stop() {
|
16097 | this.playing = false;
|
16098 | this.time = null;
|
16099 | this.canvas = [];
|
16100 | };
|
16101 |
|
16102 | _proto.update = function update() {
|
16103 | var currentTime = clock.now();
|
16104 | this.canvas = [];
|
16105 |
|
16106 | for (var i = 0; i < this.anims.length; i++) {
|
16107 | var propertyAnim = this.anims[i];
|
16108 |
|
16109 | if (currentTime < propertyAnim.startTime || propertyAnim.hasEnded) {
|
16110 | continue;
|
16111 | }
|
16112 |
|
16113 | var shape = propertyAnim.shape;
|
16114 |
|
16115 | if (shape.get('destroyed')) {
|
16116 | this.anims.splice(i, 1);
|
16117 | i--;
|
16118 | continue;
|
16119 | }
|
16120 |
|
16121 | var startState = propertyAnim.startState,
|
16122 | endState = propertyAnim.endState,
|
16123 | interpolate = propertyAnim.interpolate,
|
16124 | duration = propertyAnim.duration;
|
16125 |
|
16126 | if (currentTime >= propertyAnim.startTime && !propertyAnim.hasStarted) {
|
16127 | propertyAnim.hasStarted = true;
|
16128 |
|
16129 | if (propertyAnim.onStart) {
|
16130 | propertyAnim.onStart();
|
16131 | }
|
16132 | }
|
16133 |
|
16134 | var t = (currentTime - propertyAnim.startTime) / duration;
|
16135 | t = Math.max(0, Math.min(t, 1));
|
16136 | t = propertyAnim.easing(t);
|
16137 |
|
16138 | if (propertyAnim.onFrame) {
|
16139 | propertyAnim.onFrame(t);
|
16140 | } else {
|
16141 | for (var key in interpolate) {
|
16142 | var diff = interpolate[key];
|
16143 | var value = diff(t);
|
16144 | var newValue = void 0;
|
16145 |
|
16146 | if (key === 'points') {
|
16147 | newValue = [];
|
16148 | var aLen = Math.max(startState.points.length, endState.points.length);
|
16149 |
|
16150 | for (var j = 0; j < aLen; j += 2) {
|
16151 | newValue.push({
|
16152 | x: value[j],
|
16153 | y: value[j + 1]
|
16154 | });
|
16155 | }
|
16156 | } else {
|
16157 | newValue = value;
|
16158 | }
|
16159 |
|
16160 | shape._attrs.attrs[key] = newValue;
|
16161 | shape._attrs.bbox = null;
|
16162 | }
|
16163 | }
|
16164 |
|
16165 | var canvas = shape.get('canvas');
|
16166 |
|
16167 | if (this.canvas.indexOf(canvas) === -1) {
|
16168 | this.canvas.push(canvas);
|
16169 | }
|
16170 |
|
16171 | if (propertyAnim.onUpdate) {
|
16172 | propertyAnim.onUpdate(t);
|
16173 | }
|
16174 |
|
16175 | if (currentTime >= propertyAnim.endTime && !propertyAnim.hasEnded) {
|
16176 | propertyAnim.hasEnded = true;
|
16177 |
|
16178 | if (propertyAnim.onEnd) {
|
16179 | propertyAnim.onEnd();
|
16180 | }
|
16181 | }
|
16182 |
|
16183 | if (t === 1) {
|
16184 |
|
16185 | this.anims.splice(i, 1);
|
16186 | i--;
|
16187 | }
|
16188 | }
|
16189 |
|
16190 | this.canvas.map(function (c) {
|
16191 | c.draw();
|
16192 | return c;
|
16193 | });
|
16194 | this.time = clock.now();
|
16195 | };
|
16196 |
|
16197 | return Timeline;
|
16198 | }();
|
16199 |
|
16200 | module.exports = Timeline;
|
16201 |
|
16202 | }),
|
16203 |
|
16204 | (function(module, exports, __webpack_require__) {
|
16205 |
|
16206 | var Easing = __webpack_require__(127);
|
16207 |
|
16208 | function plainArray(arr) {
|
16209 | var result = [];
|
16210 |
|
16211 | for (var i = 0, len = arr.length; i < len; i++) {
|
16212 | if (arr[i]) {
|
16213 | result.push(arr[i].x);
|
16214 | result.push(arr[i].y);
|
16215 | }
|
16216 | }
|
16217 |
|
16218 | return result;
|
16219 | }
|
16220 |
|
16221 | function interpolateNumber(a, b) {
|
16222 | a = +a;
|
16223 | b -= a;
|
16224 | return function (t) {
|
16225 | return a + b * t;
|
16226 | };
|
16227 | }
|
16228 |
|
16229 | function interpolateArray(a, b) {
|
16230 | var nb = b ? b.length : 0;
|
16231 | var na = a ? Math.min(nb, a.length) : 0;
|
16232 | var x = new Array(na);
|
16233 | var c = new Array(nb);
|
16234 | var i;
|
16235 |
|
16236 | for (i = 0; i < na; ++i) {
|
16237 | x[i] = interpolateNumber(a[i], b[i]);
|
16238 | }
|
16239 |
|
16240 | for (; i < nb; ++i) {
|
16241 | c[i] = b[i];
|
16242 | }
|
16243 |
|
16244 | return function (t) {
|
16245 | for (i = 0; i < na; ++i) {
|
16246 | c[i] = x[i](t);
|
16247 | }
|
16248 |
|
16249 | return c;
|
16250 | };
|
16251 | }
|
16252 |
|
16253 | var Animator =
|
16254 |
|
16255 | function () {
|
16256 | function Animator(shape, source, timeline) {
|
16257 | this.hasStarted = false;
|
16258 | this.hasEnded = false;
|
16259 | this.shape = shape;
|
16260 | this.source = source;
|
16261 | this.timeline = timeline;
|
16262 | this.animate = null;
|
16263 | }
|
16264 |
|
16265 |
|
16266 | var _proto = Animator.prototype;
|
16267 |
|
16268 | _proto.to = function to(cfg) {
|
16269 | if (cfg === void 0) {
|
16270 | cfg = {};
|
16271 | }
|
16272 |
|
16273 | var delay = cfg.delay || 0;
|
16274 | var attrs = cfg.attrs || {};
|
16275 | var duration = cfg.duration || 1000;
|
16276 | var easing;
|
16277 |
|
16278 | if (typeof cfg.easing === 'function') {
|
16279 | easing = cfg.easing;
|
16280 | } else {
|
16281 | easing = Easing[cfg.easing] || Easing.linear;
|
16282 | }
|
16283 |
|
16284 | var animInfo = {
|
16285 | shape: this.shape,
|
16286 | startTime: this.timeline.time + delay,
|
16287 | duration: duration,
|
16288 | easing: easing
|
16289 | };
|
16290 | var interpolate = {};
|
16291 |
|
16292 | for (var attrName in attrs) {
|
16293 | var startValue = this.source[attrName];
|
16294 | var endValue = attrs[attrName];
|
16295 |
|
16296 | if (attrName === 'points') {
|
16297 | startValue = plainArray(startValue);
|
16298 | endValue = plainArray(endValue);
|
16299 | interpolate.points = interpolateArray(startValue, endValue);
|
16300 | this.source.points = startValue;
|
16301 | attrs.points = endValue;
|
16302 | } else if (attrName === 'matrix') {
|
16303 | interpolate.matrix = interpolateArray(startValue, endValue);
|
16304 | } else {
|
16305 | interpolate[attrName] = interpolateNumber(startValue, endValue);
|
16306 | }
|
16307 | }
|
16308 |
|
16309 | animInfo.interpolate = interpolate;
|
16310 | animInfo.startState = this.source;
|
16311 | animInfo.endState = attrs;
|
16312 | animInfo.endTime = animInfo.startTime + duration;
|
16313 | this.timeline.anims.push(animInfo);
|
16314 | this.animate = animInfo;
|
16315 | return this;
|
16316 | };
|
16317 |
|
16318 | _proto.onFrame = function onFrame(callback) {
|
16319 |
|
16320 | if (this.animate) {
|
16321 | this.animate.onFrame = function (frame) {
|
16322 | callback(frame);
|
16323 | };
|
16324 | }
|
16325 |
|
16326 | return this;
|
16327 | };
|
16328 |
|
16329 | _proto.onStart = function onStart(callback) {
|
16330 | if (this.animate) {
|
16331 | this.animate.onStart = function () {
|
16332 | callback();
|
16333 | };
|
16334 | }
|
16335 |
|
16336 | return this;
|
16337 | };
|
16338 |
|
16339 | _proto.onUpdate = function onUpdate(callback) {
|
16340 | if (this.animate) {
|
16341 | this.animate.onUpdate = function (frame) {
|
16342 | callback(frame);
|
16343 | };
|
16344 | }
|
16345 |
|
16346 | return this;
|
16347 | };
|
16348 |
|
16349 | _proto.onEnd = function onEnd(callback) {
|
16350 | if (this.animate) {
|
16351 | this.animate.onEnd = function () {
|
16352 | callback();
|
16353 | };
|
16354 | }
|
16355 |
|
16356 | return this;
|
16357 | };
|
16358 |
|
16359 | return Animator;
|
16360 | }();
|
16361 |
|
16362 | module.exports = Animator;
|
16363 |
|
16364 | }),
|
16365 |
|
16366 | (function(module, exports) {
|
16367 |
|
16368 | var Easing = {
|
16369 | linear: function linear(k) {
|
16370 | return k;
|
16371 | },
|
16372 | quadraticIn: function quadraticIn(k) {
|
16373 | return k * k;
|
16374 | },
|
16375 | quadraticOut: function quadraticOut(k) {
|
16376 | return k * (2 - k);
|
16377 | },
|
16378 | quadraticInOut: function quadraticInOut(k) {
|
16379 | if ((k *= 2) < 1) {
|
16380 | return 0.5 * k * k;
|
16381 | }
|
16382 |
|
16383 | return -0.5 * (--k * (k - 2) - 1);
|
16384 | },
|
16385 | cubicIn: function cubicIn(k) {
|
16386 | return k * k * k;
|
16387 | },
|
16388 | cubicOut: function cubicOut(k) {
|
16389 | return --k * k * k + 1;
|
16390 | },
|
16391 | cubicInOut: function cubicInOut(k) {
|
16392 | if ((k *= 2) < 1) {
|
16393 | return 0.5 * k * k * k;
|
16394 | }
|
16395 |
|
16396 | return 0.5 * ((k -= 2) * k * k + 2);
|
16397 | },
|
16398 | elasticIn: function elasticIn(k) {
|
16399 | var s;
|
16400 | var a = 0.1;
|
16401 | var p = 0.4;
|
16402 | if (k === 0) return 0;
|
16403 | if (k === 1) return 1;
|
16404 |
|
16405 | if (!p) {
|
16406 | p = 0.3;
|
16407 | }
|
16408 |
|
16409 | if (!a || a < 1) {
|
16410 | a = 1;
|
16411 | s = p / 4;
|
16412 | } else {
|
16413 | s = p / (2 * Math.PI) * Math.asin(1 / a);
|
16414 | }
|
16415 |
|
16416 | return -(a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
|
16417 | },
|
16418 | elasticOut: function elasticOut(k) {
|
16419 | var s;
|
16420 | var a = 0.1;
|
16421 | var p = 0.4;
|
16422 | if (k === 0) return 0;
|
16423 | if (k === 1) return 1;
|
16424 |
|
16425 | if (!p) {
|
16426 | p = 0.3;
|
16427 | }
|
16428 |
|
16429 | if (!a || a < 1) {
|
16430 | a = 1;
|
16431 | s = p / 4;
|
16432 | } else {
|
16433 | s = p / (2 * Math.PI) * Math.asin(1 / a);
|
16434 | }
|
16435 |
|
16436 | return a * Math.pow(2, -10 * k) * Math.sin((k - s) * (2 * Math.PI) / p) + 1;
|
16437 | },
|
16438 | elasticInOut: function elasticInOut(k) {
|
16439 | var s;
|
16440 | var a = 0.1;
|
16441 | var p = 0.4;
|
16442 | if (k === 0) return 0;
|
16443 | if (k === 1) return 1;
|
16444 |
|
16445 | if (!p) {
|
16446 | p = 0.3;
|
16447 | }
|
16448 |
|
16449 | if (!a || a < 1) {
|
16450 | a = 1;
|
16451 | s = p / 4;
|
16452 | } else {
|
16453 | s = p / (2 * Math.PI) * Math.asin(1 / a);
|
16454 | }
|
16455 |
|
16456 | if ((k *= 2) < 1) {
|
16457 | return -0.5 * (a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
|
16458 | }
|
16459 |
|
16460 | return a * Math.pow(2, -10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
|
16461 | },
|
16462 | backIn: function backIn(k) {
|
16463 | var s = 1.70158;
|
16464 | return k * k * ((s + 1) * k - s);
|
16465 | },
|
16466 | backOut: function backOut(k) {
|
16467 | var s = 1.70158;
|
16468 | return (k = k - 1) * k * ((s + 1) * k + s) + 1;
|
16469 | },
|
16470 | backInOut: function backInOut(k) {
|
16471 | var s = 1.70158 * 1.525;
|
16472 |
|
16473 | if ((k *= 2) < 1) {
|
16474 | return 0.5 * (k * k * ((s + 1) * k - s));
|
16475 | }
|
16476 |
|
16477 | return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
|
16478 | },
|
16479 | bounceIn: function bounceIn(k) {
|
16480 | return 1 - Easing.bounceOut(1 - k);
|
16481 | },
|
16482 | bounceOut: function bounceOut(k) {
|
16483 | if ((k /= 1) < 1 / 2.75) {
|
16484 | return 7.5625 * k * k;
|
16485 | } else if (k < 2 / 2.75) {
|
16486 | return 7.5625 * (k -= 1.5 / 2.75) * k + 0.75;
|
16487 | } else if (k < 2.5 / 2.75) {
|
16488 | return 7.5625 * (k -= 2.25 / 2.75) * k + 0.9375;
|
16489 | }
|
16490 |
|
16491 | return 7.5625 * (k -= 2.625 / 2.75) * k + 0.984375;
|
16492 | },
|
16493 | bounceInOut: function bounceInOut(k) {
|
16494 | if (k < 0.5) {
|
16495 | return Easing.bounceIn(k * 2) * 0.5;
|
16496 | }
|
16497 |
|
16498 | return Easing.bounceOut(k * 2 - 1) * 0.5 + 0.5;
|
16499 | }
|
16500 | };
|
16501 | module.exports = Easing;
|
16502 |
|
16503 | }),
|
16504 |
|
16505 | (function(module, exports, __webpack_require__) {
|
16506 |
|
16507 |
|
16508 |
|
16509 |
|
16510 |
|
16511 | var Util = __webpack_require__(0);
|
16512 |
|
16513 | var Helpers = __webpack_require__(46);
|
16514 |
|
16515 |
|
16516 |
|
16517 |
|
16518 |
|
16519 |
|
16520 |
|
16521 |
|
16522 |
|
16523 |
|
16524 |
|
16525 |
|
16526 |
|
16527 |
|
16528 |
|
16529 |
|
16530 |
|
16531 |
|
16532 |
|
16533 |
|
16534 |
|
16535 |
|
16536 |
|
16537 |
|
16538 |
|
16539 |
|
16540 |
|
16541 |
|
16542 |
|
16543 |
|
16544 |
|
16545 |
|
16546 |
|
16547 |
|
16548 |
|
16549 |
|
16550 |
|
16551 |
|
16552 |
|
16553 |
|
16554 |
|
16555 |
|
16556 |
|
16557 |
|
16558 | function fadeIn(shape, animateCfg) {
|
16559 | var fillOpacity = Util.isNil(shape.attr('fillOpacity')) ? 1 : shape.attr('fillOpacity');
|
16560 | var strokeOpacity = Util.isNil(shape.attr('strokeOpacity')) ? 1 : shape.attr('strokeOpacity');
|
16561 | shape.attr('fillOpacity', 0);
|
16562 | shape.attr('strokeOpacity', 0);
|
16563 | var endState = {
|
16564 | fillOpacity: fillOpacity,
|
16565 | strokeOpacity: strokeOpacity
|
16566 | };
|
16567 | Helpers.doAnimation(shape, endState, animateCfg);
|
16568 | }
|
16569 |
|
16570 | module.exports = {
|
16571 |
|
16572 |
|
16573 |
|
16574 | fadeIn: fadeIn
|
16575 | };
|
16576 |
|
16577 | }),
|
16578 |
|
16579 | (function(module, exports, __webpack_require__) {
|
16580 |
|
16581 |
|
16582 |
|
16583 |
|
16584 |
|
16585 | var Util = __webpack_require__(46);
|
16586 |
|
16587 | var Helper = __webpack_require__(20);
|
16588 |
|
16589 | var _require = __webpack_require__(3),
|
16590 | Shape = _require.Shape;
|
16591 |
|
16592 | function _groupScaleIn(container, animateCfg, coord, zeroY, type) {
|
16593 | var _Util$getCoordInfo = Util.getCoordInfo(coord),
|
16594 | start = _Util$getCoordInfo.start,
|
16595 | end = _Util$getCoordInfo.end,
|
16596 | width = _Util$getCoordInfo.width,
|
16597 | height = _Util$getCoordInfo.height;
|
16598 |
|
16599 | var x;
|
16600 | var y;
|
16601 | var clip = new Shape.Rect({
|
16602 | attrs: {
|
16603 | x: start.x,
|
16604 | y: end.y,
|
16605 | width: width,
|
16606 | height: height
|
16607 | }
|
16608 | });
|
16609 |
|
16610 | if (type === 'y') {
|
16611 | x = start.x + width / 2;
|
16612 | y = zeroY.y < start.y ? zeroY.y : start.y;
|
16613 | } else if (type === 'x') {
|
16614 | x = zeroY.x > start.x ? zeroY.x : start.x;
|
16615 | y = start.y + height / 2;
|
16616 | } else if (type === 'xy') {
|
16617 | if (coord.isPolar) {
|
16618 | x = coord.center.x;
|
16619 | y = coord.center.y;
|
16620 | } else {
|
16621 | x = (start.x + end.x) / 2;
|
16622 | y = (start.y + end.y) / 2;
|
16623 | }
|
16624 | }
|
16625 |
|
16626 | var endMatrix = Util.getScaledMatrix(clip, [x, y], type);
|
16627 | clip.isClip = true;
|
16628 | clip.endState = {
|
16629 | matrix: endMatrix
|
16630 | };
|
16631 | clip.set('canvas', container.get('canvas'));
|
16632 | container.attr('clip', clip);
|
16633 |
|
16634 | var onEnd = function onEnd() {
|
16635 | container.attr('clip', null);
|
16636 | clip.remove(true);
|
16637 | };
|
16638 |
|
16639 | Util.doAnimation(clip, clip.endState, animateCfg, onEnd);
|
16640 | }
|
16641 |
|
16642 | function _shapeScale(container, animateCfg, type) {
|
16643 | var shapes = container.get('children');
|
16644 | var x;
|
16645 | var y;
|
16646 | var endMatrix;
|
16647 |
|
16648 | for (var i = 0, len = shapes.length; i < len; i++) {
|
16649 | var shape = shapes[i];
|
16650 | var box = shape.getBBox();
|
16651 | x = (box.minX + box.maxX) / 2;
|
16652 | y = (box.minY + box.maxY) / 2;
|
16653 | endMatrix = Util.getScaledMatrix(shape, [x, y], type);
|
16654 | Util.doAnimation(shape, {
|
16655 | matrix: endMatrix
|
16656 | }, animateCfg);
|
16657 | }
|
16658 | }
|
16659 |
|
16660 | function groupScaleInX(container, animateCfg, coord, zeroY) {
|
16661 | _groupScaleIn(container, animateCfg, coord, zeroY, 'x');
|
16662 | }
|
16663 |
|
16664 | function groupScaleInY(container, animateCfg, coord, zeroY) {
|
16665 | _groupScaleIn(container, animateCfg, coord, zeroY, 'y');
|
16666 | }
|
16667 |
|
16668 | function groupScaleInXY(container, animateCfg, coord, zeroY) {
|
16669 | _groupScaleIn(container, animateCfg, coord, zeroY, 'xy');
|
16670 | }
|
16671 |
|
16672 | function shapesScaleInX(container, animateCfg) {
|
16673 | _shapeScale(container, animateCfg, 'x');
|
16674 | }
|
16675 |
|
16676 | function shapesScaleInY(container, animateCfg) {
|
16677 | _shapeScale(container, animateCfg, 'y');
|
16678 | }
|
16679 |
|
16680 | function shapesScaleInXY(container, animateCfg) {
|
16681 | _shapeScale(container, animateCfg, 'xy');
|
16682 | }
|
16683 |
|
16684 | function groupWaveIn(container, animateCfg, coord) {
|
16685 | var clip = Helper.getClip(coord);
|
16686 | clip.set('canvas', container.get('canvas'));
|
16687 | container.attr('clip', clip);
|
16688 |
|
16689 | var onEnd = function onEnd() {
|
16690 | container.attr('clip', null);
|
16691 | clip.remove(true);
|
16692 | };
|
16693 |
|
16694 | var endState = {};
|
16695 |
|
16696 | if (coord.isPolar) {
|
16697 | var startAngle = coord.startAngle,
|
16698 | endAngle = coord.endAngle;
|
16699 | endState.endAngle = endAngle;
|
16700 | clip.attr('endAngle', startAngle);
|
16701 | } else {
|
16702 | var start = coord.start,
|
16703 | end = coord.end;
|
16704 | var width = Math.abs(start.x - end.x);
|
16705 | var height = Math.abs(start.y - end.y);
|
16706 |
|
16707 | if (coord.isTransposed) {
|
16708 | clip.attr('height', 0);
|
16709 | endState.height = height;
|
16710 | } else {
|
16711 | clip.attr('width', 0);
|
16712 | endState.width = width;
|
16713 | }
|
16714 | }
|
16715 |
|
16716 | Util.doAnimation(clip, endState, animateCfg, onEnd);
|
16717 | }
|
16718 |
|
16719 | module.exports = {
|
16720 | groupWaveIn: groupWaveIn,
|
16721 | groupScaleInX: groupScaleInX,
|
16722 | groupScaleInY: groupScaleInY,
|
16723 | groupScaleInXY: groupScaleInXY,
|
16724 | shapesScaleInX: shapesScaleInX,
|
16725 | shapesScaleInY: shapesScaleInY,
|
16726 | shapesScaleInXY: shapesScaleInXY
|
16727 | };
|
16728 |
|
16729 | }),
|
16730 |
|
16731 | (function(module, exports, __webpack_require__) {
|
16732 |
|
16733 | var Helper = __webpack_require__(29);
|
16734 |
|
16735 | var Util = __webpack_require__(0);
|
16736 |
|
16737 | var DEFAULT_CFG = {
|
16738 | mode: 'x',
|
16739 | xStyle: {
|
16740 | backgroundColor: 'rgba(202, 215, 239, .2)',
|
16741 | fillerColor: 'rgba(202, 215, 239, .5)',
|
16742 | size: 4,
|
16743 | lineCap: 'round',
|
16744 | offsetX: 0,
|
16745 | offsetY: 8
|
16746 | },
|
16747 | yStyle: {
|
16748 | backgroundColor: 'rgba(202, 215, 239, .2)',
|
16749 | fillerColor: 'rgba(202, 215, 239, .5)',
|
16750 | size: 4,
|
16751 | lineCap: 'round',
|
16752 | offsetX: 8,
|
16753 | offsetY: 0
|
16754 | }
|
16755 | };
|
16756 | module.exports = {
|
16757 | init: function init(chart) {
|
16758 | chart.set('_limitRange', {});
|
16759 |
|
16760 | chart.scrollBar = function (cfg) {
|
16761 | if (cfg === true) {
|
16762 | cfg = DEFAULT_CFG;
|
16763 | } else if (Util.isObject(cfg)) {
|
16764 | cfg = Util.deepMix({}, DEFAULT_CFG, cfg);
|
16765 | }
|
16766 |
|
16767 | this.set('_scrollBarCfg', cfg);
|
16768 | };
|
16769 | },
|
16770 | clear: function clear(chart) {
|
16771 | chart.set('_limitRange', {});
|
16772 | },
|
16773 | changeData: function changeData(chart) {
|
16774 | chart.set('_limitRange', {});
|
16775 | },
|
16776 | clearInner: function clearInner(chart) {
|
16777 | var hBar = chart.get('_horizontalBar');
|
16778 | var vBar = chart.get('_verticalBar');
|
16779 | hBar && hBar.remove(true);
|
16780 | vBar && vBar.remove(true);
|
16781 | chart.set('_horizontalBar', null);
|
16782 | chart.set('_verticalBar', null);
|
16783 | },
|
16784 | afterGeomDraw: function afterGeomDraw(chart) {
|
16785 | var scrollBarCfg = chart.get('_scrollBarCfg');
|
16786 | if (!scrollBarCfg) return;
|
16787 | var data = chart.get('data');
|
16788 | var plotRange = chart.get('plotRange');
|
16789 | var backPlot = chart.get('backPlot');
|
16790 | var canvas = chart.get('canvas');
|
16791 | var canvasHeight = canvas.get('height');
|
16792 | var limitRange = chart.get('_limitRange');
|
16793 | var mode = scrollBarCfg.mode;
|
16794 |
|
16795 | if (Util.directionEnabled(mode, 'x')) {
|
16796 | var _scrollBarCfg$xStyle = scrollBarCfg.xStyle,
|
16797 | offsetX = _scrollBarCfg$xStyle.offsetX,
|
16798 | offsetY = _scrollBarCfg$xStyle.offsetY,
|
16799 | lineCap = _scrollBarCfg$xStyle.lineCap,
|
16800 | backgroundColor = _scrollBarCfg$xStyle.backgroundColor,
|
16801 | fillerColor = _scrollBarCfg$xStyle.fillerColor,
|
16802 | size = _scrollBarCfg$xStyle.size;
|
16803 | var xScale = chart.getXScale();
|
16804 | var xLimitRange = limitRange[xScale.field];
|
16805 |
|
16806 | if (!xLimitRange) {
|
16807 | xLimitRange = Helper.getLimitRange(data, xScale);
|
16808 | limitRange[xScale.field] = xLimitRange;
|
16809 | }
|
16810 |
|
16811 | var currentRange = Helper.getFieldRange(xScale, xLimitRange, xScale.type);
|
16812 | var horizontalBar = chart.get('_horizontalBar');
|
16813 | var yPos = canvasHeight - size / 2 + offsetY;
|
16814 |
|
16815 | if (horizontalBar) {
|
16816 | var progressLine = horizontalBar.get('children')[1];
|
16817 | progressLine.attr({
|
16818 | x1: Math.max(plotRange.bl.x + plotRange.width * currentRange[0] + offsetX, plotRange.bl.x),
|
16819 | x2: Math.min(plotRange.bl.x + plotRange.width * currentRange[1] + offsetX, plotRange.br.x)
|
16820 | });
|
16821 | } else {
|
16822 | horizontalBar = backPlot.addGroup({
|
16823 | className: 'horizontalBar'
|
16824 | });
|
16825 | horizontalBar.addShape('line', {
|
16826 | attrs: {
|
16827 | x1: plotRange.bl.x + offsetX,
|
16828 | y1: yPos,
|
16829 | x2: plotRange.br.x + offsetX,
|
16830 | y2: yPos,
|
16831 | lineWidth: size,
|
16832 | stroke: backgroundColor,
|
16833 | lineCap: lineCap
|
16834 | }
|
16835 | });
|
16836 | horizontalBar.addShape('line', {
|
16837 | attrs: {
|
16838 | x1: Math.max(plotRange.bl.x + plotRange.width * currentRange[0] + offsetX, plotRange.bl.x),
|
16839 | y1: yPos,
|
16840 | x2: Math.min(plotRange.bl.x + plotRange.width * currentRange[1] + offsetX, plotRange.br.x),
|
16841 | y2: yPos,
|
16842 | lineWidth: size,
|
16843 | stroke: fillerColor,
|
16844 | lineCap: lineCap
|
16845 | }
|
16846 | });
|
16847 | chart.set('_horizontalBar', horizontalBar);
|
16848 | }
|
16849 | }
|
16850 |
|
16851 | if (Util.directionEnabled(mode, 'y')) {
|
16852 | var _scrollBarCfg$yStyle = scrollBarCfg.yStyle,
|
16853 | _offsetX = _scrollBarCfg$yStyle.offsetX,
|
16854 | _offsetY = _scrollBarCfg$yStyle.offsetY,
|
16855 | _lineCap = _scrollBarCfg$yStyle.lineCap,
|
16856 | _backgroundColor = _scrollBarCfg$yStyle.backgroundColor,
|
16857 | _fillerColor = _scrollBarCfg$yStyle.fillerColor,
|
16858 | _size = _scrollBarCfg$yStyle.size;
|
16859 | var yScale = chart.getYScales()[0];
|
16860 | var yLimitRange = limitRange[yScale.field];
|
16861 |
|
16862 | if (!yLimitRange) {
|
16863 | yLimitRange = Helper.getLimitRange(data, yScale);
|
16864 | limitRange[yScale.field] = yLimitRange;
|
16865 | }
|
16866 |
|
16867 | var _currentRange = Helper.getFieldRange(yScale, yLimitRange, yScale.type);
|
16868 |
|
16869 | var verticalBar = chart.get('_verticalBar');
|
16870 | var xPos = _size / 2 + _offsetX;
|
16871 |
|
16872 | if (verticalBar) {
|
16873 | var _progressLine = verticalBar.get('children')[1];
|
16874 |
|
16875 | _progressLine.attr({
|
16876 | y1: Math.max(plotRange.tl.y + plotRange.height * _currentRange[0] + _offsetY, plotRange.tl.y),
|
16877 | y2: Math.min(plotRange.tl.y + plotRange.height * _currentRange[1] + _offsetY, plotRange.bl.y)
|
16878 | });
|
16879 | } else {
|
16880 | verticalBar = backPlot.addGroup({
|
16881 | className: 'verticalBar'
|
16882 | });
|
16883 | verticalBar.addShape('line', {
|
16884 | attrs: {
|
16885 | x1: xPos,
|
16886 | y1: plotRange.tl.y + _offsetY,
|
16887 | x2: xPos,
|
16888 | y2: plotRange.bl.y + _offsetY,
|
16889 | lineWidth: _size,
|
16890 | stroke: _backgroundColor,
|
16891 | lineCap: _lineCap
|
16892 | }
|
16893 | });
|
16894 | verticalBar.addShape('line', {
|
16895 | attrs: {
|
16896 | x1: xPos,
|
16897 | y1: Math.max(plotRange.tl.y + plotRange.height * _currentRange[0] + _offsetY, plotRange.tl.y),
|
16898 | x2: xPos,
|
16899 | y2: Math.min(plotRange.tl.y + plotRange.height * _currentRange[1] + _offsetY, plotRange.bl.y),
|
16900 | lineWidth: _size,
|
16901 | stroke: _fillerColor,
|
16902 | lineCap: _lineCap
|
16903 | }
|
16904 | });
|
16905 | chart.set('_verticalBar', verticalBar);
|
16906 | }
|
16907 | }
|
16908 | }
|
16909 | };
|
16910 |
|
16911 | }),
|
16912 |
|
16913 | (function(module, exports, __webpack_require__) {
|
16914 |
|
16915 | var Util = __webpack_require__(0);
|
16916 |
|
16917 | var _require = __webpack_require__(3),
|
16918 | Group = _require.Group;
|
16919 |
|
16920 | var DEFAULT_CFG = {
|
16921 | anchorOffset: 5,
|
16922 |
|
16923 | inflectionOffset: 15,
|
16924 |
|
16925 | sidePadding: 20,
|
16926 |
|
16927 | lineHeight: 32,
|
16928 |
|
16929 | adjustOffset: 15,
|
16930 |
|
16931 | skipOverlapLabels: false,
|
16932 |
|
16933 | triggerOn: 'touchstart',
|
16934 |
|
16935 | activeShape: false,
|
16936 |
|
16937 | activeStyle: {
|
16938 | offset: 1,
|
16939 | appendRadius: 8,
|
16940 | fillOpacity: 0.5
|
16941 | }
|
16942 | };
|
16943 |
|
16944 | function getEndPoint(center, angle, r) {
|
16945 | return {
|
16946 | x: center.x + r * Math.cos(angle),
|
16947 | y: center.y + r * Math.sin(angle)
|
16948 | };
|
16949 | }
|
16950 |
|
16951 |
|
16952 | function getMiddleAngle(startAngle, endAngle) {
|
16953 | if (endAngle < startAngle) {
|
16954 | endAngle += Math.PI * 2;
|
16955 | }
|
16956 |
|
16957 | return (endAngle + startAngle) / 2;
|
16958 | }
|
16959 |
|
16960 |
|
16961 | function isOverlap(label1, label2) {
|
16962 | var label1BBox = label1.getBBox();
|
16963 | var label2BBox = label2.getBBox();
|
16964 | 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);
|
16965 | }
|
16966 |
|
16967 | var controller =
|
16968 |
|
16969 | function () {
|
16970 | function controller(cfg) {
|
16971 | Util.mix(this, cfg);
|
16972 | var chart = this.chart;
|
16973 | this.canvasDom = chart.get('canvas').get('el');
|
16974 | }
|
16975 |
|
16976 | var _proto = controller.prototype;
|
16977 |
|
16978 | _proto.renderLabels = function renderLabels() {
|
16979 | var self = this;
|
16980 | var chart = self.chart,
|
16981 | pieLabelCfg = self.pieLabelCfg,
|
16982 | labelGroup = self.labelGroup;
|
16983 | var halves = [[],
|
16984 | []
|
16985 | ];
|
16986 |
|
16987 | var geom = chart.get('geoms')[0];
|
16988 | var shapes = geom.get('container').get('children');
|
16989 | var anchorOffset = pieLabelCfg.anchorOffset,
|
16990 | inflectionOffset = pieLabelCfg.inflectionOffset,
|
16991 | label1 = pieLabelCfg.label1,
|
16992 | label2 = pieLabelCfg.label2,
|
16993 | lineHeight = pieLabelCfg.lineHeight,
|
16994 | skipOverlapLabels = pieLabelCfg.skipOverlapLabels;
|
16995 | var coord = chart.get('coord');
|
16996 | var center = coord.center,
|
16997 | radius = coord.circleRadius;
|
16998 | shapes.forEach(function (shape) {
|
16999 | var _shape$_attrs$attrs = shape._attrs.attrs,
|
17000 | startAngle = _shape$_attrs$attrs.startAngle,
|
17001 | endAngle = _shape$_attrs$attrs.endAngle;
|
17002 | var middleAngle = getMiddleAngle(startAngle, endAngle);
|
17003 | var anchorPoint = getEndPoint(center, middleAngle, radius + anchorOffset);
|
17004 | var inflectionPoint = getEndPoint(center, middleAngle, radius + inflectionOffset);
|
17005 | var origin = shape.get('origin');
|
17006 | var _origin = origin._origin,
|
17007 | color = origin.color;
|
17008 | var label = {
|
17009 | _anchor: anchorPoint,
|
17010 | _inflection: inflectionPoint,
|
17011 | _data: _origin,
|
17012 | x: inflectionPoint.x,
|
17013 | y: inflectionPoint.y,
|
17014 | r: radius + inflectionOffset,
|
17015 | fill: color
|
17016 | };
|
17017 | var textGroup = new Group({
|
17018 | data: _origin
|
17019 |
|
17020 | });
|
17021 | var textAttrs = {
|
17022 | x: 0,
|
17023 | y: 0,
|
17024 | fontSize: 12,
|
17025 | lineHeight: 12,
|
17026 | fill: '#808080'
|
17027 | };
|
17028 |
|
17029 | if (Util.isFunction(label1)) {
|
17030 | textGroup.addShape('Text', {
|
17031 | attrs: Util.mix({
|
17032 | textBaseline: 'bottom'
|
17033 | }, textAttrs, label1(_origin, color)),
|
17034 | data: _origin
|
17035 |
|
17036 | });
|
17037 | }
|
17038 |
|
17039 | if (Util.isFunction(label2)) {
|
17040 | textGroup.addShape('Text', {
|
17041 | attrs: Util.mix({
|
17042 | textBaseline: 'top'
|
17043 | }, textAttrs, label2(_origin, color)),
|
17044 | data: _origin
|
17045 |
|
17046 | });
|
17047 | }
|
17048 |
|
17049 | label.textGroup = textGroup;
|
17050 |
|
17051 | if (anchorPoint.x < center.x) {
|
17052 | label._side = 'left';
|
17053 | halves[0].push(label);
|
17054 | } else {
|
17055 | label._side = 'right';
|
17056 | halves[1].push(label);
|
17057 | }
|
17058 | });
|
17059 | var drawnLabels = [];
|
17060 |
|
17061 | if (skipOverlapLabels) {
|
17062 | var lastLabel;
|
17063 |
|
17064 | var labels = halves[1].concat(halves[0]);
|
17065 |
|
17066 | for (var i = 0, len = labels.length; i < len; i++) {
|
17067 | var label = labels[i];
|
17068 |
|
17069 | var textGroup = self._drawLabel(label);
|
17070 |
|
17071 | if (lastLabel) {
|
17072 | if (isOverlap(textGroup, lastLabel)) {
|
17073 |
|
17074 | continue;
|
17075 | }
|
17076 | }
|
17077 |
|
17078 | labelGroup.add(textGroup);
|
17079 |
|
17080 | self._drawLabelLine(label);
|
17081 |
|
17082 | lastLabel = textGroup;
|
17083 | drawnLabels.push(textGroup);
|
17084 | }
|
17085 | } else {
|
17086 | var height = chart.get('height');
|
17087 | var maxCountForOneSide = parseInt(height / lineHeight, 10);
|
17088 | halves.forEach(function (half) {
|
17089 | if (half.length > maxCountForOneSide) {
|
17090 | half.splice(maxCountForOneSide, half.length - maxCountForOneSide);
|
17091 | }
|
17092 |
|
17093 | half.sort(function (a, b) {
|
17094 | return a.y - b.y;
|
17095 | });
|
17096 |
|
17097 | var labels = self._antiCollision(half);
|
17098 |
|
17099 | drawnLabels = drawnLabels.concat(labels);
|
17100 | });
|
17101 | }
|
17102 |
|
17103 | this.drawnLabels = drawnLabels;
|
17104 | };
|
17105 |
|
17106 | _proto.bindEvents = function bindEvents() {
|
17107 | var pieLabelCfg = this.pieLabelCfg;
|
17108 | var triggerOn = pieLabelCfg.triggerOn || 'touchstart';
|
17109 | var method = Util.wrapBehavior(this, '_handleEvent');
|
17110 | Util.addEventListener(this.canvasDom, triggerOn, method);
|
17111 | };
|
17112 |
|
17113 | _proto.unBindEvents = function unBindEvents() {
|
17114 | var pieLabelCfg = this.pieLabelCfg;
|
17115 | var triggerOn = pieLabelCfg.triggerOn || 'touchstart';
|
17116 | var method = Util.getWrapBehavior(this, '_handleEvent');
|
17117 | Util.removeEventListener(this.canvasDom, triggerOn, method);
|
17118 | };
|
17119 |
|
17120 | _proto.clear = function clear() {
|
17121 | this.labelGroup && this.labelGroup.clear();
|
17122 | this.halo && this.halo.remove(true);
|
17123 | this.lastSelectedData = null;
|
17124 | this.drawnLabels = [];
|
17125 | this.unBindEvents();
|
17126 | };
|
17127 |
|
17128 | _proto._drawLabel = function _drawLabel(label) {
|
17129 | var pieLabelCfg = this.pieLabelCfg,
|
17130 | chart = this.chart;
|
17131 | var canvasWidth = chart.get('width');
|
17132 | var sidePadding = pieLabelCfg.sidePadding;
|
17133 | var y = label.y,
|
17134 | textGroup = label.textGroup;
|
17135 | var children = textGroup.get('children');
|
17136 | var textAttrs = {
|
17137 | textAlign: label._side === 'left' ? 'left' : 'right',
|
17138 | x: label._side === 'left' ? sidePadding : canvasWidth - sidePadding,
|
17139 | y: y
|
17140 | };
|
17141 | children.forEach(function (child) {
|
17142 | child.attr(textAttrs);
|
17143 | });
|
17144 | return textGroup;
|
17145 | };
|
17146 |
|
17147 | _proto._drawLabelLine = function _drawLabelLine(label, maxLabelWidth) {
|
17148 | var chart = this.chart,
|
17149 | pieLabelCfg = this.pieLabelCfg,
|
17150 | labelGroup = this.labelGroup;
|
17151 | var canvasWidth = chart.get('width');
|
17152 | var sidePadding = pieLabelCfg.sidePadding,
|
17153 | adjustOffset = pieLabelCfg.adjustOffset,
|
17154 | lineStyle = pieLabelCfg.lineStyle,
|
17155 | anchorStyle = pieLabelCfg.anchorStyle,
|
17156 | skipOverlapLabels = pieLabelCfg.skipOverlapLabels;
|
17157 | var _anchor = label._anchor,
|
17158 | _inflection = label._inflection,
|
17159 | fill = label.fill,
|
17160 | y = label.y;
|
17161 | var lastPoint = {
|
17162 | x: label._side === 'left' ? sidePadding : canvasWidth - sidePadding,
|
17163 | y: y
|
17164 | };
|
17165 | var points = [_anchor, _inflection, lastPoint];
|
17166 |
|
17167 | if (!skipOverlapLabels && _inflection.y !== y) {
|
17168 |
|
17169 | if (_inflection.y < y) {
|
17170 |
|
17171 | var point1 = _inflection;
|
17172 | var point2 = {
|
17173 | x: label._side === 'left' ? lastPoint.x + maxLabelWidth + adjustOffset : lastPoint.x - maxLabelWidth - adjustOffset,
|
17174 | y: _inflection.y
|
17175 | };
|
17176 | var point3 = {
|
17177 | x: label._side === 'left' ? lastPoint.x + maxLabelWidth : lastPoint.x - maxLabelWidth,
|
17178 | y: lastPoint.y
|
17179 | };
|
17180 | points = [_anchor, point1, point2, point3, lastPoint];
|
17181 |
|
17182 | if (label._side === 'right' && point2.x < point1.x || label._side === 'left' && point2.x > point1.x) {
|
17183 | points = [_anchor, point3, lastPoint];
|
17184 | }
|
17185 | } else {
|
17186 | points = [_anchor, {
|
17187 | x: _inflection.x,
|
17188 | y: y
|
17189 | }, lastPoint];
|
17190 | }
|
17191 | }
|
17192 |
|
17193 | labelGroup.addShape('Polyline', {
|
17194 | attrs: Util.mix({
|
17195 | points: points,
|
17196 | lineWidth: 1,
|
17197 | stroke: fill
|
17198 | }, lineStyle)
|
17199 | });
|
17200 |
|
17201 | labelGroup.addShape('Circle', {
|
17202 | attrs: Util.mix({
|
17203 | x: _anchor.x,
|
17204 | y: _anchor.y,
|
17205 | r: 2,
|
17206 | fill: fill
|
17207 | }, anchorStyle)
|
17208 | });
|
17209 | };
|
17210 |
|
17211 | _proto._antiCollision = function _antiCollision(half) {
|
17212 | var self = this;
|
17213 | var chart = self.chart,
|
17214 | pieLabelCfg = self.pieLabelCfg;
|
17215 | var coord = chart.get('coord');
|
17216 | var canvasHeight = chart.get('height');
|
17217 | var center = coord.center,
|
17218 | r = coord.circleRadius;
|
17219 | var inflectionOffset = pieLabelCfg.inflectionOffset,
|
17220 | lineHeight = pieLabelCfg.lineHeight;
|
17221 | var startY = center.y - r - inflectionOffset - lineHeight;
|
17222 | var overlapping = true;
|
17223 | var totalH = canvasHeight;
|
17224 | var i;
|
17225 | var maxY = 0;
|
17226 | var minY = Number.MIN_VALUE;
|
17227 | var maxLabelWidth = 0;
|
17228 | var boxes = half.map(function (label) {
|
17229 | var labelY = label.y;
|
17230 |
|
17231 | if (labelY > maxY) {
|
17232 | maxY = labelY;
|
17233 | }
|
17234 |
|
17235 | if (labelY < minY) {
|
17236 | minY = labelY;
|
17237 | }
|
17238 |
|
17239 | var textGroup = label.textGroup;
|
17240 | var labelWidth = textGroup.getBBox().width;
|
17241 |
|
17242 | if (labelWidth >= maxLabelWidth) {
|
17243 | maxLabelWidth = labelWidth;
|
17244 | }
|
17245 |
|
17246 | return {
|
17247 | size: lineHeight,
|
17248 | targets: [labelY - startY]
|
17249 | };
|
17250 | });
|
17251 |
|
17252 | if (maxY - startY > totalH) {
|
17253 | totalH = maxY - startY;
|
17254 | }
|
17255 |
|
17256 | var iteratorBoxed = function iteratorBoxed(boxes) {
|
17257 | boxes.forEach(function (box) {
|
17258 | var target = (Math.min.apply(minY, box.targets) + Math.max.apply(minY, box.targets)) / 2;
|
17259 | box.pos = Math.min(Math.max(minY, target - box.size / 2), totalH - box.size);
|
17260 | });
|
17261 | };
|
17262 |
|
17263 | while (overlapping) {
|
17264 | iteratorBoxed(boxes);
|
17265 |
|
17266 | overlapping = false;
|
17267 | i = boxes.length;
|
17268 |
|
17269 | while (i--) {
|
17270 | if (i > 0) {
|
17271 | var previousBox = boxes[i - 1];
|
17272 | var box = boxes[i];
|
17273 |
|
17274 | if (previousBox.pos + previousBox.size > box.pos) {
|
17275 |
|
17276 | previousBox.size += box.size;
|
17277 | previousBox.targets = previousBox.targets.concat(box.targets);
|
17278 |
|
17279 | if (previousBox.pos + previousBox.size > totalH) {
|
17280 | previousBox.pos = totalH - previousBox.size;
|
17281 | }
|
17282 |
|
17283 | boxes.splice(i, 1);
|
17284 |
|
17285 | overlapping = true;
|
17286 | }
|
17287 | }
|
17288 | }
|
17289 | }
|
17290 |
|
17291 | i = 0;
|
17292 | boxes.forEach(function (b) {
|
17293 | var posInCompositeBox = startY;
|
17294 |
|
17295 | b.targets.forEach(function () {
|
17296 | half[i].y = b.pos + posInCompositeBox + lineHeight / 2;
|
17297 | posInCompositeBox += lineHeight;
|
17298 | i++;
|
17299 | });
|
17300 | });
|
17301 | var drawnLabels = [];
|
17302 | half.forEach(function (label) {
|
17303 | var textGroup = self._drawLabel(label);
|
17304 |
|
17305 | var labelGroup = self.labelGroup;
|
17306 | labelGroup.add(textGroup);
|
17307 |
|
17308 | self._drawLabelLine(label, maxLabelWidth);
|
17309 |
|
17310 | drawnLabels.push(textGroup);
|
17311 | });
|
17312 | return drawnLabels;
|
17313 | };
|
17314 |
|
17315 | _proto._handleEvent = function _handleEvent(ev) {
|
17316 | var self = this;
|
17317 | var chart = self.chart,
|
17318 | drawnLabels = self.drawnLabels,
|
17319 | pieLabelCfg = self.pieLabelCfg;
|
17320 | var onClick = pieLabelCfg.onClick,
|
17321 | activeShape = pieLabelCfg.activeShape;
|
17322 | var canvasEvent = Util.createEvent(ev, chart);
|
17323 | var x = canvasEvent.x,
|
17324 | y = canvasEvent.y;
|
17325 |
|
17326 | var clickedShape;
|
17327 |
|
17328 | for (var i = 0, len = drawnLabels.length; i < len; i++) {
|
17329 | var shape = drawnLabels[i];
|
17330 | var bbox = shape.getBBox();
|
17331 |
|
17332 | if (x >= bbox.minX && x <= bbox.maxX && y >= bbox.minY && y <= bbox.maxY) {
|
17333 | clickedShape = shape;
|
17334 | break;
|
17335 | }
|
17336 | }
|
17337 |
|
17338 | var pieData = chart.getSnapRecords({
|
17339 | x: x,
|
17340 | y: y
|
17341 | });
|
17342 |
|
17343 | if (clickedShape) {
|
17344 | canvasEvent.data = clickedShape.get('data');
|
17345 | } else if (pieData.length) {
|
17346 |
|
17347 | canvasEvent.data = pieData[0]._origin;
|
17348 | }
|
17349 |
|
17350 | onClick && onClick(canvasEvent);
|
17351 | canvasEvent.data && activeShape && this._activeShape(canvasEvent.data);
|
17352 | };
|
17353 |
|
17354 | _proto._getSelectedShapeByData = function _getSelectedShapeByData(data) {
|
17355 | var selectedShape = null;
|
17356 | var chart = this.chart;
|
17357 | var geom = chart.get('geoms')[0];
|
17358 | var container = geom.get('container');
|
17359 | var children = container.get('children');
|
17360 | Util.each(children, function (child) {
|
17361 | if (child.get('isShape') && child.get('className') === geom.get('type')) {
|
17362 |
|
17363 | var shapeData = child.get('origin')._origin;
|
17364 |
|
17365 | if (Util.isObjectValueEqual(shapeData, data)) {
|
17366 | selectedShape = child;
|
17367 | return false;
|
17368 | }
|
17369 | }
|
17370 | });
|
17371 | return selectedShape;
|
17372 | };
|
17373 |
|
17374 | _proto._activeShape = function _activeShape(data) {
|
17375 | var chart = this.chart,
|
17376 | lastSelectedData = this.lastSelectedData,
|
17377 | pieLabelCfg = this.pieLabelCfg;
|
17378 |
|
17379 | if (data === lastSelectedData) {
|
17380 | return;
|
17381 | }
|
17382 |
|
17383 | this.lastSelectedData = data;
|
17384 | var activeStyle = pieLabelCfg.activeStyle;
|
17385 |
|
17386 | var selectedShape = this._getSelectedShapeByData(data);
|
17387 |
|
17388 | var _selectedShape$_attrs = selectedShape._attrs.attrs,
|
17389 | x = _selectedShape$_attrs.x,
|
17390 | y = _selectedShape$_attrs.y,
|
17391 | startAngle = _selectedShape$_attrs.startAngle,
|
17392 | endAngle = _selectedShape$_attrs.endAngle,
|
17393 | r = _selectedShape$_attrs.r,
|
17394 | fill = _selectedShape$_attrs.fill;
|
17395 | var frontPlot = chart.get('frontPlot');
|
17396 | this.halo && this.halo.remove(true);
|
17397 | var halo = frontPlot.addShape('sector', {
|
17398 | attrs: Util.mix({
|
17399 | x: x,
|
17400 | y: y,
|
17401 | r: r + activeStyle.offset + activeStyle.appendRadius,
|
17402 | r0: r + activeStyle.offset,
|
17403 | fill: fill,
|
17404 | startAngle: startAngle,
|
17405 | endAngle: endAngle
|
17406 | }, activeStyle)
|
17407 | });
|
17408 | this.halo = halo;
|
17409 | chart.get('canvas').draw();
|
17410 | };
|
17411 |
|
17412 | return controller;
|
17413 | }();
|
17414 |
|
17415 | module.exports = {
|
17416 | init: function init(chart) {
|
17417 | var frontPlot = chart.get('frontPlot');
|
17418 | var labelGroup = frontPlot.addGroup({
|
17419 | className: 'pie-label',
|
17420 | zIndex: 0
|
17421 | });
|
17422 | var pieLabelController = new controller({
|
17423 | chart: chart,
|
17424 | labelGroup: labelGroup
|
17425 | });
|
17426 | chart.set('pieLabelController', pieLabelController);
|
17427 |
|
17428 | chart.pieLabel = function (cfg) {
|
17429 | cfg = Util.deepMix({}, DEFAULT_CFG, cfg);
|
17430 | pieLabelController.pieLabelCfg = cfg;
|
17431 | return this;
|
17432 | };
|
17433 | },
|
17434 | afterGeomDraw: function afterGeomDraw(chart) {
|
17435 | var controller = chart.get('pieLabelController');
|
17436 |
|
17437 | if (controller.pieLabelCfg) {
|
17438 |
|
17439 | controller.renderLabels();
|
17440 | controller.bindEvents();
|
17441 | }
|
17442 | },
|
17443 | clearInner: function clearInner(chart) {
|
17444 | var controller = chart.get('pieLabelController');
|
17445 |
|
17446 | if (controller.pieLabelCfg) {
|
17447 |
|
17448 | controller.clear();
|
17449 | }
|
17450 | }
|
17451 | };
|
17452 |
|
17453 | }),
|
17454 |
|
17455 | (function(module, exports, __webpack_require__) {
|
17456 |
|
17457 | function _inheritsLoose(subClass, superClass) {
|
17458 | subClass.prototype = Object.create(superClass.prototype);
|
17459 | subClass.prototype.constructor = subClass;
|
17460 | subClass.__proto__ = superClass;
|
17461 | }
|
17462 |
|
17463 | function _assertThisInitialized(self) {
|
17464 | if (self === void 0) {
|
17465 | throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
17466 | }
|
17467 |
|
17468 | return self;
|
17469 | }
|
17470 |
|
17471 | var Util = __webpack_require__(0);
|
17472 |
|
17473 | var Interaction = __webpack_require__(22);
|
17474 |
|
17475 | var Chart = __webpack_require__(12);
|
17476 |
|
17477 | var PieSelect =
|
17478 |
|
17479 | function (_Interaction) {
|
17480 | _inheritsLoose(PieSelect, _Interaction);
|
17481 |
|
17482 | var _proto = PieSelect.prototype;
|
17483 |
|
17484 | _proto.getDefaultCfg = function getDefaultCfg() {
|
17485 | var defaultCfg = _Interaction.prototype.getDefaultCfg.call(this);
|
17486 |
|
17487 | defaultCfg = Util.mix({}, defaultCfg, {
|
17488 | startEvent: 'tap',
|
17489 | processEvent: null,
|
17490 | animate: false,
|
17491 | offset: 1,
|
17492 | appendRadius: 8,
|
17493 | style: {
|
17494 | fillOpacity: 0.5
|
17495 | },
|
17496 | cancelable: true,
|
17497 | defaultSelected: null
|
17498 |
|
17499 | });
|
17500 |
|
17501 | if (Util.isWx || Util.isMy) {
|
17502 |
|
17503 | defaultCfg.startEvent = 'touchstart';
|
17504 | defaultCfg.endEvent = 'touchend';
|
17505 | }
|
17506 |
|
17507 | return defaultCfg;
|
17508 | };
|
17509 |
|
17510 | function PieSelect(cfg, chart) {
|
17511 | var _this;
|
17512 |
|
17513 | _this = _Interaction.call(this, cfg, chart) || this;
|
17514 |
|
17515 | var self = _assertThisInitialized(_assertThisInitialized(_this));
|
17516 |
|
17517 | chart.registerPlugins({
|
17518 | clearInner: function clearInner() {
|
17519 | self.halo && self.halo.remove(true);
|
17520 | self.selected = false;
|
17521 | self.selectedShape = null;
|
17522 | self.lastShape = null;
|
17523 | self.halo = null;
|
17524 | self.defaultSelected = null;
|
17525 | }
|
17526 | });
|
17527 | var defaultSelected = self.defaultSelected;
|
17528 |
|
17529 | if (Util.isObject(defaultSelected)) {
|
17530 | var selectedShape = self._getSelectedShapeByData(defaultSelected);
|
17531 |
|
17532 | selectedShape && self._selectedShape(selectedShape);
|
17533 |
|
17534 | _this.canvas.draw();
|
17535 | }
|
17536 |
|
17537 | return _this;
|
17538 | }
|
17539 |
|
17540 | _proto._getSelectedShapeByData = function _getSelectedShapeByData(data) {
|
17541 | var selectedShape = null;
|
17542 | var chart = this.chart;
|
17543 | var geom = chart.get('geoms')[0];
|
17544 | var container = geom.get('container');
|
17545 | var children = container.get('children');
|
17546 | Util.each(children, function (child) {
|
17547 | if (child.get('isShape') && child.get('className') === geom.get('type')) {
|
17548 |
|
17549 | var shapeData = child.get('origin')._origin;
|
17550 |
|
17551 | if (Util.isObjectValueEqual(shapeData, data)) {
|
17552 | selectedShape = child;
|
17553 | return false;
|
17554 | }
|
17555 | }
|
17556 | });
|
17557 | return selectedShape;
|
17558 | };
|
17559 |
|
17560 | _proto._selectedShape = function _selectedShape(selectedShape) {
|
17561 | var offset = this.offset,
|
17562 | style = this.style,
|
17563 | appendRadius = this.appendRadius,
|
17564 | chart = this.chart;
|
17565 | this.lastShape = selectedShape;
|
17566 | var _selectedShape$_attrs = selectedShape._attrs.attrs,
|
17567 | x = _selectedShape$_attrs.x,
|
17568 | y = _selectedShape$_attrs.y,
|
17569 | startAngle = _selectedShape$_attrs.startAngle,
|
17570 | endAngle = _selectedShape$_attrs.endAngle,
|
17571 | r = _selectedShape$_attrs.r,
|
17572 | fill = _selectedShape$_attrs.fill;
|
17573 | var frontPlot = chart.get('frontPlot');
|
17574 | var halo = frontPlot.addShape('sector', {
|
17575 | attrs: Util.mix({
|
17576 | x: x,
|
17577 | y: y,
|
17578 | r: r + offset + appendRadius,
|
17579 | r0: r + offset,
|
17580 | fill: fill,
|
17581 | startAngle: startAngle,
|
17582 | endAngle: endAngle
|
17583 | }, style)
|
17584 | });
|
17585 | this.halo = halo;
|
17586 | var animate = this.animate;
|
17587 |
|
17588 | if (animate) {
|
17589 | if (animate === true) {
|
17590 | animate = {
|
17591 | duration: 300
|
17592 | };
|
17593 | }
|
17594 |
|
17595 | halo.attr('r', r + offset);
|
17596 | halo.animate().to(Util.mix({
|
17597 | attrs: {
|
17598 | r: r + offset + appendRadius
|
17599 | }
|
17600 | }, animate));
|
17601 | }
|
17602 | };
|
17603 |
|
17604 | _proto.start = function start(ev) {
|
17605 | var chart = this.chart;
|
17606 |
|
17607 | if (ev.type === 'tap') {
|
17608 | ev.clientX = ev.center.x;
|
17609 | ev.clientY = ev.center.y;
|
17610 | }
|
17611 |
|
17612 | var _Util$createEvent = Util.createEvent(ev, chart),
|
17613 | x = _Util$createEvent.x,
|
17614 | y = _Util$createEvent.y;
|
17615 |
|
17616 | this.halo && this.halo.remove(true);
|
17617 | var records = chart.getSnapRecords({
|
17618 | x: x,
|
17619 | y: y
|
17620 | });
|
17621 |
|
17622 | if (!records.length) {
|
17623 | this.selected = false;
|
17624 | this.selectedShape = null;
|
17625 | return;
|
17626 | }
|
17627 |
|
17628 | var data = records[0]._origin;
|
17629 |
|
17630 | var selectedShape = this._getSelectedShapeByData(data);
|
17631 |
|
17632 | var lastShape = this.lastShape;
|
17633 | this.selectedShape = selectedShape;
|
17634 | this.selected = true;
|
17635 |
|
17636 | if (selectedShape === lastShape) {
|
17637 | if (!this.cancelable) {
|
17638 | return;
|
17639 | }
|
17640 |
|
17641 | this.halo && this.halo.remove(true);
|
17642 | this.lastShape = null;
|
17643 | this.selected = false;
|
17644 | } else {
|
17645 | this._selectedShape(selectedShape);
|
17646 | }
|
17647 |
|
17648 | this.canvas.draw();
|
17649 | };
|
17650 |
|
17651 | _proto.end = function end(ev) {
|
17652 | var selectedShape = this.selectedShape;
|
17653 |
|
17654 | if (selectedShape && !selectedShape.get('destroyed')) {
|
17655 | ev.data = selectedShape.get('origin')._origin;
|
17656 | ev.shapeInfo = selectedShape.get('origin');
|
17657 | ev.shape = selectedShape;
|
17658 | ev.selected = !!this.selected;
|
17659 | }
|
17660 | };
|
17661 |
|
17662 | return PieSelect;
|
17663 | }(Interaction);
|
17664 |
|
17665 | Chart.registerInteraction('pie-select', PieSelect);
|
17666 | module.exports = PieSelect;
|
17667 |
|
17668 | }),
|
17669 |
|
17670 | (function(module, exports, __webpack_require__) {
|
17671 |
|
17672 | var __WEBPACK_AMD_DEFINE_RESULT__; |
17673 |
|
17674 |
|
17675 |
|
17676 |
|
17677 | (function (window, document, exportName, undefined) {
|
17678 | 'use strict';
|
17679 |
|
17680 | var VENDOR_PREFIXES = ['', 'webkit', 'Moz', 'MS', 'ms', 'o'];
|
17681 | var TEST_ELEMENT = document.createElement('div');
|
17682 | var TYPE_FUNCTION = 'function';
|
17683 | var round = Math.round;
|
17684 | var abs = Math.abs;
|
17685 | var now = Date.now;
|
17686 | |
17687 |
|
17688 |
|
17689 |
|
17690 |
|
17691 |
|
17692 |
|
17693 |
|
17694 | function setTimeoutContext(fn, timeout, context) {
|
17695 | return setTimeout(bindFn(fn, context), timeout);
|
17696 | }
|
17697 | |
17698 |
|
17699 |
|
17700 |
|
17701 |
|
17702 |
|
17703 |
|
17704 |
|
17705 |
|
17706 |
|
17707 |
|
17708 | function invokeArrayArg(arg, fn, context) {
|
17709 | if (Array.isArray(arg)) {
|
17710 | each(arg, context[fn], context);
|
17711 | return true;
|
17712 | }
|
17713 |
|
17714 | return false;
|
17715 | }
|
17716 | |
17717 |
|
17718 |
|
17719 |
|
17720 |
|
17721 |
|
17722 |
|
17723 |
|
17724 | function each(obj, iterator, context) {
|
17725 | var i;
|
17726 |
|
17727 | if (!obj) {
|
17728 | return;
|
17729 | }
|
17730 |
|
17731 | if (obj.forEach) {
|
17732 | obj.forEach(iterator, context);
|
17733 | } else if (obj.length !== undefined) {
|
17734 | i = 0;
|
17735 |
|
17736 | while (i < obj.length) {
|
17737 | iterator.call(context, obj[i], i, obj);
|
17738 | i++;
|
17739 | }
|
17740 | } else {
|
17741 | for (i in obj) {
|
17742 | obj.hasOwnProperty(i) && iterator.call(context, obj[i], i, obj);
|
17743 | }
|
17744 | }
|
17745 | }
|
17746 | |
17747 |
|
17748 |
|
17749 |
|
17750 |
|
17751 |
|
17752 |
|
17753 |
|
17754 |
|
17755 | function deprecate(method, name, message) {
|
17756 | var deprecationMessage = 'DEPRECATED METHOD: ' + name + '\n' + message + ' AT \n';
|
17757 | return function () {
|
17758 | var e = new Error('get-stack-trace');
|
17759 | var stack = e && e.stack ? e.stack.replace(/^[^\(]+?[\n$]/gm, '').replace(/^\s+at\s+/gm, '').replace(/^Object.<anonymous>\s*\(/gm, '{anonymous}()@') : 'Unknown Stack Trace';
|
17760 | var log = window.console && (window.console.warn || window.console.log);
|
17761 |
|
17762 | if (log) {
|
17763 | log.call(window.console, deprecationMessage, stack);
|
17764 | }
|
17765 |
|
17766 | return method.apply(this, arguments);
|
17767 | };
|
17768 | }
|
17769 | |
17770 |
|
17771 |
|
17772 |
|
17773 |
|
17774 |
|
17775 |
|
17776 |
|
17777 |
|
17778 | var assign;
|
17779 |
|
17780 | if (typeof Object.assign !== 'function') {
|
17781 | assign = function assign(target) {
|
17782 | if (target === undefined || target === null) {
|
17783 | throw new TypeError('Cannot convert undefined or null to object');
|
17784 | }
|
17785 |
|
17786 | var output = Object(target);
|
17787 |
|
17788 | for (var index = 1; index < arguments.length; index++) {
|
17789 | var source = arguments[index];
|
17790 |
|
17791 | if (source !== undefined && source !== null) {
|
17792 | for (var nextKey in source) {
|
17793 | if (source.hasOwnProperty(nextKey)) {
|
17794 | output[nextKey] = source[nextKey];
|
17795 | }
|
17796 | }
|
17797 | }
|
17798 | }
|
17799 |
|
17800 | return output;
|
17801 | };
|
17802 | } else {
|
17803 | assign = Object.assign;
|
17804 | }
|
17805 | |
17806 |
|
17807 |
|
17808 |
|
17809 |
|
17810 |
|
17811 |
|
17812 |
|
17813 |
|
17814 |
|
17815 | var extend = deprecate(function extend(dest, src, merge) {
|
17816 | var keys = Object.keys(src);
|
17817 | var i = 0;
|
17818 |
|
17819 | while (i < keys.length) {
|
17820 | if (!merge || merge && dest[keys[i]] === undefined) {
|
17821 | dest[keys[i]] = src[keys[i]];
|
17822 | }
|
17823 |
|
17824 | i++;
|
17825 | }
|
17826 |
|
17827 | return dest;
|
17828 | }, 'extend', 'Use `assign`.');
|
17829 | |
17830 |
|
17831 |
|
17832 |
|
17833 |
|
17834 |
|
17835 |
|
17836 |
|
17837 | var merge = deprecate(function merge(dest, src) {
|
17838 | return extend(dest, src, true);
|
17839 | }, 'merge', 'Use `assign`.');
|
17840 | |
17841 |
|
17842 |
|
17843 |
|
17844 |
|
17845 |
|
17846 |
|
17847 | function inherit(child, base, properties) {
|
17848 | var baseP = base.prototype,
|
17849 | childP;
|
17850 | childP = child.prototype = Object.create(baseP);
|
17851 | childP.constructor = child;
|
17852 | childP._super = baseP;
|
17853 |
|
17854 | if (properties) {
|
17855 | assign(childP, properties);
|
17856 | }
|
17857 | }
|
17858 | |
17859 |
|
17860 |
|
17861 |
|
17862 |
|
17863 |
|
17864 |
|
17865 |
|
17866 | function bindFn(fn, context) {
|
17867 | return function boundFn() {
|
17868 | return fn.apply(context, arguments);
|
17869 | };
|
17870 | }
|
17871 | |
17872 |
|
17873 |
|
17874 |
|
17875 |
|
17876 |
|
17877 |
|
17878 |
|
17879 |
|
17880 | function boolOrFn(val, args) {
|
17881 | if (typeof val == TYPE_FUNCTION) {
|
17882 | return val.apply(args ? args[0] || undefined : undefined, args);
|
17883 | }
|
17884 |
|
17885 | return val;
|
17886 | }
|
17887 | |
17888 |
|
17889 |
|
17890 |
|
17891 |
|
17892 |
|
17893 |
|
17894 |
|
17895 | function ifUndefined(val1, val2) {
|
17896 | return val1 === undefined ? val2 : val1;
|
17897 | }
|
17898 | |
17899 |
|
17900 |
|
17901 |
|
17902 |
|
17903 |
|
17904 |
|
17905 |
|
17906 | function addEventListeners(target, types, handler) {
|
17907 | each(splitStr(types), function (type) {
|
17908 | target.addEventListener(type, handler, false);
|
17909 | });
|
17910 | }
|
17911 | |
17912 |
|
17913 |
|
17914 |
|
17915 |
|
17916 |
|
17917 |
|
17918 |
|
17919 | function removeEventListeners(target, types, handler) {
|
17920 | each(splitStr(types), function (type) {
|
17921 | target.removeEventListener(type, handler, false);
|
17922 | });
|
17923 | }
|
17924 | |
17925 |
|
17926 |
|
17927 |
|
17928 |
|
17929 |
|
17930 |
|
17931 |
|
17932 |
|
17933 | function hasParent(node, parent) {
|
17934 | while (node) {
|
17935 | if (node == parent) {
|
17936 | return true;
|
17937 | }
|
17938 |
|
17939 | node = node.parentNode;
|
17940 | }
|
17941 |
|
17942 | return false;
|
17943 | }
|
17944 | |
17945 |
|
17946 |
|
17947 |
|
17948 |
|
17949 |
|
17950 |
|
17951 |
|
17952 | function inStr(str, find) {
|
17953 | return str.indexOf(find) > -1;
|
17954 | }
|
17955 | |
17956 |
|
17957 |
|
17958 |
|
17959 |
|
17960 |
|
17961 |
|
17962 | function splitStr(str) {
|
17963 | return str.trim().split(/\s+/g);
|
17964 | }
|
17965 | |
17966 |
|
17967 |
|
17968 |
|
17969 |
|
17970 |
|
17971 |
|
17972 |
|
17973 |
|
17974 | function inArray(src, find, findByKey) {
|
17975 | if (src.indexOf && !findByKey) {
|
17976 | return src.indexOf(find);
|
17977 | } else {
|
17978 | var i = 0;
|
17979 |
|
17980 | while (i < src.length) {
|
17981 | if (findByKey && src[i][findByKey] == find || !findByKey && src[i] === find) {
|
17982 | return i;
|
17983 | }
|
17984 |
|
17985 | i++;
|
17986 | }
|
17987 |
|
17988 | return -1;
|
17989 | }
|
17990 | }
|
17991 | |
17992 |
|
17993 |
|
17994 |
|
17995 |
|
17996 |
|
17997 |
|
17998 | function toArray(obj) {
|
17999 | return Array.prototype.slice.call(obj, 0);
|
18000 | }
|
18001 | |
18002 |
|
18003 |
|
18004 |
|
18005 |
|
18006 |
|
18007 |
|
18008 |
|
18009 |
|
18010 | function uniqueArray(src, key, sort) {
|
18011 | var results = [];
|
18012 | var values = [];
|
18013 | var i = 0;
|
18014 |
|
18015 | while (i < src.length) {
|
18016 | var val = key ? src[i][key] : src[i];
|
18017 |
|
18018 | if (inArray(values, val) < 0) {
|
18019 | results.push(src[i]);
|
18020 | }
|
18021 |
|
18022 | values[i] = val;
|
18023 | i++;
|
18024 | }
|
18025 |
|
18026 | if (sort) {
|
18027 | if (!key) {
|
18028 | results = results.sort();
|
18029 | } else {
|
18030 | results = results.sort(function sortUniqueArray(a, b) {
|
18031 | return a[key] > b[key];
|
18032 | });
|
18033 | }
|
18034 | }
|
18035 |
|
18036 | return results;
|
18037 | }
|
18038 | |
18039 |
|
18040 |
|
18041 |
|
18042 |
|
18043 |
|
18044 |
|
18045 |
|
18046 | function prefixed(obj, property) {
|
18047 | var prefix, prop;
|
18048 | var camelProp = property[0].toUpperCase() + property.slice(1);
|
18049 | var i = 0;
|
18050 |
|
18051 | while (i < VENDOR_PREFIXES.length) {
|
18052 | prefix = VENDOR_PREFIXES[i];
|
18053 | prop = prefix ? prefix + camelProp : property;
|
18054 |
|
18055 | if (prop in obj) {
|
18056 | return prop;
|
18057 | }
|
18058 |
|
18059 | i++;
|
18060 | }
|
18061 |
|
18062 | return undefined;
|
18063 | }
|
18064 | |
18065 |
|
18066 |
|
18067 |
|
18068 |
|
18069 |
|
18070 | var _uniqueId = 1;
|
18071 |
|
18072 | function uniqueId() {
|
18073 | return _uniqueId++;
|
18074 | }
|
18075 | |
18076 |
|
18077 |
|
18078 |
|
18079 |
|
18080 |
|
18081 |
|
18082 | function getWindowForElement(element) {
|
18083 | var doc = element.ownerDocument || element;
|
18084 | return doc.defaultView || doc.parentWindow || window;
|
18085 | }
|
18086 |
|
18087 | var MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;
|
18088 | var SUPPORT_TOUCH = 'ontouchstart' in window;
|
18089 | var SUPPORT_POINTER_EVENTS = prefixed(window, 'PointerEvent') !== undefined;
|
18090 | var SUPPORT_ONLY_TOUCH = SUPPORT_TOUCH && MOBILE_REGEX.test(navigator.userAgent);
|
18091 | var INPUT_TYPE_TOUCH = 'touch';
|
18092 | var INPUT_TYPE_PEN = 'pen';
|
18093 | var INPUT_TYPE_MOUSE = 'mouse';
|
18094 | var INPUT_TYPE_KINECT = 'kinect';
|
18095 | var COMPUTE_INTERVAL = 25;
|
18096 | var INPUT_START = 1;
|
18097 | var INPUT_MOVE = 2;
|
18098 | var INPUT_END = 4;
|
18099 | var INPUT_CANCEL = 8;
|
18100 | var DIRECTION_NONE = 1;
|
18101 | var DIRECTION_LEFT = 2;
|
18102 | var DIRECTION_RIGHT = 4;
|
18103 | var DIRECTION_UP = 8;
|
18104 | var DIRECTION_DOWN = 16;
|
18105 | var DIRECTION_HORIZONTAL = DIRECTION_LEFT | DIRECTION_RIGHT;
|
18106 | var DIRECTION_VERTICAL = DIRECTION_UP | DIRECTION_DOWN;
|
18107 | var DIRECTION_ALL = DIRECTION_HORIZONTAL | DIRECTION_VERTICAL;
|
18108 | var PROPS_XY = ['x', 'y'];
|
18109 | var PROPS_CLIENT_XY = ['clientX', 'clientY'];
|
18110 | |
18111 |
|
18112 |
|
18113 |
|
18114 |
|
18115 |
|
18116 |
|
18117 |
|
18118 | function Input(manager, callback) {
|
18119 | var self = this;
|
18120 | this.manager = manager;
|
18121 | this.callback = callback;
|
18122 | this.element = manager.element;
|
18123 | this.target = manager.options.inputTarget;
|
18124 |
|
18125 |
|
18126 | this.domHandler = function (ev) {
|
18127 | if (boolOrFn(manager.options.enable, [manager])) {
|
18128 | self.handler(ev);
|
18129 | }
|
18130 | };
|
18131 |
|
18132 | this.init();
|
18133 | }
|
18134 |
|
18135 | Input.prototype = {
|
18136 | |
18137 |
|
18138 |
|
18139 |
|
18140 | handler: function () {},
|
18141 |
|
18142 | |
18143 |
|
18144 |
|
18145 | init: function () {
|
18146 | this.evEl && addEventListeners(this.element, this.evEl, this.domHandler);
|
18147 | this.evTarget && addEventListeners(this.target, this.evTarget, this.domHandler);
|
18148 | this.evWin && addEventListeners(getWindowForElement(this.element), this.evWin, this.domHandler);
|
18149 | },
|
18150 |
|
18151 | |
18152 |
|
18153 |
|
18154 | destroy: function () {
|
18155 | this.evEl && removeEventListeners(this.element, this.evEl, this.domHandler);
|
18156 | this.evTarget && removeEventListeners(this.target, this.evTarget, this.domHandler);
|
18157 | this.evWin && removeEventListeners(getWindowForElement(this.element), this.evWin, this.domHandler);
|
18158 | }
|
18159 | };
|
18160 | |
18161 |
|
18162 |
|
18163 |
|
18164 |
|
18165 |
|
18166 |
|
18167 | function createInputInstance(manager) {
|
18168 | var Type;
|
18169 | var inputClass = manager.options.inputClass;
|
18170 |
|
18171 | if (inputClass) {
|
18172 | Type = inputClass;
|
18173 | } else if (SUPPORT_POINTER_EVENTS) {
|
18174 | Type = PointerEventInput;
|
18175 | } else if (SUPPORT_ONLY_TOUCH) {
|
18176 | Type = TouchInput;
|
18177 | } else if (!SUPPORT_TOUCH) {
|
18178 | Type = MouseInput;
|
18179 | } else {
|
18180 | Type = TouchMouseInput;
|
18181 | }
|
18182 |
|
18183 | return new Type(manager, inputHandler);
|
18184 | }
|
18185 | |
18186 |
|
18187 |
|
18188 |
|
18189 |
|
18190 |
|
18191 |
|
18192 |
|
18193 | function inputHandler(manager, eventType, input) {
|
18194 | var pointersLen = input.pointers.length;
|
18195 | var changedPointersLen = input.changedPointers.length;
|
18196 | var isFirst = eventType & INPUT_START && pointersLen - changedPointersLen === 0;
|
18197 | var isFinal = eventType & (INPUT_END | INPUT_CANCEL) && pointersLen - changedPointersLen === 0;
|
18198 | input.isFirst = !!isFirst;
|
18199 | input.isFinal = !!isFinal;
|
18200 |
|
18201 | if (isFirst) {
|
18202 | manager.session = {};
|
18203 | }
|
18204 |
|
18205 |
|
18206 |
|
18207 | input.eventType = eventType;
|
18208 |
|
18209 | computeInputData(manager, input);
|
18210 |
|
18211 | manager.emit('hammer.input', input);
|
18212 | manager.recognize(input);
|
18213 | manager.session.prevInput = input;
|
18214 | }
|
18215 | |
18216 |
|
18217 |
|
18218 |
|
18219 |
|
18220 |
|
18221 |
|
18222 | function computeInputData(manager, input) {
|
18223 | var session = manager.session;
|
18224 | var pointers = input.pointers;
|
18225 | var pointersLength = pointers.length;
|
18226 |
|
18227 | if (!session.firstInput) {
|
18228 | session.firstInput = simpleCloneInputData(input);
|
18229 | }
|
18230 |
|
18231 |
|
18232 | if (pointersLength > 1 && !session.firstMultiple) {
|
18233 | session.firstMultiple = simpleCloneInputData(input);
|
18234 | } else if (pointersLength === 1) {
|
18235 | session.firstMultiple = false;
|
18236 | }
|
18237 |
|
18238 | var firstInput = session.firstInput;
|
18239 | var firstMultiple = session.firstMultiple;
|
18240 | var offsetCenter = firstMultiple ? firstMultiple.center : firstInput.center;
|
18241 | var center = input.center = getCenter(pointers);
|
18242 | input.timeStamp = now();
|
18243 | input.deltaTime = input.timeStamp - firstInput.timeStamp;
|
18244 | input.angle = getAngle(offsetCenter, center);
|
18245 | input.distance = getDistance(offsetCenter, center);
|
18246 | computeDeltaXY(session, input);
|
18247 | input.offsetDirection = getDirection(input.deltaX, input.deltaY);
|
18248 | var overallVelocity = getVelocity(input.deltaTime, input.deltaX, input.deltaY);
|
18249 | input.overallVelocityX = overallVelocity.x;
|
18250 | input.overallVelocityY = overallVelocity.y;
|
18251 | input.overallVelocity = abs(overallVelocity.x) > abs(overallVelocity.y) ? overallVelocity.x : overallVelocity.y;
|
18252 | input.scale = firstMultiple ? getScale(firstMultiple.pointers, pointers) : 1;
|
18253 | input.rotation = firstMultiple ? getRotation(firstMultiple.pointers, pointers) : 0;
|
18254 | input.maxPointers = !session.prevInput ? input.pointers.length : input.pointers.length > session.prevInput.maxPointers ? input.pointers.length : session.prevInput.maxPointers;
|
18255 | computeIntervalInputData(session, input);
|
18256 |
|
18257 | var target = manager.element;
|
18258 |
|
18259 | if (hasParent(input.srcEvent.target, target)) {
|
18260 | target = input.srcEvent.target;
|
18261 | }
|
18262 |
|
18263 | input.target = target;
|
18264 | }
|
18265 |
|
18266 | function computeDeltaXY(session, input) {
|
18267 | var center = input.center;
|
18268 | var offset = session.offsetDelta || {};
|
18269 | var prevDelta = session.prevDelta || {};
|
18270 | var prevInput = session.prevInput || {};
|
18271 |
|
18272 | if (input.eventType === INPUT_START || prevInput.eventType === INPUT_END) {
|
18273 | prevDelta = session.prevDelta = {
|
18274 | x: prevInput.deltaX || 0,
|
18275 | y: prevInput.deltaY || 0
|
18276 | };
|
18277 | offset = session.offsetDelta = {
|
18278 | x: center.x,
|
18279 | y: center.y
|
18280 | };
|
18281 | }
|
18282 |
|
18283 | input.deltaX = prevDelta.x + (center.x - offset.x);
|
18284 | input.deltaY = prevDelta.y + (center.y - offset.y);
|
18285 | }
|
18286 | |
18287 |
|
18288 |
|
18289 |
|
18290 |
|
18291 |
|
18292 |
|
18293 | function computeIntervalInputData(session, input) {
|
18294 | var last = session.lastInterval || input,
|
18295 | deltaTime = input.timeStamp - last.timeStamp,
|
18296 | velocity,
|
18297 | velocityX,
|
18298 | velocityY,
|
18299 | direction;
|
18300 |
|
18301 | if (input.eventType != INPUT_CANCEL && (deltaTime > COMPUTE_INTERVAL || last.velocity === undefined)) {
|
18302 | var deltaX = input.deltaX - last.deltaX;
|
18303 | var deltaY = input.deltaY - last.deltaY;
|
18304 | var v = getVelocity(deltaTime, deltaX, deltaY);
|
18305 | velocityX = v.x;
|
18306 | velocityY = v.y;
|
18307 | velocity = abs(v.x) > abs(v.y) ? v.x : v.y;
|
18308 | direction = getDirection(deltaX, deltaY);
|
18309 | session.lastInterval = input;
|
18310 | } else {
|
18311 |
|
18312 | velocity = last.velocity;
|
18313 | velocityX = last.velocityX;
|
18314 | velocityY = last.velocityY;
|
18315 | direction = last.direction;
|
18316 | }
|
18317 |
|
18318 | input.velocity = velocity;
|
18319 | input.velocityX = velocityX;
|
18320 | input.velocityY = velocityY;
|
18321 | input.direction = direction;
|
18322 | }
|
18323 | |
18324 |
|
18325 |
|
18326 |
|
18327 |
|
18328 |
|
18329 |
|
18330 | function simpleCloneInputData(input) {
|
18331 |
|
18332 |
|
18333 | var pointers = [];
|
18334 | var i = 0;
|
18335 |
|
18336 | while (i < input.pointers.length) {
|
18337 | pointers[i] = {
|
18338 | clientX: round(input.pointers[i].clientX),
|
18339 | clientY: round(input.pointers[i].clientY)
|
18340 | };
|
18341 | i++;
|
18342 | }
|
18343 |
|
18344 | return {
|
18345 | timeStamp: now(),
|
18346 | pointers: pointers,
|
18347 | center: getCenter(pointers),
|
18348 | deltaX: input.deltaX,
|
18349 | deltaY: input.deltaY
|
18350 | };
|
18351 | }
|
18352 | |
18353 |
|
18354 |
|
18355 |
|
18356 |
|
18357 |
|
18358 |
|
18359 | function getCenter(pointers) {
|
18360 | var pointersLength = pointers.length;
|
18361 |
|
18362 | if (pointersLength === 1) {
|
18363 | return {
|
18364 | x: round(pointers[0].clientX),
|
18365 | y: round(pointers[0].clientY)
|
18366 | };
|
18367 | }
|
18368 |
|
18369 | var x = 0,
|
18370 | y = 0,
|
18371 | i = 0;
|
18372 |
|
18373 | while (i < pointersLength) {
|
18374 | x += pointers[i].clientX;
|
18375 | y += pointers[i].clientY;
|
18376 | i++;
|
18377 | }
|
18378 |
|
18379 | return {
|
18380 | x: round(x / pointersLength),
|
18381 | y: round(y / pointersLength)
|
18382 | };
|
18383 | }
|
18384 | |
18385 |
|
18386 |
|
18387 |
|
18388 |
|
18389 |
|
18390 |
|
18391 |
|
18392 |
|
18393 | function getVelocity(deltaTime, x, y) {
|
18394 | return {
|
18395 | x: x / deltaTime || 0,
|
18396 | y: y / deltaTime || 0
|
18397 | };
|
18398 | }
|
18399 | |
18400 |
|
18401 |
|
18402 |
|
18403 |
|
18404 |
|
18405 |
|
18406 |
|
18407 | function getDirection(x, y) {
|
18408 | if (x === y) {
|
18409 | return DIRECTION_NONE;
|
18410 | }
|
18411 |
|
18412 | if (abs(x) >= abs(y)) {
|
18413 | return x < 0 ? DIRECTION_LEFT : DIRECTION_RIGHT;
|
18414 | }
|
18415 |
|
18416 | return y < 0 ? DIRECTION_UP : DIRECTION_DOWN;
|
18417 | }
|
18418 | |
18419 |
|
18420 |
|
18421 |
|
18422 |
|
18423 |
|
18424 |
|
18425 |
|
18426 |
|
18427 | function getDistance(p1, p2, props) {
|
18428 | if (!props) {
|
18429 | props = PROPS_XY;
|
18430 | }
|
18431 |
|
18432 | var x = p2[props[0]] - p1[props[0]],
|
18433 | y = p2[props[1]] - p1[props[1]];
|
18434 | return Math.sqrt(x * x + y * y);
|
18435 | }
|
18436 | |
18437 |
|
18438 |
|
18439 |
|
18440 |
|
18441 |
|
18442 |
|
18443 |
|
18444 |
|
18445 | function getAngle(p1, p2, props) {
|
18446 | if (!props) {
|
18447 | props = PROPS_XY;
|
18448 | }
|
18449 |
|
18450 | var x = p2[props[0]] - p1[props[0]],
|
18451 | y = p2[props[1]] - p1[props[1]];
|
18452 | return Math.atan2(y, x) * 180 / Math.PI;
|
18453 | }
|
18454 | |
18455 |
|
18456 |
|
18457 |
|
18458 |
|
18459 |
|
18460 |
|
18461 |
|
18462 | function getRotation(start, end) {
|
18463 | return getAngle(end[1], end[0], PROPS_CLIENT_XY) + getAngle(start[1], start[0], PROPS_CLIENT_XY);
|
18464 | }
|
18465 | |
18466 |
|
18467 |
|
18468 |
|
18469 |
|
18470 |
|
18471 |
|
18472 |
|
18473 |
|
18474 | function getScale(start, end) {
|
18475 | return getDistance(end[0], end[1], PROPS_CLIENT_XY) / getDistance(start[0], start[1], PROPS_CLIENT_XY);
|
18476 | }
|
18477 |
|
18478 | var MOUSE_INPUT_MAP = {
|
18479 | mousedown: INPUT_START,
|
18480 | mousemove: INPUT_MOVE,
|
18481 | mouseup: INPUT_END
|
18482 | };
|
18483 | var MOUSE_ELEMENT_EVENTS = 'mousedown';
|
18484 | var MOUSE_WINDOW_EVENTS = 'mousemove mouseup';
|
18485 | |
18486 |
|
18487 |
|
18488 |
|
18489 |
|
18490 |
|
18491 | function MouseInput() {
|
18492 | this.evEl = MOUSE_ELEMENT_EVENTS;
|
18493 | this.evWin = MOUSE_WINDOW_EVENTS;
|
18494 | this.pressed = false;
|
18495 |
|
18496 | Input.apply(this, arguments);
|
18497 | }
|
18498 |
|
18499 | inherit(MouseInput, Input, {
|
18500 | |
18501 |
|
18502 |
|
18503 |
|
18504 | handler: function MEhandler(ev) {
|
18505 | var eventType = MOUSE_INPUT_MAP[ev.type];
|
18506 |
|
18507 | if (eventType & INPUT_START && ev.button === 0) {
|
18508 | this.pressed = true;
|
18509 | }
|
18510 |
|
18511 | if (eventType & INPUT_MOVE && ev.which !== 1) {
|
18512 | eventType = INPUT_END;
|
18513 | }
|
18514 |
|
18515 |
|
18516 | if (!this.pressed) {
|
18517 | return;
|
18518 | }
|
18519 |
|
18520 | if (eventType & INPUT_END) {
|
18521 | this.pressed = false;
|
18522 | }
|
18523 |
|
18524 | this.callback(this.manager, eventType, {
|
18525 | pointers: [ev],
|
18526 | changedPointers: [ev],
|
18527 | pointerType: INPUT_TYPE_MOUSE,
|
18528 | srcEvent: ev
|
18529 | });
|
18530 | }
|
18531 | });
|
18532 | var POINTER_INPUT_MAP = {
|
18533 | pointerdown: INPUT_START,
|
18534 | pointermove: INPUT_MOVE,
|
18535 | pointerup: INPUT_END,
|
18536 | pointercancel: INPUT_CANCEL,
|
18537 | pointerout: INPUT_CANCEL
|
18538 | };
|
18539 |
|
18540 | var IE10_POINTER_TYPE_ENUM = {
|
18541 | 2: INPUT_TYPE_TOUCH,
|
18542 | 3: INPUT_TYPE_PEN,
|
18543 | 4: INPUT_TYPE_MOUSE,
|
18544 | 5: INPUT_TYPE_KINECT
|
18545 |
|
18546 | };
|
18547 | var POINTER_ELEMENT_EVENTS = 'pointerdown';
|
18548 | var POINTER_WINDOW_EVENTS = 'pointermove pointerup pointercancel';
|
18549 |
|
18550 | if (window.MSPointerEvent && !window.PointerEvent) {
|
18551 | POINTER_ELEMENT_EVENTS = 'MSPointerDown';
|
18552 | POINTER_WINDOW_EVENTS = 'MSPointerMove MSPointerUp MSPointerCancel';
|
18553 | }
|
18554 | |
18555 |
|
18556 |
|
18557 |
|
18558 |
|
18559 |
|
18560 |
|
18561 | function PointerEventInput() {
|
18562 | this.evEl = POINTER_ELEMENT_EVENTS;
|
18563 | this.evWin = POINTER_WINDOW_EVENTS;
|
18564 | Input.apply(this, arguments);
|
18565 | this.store = this.manager.session.pointerEvents = [];
|
18566 | }
|
18567 |
|
18568 | inherit(PointerEventInput, Input, {
|
18569 | |
18570 |
|
18571 |
|
18572 |
|
18573 | handler: function PEhandler(ev) {
|
18574 | var store = this.store;
|
18575 | var removePointer = false;
|
18576 | var eventTypeNormalized = ev.type.toLowerCase().replace('ms', '');
|
18577 | var eventType = POINTER_INPUT_MAP[eventTypeNormalized];
|
18578 | var pointerType = IE10_POINTER_TYPE_ENUM[ev.pointerType] || ev.pointerType;
|
18579 | var isTouch = pointerType == INPUT_TYPE_TOUCH;
|
18580 |
|
18581 | var storeIndex = inArray(store, ev.pointerId, 'pointerId');
|
18582 |
|
18583 | if (eventType & INPUT_START && (ev.button === 0 || isTouch)) {
|
18584 | if (storeIndex < 0) {
|
18585 | store.push(ev);
|
18586 | storeIndex = store.length - 1;
|
18587 | }
|
18588 | } else if (eventType & (INPUT_END | INPUT_CANCEL)) {
|
18589 | removePointer = true;
|
18590 | }
|
18591 |
|
18592 |
|
18593 | if (storeIndex < 0) {
|
18594 | return;
|
18595 | }
|
18596 |
|
18597 |
|
18598 | store[storeIndex] = ev;
|
18599 | this.callback(this.manager, eventType, {
|
18600 | pointers: store,
|
18601 | changedPointers: [ev],
|
18602 | pointerType: pointerType,
|
18603 | srcEvent: ev
|
18604 | });
|
18605 |
|
18606 | if (removePointer) {
|
18607 |
|
18608 | store.splice(storeIndex, 1);
|
18609 | }
|
18610 | }
|
18611 | });
|
18612 | var SINGLE_TOUCH_INPUT_MAP = {
|
18613 | touchstart: INPUT_START,
|
18614 | touchmove: INPUT_MOVE,
|
18615 | touchend: INPUT_END,
|
18616 | touchcancel: INPUT_CANCEL
|
18617 | };
|
18618 | var SINGLE_TOUCH_TARGET_EVENTS = 'touchstart';
|
18619 | var SINGLE_TOUCH_WINDOW_EVENTS = 'touchstart touchmove touchend touchcancel';
|
18620 | |
18621 |
|
18622 |
|
18623 |
|
18624 |
|
18625 |
|
18626 | function SingleTouchInput() {
|
18627 | this.evTarget = SINGLE_TOUCH_TARGET_EVENTS;
|
18628 | this.evWin = SINGLE_TOUCH_WINDOW_EVENTS;
|
18629 | this.started = false;
|
18630 | Input.apply(this, arguments);
|
18631 | }
|
18632 |
|
18633 | inherit(SingleTouchInput, Input, {
|
18634 | handler: function TEhandler(ev) {
|
18635 | var type = SINGLE_TOUCH_INPUT_MAP[ev.type];
|
18636 |
|
18637 | if (type === INPUT_START) {
|
18638 | this.started = true;
|
18639 | }
|
18640 |
|
18641 | if (!this.started) {
|
18642 | return;
|
18643 | }
|
18644 |
|
18645 | var touches = normalizeSingleTouches.call(this, ev, type);
|
18646 |
|
18647 | if (type & (INPUT_END | INPUT_CANCEL) && touches[0].length - touches[1].length === 0) {
|
18648 | this.started = false;
|
18649 | }
|
18650 |
|
18651 | this.callback(this.manager, type, {
|
18652 | pointers: touches[0],
|
18653 | changedPointers: touches[1],
|
18654 | pointerType: INPUT_TYPE_TOUCH,
|
18655 | srcEvent: ev
|
18656 | });
|
18657 | }
|
18658 | });
|
18659 | |
18660 |
|
18661 |
|
18662 |
|
18663 |
|
18664 |
|
18665 |
|
18666 | function normalizeSingleTouches(ev, type) {
|
18667 | var all = toArray(ev.touches);
|
18668 | var changed = toArray(ev.changedTouches);
|
18669 |
|
18670 | if (type & (INPUT_END | INPUT_CANCEL)) {
|
18671 | all = uniqueArray(all.concat(changed), 'identifier', true);
|
18672 | }
|
18673 |
|
18674 | return [all, changed];
|
18675 | }
|
18676 |
|
18677 | var TOUCH_INPUT_MAP = {
|
18678 | touchstart: INPUT_START,
|
18679 | touchmove: INPUT_MOVE,
|
18680 | touchend: INPUT_END,
|
18681 | touchcancel: INPUT_CANCEL
|
18682 | };
|
18683 | var TOUCH_TARGET_EVENTS = 'touchstart touchmove touchend touchcancel';
|
18684 | |
18685 |
|
18686 |
|
18687 |
|
18688 |
|
18689 |
|
18690 | function TouchInput() {
|
18691 | this.evTarget = TOUCH_TARGET_EVENTS;
|
18692 | this.targetIds = {};
|
18693 | Input.apply(this, arguments);
|
18694 | }
|
18695 |
|
18696 | inherit(TouchInput, Input, {
|
18697 | handler: function MTEhandler(ev) {
|
18698 | var type = TOUCH_INPUT_MAP[ev.type];
|
18699 | var touches = getTouches.call(this, ev, type);
|
18700 |
|
18701 | if (!touches) {
|
18702 | return;
|
18703 | }
|
18704 |
|
18705 | this.callback(this.manager, type, {
|
18706 | pointers: touches[0],
|
18707 | changedPointers: touches[1],
|
18708 | pointerType: INPUT_TYPE_TOUCH,
|
18709 | srcEvent: ev
|
18710 | });
|
18711 | }
|
18712 | });
|
18713 | |
18714 |
|
18715 |
|
18716 |
|
18717 |
|
18718 |
|
18719 |
|
18720 | function getTouches(ev, type) {
|
18721 | var allTouches = toArray(ev.touches);
|
18722 | var targetIds = this.targetIds;
|
18723 |
|
18724 | if (type & (INPUT_START | INPUT_MOVE) && allTouches.length === 1) {
|
18725 | targetIds[allTouches[0].identifier] = true;
|
18726 | return [allTouches, allTouches];
|
18727 | }
|
18728 |
|
18729 | var i,
|
18730 | targetTouches,
|
18731 | changedTouches = toArray(ev.changedTouches),
|
18732 | changedTargetTouches = [],
|
18733 | target = this.target;
|
18734 |
|
18735 | targetTouches = allTouches.filter(function (touch) {
|
18736 | return hasParent(touch.target, target);
|
18737 | });
|
18738 |
|
18739 | if (type === INPUT_START) {
|
18740 | i = 0;
|
18741 |
|
18742 | while (i < targetTouches.length) {
|
18743 | targetIds[targetTouches[i].identifier] = true;
|
18744 | i++;
|
18745 | }
|
18746 | }
|
18747 |
|
18748 |
|
18749 | i = 0;
|
18750 |
|
18751 | while (i < changedTouches.length) {
|
18752 | if (targetIds[changedTouches[i].identifier]) {
|
18753 | changedTargetTouches.push(changedTouches[i]);
|
18754 | }
|
18755 |
|
18756 |
|
18757 | if (type & (INPUT_END | INPUT_CANCEL)) {
|
18758 | delete targetIds[changedTouches[i].identifier];
|
18759 | }
|
18760 |
|
18761 | i++;
|
18762 | }
|
18763 |
|
18764 | if (!changedTargetTouches.length) {
|
18765 | return;
|
18766 | }
|
18767 |
|
18768 | return [
|
18769 | uniqueArray(targetTouches.concat(changedTargetTouches), 'identifier', true), changedTargetTouches];
|
18770 | }
|
18771 | |
18772 |
|
18773 |
|
18774 |
|
18775 |
|
18776 |
|
18777 |
|
18778 |
|
18779 |
|
18780 |
|
18781 |
|
18782 | var DEDUP_TIMEOUT = 2500;
|
18783 | var DEDUP_DISTANCE = 25;
|
18784 |
|
18785 | function TouchMouseInput() {
|
18786 | Input.apply(this, arguments);
|
18787 | var handler = bindFn(this.handler, this);
|
18788 | this.touch = new TouchInput(this.manager, handler);
|
18789 | this.mouse = new MouseInput(this.manager, handler);
|
18790 | this.primaryTouch = null;
|
18791 | this.lastTouches = [];
|
18792 | }
|
18793 |
|
18794 | inherit(TouchMouseInput, Input, {
|
18795 | |
18796 |
|
18797 |
|
18798 |
|
18799 |
|
18800 |
|
18801 | handler: function TMEhandler(manager, inputEvent, inputData) {
|
18802 | var isTouch = inputData.pointerType == INPUT_TYPE_TOUCH,
|
18803 | isMouse = inputData.pointerType == INPUT_TYPE_MOUSE;
|
18804 |
|
18805 | if (isMouse && inputData.sourceCapabilities && inputData.sourceCapabilities.firesTouchEvents) {
|
18806 | return;
|
18807 | }
|
18808 |
|
18809 |
|
18810 | if (isTouch) {
|
18811 | recordTouches.call(this, inputEvent, inputData);
|
18812 | } else if (isMouse && isSyntheticEvent.call(this, inputData)) {
|
18813 | return;
|
18814 | }
|
18815 |
|
18816 | this.callback(manager, inputEvent, inputData);
|
18817 | },
|
18818 |
|
18819 | |
18820 |
|
18821 |
|
18822 | destroy: function destroy() {
|
18823 | this.touch.destroy();
|
18824 | this.mouse.destroy();
|
18825 | }
|
18826 | });
|
18827 |
|
18828 | function recordTouches(eventType, eventData) {
|
18829 | if (eventType & INPUT_START) {
|
18830 | this.primaryTouch = eventData.changedPointers[0].identifier;
|
18831 | setLastTouch.call(this, eventData);
|
18832 | } else if (eventType & (INPUT_END | INPUT_CANCEL)) {
|
18833 | setLastTouch.call(this, eventData);
|
18834 | }
|
18835 | }
|
18836 |
|
18837 | function setLastTouch(eventData) {
|
18838 | var touch = eventData.changedPointers[0];
|
18839 |
|
18840 | if (touch.identifier === this.primaryTouch) {
|
18841 | var lastTouch = {
|
18842 | x: touch.clientX,
|
18843 | y: touch.clientY
|
18844 | };
|
18845 | this.lastTouches.push(lastTouch);
|
18846 | var lts = this.lastTouches;
|
18847 |
|
18848 | var removeLastTouch = function () {
|
18849 | var i = lts.indexOf(lastTouch);
|
18850 |
|
18851 | if (i > -1) {
|
18852 | lts.splice(i, 1);
|
18853 | }
|
18854 | };
|
18855 |
|
18856 | setTimeout(removeLastTouch, DEDUP_TIMEOUT);
|
18857 | }
|
18858 | }
|
18859 |
|
18860 | function isSyntheticEvent(eventData) {
|
18861 | var x = eventData.srcEvent.clientX,
|
18862 | y = eventData.srcEvent.clientY;
|
18863 |
|
18864 | for (var i = 0; i < this.lastTouches.length; i++) {
|
18865 | var t = this.lastTouches[i];
|
18866 | var dx = Math.abs(x - t.x),
|
18867 | dy = Math.abs(y - t.y);
|
18868 |
|
18869 | if (dx <= DEDUP_DISTANCE && dy <= DEDUP_DISTANCE) {
|
18870 | return true;
|
18871 | }
|
18872 | }
|
18873 |
|
18874 | return false;
|
18875 | }
|
18876 |
|
18877 | var PREFIXED_TOUCH_ACTION = prefixed(TEST_ELEMENT.style, 'touchAction');
|
18878 | var NATIVE_TOUCH_ACTION = PREFIXED_TOUCH_ACTION !== undefined;
|
18879 |
|
18880 | var TOUCH_ACTION_COMPUTE = 'compute';
|
18881 | var TOUCH_ACTION_AUTO = 'auto';
|
18882 | var TOUCH_ACTION_MANIPULATION = 'manipulation';
|
18883 |
|
18884 | var TOUCH_ACTION_NONE = 'none';
|
18885 | var TOUCH_ACTION_PAN_X = 'pan-x';
|
18886 | var TOUCH_ACTION_PAN_Y = 'pan-y';
|
18887 | var TOUCH_ACTION_MAP = getTouchActionProps();
|
18888 | |
18889 |
|
18890 |
|
18891 |
|
18892 |
|
18893 |
|
18894 |
|
18895 |
|
18896 | function TouchAction(manager, value) {
|
18897 | this.manager = manager;
|
18898 | this.set(value);
|
18899 | }
|
18900 |
|
18901 | TouchAction.prototype = {
|
18902 | |
18903 |
|
18904 |
|
18905 |
|
18906 | set: function (value) {
|
18907 |
|
18908 | if (value == TOUCH_ACTION_COMPUTE) {
|
18909 | value = this.compute();
|
18910 | }
|
18911 |
|
18912 | if (NATIVE_TOUCH_ACTION && this.manager.element.style && TOUCH_ACTION_MAP[value]) {
|
18913 | this.manager.element.style[PREFIXED_TOUCH_ACTION] = value;
|
18914 | }
|
18915 |
|
18916 | this.actions = value.toLowerCase().trim();
|
18917 | },
|
18918 |
|
18919 | |
18920 |
|
18921 |
|
18922 | update: function () {
|
18923 | this.set(this.manager.options.touchAction);
|
18924 | },
|
18925 |
|
18926 | |
18927 |
|
18928 |
|
18929 |
|
18930 | compute: function () {
|
18931 | var actions = [];
|
18932 | each(this.manager.recognizers, function (recognizer) {
|
18933 | if (boolOrFn(recognizer.options.enable, [recognizer])) {
|
18934 | actions = actions.concat(recognizer.getTouchAction());
|
18935 | }
|
18936 | });
|
18937 | return cleanTouchActions(actions.join(' '));
|
18938 | },
|
18939 |
|
18940 | |
18941 |
|
18942 |
|
18943 |
|
18944 | preventDefaults: function (input) {
|
18945 | var srcEvent = input.srcEvent;
|
18946 | var direction = input.offsetDirection;
|
18947 |
|
18948 | if (this.manager.session.prevented) {
|
18949 | srcEvent.preventDefault();
|
18950 | return;
|
18951 | }
|
18952 |
|
18953 | var actions = this.actions;
|
18954 | var hasNone = inStr(actions, TOUCH_ACTION_NONE) && !TOUCH_ACTION_MAP[TOUCH_ACTION_NONE];
|
18955 | var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y) && !TOUCH_ACTION_MAP[TOUCH_ACTION_PAN_Y];
|
18956 | var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X) && !TOUCH_ACTION_MAP[TOUCH_ACTION_PAN_X];
|
18957 |
|
18958 | if (hasNone) {
|
18959 |
|
18960 | var isTapPointer = input.pointers.length === 1;
|
18961 | var isTapMovement = input.distance < 2;
|
18962 | var isTapTouchTime = input.deltaTime < 250;
|
18963 |
|
18964 | if (isTapPointer && isTapMovement && isTapTouchTime) {
|
18965 | return;
|
18966 | }
|
18967 | }
|
18968 |
|
18969 | if (hasPanX && hasPanY) {
|
18970 |
|
18971 | return;
|
18972 | }
|
18973 |
|
18974 | if (hasNone || hasPanY && direction & DIRECTION_HORIZONTAL || hasPanX && direction & DIRECTION_VERTICAL) {
|
18975 | return this.preventSrc(srcEvent);
|
18976 | }
|
18977 | },
|
18978 |
|
18979 | |
18980 |
|
18981 |
|
18982 |
|
18983 | preventSrc: function (srcEvent) {
|
18984 | this.manager.session.prevented = true;
|
18985 | srcEvent.preventDefault();
|
18986 | }
|
18987 | };
|
18988 | |
18989 |
|
18990 |
|
18991 |
|
18992 |
|
18993 |
|
18994 | function cleanTouchActions(actions) {
|
18995 |
|
18996 | if (inStr(actions, TOUCH_ACTION_NONE)) {
|
18997 | return TOUCH_ACTION_NONE;
|
18998 | }
|
18999 |
|
19000 | var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X);
|
19001 | var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y);
|
19002 |
|
19003 |
|
19004 |
|
19005 |
|
19006 | if (hasPanX && hasPanY) {
|
19007 | return TOUCH_ACTION_NONE;
|
19008 | }
|
19009 |
|
19010 |
|
19011 | if (hasPanX || hasPanY) {
|
19012 | return hasPanX ? TOUCH_ACTION_PAN_X : TOUCH_ACTION_PAN_Y;
|
19013 | }
|
19014 |
|
19015 |
|
19016 | if (inStr(actions, TOUCH_ACTION_MANIPULATION)) {
|
19017 | return TOUCH_ACTION_MANIPULATION;
|
19018 | }
|
19019 |
|
19020 | return TOUCH_ACTION_AUTO;
|
19021 | }
|
19022 |
|
19023 | function getTouchActionProps() {
|
19024 | if (!NATIVE_TOUCH_ACTION) {
|
19025 | return false;
|
19026 | }
|
19027 |
|
19028 | var touchMap = {};
|
19029 | var cssSupports = window.CSS && window.CSS.supports;
|
19030 | ['auto', 'manipulation', 'pan-y', 'pan-x', 'pan-x pan-y', 'none'].forEach(function (val) {
|
19031 |
|
19032 |
|
19033 | touchMap[val] = cssSupports ? window.CSS.supports('touch-action', val) : true;
|
19034 | });
|
19035 | return touchMap;
|
19036 | }
|
19037 | |
19038 |
|
19039 |
|
19040 |
|
19041 |
|
19042 |
|
19043 |
|
19044 |
|
19045 |
|
19046 |
|
19047 |
|
19048 |
|
19049 |
|
19050 |
|
19051 |
|
19052 |
|
19053 |
|
19054 |
|
19055 |
|
19056 |
|
19057 |
|
19058 |
|
19059 |
|
19060 |
|
19061 |
|
19062 |
|
19063 |
|
19064 |
|
19065 |
|
19066 | var STATE_POSSIBLE = 1;
|
19067 | var STATE_BEGAN = 2;
|
19068 | var STATE_CHANGED = 4;
|
19069 | var STATE_ENDED = 8;
|
19070 | var STATE_RECOGNIZED = STATE_ENDED;
|
19071 | var STATE_CANCELLED = 16;
|
19072 | var STATE_FAILED = 32;
|
19073 | |
19074 |
|
19075 |
|
19076 |
|
19077 |
|
19078 |
|
19079 |
|
19080 | function Recognizer(options) {
|
19081 | this.options = assign({}, this.defaults, options || {});
|
19082 | this.id = uniqueId();
|
19083 | this.manager = null;
|
19084 |
|
19085 | this.options.enable = ifUndefined(this.options.enable, true);
|
19086 | this.state = STATE_POSSIBLE;
|
19087 | this.simultaneous = {};
|
19088 | this.requireFail = [];
|
19089 | }
|
19090 |
|
19091 | Recognizer.prototype = {
|
19092 | |
19093 |
|
19094 |
|
19095 |
|
19096 | defaults: {},
|
19097 |
|
19098 | |
19099 |
|
19100 |
|
19101 |
|
19102 |
|
19103 | set: function (options) {
|
19104 | assign(this.options, options);
|
19105 |
|
19106 | this.manager && this.manager.touchAction.update();
|
19107 | return this;
|
19108 | },
|
19109 |
|
19110 | |
19111 |
|
19112 |
|
19113 |
|
19114 |
|
19115 | recognizeWith: function (otherRecognizer) {
|
19116 | if (invokeArrayArg(otherRecognizer, 'recognizeWith', this)) {
|
19117 | return this;
|
19118 | }
|
19119 |
|
19120 | var simultaneous = this.simultaneous;
|
19121 | otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
|
19122 |
|
19123 | if (!simultaneous[otherRecognizer.id]) {
|
19124 | simultaneous[otherRecognizer.id] = otherRecognizer;
|
19125 | otherRecognizer.recognizeWith(this);
|
19126 | }
|
19127 |
|
19128 | return this;
|
19129 | },
|
19130 |
|
19131 | |
19132 |
|
19133 |
|
19134 |
|
19135 |
|
19136 | dropRecognizeWith: function (otherRecognizer) {
|
19137 | if (invokeArrayArg(otherRecognizer, 'dropRecognizeWith', this)) {
|
19138 | return this;
|
19139 | }
|
19140 |
|
19141 | otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
|
19142 | delete this.simultaneous[otherRecognizer.id];
|
19143 | return this;
|
19144 | },
|
19145 |
|
19146 | |
19147 |
|
19148 |
|
19149 |
|
19150 |
|
19151 | requireFailure: function (otherRecognizer) {
|
19152 | if (invokeArrayArg(otherRecognizer, 'requireFailure', this)) {
|
19153 | return this;
|
19154 | }
|
19155 |
|
19156 | var requireFail = this.requireFail;
|
19157 | otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
|
19158 |
|
19159 | if (inArray(requireFail, otherRecognizer) === -1) {
|
19160 | requireFail.push(otherRecognizer);
|
19161 | otherRecognizer.requireFailure(this);
|
19162 | }
|
19163 |
|
19164 | return this;
|
19165 | },
|
19166 |
|
19167 | |
19168 |
|
19169 |
|
19170 |
|
19171 |
|
19172 | dropRequireFailure: function (otherRecognizer) {
|
19173 | if (invokeArrayArg(otherRecognizer, 'dropRequireFailure', this)) {
|
19174 | return this;
|
19175 | }
|
19176 |
|
19177 | otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
|
19178 | var index = inArray(this.requireFail, otherRecognizer);
|
19179 |
|
19180 | if (index > -1) {
|
19181 | this.requireFail.splice(index, 1);
|
19182 | }
|
19183 |
|
19184 | return this;
|
19185 | },
|
19186 |
|
19187 | |
19188 |
|
19189 |
|
19190 |
|
19191 | hasRequireFailures: function () {
|
19192 | return this.requireFail.length > 0;
|
19193 | },
|
19194 |
|
19195 | |
19196 |
|
19197 |
|
19198 |
|
19199 |
|
19200 | canRecognizeWith: function (otherRecognizer) {
|
19201 | return !!this.simultaneous[otherRecognizer.id];
|
19202 | },
|
19203 |
|
19204 | |
19205 |
|
19206 |
|
19207 |
|
19208 |
|
19209 | emit: function (input) {
|
19210 | var self = this;
|
19211 | var state = this.state;
|
19212 |
|
19213 | function emit(event) {
|
19214 | self.manager.emit(event, input);
|
19215 | }
|
19216 |
|
19217 |
|
19218 | if (state < STATE_ENDED) {
|
19219 | emit(self.options.event + stateStr(state));
|
19220 | }
|
19221 |
|
19222 | emit(self.options.event);
|
19223 |
|
19224 | if (input.additionalEvent) {
|
19225 |
|
19226 | emit(input.additionalEvent);
|
19227 | }
|
19228 |
|
19229 |
|
19230 | if (state >= STATE_ENDED) {
|
19231 | emit(self.options.event + stateStr(state));
|
19232 | }
|
19233 | },
|
19234 |
|
19235 | |
19236 |
|
19237 |
|
19238 |
|
19239 |
|
19240 |
|
19241 | tryEmit: function (input) {
|
19242 | if (this.canEmit()) {
|
19243 | return this.emit(input);
|
19244 | }
|
19245 |
|
19246 |
|
19247 | this.state = STATE_FAILED;
|
19248 | },
|
19249 |
|
19250 | |
19251 |
|
19252 |
|
19253 |
|
19254 | canEmit: function () {
|
19255 | var i = 0;
|
19256 |
|
19257 | while (i < this.requireFail.length) {
|
19258 | if (!(this.requireFail[i].state & (STATE_FAILED | STATE_POSSIBLE))) {
|
19259 | return false;
|
19260 | }
|
19261 |
|
19262 | i++;
|
19263 | }
|
19264 |
|
19265 | return true;
|
19266 | },
|
19267 |
|
19268 | |
19269 |
|
19270 |
|
19271 |
|
19272 | recognize: function (inputData) {
|
19273 |
|
19274 |
|
19275 | var inputDataClone = assign({}, inputData);
|
19276 |
|
19277 | if (!boolOrFn(this.options.enable, [this, inputDataClone])) {
|
19278 | this.reset();
|
19279 | this.state = STATE_FAILED;
|
19280 | return;
|
19281 | }
|
19282 |
|
19283 |
|
19284 | if (this.state & (STATE_RECOGNIZED | STATE_CANCELLED | STATE_FAILED)) {
|
19285 | this.state = STATE_POSSIBLE;
|
19286 | }
|
19287 |
|
19288 | this.state = this.process(inputDataClone);
|
19289 |
|
19290 |
|
19291 | if (this.state & (STATE_BEGAN | STATE_CHANGED | STATE_ENDED | STATE_CANCELLED)) {
|
19292 | this.tryEmit(inputDataClone);
|
19293 | }
|
19294 | },
|
19295 |
|
19296 | |
19297 |
|
19298 |
|
19299 |
|
19300 |
|
19301 |
|
19302 |
|
19303 | process: function (inputData) {},
|
19304 |
|
19305 |
|
19306 | |
19307 |
|
19308 |
|
19309 |
|
19310 |
|
19311 | getTouchAction: function () {},
|
19312 |
|
19313 | |
19314 |
|
19315 |
|
19316 |
|
19317 |
|
19318 | reset: function () {}
|
19319 | };
|
19320 | |
19321 |
|
19322 |
|
19323 |
|
19324 |
|
19325 |
|
19326 | function stateStr(state) {
|
19327 | if (state & STATE_CANCELLED) {
|
19328 | return 'cancel';
|
19329 | } else if (state & STATE_ENDED) {
|
19330 | return 'end';
|
19331 | } else if (state & STATE_CHANGED) {
|
19332 | return 'move';
|
19333 | } else if (state & STATE_BEGAN) {
|
19334 | return 'start';
|
19335 | }
|
19336 |
|
19337 | return '';
|
19338 | }
|
19339 | |
19340 |
|
19341 |
|
19342 |
|
19343 |
|
19344 |
|
19345 |
|
19346 | function directionStr(direction) {
|
19347 | if (direction == DIRECTION_DOWN) {
|
19348 | return 'down';
|
19349 | } else if (direction == DIRECTION_UP) {
|
19350 | return 'up';
|
19351 | } else if (direction == DIRECTION_LEFT) {
|
19352 | return 'left';
|
19353 | } else if (direction == DIRECTION_RIGHT) {
|
19354 | return 'right';
|
19355 | }
|
19356 |
|
19357 | return '';
|
19358 | }
|
19359 | |
19360 |
|
19361 |
|
19362 |
|
19363 |
|
19364 |
|
19365 |
|
19366 |
|
19367 | function getRecognizerByNameIfManager(otherRecognizer, recognizer) {
|
19368 | var manager = recognizer.manager;
|
19369 |
|
19370 | if (manager) {
|
19371 | return manager.get(otherRecognizer);
|
19372 | }
|
19373 |
|
19374 | return otherRecognizer;
|
19375 | }
|
19376 | |
19377 |
|
19378 |
|
19379 |
|
19380 |
|
19381 |
|
19382 |
|
19383 | function AttrRecognizer() {
|
19384 | Recognizer.apply(this, arguments);
|
19385 | }
|
19386 |
|
19387 | inherit(AttrRecognizer, Recognizer, {
|
19388 | |
19389 |
|
19390 |
|
19391 |
|
19392 | defaults: {
|
19393 | |
19394 |
|
19395 |
|
19396 |
|
19397 | pointers: 1
|
19398 | },
|
19399 |
|
19400 | |
19401 |
|
19402 |
|
19403 |
|
19404 |
|
19405 |
|
19406 | attrTest: function (input) {
|
19407 | var optionPointers = this.options.pointers;
|
19408 | return optionPointers === 0 || input.pointers.length === optionPointers;
|
19409 | },
|
19410 |
|
19411 | |
19412 |
|
19413 |
|
19414 |
|
19415 |
|
19416 |
|
19417 | process: function (input) {
|
19418 | var state = this.state;
|
19419 | var eventType = input.eventType;
|
19420 | var isRecognized = state & (STATE_BEGAN | STATE_CHANGED);
|
19421 | var isValid = this.attrTest(input);
|
19422 |
|
19423 | if (isRecognized && (eventType & INPUT_CANCEL || !isValid)) {
|
19424 | return state | STATE_CANCELLED;
|
19425 | } else if (isRecognized || isValid) {
|
19426 | if (eventType & INPUT_END) {
|
19427 | return state | STATE_ENDED;
|
19428 | } else if (!(state & STATE_BEGAN)) {
|
19429 | return STATE_BEGAN;
|
19430 | }
|
19431 |
|
19432 | return state | STATE_CHANGED;
|
19433 | }
|
19434 |
|
19435 | return STATE_FAILED;
|
19436 | }
|
19437 | });
|
19438 | |
19439 |
|
19440 |
|
19441 |
|
19442 |
|
19443 |
|
19444 |
|
19445 | function PanRecognizer() {
|
19446 | AttrRecognizer.apply(this, arguments);
|
19447 | this.pX = null;
|
19448 | this.pY = null;
|
19449 | }
|
19450 |
|
19451 | inherit(PanRecognizer, AttrRecognizer, {
|
19452 | |
19453 |
|
19454 |
|
19455 |
|
19456 | defaults: {
|
19457 | event: 'pan',
|
19458 | threshold: 10,
|
19459 | pointers: 1,
|
19460 | direction: DIRECTION_ALL
|
19461 | },
|
19462 | getTouchAction: function () {
|
19463 | var direction = this.options.direction;
|
19464 | var actions = [];
|
19465 |
|
19466 | if (direction & DIRECTION_HORIZONTAL) {
|
19467 | actions.push(TOUCH_ACTION_PAN_Y);
|
19468 | }
|
19469 |
|
19470 | if (direction & DIRECTION_VERTICAL) {
|
19471 | actions.push(TOUCH_ACTION_PAN_X);
|
19472 | }
|
19473 |
|
19474 | return actions;
|
19475 | },
|
19476 | directionTest: function (input) {
|
19477 | var options = this.options;
|
19478 | var hasMoved = true;
|
19479 | var distance = input.distance;
|
19480 | var direction = input.direction;
|
19481 | var x = input.deltaX;
|
19482 | var y = input.deltaY;
|
19483 |
|
19484 | if (!(direction & options.direction)) {
|
19485 | if (options.direction & DIRECTION_HORIZONTAL) {
|
19486 | direction = x === 0 ? DIRECTION_NONE : x < 0 ? DIRECTION_LEFT : DIRECTION_RIGHT;
|
19487 | hasMoved = x != this.pX;
|
19488 | distance = Math.abs(input.deltaX);
|
19489 | } else {
|
19490 | direction = y === 0 ? DIRECTION_NONE : y < 0 ? DIRECTION_UP : DIRECTION_DOWN;
|
19491 | hasMoved = y != this.pY;
|
19492 | distance = Math.abs(input.deltaY);
|
19493 | }
|
19494 | }
|
19495 |
|
19496 | input.direction = direction;
|
19497 | return hasMoved && distance > options.threshold && direction & options.direction;
|
19498 | },
|
19499 | attrTest: function (input) {
|
19500 | return AttrRecognizer.prototype.attrTest.call(this, input) && (this.state & STATE_BEGAN || !(this.state & STATE_BEGAN) && this.directionTest(input));
|
19501 | },
|
19502 | emit: function (input) {
|
19503 | this.pX = input.deltaX;
|
19504 | this.pY = input.deltaY;
|
19505 | var direction = directionStr(input.direction);
|
19506 |
|
19507 | if (direction) {
|
19508 | input.additionalEvent = this.options.event + direction;
|
19509 | }
|
19510 |
|
19511 | this._super.emit.call(this, input);
|
19512 | }
|
19513 | });
|
19514 | |
19515 |
|
19516 |
|
19517 |
|
19518 |
|
19519 |
|
19520 |
|
19521 | function PinchRecognizer() {
|
19522 | AttrRecognizer.apply(this, arguments);
|
19523 | }
|
19524 |
|
19525 | inherit(PinchRecognizer, AttrRecognizer, {
|
19526 | |
19527 |
|
19528 |
|
19529 |
|
19530 | defaults: {
|
19531 | event: 'pinch',
|
19532 | threshold: 0,
|
19533 | pointers: 2
|
19534 | },
|
19535 | getTouchAction: function () {
|
19536 | return [TOUCH_ACTION_NONE];
|
19537 | },
|
19538 | attrTest: function (input) {
|
19539 | return this._super.attrTest.call(this, input) && (Math.abs(input.scale - 1) > this.options.threshold || this.state & STATE_BEGAN);
|
19540 | },
|
19541 | emit: function (input) {
|
19542 | if (input.scale !== 1) {
|
19543 | var inOut = input.scale < 1 ? 'in' : 'out';
|
19544 | input.additionalEvent = this.options.event + inOut;
|
19545 | }
|
19546 |
|
19547 | this._super.emit.call(this, input);
|
19548 | }
|
19549 | });
|
19550 | |
19551 |
|
19552 |
|
19553 |
|
19554 |
|
19555 |
|
19556 |
|
19557 | function PressRecognizer() {
|
19558 | Recognizer.apply(this, arguments);
|
19559 | this._timer = null;
|
19560 | this._input = null;
|
19561 | }
|
19562 |
|
19563 | inherit(PressRecognizer, Recognizer, {
|
19564 | |
19565 |
|
19566 |
|
19567 |
|
19568 | defaults: {
|
19569 | event: 'press',
|
19570 | pointers: 1,
|
19571 | time: 251,
|
19572 |
|
19573 | threshold: 9
|
19574 |
|
19575 | },
|
19576 | getTouchAction: function () {
|
19577 | return [TOUCH_ACTION_AUTO];
|
19578 | },
|
19579 | process: function (input) {
|
19580 | var options = this.options;
|
19581 | var validPointers = input.pointers.length === options.pointers;
|
19582 | var validMovement = input.distance < options.threshold;
|
19583 | var validTime = input.deltaTime > options.time;
|
19584 | this._input = input;
|
19585 |
|
19586 |
|
19587 | if (!validMovement || !validPointers || input.eventType & (INPUT_END | INPUT_CANCEL) && !validTime) {
|
19588 | this.reset();
|
19589 | } else if (input.eventType & INPUT_START) {
|
19590 | this.reset();
|
19591 | this._timer = setTimeoutContext(function () {
|
19592 | this.state = STATE_RECOGNIZED;
|
19593 | this.tryEmit();
|
19594 | }, options.time, this);
|
19595 | } else if (input.eventType & INPUT_END) {
|
19596 | return STATE_RECOGNIZED;
|
19597 | }
|
19598 |
|
19599 | return STATE_FAILED;
|
19600 | },
|
19601 | reset: function () {
|
19602 | clearTimeout(this._timer);
|
19603 | },
|
19604 | emit: function (input) {
|
19605 | if (this.state !== STATE_RECOGNIZED) {
|
19606 | return;
|
19607 | }
|
19608 |
|
19609 | if (input && input.eventType & INPUT_END) {
|
19610 | this.manager.emit(this.options.event + 'up', input);
|
19611 | } else {
|
19612 | this._input.timeStamp = now();
|
19613 | this.manager.emit(this.options.event, this._input);
|
19614 | }
|
19615 | }
|
19616 | });
|
19617 | |
19618 |
|
19619 |
|
19620 |
|
19621 |
|
19622 |
|
19623 |
|
19624 | function RotateRecognizer() {
|
19625 | AttrRecognizer.apply(this, arguments);
|
19626 | }
|
19627 |
|
19628 | inherit(RotateRecognizer, AttrRecognizer, {
|
19629 | |
19630 |
|
19631 |
|
19632 |
|
19633 | defaults: {
|
19634 | event: 'rotate',
|
19635 | threshold: 0,
|
19636 | pointers: 2
|
19637 | },
|
19638 | getTouchAction: function () {
|
19639 | return [TOUCH_ACTION_NONE];
|
19640 | },
|
19641 | attrTest: function (input) {
|
19642 | return this._super.attrTest.call(this, input) && (Math.abs(input.rotation) > this.options.threshold || this.state & STATE_BEGAN);
|
19643 | }
|
19644 | });
|
19645 | |
19646 |
|
19647 |
|
19648 |
|
19649 |
|
19650 |
|
19651 |
|
19652 | function SwipeRecognizer() {
|
19653 | AttrRecognizer.apply(this, arguments);
|
19654 | }
|
19655 |
|
19656 | inherit(SwipeRecognizer, AttrRecognizer, {
|
19657 | |
19658 |
|
19659 |
|
19660 |
|
19661 | defaults: {
|
19662 | event: 'swipe',
|
19663 | threshold: 10,
|
19664 | velocity: 0.3,
|
19665 | direction: DIRECTION_HORIZONTAL | DIRECTION_VERTICAL,
|
19666 | pointers: 1
|
19667 | },
|
19668 | getTouchAction: function () {
|
19669 | return PanRecognizer.prototype.getTouchAction.call(this);
|
19670 | },
|
19671 | attrTest: function (input) {
|
19672 | var direction = this.options.direction;
|
19673 | var velocity;
|
19674 |
|
19675 | if (direction & (DIRECTION_HORIZONTAL | DIRECTION_VERTICAL)) {
|
19676 | velocity = input.overallVelocity;
|
19677 | } else if (direction & DIRECTION_HORIZONTAL) {
|
19678 | velocity = input.overallVelocityX;
|
19679 | } else if (direction & DIRECTION_VERTICAL) {
|
19680 | velocity = input.overallVelocityY;
|
19681 | }
|
19682 |
|
19683 | 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;
|
19684 | },
|
19685 | emit: function (input) {
|
19686 | var direction = directionStr(input.offsetDirection);
|
19687 |
|
19688 | if (direction) {
|
19689 | this.manager.emit(this.options.event + direction, input);
|
19690 | }
|
19691 |
|
19692 | this.manager.emit(this.options.event, input);
|
19693 | }
|
19694 | });
|
19695 | |
19696 |
|
19697 |
|
19698 |
|
19699 |
|
19700 |
|
19701 |
|
19702 |
|
19703 |
|
19704 |
|
19705 |
|
19706 | function TapRecognizer() {
|
19707 | Recognizer.apply(this, arguments);
|
19708 |
|
19709 |
|
19710 | this.pTime = false;
|
19711 | this.pCenter = false;
|
19712 | this._timer = null;
|
19713 | this._input = null;
|
19714 | this.count = 0;
|
19715 | }
|
19716 |
|
19717 | inherit(TapRecognizer, Recognizer, {
|
19718 | |
19719 |
|
19720 |
|
19721 |
|
19722 | defaults: {
|
19723 | event: 'tap',
|
19724 | pointers: 1,
|
19725 | taps: 1,
|
19726 | interval: 300,
|
19727 |
|
19728 | time: 250,
|
19729 |
|
19730 | threshold: 9,
|
19731 |
|
19732 | posThreshold: 10
|
19733 |
|
19734 | },
|
19735 | getTouchAction: function () {
|
19736 | return [TOUCH_ACTION_MANIPULATION];
|
19737 | },
|
19738 | process: function (input) {
|
19739 | var options = this.options;
|
19740 | var validPointers = input.pointers.length === options.pointers;
|
19741 | var validMovement = input.distance < options.threshold;
|
19742 | var validTouchTime = input.deltaTime < options.time;
|
19743 | this.reset();
|
19744 |
|
19745 | if (input.eventType & INPUT_START && this.count === 0) {
|
19746 | return this.failTimeout();
|
19747 | }
|
19748 |
|
19749 |
|
19750 |
|
19751 | if (validMovement && validTouchTime && validPointers) {
|
19752 | if (input.eventType != INPUT_END) {
|
19753 | return this.failTimeout();
|
19754 | }
|
19755 |
|
19756 | var validInterval = this.pTime ? input.timeStamp - this.pTime < options.interval : true;
|
19757 | var validMultiTap = !this.pCenter || getDistance(this.pCenter, input.center) < options.posThreshold;
|
19758 | this.pTime = input.timeStamp;
|
19759 | this.pCenter = input.center;
|
19760 |
|
19761 | if (!validMultiTap || !validInterval) {
|
19762 | this.count = 1;
|
19763 | } else {
|
19764 | this.count += 1;
|
19765 | }
|
19766 |
|
19767 | this._input = input;
|
19768 |
|
19769 |
|
19770 | var tapCount = this.count % options.taps;
|
19771 |
|
19772 | if (tapCount === 0) {
|
19773 |
|
19774 |
|
19775 | if (!this.hasRequireFailures()) {
|
19776 | return STATE_RECOGNIZED;
|
19777 | } else {
|
19778 | this._timer = setTimeoutContext(function () {
|
19779 | this.state = STATE_RECOGNIZED;
|
19780 | this.tryEmit();
|
19781 | }, options.interval, this);
|
19782 | return STATE_BEGAN;
|
19783 | }
|
19784 | }
|
19785 | }
|
19786 |
|
19787 | return STATE_FAILED;
|
19788 | },
|
19789 | failTimeout: function () {
|
19790 | this._timer = setTimeoutContext(function () {
|
19791 | this.state = STATE_FAILED;
|
19792 | }, this.options.interval, this);
|
19793 | return STATE_FAILED;
|
19794 | },
|
19795 | reset: function () {
|
19796 | clearTimeout(this._timer);
|
19797 | },
|
19798 | emit: function () {
|
19799 | if (this.state == STATE_RECOGNIZED) {
|
19800 | this._input.tapCount = this.count;
|
19801 | this.manager.emit(this.options.event, this._input);
|
19802 | }
|
19803 | }
|
19804 | });
|
19805 | |
19806 |
|
19807 |
|
19808 |
|
19809 |
|
19810 |
|
19811 |
|
19812 | function Hammer(element, options) {
|
19813 | options = options || {};
|
19814 | options.recognizers = ifUndefined(options.recognizers, Hammer.defaults.preset);
|
19815 | return new Manager(element, options);
|
19816 | }
|
19817 | |
19818 |
|
19819 |
|
19820 |
|
19821 |
|
19822 | Hammer.VERSION = '2.0.7';
|
19823 | |
19824 |
|
19825 |
|
19826 |
|
19827 |
|
19828 | Hammer.defaults = {
|
19829 | |
19830 |
|
19831 |
|
19832 |
|
19833 |
|
19834 |
|
19835 | domEvents: false,
|
19836 |
|
19837 | |
19838 |
|
19839 |
|
19840 |
|
19841 |
|
19842 |
|
19843 | touchAction: TOUCH_ACTION_COMPUTE,
|
19844 |
|
19845 | |
19846 |
|
19847 |
|
19848 |
|
19849 | enable: true,
|
19850 |
|
19851 | |
19852 |
|
19853 |
|
19854 |
|
19855 |
|
19856 |
|
19857 |
|
19858 | inputTarget: null,
|
19859 |
|
19860 | |
19861 |
|
19862 |
|
19863 |
|
19864 |
|
19865 | inputClass: null,
|
19866 |
|
19867 | |
19868 |
|
19869 |
|
19870 |
|
19871 |
|
19872 | preset: [
|
19873 | [RotateRecognizer, {
|
19874 | enable: false
|
19875 | }], [PinchRecognizer, {
|
19876 | enable: false
|
19877 | }, ['rotate']], [SwipeRecognizer, {
|
19878 | direction: DIRECTION_HORIZONTAL
|
19879 | }], [PanRecognizer, {
|
19880 | direction: DIRECTION_HORIZONTAL
|
19881 | }, ['swipe']], [TapRecognizer], [TapRecognizer, {
|
19882 | event: 'doubletap',
|
19883 | taps: 2
|
19884 | }, ['tap']], [PressRecognizer]],
|
19885 |
|
19886 | |
19887 |
|
19888 |
|
19889 |
|
19890 |
|
19891 | cssProps: {
|
19892 | |
19893 |
|
19894 |
|
19895 |
|
19896 |
|
19897 | userSelect: 'none',
|
19898 |
|
19899 | |
19900 |
|
19901 |
|
19902 |
|
19903 |
|
19904 | touchSelect: 'none',
|
19905 |
|
19906 | |
19907 |
|
19908 |
|
19909 |
|
19910 |
|
19911 |
|
19912 |
|
19913 | touchCallout: 'none',
|
19914 |
|
19915 | |
19916 |
|
19917 |
|
19918 |
|
19919 |
|
19920 | contentZooming: 'none',
|
19921 |
|
19922 | |
19923 |
|
19924 |
|
19925 |
|
19926 |
|
19927 | userDrag: 'none',
|
19928 |
|
19929 | |
19930 |
|
19931 |
|
19932 |
|
19933 |
|
19934 |
|
19935 | tapHighlightColor: 'rgba(0,0,0,0)'
|
19936 | }
|
19937 | };
|
19938 | var STOP = 1;
|
19939 | var FORCED_STOP = 2;
|
19940 | |
19941 |
|
19942 |
|
19943 |
|
19944 |
|
19945 |
|
19946 |
|
19947 | function Manager(element, options) {
|
19948 | this.options = assign({}, Hammer.defaults, options || {});
|
19949 | this.options.inputTarget = this.options.inputTarget || element;
|
19950 | this.handlers = {};
|
19951 | this.session = {};
|
19952 | this.recognizers = [];
|
19953 | this.oldCssProps = {};
|
19954 | this.element = element;
|
19955 | this.input = createInputInstance(this);
|
19956 | this.touchAction = new TouchAction(this, this.options.touchAction);
|
19957 | toggleCssProps(this, true);
|
19958 | each(this.options.recognizers, function (item) {
|
19959 | var recognizer = this.add(new item[0](item[1]));
|
19960 | item[2] && recognizer.recognizeWith(item[2]);
|
19961 | item[3] && recognizer.requireFailure(item[3]);
|
19962 | }, this);
|
19963 | }
|
19964 |
|
19965 | Manager.prototype = {
|
19966 | |
19967 |
|
19968 |
|
19969 |
|
19970 |
|
19971 | set: function (options) {
|
19972 | assign(this.options, options);
|
19973 |
|
19974 | if (options.touchAction) {
|
19975 | this.touchAction.update();
|
19976 | }
|
19977 |
|
19978 | if (options.inputTarget) {
|
19979 |
|
19980 | this.input.destroy();
|
19981 | this.input.target = options.inputTarget;
|
19982 | this.input.init();
|
19983 | }
|
19984 |
|
19985 | return this;
|
19986 | },
|
19987 |
|
19988 | |
19989 |
|
19990 |
|
19991 |
|
19992 |
|
19993 |
|
19994 | stop: function (force) {
|
19995 | this.session.stopped = force ? FORCED_STOP : STOP;
|
19996 | },
|
19997 |
|
19998 | |
19999 |
|
20000 |
|
20001 |
|
20002 |
|
20003 |
|
20004 | recognize: function (inputData) {
|
20005 | var session = this.session;
|
20006 |
|
20007 | if (session.stopped) {
|
20008 | return;
|
20009 | }
|
20010 |
|
20011 |
|
20012 | this.touchAction.preventDefaults(inputData);
|
20013 | var recognizer;
|
20014 | var recognizers = this.recognizers;
|
20015 |
|
20016 |
|
20017 |
|
20018 | var curRecognizer = session.curRecognizer;
|
20019 |
|
20020 |
|
20021 | if (!curRecognizer || curRecognizer && curRecognizer.state & STATE_RECOGNIZED) {
|
20022 | curRecognizer = session.curRecognizer = null;
|
20023 | }
|
20024 |
|
20025 | var i = 0;
|
20026 |
|
20027 | while (i < recognizers.length) {
|
20028 | recognizer = recognizers[i];
|
20029 |
|
20030 |
|
20031 |
|
20032 |
|
20033 |
|
20034 |
|
20035 | if (session.stopped !== FORCED_STOP && (
|
20036 | !curRecognizer || recognizer == curRecognizer ||
|
20037 | recognizer.canRecognizeWith(curRecognizer))) {
|
20038 |
|
20039 | recognizer.recognize(inputData);
|
20040 | } else {
|
20041 | recognizer.reset();
|
20042 | }
|
20043 |
|
20044 |
|
20045 |
|
20046 | if (!curRecognizer && recognizer.state & (STATE_BEGAN | STATE_CHANGED | STATE_ENDED)) {
|
20047 | curRecognizer = session.curRecognizer = recognizer;
|
20048 | }
|
20049 |
|
20050 | i++;
|
20051 | }
|
20052 | },
|
20053 |
|
20054 | |
20055 |
|
20056 |
|
20057 |
|
20058 |
|
20059 | get: function (recognizer) {
|
20060 | if (recognizer instanceof Recognizer) {
|
20061 | return recognizer;
|
20062 | }
|
20063 |
|
20064 | var recognizers = this.recognizers;
|
20065 |
|
20066 | for (var i = 0; i < recognizers.length; i++) {
|
20067 | if (recognizers[i].options.event == recognizer) {
|
20068 | return recognizers[i];
|
20069 | }
|
20070 | }
|
20071 |
|
20072 | return null;
|
20073 | },
|
20074 |
|
20075 | |
20076 |
|
20077 |
|
20078 |
|
20079 |
|
20080 |
|
20081 | add: function (recognizer) {
|
20082 | if (invokeArrayArg(recognizer, 'add', this)) {
|
20083 | return this;
|
20084 | }
|
20085 |
|
20086 |
|
20087 | var existing = this.get(recognizer.options.event);
|
20088 |
|
20089 | if (existing) {
|
20090 | this.remove(existing);
|
20091 | }
|
20092 |
|
20093 | this.recognizers.push(recognizer);
|
20094 | recognizer.manager = this;
|
20095 | this.touchAction.update();
|
20096 | return recognizer;
|
20097 | },
|
20098 |
|
20099 | |
20100 |
|
20101 |
|
20102 |
|
20103 |
|
20104 | remove: function (recognizer) {
|
20105 | if (invokeArrayArg(recognizer, 'remove', this)) {
|
20106 | return this;
|
20107 | }
|
20108 |
|
20109 | recognizer = this.get(recognizer);
|
20110 |
|
20111 | if (recognizer) {
|
20112 | var recognizers = this.recognizers;
|
20113 | var index = inArray(recognizers, recognizer);
|
20114 |
|
20115 | if (index !== -1) {
|
20116 | recognizers.splice(index, 1);
|
20117 | this.touchAction.update();
|
20118 | }
|
20119 | }
|
20120 |
|
20121 | return this;
|
20122 | },
|
20123 |
|
20124 | |
20125 |
|
20126 |
|
20127 |
|
20128 |
|
20129 |
|
20130 | on: function (events, handler) {
|
20131 | if (events === undefined) {
|
20132 | return;
|
20133 | }
|
20134 |
|
20135 | if (handler === undefined) {
|
20136 | return;
|
20137 | }
|
20138 |
|
20139 | var handlers = this.handlers;
|
20140 | each(splitStr(events), function (event) {
|
20141 | handlers[event] = handlers[event] || [];
|
20142 | handlers[event].push(handler);
|
20143 | });
|
20144 | return this;
|
20145 | },
|
20146 |
|
20147 | |
20148 |
|
20149 |
|
20150 |
|
20151 |
|
20152 |
|
20153 | off: function (events, handler) {
|
20154 | if (events === undefined) {
|
20155 | return;
|
20156 | }
|
20157 |
|
20158 | var handlers = this.handlers;
|
20159 | each(splitStr(events), function (event) {
|
20160 | if (!handler) {
|
20161 | delete handlers[event];
|
20162 | } else {
|
20163 | handlers[event] && handlers[event].splice(inArray(handlers[event], handler), 1);
|
20164 | }
|
20165 | });
|
20166 | return this;
|
20167 | },
|
20168 |
|
20169 | |
20170 |
|
20171 |
|
20172 |
|
20173 |
|
20174 | emit: function (event, data) {
|
20175 |
|
20176 | if (this.options.domEvents) {
|
20177 | triggerDomEvent(event, data);
|
20178 | }
|
20179 |
|
20180 |
|
20181 | var handlers = this.handlers[event] && this.handlers[event].slice();
|
20182 |
|
20183 | if (!handlers || !handlers.length) {
|
20184 | return;
|
20185 | }
|
20186 |
|
20187 | data.type = event;
|
20188 |
|
20189 | data.preventDefault = function () {
|
20190 | data.srcEvent.preventDefault();
|
20191 | };
|
20192 |
|
20193 | var i = 0;
|
20194 |
|
20195 | while (i < handlers.length) {
|
20196 | handlers[i](data);
|
20197 | i++;
|
20198 | }
|
20199 | },
|
20200 |
|
20201 | |
20202 |
|
20203 |
|
20204 |
|
20205 | destroy: function () {
|
20206 | this.element && toggleCssProps(this, false);
|
20207 | this.handlers = {};
|
20208 | this.session = {};
|
20209 | this.input.destroy();
|
20210 | this.element = null;
|
20211 | }
|
20212 | };
|
20213 | |
20214 |
|
20215 |
|
20216 |
|
20217 |
|
20218 |
|
20219 | function toggleCssProps(manager, add) {
|
20220 | var element = manager.element;
|
20221 |
|
20222 | if (!element.style) {
|
20223 | return;
|
20224 | }
|
20225 |
|
20226 | var prop;
|
20227 | each(manager.options.cssProps, function (value, name) {
|
20228 | prop = prefixed(element.style, name);
|
20229 |
|
20230 | if (add) {
|
20231 | manager.oldCssProps[prop] = element.style[prop];
|
20232 | element.style[prop] = value;
|
20233 | } else {
|
20234 | element.style[prop] = manager.oldCssProps[prop] || '';
|
20235 | }
|
20236 | });
|
20237 |
|
20238 | if (!add) {
|
20239 | manager.oldCssProps = {};
|
20240 | }
|
20241 | }
|
20242 | |
20243 |
|
20244 |
|
20245 |
|
20246 |
|
20247 |
|
20248 |
|
20249 | function triggerDomEvent(event, data) {
|
20250 | var gestureEvent = document.createEvent('Event');
|
20251 | gestureEvent.initEvent(event, true, true);
|
20252 | gestureEvent.gesture = data;
|
20253 | data.target.dispatchEvent(gestureEvent);
|
20254 | }
|
20255 |
|
20256 | assign(Hammer, {
|
20257 | INPUT_START: INPUT_START,
|
20258 | INPUT_MOVE: INPUT_MOVE,
|
20259 | INPUT_END: INPUT_END,
|
20260 | INPUT_CANCEL: INPUT_CANCEL,
|
20261 | STATE_POSSIBLE: STATE_POSSIBLE,
|
20262 | STATE_BEGAN: STATE_BEGAN,
|
20263 | STATE_CHANGED: STATE_CHANGED,
|
20264 | STATE_ENDED: STATE_ENDED,
|
20265 | STATE_RECOGNIZED: STATE_RECOGNIZED,
|
20266 | STATE_CANCELLED: STATE_CANCELLED,
|
20267 | STATE_FAILED: STATE_FAILED,
|
20268 | DIRECTION_NONE: DIRECTION_NONE,
|
20269 | DIRECTION_LEFT: DIRECTION_LEFT,
|
20270 | DIRECTION_RIGHT: DIRECTION_RIGHT,
|
20271 | DIRECTION_UP: DIRECTION_UP,
|
20272 | DIRECTION_DOWN: DIRECTION_DOWN,
|
20273 | DIRECTION_HORIZONTAL: DIRECTION_HORIZONTAL,
|
20274 | DIRECTION_VERTICAL: DIRECTION_VERTICAL,
|
20275 | DIRECTION_ALL: DIRECTION_ALL,
|
20276 | Manager: Manager,
|
20277 | Input: Input,
|
20278 | TouchAction: TouchAction,
|
20279 | TouchInput: TouchInput,
|
20280 | MouseInput: MouseInput,
|
20281 | PointerEventInput: PointerEventInput,
|
20282 | TouchMouseInput: TouchMouseInput,
|
20283 | SingleTouchInput: SingleTouchInput,
|
20284 | Recognizer: Recognizer,
|
20285 | AttrRecognizer: AttrRecognizer,
|
20286 | Tap: TapRecognizer,
|
20287 | Pan: PanRecognizer,
|
20288 | Swipe: SwipeRecognizer,
|
20289 | Pinch: PinchRecognizer,
|
20290 | Rotate: RotateRecognizer,
|
20291 | Press: PressRecognizer,
|
20292 | on: addEventListeners,
|
20293 | off: removeEventListeners,
|
20294 | each: each,
|
20295 | merge: merge,
|
20296 | extend: extend,
|
20297 | assign: assign,
|
20298 | inherit: inherit,
|
20299 | bindFn: bindFn,
|
20300 | prefixed: prefixed
|
20301 | });
|
20302 |
|
20303 |
|
20304 | var freeGlobal = typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {};
|
20305 |
|
20306 | freeGlobal.Hammer = Hammer;
|
20307 |
|
20308 | if (true) {
|
20309 | !(__WEBPACK_AMD_DEFINE_RESULT__ = (function () {
|
20310 | return Hammer;
|
20311 | }).call(exports, __webpack_require__, exports, module),
|
20312 | __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
20313 | } else if (typeof module != 'undefined' && module.exports) {
|
20314 | module.exports = Hammer;
|
20315 | } else {
|
20316 | window[exportName] = Hammer;
|
20317 | }
|
20318 | })(window, document, 'Hammer');
|
20319 |
|
20320 | }),
|
20321 |
|
20322 | (function(module, exports, __webpack_require__) {
|
20323 |
|
20324 | function _inheritsLoose(subClass, superClass) {
|
20325 | subClass.prototype = Object.create(superClass.prototype);
|
20326 | subClass.prototype.constructor = subClass;
|
20327 | subClass.__proto__ = superClass;
|
20328 | }
|
20329 |
|
20330 | var Util = __webpack_require__(0);
|
20331 |
|
20332 | var Helper = __webpack_require__(20);
|
20333 |
|
20334 | var Interaction = __webpack_require__(22);
|
20335 |
|
20336 | var Chart = __webpack_require__(12);
|
20337 |
|
20338 | var IntervalSelect =
|
20339 |
|
20340 | function (_Interaction) {
|
20341 | _inheritsLoose(IntervalSelect, _Interaction);
|
20342 |
|
20343 | var _proto = IntervalSelect.prototype;
|
20344 |
|
20345 | _proto.getDefaultCfg = function getDefaultCfg() {
|
20346 | var defaultCfg = _Interaction.prototype.getDefaultCfg.call(this);
|
20347 |
|
20348 | defaultCfg = Util.mix({}, defaultCfg, {
|
20349 | startEvent: 'tap',
|
20350 | processEvent: null,
|
20351 | selectAxis: true,
|
20352 | selectAxisStyle: {
|
20353 | fontWeight: 'bold'
|
20354 | },
|
20355 | mode: 'shape',
|
20356 | selectStyle: {
|
20357 | fillOpacity: 1
|
20358 | },
|
20359 | unSelectStyle: {
|
20360 | fillOpacity: 0.4
|
20361 | },
|
20362 | cancelable: true,
|
20363 | defaultSelected: null
|
20364 |
|
20365 | });
|
20366 |
|
20367 | if (Util.isWx || Util.isMy) {
|
20368 |
|
20369 | defaultCfg.startEvent = 'touchstart';
|
20370 | defaultCfg.endEvent = 'touchend';
|
20371 | }
|
20372 |
|
20373 | return defaultCfg;
|
20374 | };
|
20375 |
|
20376 | function IntervalSelect(cfg, chart) {
|
20377 | var _this;
|
20378 |
|
20379 | _this = _Interaction.call(this, cfg, chart) || this;
|
20380 | var defaultSelected = _this.defaultSelected;
|
20381 |
|
20382 | if (Util.isObject(defaultSelected)) {
|
20383 | var _this$_selectShapesBy = _this._selectShapesByData(defaultSelected),
|
20384 | selectedShape = _this$_selectShapesBy.selectedShape,
|
20385 | unSelectedShapes = _this$_selectShapesBy.unSelectedShapes;
|
20386 |
|
20387 | selectedShape && _this._selectShapes(selectedShape, unSelectedShapes);
|
20388 | _this.selectedShape = selectedShape;
|
20389 | }
|
20390 |
|
20391 | return _this;
|
20392 | }
|
20393 |
|
20394 | _proto._getIntervalShapes = function _getIntervalShapes() {
|
20395 | var children = [];
|
20396 | var chart = this.chart;
|
20397 | var geoms = chart.get('geoms');
|
20398 | geoms.forEach(function (geom) {
|
20399 | if (geom.get('type') === 'interval') {
|
20400 |
|
20401 | var container = geom.get('container');
|
20402 | children = children.concat(container.get('children'));
|
20403 | }
|
20404 | });
|
20405 | return children;
|
20406 | };
|
20407 |
|
20408 | _proto._resetShape = function _resetShape(shape) {
|
20409 | var originAttrs = shape.get('_originAttrs');
|
20410 |
|
20411 | if (originAttrs) {
|
20412 | shape._attrs.attrs = originAttrs;
|
20413 | shape.set('_originAttrs', null);
|
20414 | }
|
20415 | };
|
20416 |
|
20417 | _proto._setEventData = function _setEventData(ev) {
|
20418 | var selectedShape = this.selectedShape;
|
20419 |
|
20420 | if (selectedShape && !selectedShape.get('destroyed')) {
|
20421 | ev.data = selectedShape.get('origin')._origin;
|
20422 | ev.shapeInfo = selectedShape.get('origin');
|
20423 | ev.shape = selectedShape;
|
20424 | ev.selected = !!selectedShape.get('_selected');
|
20425 | }
|
20426 | };
|
20427 |
|
20428 | _proto._selectShapesByData = function _selectShapesByData(data) {
|
20429 | var children = this._getIntervalShapes();
|
20430 |
|
20431 | var selectedShape = null;
|
20432 | var unSelectedShapes = [];
|
20433 | Util.each(children, function (child) {
|
20434 | if (child.get('isShape') && child.get('className') === 'interval') {
|
20435 |
|
20436 | var shapeData = child.get('origin')._origin;
|
20437 |
|
20438 | if (Util.isObjectValueEqual(shapeData, data)) {
|
20439 | selectedShape = child;
|
20440 | } else {
|
20441 | unSelectedShapes.push(child);
|
20442 | }
|
20443 | }
|
20444 | });
|
20445 | return {
|
20446 | selectedShape: selectedShape,
|
20447 | unSelectedShapes: unSelectedShapes
|
20448 | };
|
20449 | };
|
20450 |
|
20451 | _proto._selectShapes = function _selectShapes(selectedShape, unSelectedShapes) {
|
20452 | var selectStyle = this.selectStyle,
|
20453 | unSelectStyle = this.unSelectStyle,
|
20454 | selectAxisStyle = this.selectAxisStyle,
|
20455 | chart = this.chart;
|
20456 |
|
20457 | if (!selectedShape.get('_originAttrs')) {
|
20458 | var originAttrs = Object.assign({}, selectedShape.attr());
|
20459 | selectedShape.set('_originAttrs', originAttrs);
|
20460 | }
|
20461 |
|
20462 | selectedShape.attr(selectStyle);
|
20463 | Util.each(unSelectedShapes, function (child) {
|
20464 | if (!child.get('_originAttrs')) {
|
20465 | var _originAttrs = Object.assign({}, child.attr());
|
20466 |
|
20467 | child.set('_originAttrs', _originAttrs);
|
20468 | } else {
|
20469 | child.attr(child.get('_originAttrs'));
|
20470 | }
|
20471 |
|
20472 | child.set('_selected', false);
|
20473 | unSelectStyle && child.attr(unSelectStyle);
|
20474 | });
|
20475 | selectedShape.set('_selected', true);
|
20476 |
|
20477 | if (this.selectAxis) {
|
20478 | if (this.selectedAxisShape) {
|
20479 | this._resetShape(this.selectedAxisShape);
|
20480 | }
|
20481 |
|
20482 | var xScale = chart.getXScale();
|
20483 |
|
20484 | var origin = selectedShape.get('origin')._origin;
|
20485 |
|
20486 | var _chart$get = chart.get('axisController'),
|
20487 | frontPlot = _chart$get.frontPlot,
|
20488 | backPlot = _chart$get.backPlot;
|
20489 |
|
20490 | var axisShape;
|
20491 | Util.each(frontPlot.get('children').concat(backPlot.get('children')), function (s) {
|
20492 | if (s.get('value') === xScale.scale(origin[xScale.field])) {
|
20493 | axisShape = s;
|
20494 | return false;
|
20495 | }
|
20496 | });
|
20497 | this.selectedAxisShape = axisShape;
|
20498 | axisShape.set('_originAttrs', Object.assign({}, axisShape.attr()));
|
20499 | axisShape.attr(selectAxisStyle);
|
20500 | }
|
20501 |
|
20502 | this.canvas.draw();
|
20503 | };
|
20504 |
|
20505 | _proto.reset = function reset() {
|
20506 | var self = this;
|
20507 |
|
20508 | if (!self.selectedShape) {
|
20509 | return;
|
20510 | }
|
20511 |
|
20512 | var children = self._getIntervalShapes();
|
20513 |
|
20514 | Util.each(children, function (child) {
|
20515 | self._resetShape(child);
|
20516 |
|
20517 | child.set('_selected', false);
|
20518 | });
|
20519 |
|
20520 | if (self.selectedAxisShape) {
|
20521 | self._resetShape(self.selectedAxisShape);
|
20522 | }
|
20523 |
|
20524 | self.canvas.draw();
|
20525 | self.selectedShape = null;
|
20526 | self.selectedAxisShape = null;
|
20527 | };
|
20528 |
|
20529 | _proto.start = function start(ev) {
|
20530 | var chart = this.chart;
|
20531 |
|
20532 | if (ev.type === 'tap') {
|
20533 | ev.clientX = ev.center.x;
|
20534 | ev.clientY = ev.center.y;
|
20535 | }
|
20536 |
|
20537 | var _Util$createEvent = Util.createEvent(ev, chart),
|
20538 | x = _Util$createEvent.x,
|
20539 | y = _Util$createEvent.y;
|
20540 |
|
20541 | var mode = this.mode;
|
20542 |
|
20543 | var children = this._getIntervalShapes();
|
20544 |
|
20545 | var selectedShape;
|
20546 | var unSelectedShapes = [];
|
20547 |
|
20548 | if (mode === 'shape') {
|
20549 | var plot = chart.get('plotRange');
|
20550 |
|
20551 | if (!Helper.isPointInPlot({
|
20552 | x: x,
|
20553 | y: y
|
20554 | }, plot)) {
|
20555 | this.reset();
|
20556 | return;
|
20557 | }
|
20558 |
|
20559 | Util.each(children, function (child) {
|
20560 | var box = child.getBBox();
|
20561 |
|
20562 | if (x >= box.x && x <= box.x + box.width && y >= box.y && y <= box.height + box.y) {
|
20563 |
|
20564 | selectedShape = child;
|
20565 | } else {
|
20566 | unSelectedShapes.push(child);
|
20567 | }
|
20568 | });
|
20569 | } else if (mode === 'range') {
|
20570 | var records = chart.getSnapRecords({
|
20571 | x: x,
|
20572 | y: y
|
20573 | });
|
20574 |
|
20575 | if (!records.length) {
|
20576 | this.reset();
|
20577 | return;
|
20578 | }
|
20579 |
|
20580 | var data = records[0]._origin;
|
20581 |
|
20582 | var result = this._selectShapesByData(data);
|
20583 |
|
20584 | selectedShape = result.selectedShape;
|
20585 | unSelectedShapes = result.unSelectedShapes;
|
20586 | }
|
20587 |
|
20588 | if (selectedShape) {
|
20589 | this.selectedShape = selectedShape;
|
20590 |
|
20591 | if (selectedShape.get('_selected')) {
|
20592 | if (!this.cancelable) {
|
20593 | this._setEventData(ev);
|
20594 |
|
20595 | return;
|
20596 | }
|
20597 |
|
20598 | this.reset();
|
20599 | } else {
|
20600 | this._selectShapes(selectedShape, unSelectedShapes);
|
20601 | }
|
20602 | } else {
|
20603 | this.reset();
|
20604 | }
|
20605 |
|
20606 | this._setEventData(ev);
|
20607 | };
|
20608 |
|
20609 | _proto.end = function end(ev) {
|
20610 | this._setEventData(ev);
|
20611 | };
|
20612 |
|
20613 | return IntervalSelect;
|
20614 | }(Interaction);
|
20615 |
|
20616 | Chart.registerInteraction('interval-select', IntervalSelect);
|
20617 | module.exports = IntervalSelect;
|
20618 |
|
20619 | }),
|
20620 |
|
20621 | (function(module, exports, __webpack_require__) {
|
20622 |
|
20623 | function _inheritsLoose(subClass, superClass) {
|
20624 | subClass.prototype = Object.create(superClass.prototype);
|
20625 | subClass.prototype.constructor = subClass;
|
20626 | subClass.__proto__ = superClass;
|
20627 | }
|
20628 |
|
20629 | function _assertThisInitialized(self) {
|
20630 | if (self === void 0) {
|
20631 | throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
20632 | }
|
20633 |
|
20634 | return self;
|
20635 | }
|
20636 |
|
20637 | var Util = __webpack_require__(0);
|
20638 |
|
20639 | var Interaction = __webpack_require__(22);
|
20640 |
|
20641 | var Chart = __webpack_require__(12);
|
20642 |
|
20643 | var FilterPlugin = __webpack_require__(136);
|
20644 |
|
20645 | var MoveMixin = __webpack_require__(137);
|
20646 |
|
20647 | var PressTooltipMixin = __webpack_require__(138);
|
20648 |
|
20649 | var UpdateScaleMixin = __webpack_require__(139);
|
20650 |
|
20651 | var Pan =
|
20652 |
|
20653 | function (_Interaction) {
|
20654 | _inheritsLoose(Pan, _Interaction);
|
20655 |
|
20656 | var _proto = Pan.prototype;
|
20657 |
|
20658 | _proto.getDefaultCfg = function getDefaultCfg() {
|
20659 | var defaultCfg = _Interaction.prototype.getDefaultCfg.call(this);
|
20660 |
|
20661 | defaultCfg = Util.mix({}, defaultCfg, {
|
20662 | startEvent: 'panstart',
|
20663 | processEvent: 'panmove',
|
20664 | endEvent: 'panend',
|
20665 | resetEvent: 'touchend',
|
20666 | mode: 'x',
|
20667 | panThreshold: 10,
|
20668 |
|
20669 | pressThreshold: 9,
|
20670 |
|
20671 | pressTime: 251,
|
20672 |
|
20673 | currentDeltaX: null,
|
20674 | currentDeltaY: null,
|
20675 | limitRange: {},
|
20676 | _timestamp: 0,
|
20677 | lastPoint: null,
|
20678 | _panCumulativeDelta: 0,
|
20679 | speed: 5
|
20680 | });
|
20681 |
|
20682 | if (Util.isWx || Util.isMy) {
|
20683 |
|
20684 | defaultCfg.startEvent = 'touchstart';
|
20685 | defaultCfg.processEvent = 'touchmove';
|
20686 | defaultCfg.endEvent = 'touchend';
|
20687 | }
|
20688 |
|
20689 | return defaultCfg;
|
20690 | };
|
20691 |
|
20692 | function Pan(cfg, chart) {
|
20693 | var _this;
|
20694 |
|
20695 | _this = _Interaction.call(this, cfg, chart) || this;
|
20696 |
|
20697 | var self = _assertThisInitialized(_assertThisInitialized(_this));
|
20698 |
|
20699 | var hammer = self.hammer,
|
20700 | panThreshold = self.panThreshold;
|
20701 |
|
20702 | if (hammer) {
|
20703 | hammer.get('pan').set({
|
20704 | threshold: panThreshold
|
20705 | });
|
20706 | }
|
20707 |
|
20708 | chart.registerPlugins([FilterPlugin, {
|
20709 | changeData: function changeData() {
|
20710 | self.limitRange = {};
|
20711 | },
|
20712 | clear: function clear() {
|
20713 | self.limitRange = {};
|
20714 | }
|
20715 | }]);
|
20716 | Util.mix(_assertThisInitialized(_assertThisInitialized(_this)), UpdateScaleMixin, MoveMixin, PressTooltipMixin);
|
20717 |
|
20718 | _this._bindPress();
|
20719 |
|
20720 | return _this;
|
20721 | }
|
20722 |
|
20723 | _proto.start = function start(e) {
|
20724 | if (this.pressed) return;
|
20725 | this.currentDeltaX = 0;
|
20726 | this.currentDeltaY = 0;
|
20727 |
|
20728 | if (e.type === 'touchstart' || e.type === 'touchStart') {
|
20729 | this.lastPoint = e.touches[0];
|
20730 | }
|
20731 |
|
20732 | this._handleMove(e);
|
20733 | };
|
20734 |
|
20735 | _proto.process = function process(e) {
|
20736 | if (this.pressed) return;
|
20737 |
|
20738 | this._handleMove(e);
|
20739 | };
|
20740 |
|
20741 | _proto.end = function end() {
|
20742 | if (this.pressed) return;
|
20743 | this.currentDeltaX = null;
|
20744 | this.currentDeltaY = null;
|
20745 | this.lastPoint = null;
|
20746 | this._panCumulativeDelta = 0;
|
20747 | };
|
20748 |
|
20749 | return Pan;
|
20750 | }(Interaction);
|
20751 |
|
20752 | Chart.registerInteraction('pan', Pan);
|
20753 | module.exports = Pan;
|
20754 |
|
20755 | }),
|
20756 |
|
20757 | (function(module, exports, __webpack_require__) {
|
20758 |
|
20759 |
|
20760 |
|
20761 |
|
20762 | var Util = __webpack_require__(0);
|
20763 |
|
20764 | var TimeUtil = __webpack_require__(28);
|
20765 |
|
20766 | module.exports = {
|
20767 | beforeGeomInit: function beforeGeomInit(chart) {
|
20768 | chart.set('limitInPlot', true);
|
20769 | var data = chart.get('data');
|
20770 | var colDefs = chart.get('colDefs');
|
20771 | if (!colDefs) return data;
|
20772 | var geoms = chart.get('geoms');
|
20773 | var isSpecialGeom = false;
|
20774 |
|
20775 | Util.each(geoms, function (geom) {
|
20776 | if (['area', 'line', 'path'].indexOf(geom.get('type')) !== -1) {
|
20777 | isSpecialGeom = true;
|
20778 | return false;
|
20779 | }
|
20780 | });
|
20781 | var fields = [];
|
20782 | Util.each(colDefs, function (def, key) {
|
20783 | if (!isSpecialGeom && def && (def.values || def.min || def.max)) {
|
20784 | fields.push(key);
|
20785 | }
|
20786 | });
|
20787 |
|
20788 | if (fields.length === 0) {
|
20789 | return data;
|
20790 | }
|
20791 |
|
20792 | var geomData = [];
|
20793 | Util.each(data, function (obj) {
|
20794 | var flag = true;
|
20795 | Util.each(fields, function (field) {
|
20796 | var value = obj[field];
|
20797 |
|
20798 | if (value) {
|
20799 | var colDef = colDefs[field];
|
20800 |
|
20801 | if (colDef.type === 'timeCat') {
|
20802 | var values = colDef.values;
|
20803 |
|
20804 | if (Util.isNumber(values[0])) {
|
20805 | value = TimeUtil.toTimeStamp(value);
|
20806 | }
|
20807 | }
|
20808 |
|
20809 | if (colDef.values && colDef.values.indexOf(value) === -1 || colDef.min && value < colDef.min || colDef.max && value > colDef.max) {
|
20810 | flag = false;
|
20811 | }
|
20812 | }
|
20813 | });
|
20814 |
|
20815 | if (flag) {
|
20816 | geomData.push(obj);
|
20817 | }
|
20818 | });
|
20819 | chart.set('filteredData', geomData);
|
20820 | }
|
20821 | };
|
20822 |
|
20823 | }),
|
20824 |
|
20825 | (function(module, exports, __webpack_require__) {
|
20826 |
|
20827 | var Util = __webpack_require__(0);
|
20828 |
|
20829 | var Helper = __webpack_require__(29);
|
20830 |
|
20831 | var TOUCH_EVENTS = ['touchstart', 'touchmove', 'touchend', 'touchStart', 'touchMove', 'touchEnd'];
|
20832 | var DAY_TIMESTAMPS = 86400000;
|
20833 | module.exports = {
|
20834 | _handleMove: function _handleMove(e) {
|
20835 | if (e.type === 'swipe' && e.deltaTime > 350) {
|
20836 |
|
20837 | return null;
|
20838 | }
|
20839 |
|
20840 | var currentDeltaX = this.currentDeltaX,
|
20841 | currentDeltaY = this.currentDeltaY,
|
20842 | lastPoint = this.lastPoint;
|
20843 | var deltaX;
|
20844 | var deltaY;
|
20845 |
|
20846 | if (TOUCH_EVENTS.indexOf(e.type) !== -1) {
|
20847 |
|
20848 | var currentPoint = e.touches[0];
|
20849 | deltaX = currentPoint.x - lastPoint.x;
|
20850 | deltaY = currentPoint.y - lastPoint.y;
|
20851 | this.lastPoint = currentPoint;
|
20852 | } else if (currentDeltaX !== null && currentDeltaY !== null) {
|
20853 | deltaX = e.deltaX - currentDeltaX;
|
20854 | deltaY = e.deltaY - currentDeltaY;
|
20855 | this.currentDeltaX = e.deltaX;
|
20856 | this.currentDeltaY = e.deltaY;
|
20857 | }
|
20858 |
|
20859 | if (Math.abs(deltaX) > 0 || Math.abs(deltaY) > 0) {
|
20860 | var lastTimestamp = this._timestamp;
|
20861 | var now = +new Date();
|
20862 |
|
20863 | if (now - lastTimestamp > 16) {
|
20864 | this._doMove(deltaX, deltaY);
|
20865 |
|
20866 | this._timestamp = now;
|
20867 | }
|
20868 | }
|
20869 | },
|
20870 | _doMove: function _doMove(deltaX, deltaY) {
|
20871 | var self = this;
|
20872 | var mode = self.mode,
|
20873 | chart = self.chart,
|
20874 | limitRange = self.limitRange;
|
20875 | var coord = chart.get('coord');
|
20876 | var start = coord.start,
|
20877 | end = coord.end;
|
20878 | var data = chart.get('data');
|
20879 |
|
20880 | if (Util.directionEnabled(mode, 'x') && deltaX !== 0) {
|
20881 | var xScale = chart.getXScale();
|
20882 | var xField = xScale.field;
|
20883 |
|
20884 | if (!limitRange[xField]) {
|
20885 | limitRange[xField] = Helper.getLimitRange(data, xScale);
|
20886 | }
|
20887 |
|
20888 | var coordWidth = end.x - start.x;
|
20889 |
|
20890 | if (xScale.isCategory) {
|
20891 | self._handleCatScale(xScale, deltaX, coordWidth);
|
20892 | } else if (xScale.isLinear) {
|
20893 | self._handleLinearScale(xScale, deltaX, coordWidth, 'x');
|
20894 | }
|
20895 |
|
20896 | var xDef = Helper.getColDef(chart, xField);
|
20897 | self.xRange = Helper.getFieldRange(xDef, limitRange[xField], xScale.type);
|
20898 | }
|
20899 |
|
20900 | if (Util.directionEnabled(mode, 'y') && deltaY !== 0) {
|
20901 | var coordHeight = start.y - end.y;
|
20902 | var yScales = chart.getYScales();
|
20903 | Util.each(yScales, function (yScale) {
|
20904 | var yField = yScale.field;
|
20905 |
|
20906 | if (!limitRange[yField]) {
|
20907 | limitRange[yField] = Helper.getLimitRange(data, yScale);
|
20908 | }
|
20909 |
|
20910 | yScale.isLinear && self._handleLinearScale(yScale, deltaY, coordHeight, 'y');
|
20911 | });
|
20912 | var yDef = Helper.getColDef(chart, yScales[0].field);
|
20913 | self.yRange = Helper.getFieldRange(yDef, limitRange[yScales[0].field], yScales[0].type);
|
20914 | }
|
20915 |
|
20916 | chart.repaint();
|
20917 | },
|
20918 | _handleLinearScale: function _handleLinearScale(scale, delta, range, flag) {
|
20919 | var field = scale.field,
|
20920 | min = scale.min,
|
20921 | max = scale.max;
|
20922 | var limitRange = this.limitRange;
|
20923 | if (min === limitRange[field].min && max === limitRange[field].max) return;
|
20924 | var ratio = delta / range;
|
20925 | var panValue = ratio * (max - min);
|
20926 | var newMax = flag === 'x' ? max - panValue : max + panValue;
|
20927 | var newMin = flag === 'x' ? min - panValue : min + panValue;
|
20928 |
|
20929 | if (limitRange[field] && !Util.isNil(limitRange[field].min) && newMin <= limitRange[field].min) {
|
20930 | newMin = limitRange[field].min;
|
20931 | newMax = max - min + newMin;
|
20932 | }
|
20933 |
|
20934 | if (limitRange[field] && !Util.isNil(limitRange[field].max) && newMax >= limitRange[field].max) {
|
20935 | newMax = limitRange[field].max;
|
20936 | newMin = newMax - (max - min);
|
20937 | }
|
20938 |
|
20939 | this.updateLinearScale(field, newMin, newMax);
|
20940 | },
|
20941 | _handleCatScale: function _handleCatScale(scale, delta, range) {
|
20942 | var type = scale.type,
|
20943 | field = scale.field,
|
20944 | values = scale.values,
|
20945 | ticks = scale.ticks;
|
20946 | var originValues = this.limitRange[field];
|
20947 | var lastValueIndex = originValues.length - 1;
|
20948 | var currentLength = values.length;
|
20949 | var speed = this.speed || 1;
|
20950 | var step = range / (currentLength * speed);
|
20951 | var firstIndex = originValues.indexOf(values[0]);
|
20952 | var lastIndex = originValues.indexOf(values[currentLength - 1]);
|
20953 | var minIndex = firstIndex;
|
20954 | var maxIndex = lastIndex;
|
20955 | var ratio = Math.abs(delta / range);
|
20956 | var panStep = this.step || Math.max(1, parseInt(ratio * currentLength));
|
20957 | this._panCumulativeDelta += delta;
|
20958 | minIndex = this._panCumulativeDelta > step ? Math.max(0, minIndex - panStep) : this._panCumulativeDelta < -step ? Math.min(lastValueIndex - currentLength + 1, minIndex + panStep) : minIndex;
|
20959 | maxIndex = Math.min(lastValueIndex, minIndex + currentLength - 1);
|
20960 |
|
20961 | if (minIndex === firstIndex && maxIndex === lastIndex) {
|
20962 | return null;
|
20963 | }
|
20964 |
|
20965 | var newValues = originValues.slice(minIndex, maxIndex + 1);
|
20966 | var newTicks = null;
|
20967 |
|
20968 | if (type === 'timeCat') {
|
20969 | var tickGap = ticks.length > 2 ? ticks[1] - ticks[0] : DAY_TIMESTAMPS;
|
20970 |
|
20971 | if (this._panCumulativeDelta > step) {
|
20972 | for (var i = ticks[0] - tickGap; i >= newValues[0]; i -= tickGap) {
|
20973 | ticks.unshift(i);
|
20974 | }
|
20975 | } else if (this._panCumulativeDelta < -step) {
|
20976 | for (var _i = ticks[ticks.length - 1] + tickGap; _i <= newValues[newValues.length - 1]; _i += tickGap) {
|
20977 | ticks.push(_i);
|
20978 | }
|
20979 | }
|
20980 |
|
20981 | newTicks = ticks;
|
20982 | }
|
20983 |
|
20984 | this.updateCatScale(field, newValues, newTicks, originValues, minIndex, maxIndex);
|
20985 | this._panCumulativeDelta = minIndex !== firstIndex ? 0 : this._panCumulativeDelta;
|
20986 | }
|
20987 | };
|
20988 |
|
20989 | }),
|
20990 |
|
20991 | (function(module, exports, __webpack_require__) {
|
20992 |
|
20993 | var Util = __webpack_require__(0);
|
20994 |
|
20995 | module.exports = {
|
20996 | _bindPress: function _bindPress() {
|
20997 | var chart = this.chart,
|
20998 | hammer = this.hammer,
|
20999 | el = this.el,
|
21000 | pressThreshold = this.pressThreshold,
|
21001 | pressTime = this.pressTime;
|
21002 | var tooltipController = chart.get('tooltipController');
|
21003 |
|
21004 | if (tooltipController && tooltipController.enable) {
|
21005 | chart.set('_closeTooltip', true);
|
21006 |
|
21007 | if (hammer) {
|
21008 | hammer.get('press').set({
|
21009 | threshold: pressThreshold,
|
21010 | time: pressTime
|
21011 | });
|
21012 | hammer.on('press', Util.wrapBehavior(this, '_handlePress'));
|
21013 | } else {
|
21014 | Util.addEventListener(el, 'press', Util.wrapBehavior(this, '_handlePress'));
|
21015 | }
|
21016 | }
|
21017 | },
|
21018 | reset: function reset() {
|
21019 | var chart = this.chart;
|
21020 | var tooltipController = chart.get('tooltipController');
|
21021 |
|
21022 | if (tooltipController) {
|
21023 | this.pressed = false;
|
21024 | !tooltipController.cfg.alwaysShow && chart.hideTooltip();
|
21025 | chart.set('_closeTooltip', true);
|
21026 | }
|
21027 | },
|
21028 | _handlePress: function _handlePress(e) {
|
21029 | this.pressed = true;
|
21030 | var center = e.center || e.touches[0];
|
21031 | this.chart.set('_closeTooltip', false);
|
21032 |
|
21033 | this.chart.showTooltip(center);
|
21034 | }
|
21035 | };
|
21036 |
|
21037 | }),
|
21038 |
|
21039 | (function(module, exports, __webpack_require__) {
|
21040 |
|
21041 | var Helper = __webpack_require__(29);
|
21042 |
|
21043 | var Util = __webpack_require__(0);
|
21044 |
|
21045 | module.exports = {
|
21046 | updateLinearScale: function updateLinearScale(field, min, max) {
|
21047 | var chart = this.chart;
|
21048 | var colDef = Helper.getColDef(chart, field);
|
21049 | chart.scale(field, Util.mix({}, colDef, {
|
21050 | min: min,
|
21051 | max: max,
|
21052 | nice: false
|
21053 | }));
|
21054 | },
|
21055 | updateCatScale: function updateCatScale(field, newValues, ticks, values, minIndex, maxIndex) {
|
21056 | var chart = this.chart;
|
21057 | var colDef = Helper.getColDef(chart, field);
|
21058 | chart.scale(field, Util.mix({}, colDef, {
|
21059 | values: newValues,
|
21060 | ticks: ticks,
|
21061 | scale: function scale(value) {
|
21062 | if (this.type === 'timeCat') {
|
21063 | value = this._toTimeStamp(value);
|
21064 | }
|
21065 |
|
21066 | var rangeMin = this.rangeMin();
|
21067 | var rangeMax = this.rangeMax();
|
21068 | var range = rangeMax - rangeMin;
|
21069 | var min;
|
21070 | var max;
|
21071 | var percent;
|
21072 | var currentIndex = values.indexOf(value);
|
21073 |
|
21074 | if (currentIndex >= 0 && currentIndex < minIndex) {
|
21075 |
|
21076 | max = rangeMin > 0 ? -0.1 : rangeMin - 0.1;
|
21077 | min = max - range;
|
21078 | percent = currentIndex / minIndex;
|
21079 | } else if (currentIndex >= 0 && currentIndex > maxIndex) {
|
21080 |
|
21081 | min = rangeMax < 1 ? 1.1 : rangeMax + 0.1;
|
21082 | max = min + range;
|
21083 | percent = (currentIndex - maxIndex - 1) / (values.length - 1 - maxIndex);
|
21084 | } else {
|
21085 |
|
21086 | var index = this.translate(value);
|
21087 |
|
21088 | if (this.values.length === 1) {
|
21089 | percent = index;
|
21090 | } else {
|
21091 | percent = index / (this.values.length - 1);
|
21092 | }
|
21093 |
|
21094 | min = rangeMin;
|
21095 | max = rangeMax;
|
21096 | }
|
21097 |
|
21098 | return min + percent * (max - min);
|
21099 | },
|
21100 | getTicks: function getTicks() {
|
21101 | var self = this;
|
21102 | var ticks = this.ticks;
|
21103 | var rst = [];
|
21104 | Util.each(ticks, function (tick) {
|
21105 | var obj;
|
21106 |
|
21107 | if (Util.isObject(tick)) {
|
21108 | obj = tick;
|
21109 | } else {
|
21110 | var value = self.scale(tick);
|
21111 | value = value >= 0 && value <= 1 ? value : NaN;
|
21112 | obj = {
|
21113 | text: Util.isString(tick) ? tick : self.getText(tick),
|
21114 | value: value,
|
21115 | tickValue: tick
|
21116 |
|
21117 | };
|
21118 | }
|
21119 |
|
21120 | rst.push(obj);
|
21121 | });
|
21122 | return rst;
|
21123 | }
|
21124 | }));
|
21125 | }
|
21126 | };
|
21127 |
|
21128 | })
|
21129 | ]);
|
21130 | });
|
21131 |
|
\ | No newline at end of file |