UNPKG

36.3 kBJavaScriptView Raw
1(function webpackUniversalModuleDefinition(root, factory) {
2 if(typeof exports === 'object' && typeof module === 'object')
3 module.exports = factory(require("react"));
4 else if(typeof define === 'function' && define.amd)
5 define(["react"], factory);
6 else if(typeof exports === 'object')
7 exports["BizChartsPluginSlider"] = factory(require("react"));
8 else
9 root["BizChartsPluginSlider"] = factory(root["React"]);
10})(this, function(__WEBPACK_EXTERNAL_MODULE_1__) {
11return /******/ (function(modules) { // webpackBootstrap
12/******/ // The module cache
13/******/ var installedModules = {};
14/******/
15/******/ // The require function
16/******/ function __webpack_require__(moduleId) {
17/******/
18/******/ // Check if module is in cache
19/******/ if(installedModules[moduleId]) {
20/******/ return installedModules[moduleId].exports;
21/******/ }
22/******/ // Create a new module (and put it into the cache)
23/******/ var module = installedModules[moduleId] = {
24/******/ i: moduleId,
25/******/ l: false,
26/******/ exports: {}
27/******/ };
28/******/
29/******/ // Execute the module function
30/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
31/******/
32/******/ // Flag the module as loaded
33/******/ module.l = true;
34/******/
35/******/ // Return the exports of the module
36/******/ return module.exports;
37/******/ }
38/******/
39/******/
40/******/ // expose the modules object (__webpack_modules__)
41/******/ __webpack_require__.m = modules;
42/******/
43/******/ // expose the module cache
44/******/ __webpack_require__.c = installedModules;
45/******/
46/******/ // identity function for calling harmony imports with the correct context
47/******/ __webpack_require__.i = function(value) { return value; };
48/******/
49/******/ // define getter function for harmony exports
50/******/ __webpack_require__.d = function(exports, name, getter) {
51/******/ if(!__webpack_require__.o(exports, name)) {
52/******/ Object.defineProperty(exports, name, {
53/******/ configurable: false,
54/******/ enumerable: true,
55/******/ get: getter
56/******/ });
57/******/ }
58/******/ };
59/******/
60/******/ // getDefaultExport function for compatibility with non-harmony modules
61/******/ __webpack_require__.n = function(module) {
62/******/ var getter = module && module.__esModule ?
63/******/ function getDefault() { return module['default']; } :
64/******/ function getModuleExports() { return module; };
65/******/ __webpack_require__.d(getter, 'a', getter);
66/******/ return getter;
67/******/ };
68/******/
69/******/ // Object.prototype.hasOwnProperty.call
70/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
71/******/
72/******/ // __webpack_public_path__
73/******/ __webpack_require__.p = "";
74/******/
75/******/ // Load entry module and return exports
76/******/ return __webpack_require__(__webpack_require__.s = 4);
77/******/ })
78/************************************************************************/
79/******/ ([
80/* 0 */
81/***/ (function(module, exports, __webpack_require__) {
82
83"use strict";
84
85
86var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
87
88var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
89
90var _g2PluginSlider = __webpack_require__(2);
91
92var _g2PluginSlider2 = _interopRequireDefault(_g2PluginSlider);
93
94var _react = __webpack_require__(1);
95
96var _react2 = _interopRequireDefault(_react);
97
98var _errorBoundary = __webpack_require__(3);
99
100var _errorBoundary2 = _interopRequireDefault(_errorBoundary);
101
102function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
103
104function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
105
106function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
107
108function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
109
110function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
111
112var SliderAttrs = ['width', 'height', 'padding', 'xAis', 'yAxis', 'start', 'end', 'fillerStyle', 'backgroundStyle', 'scales', 'textStyle', 'handleStyle', 'backgroundChart'];
113
114function sliderNeedRebuild(props, nextProps) {
115 if (props.onChange !== nextProps.onChange) {
116 return true;
117 }
118
119 for (var i = 0; i < SliderAttrs.length; i += 1) {
120 var attr = SliderAttrs[i];
121 if (!window.G2.Util.isEqual(props[attr], nextProps[attr])) {
122 return true;
123 }
124 }
125
126 return false;
127}
128
129var Slider = function (_Component) {
130 _inherits(Slider, _Component);
131
132 function Slider() {
133 _classCallCheck(this, Slider);
134
135 var _this = _possibleConstructorReturn(this, (Slider.__proto__ || Object.getPrototypeOf(Slider)).call(this));
136
137 _this.refHandle = function (cw) {
138 // chart container wrap for reset operation
139 if (!_this.container) {
140 _this.container = cw;
141 }
142 };
143
144 _this.reBuild = false;
145 return _this;
146 }
147
148 _createClass(Slider, [{
149 key: 'componentDidMount',
150 value: function componentDidMount() {
151 var slider = this.createG2Instance();
152 slider.render();
153 }
154 }, {
155 key: 'componentWillReceiveProps',
156 value: function componentWillReceiveProps(nextProps) {
157 var _props = this.props,
158 data = _props.data,
159 others = _objectWithoutProperties(_props, ['data']);
160
161 var nextData = nextProps.data,
162 nextOthers = _objectWithoutProperties(nextProps, ['data']);
163 // refrence compare
164
165
166 if (data !== nextData) {
167 this.slider.changeData(nextData);
168 this.slider.repaint();
169 }
170
171 if (sliderNeedRebuild(others, nextOthers)) {
172 this.reBuild = true;
173 }
174 }
175 }, {
176 key: 'componentDidUpdate',
177 value: function componentDidUpdate() {
178 if (!this.reBuild) {
179 return;
180 }
181
182 this.slider.destroy();
183 var slider = this.createG2Instance();
184 slider.render();
185 this.reBuild = false;
186 }
187 }, {
188 key: 'componentWillUnmount',
189 value: function componentWillUnmount() {
190 this.slider.destroy();
191 }
192 }, {
193 key: 'createG2Instance',
194 value: function createG2Instance() {
195 this.slider = new _g2PluginSlider2.default(_extends({ container: this.container }, this.props));
196 return this.slider;
197 }
198 }, {
199 key: 'render',
200 value: function render() {
201 return _react2.default.createElement('div', { ref: this.refHandle });
202 }
203 }]);
204
205 return Slider;
206}(_react.Component);
207
208var BSlider = function (_Component2) {
209 _inherits(BSlider, _Component2);
210
211 function BSlider() {
212 _classCallCheck(this, BSlider);
213
214 return _possibleConstructorReturn(this, (BSlider.__proto__ || Object.getPrototypeOf(BSlider)).apply(this, arguments));
215 }
216
217 _createClass(BSlider, [{
218 key: 'render',
219 value: function render() {
220 return _react2.default.createElement(
221 _errorBoundary2.default,
222 null,
223 _react2.default.createElement(Slider, this.props)
224 );
225 }
226 }]);
227
228 return BSlider;
229}(_react.Component);
230
231exports.default = BSlider;
232module.exports = exports['default'];
233
234/***/ }),
235/* 1 */
236/***/ (function(module, exports) {
237
238module.exports = __WEBPACK_EXTERNAL_MODULE_1__;
239
240/***/ }),
241/* 2 */
242/***/ (function(module, exports, __webpack_require__) {
243
244(function webpackUniversalModuleDefinition(root, factory) {
245 if(true)
246 module.exports = factory();
247 else if(typeof define === 'function' && define.amd)
248 define([], factory);
249 else if(typeof exports === 'object')
250 exports["Slider"] = factory();
251 else
252 root["Slider"] = factory();
253})(this, function() {
254return /******/ (function(modules) { // webpackBootstrap
255/******/ // The module cache
256/******/ var installedModules = {};
257/******/
258/******/ // The require function
259/******/ function __webpack_require__(moduleId) {
260/******/
261/******/ // Check if module is in cache
262/******/ if(installedModules[moduleId]) {
263/******/ return installedModules[moduleId].exports;
264/******/ }
265/******/ // Create a new module (and put it into the cache)
266/******/ var module = installedModules[moduleId] = {
267/******/ i: moduleId,
268/******/ l: false,
269/******/ exports: {}
270/******/ };
271/******/
272/******/ // Execute the module function
273/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
274/******/
275/******/ // Flag the module as loaded
276/******/ module.l = true;
277/******/
278/******/ // Return the exports of the module
279/******/ return module.exports;
280/******/ }
281/******/
282/******/
283/******/ // expose the modules object (__webpack_modules__)
284/******/ __webpack_require__.m = modules;
285/******/
286/******/ // expose the module cache
287/******/ __webpack_require__.c = installedModules;
288/******/
289/******/ // define getter function for harmony exports
290/******/ __webpack_require__.d = function(exports, name, getter) {
291/******/ if(!__webpack_require__.o(exports, name)) {
292/******/ Object.defineProperty(exports, name, {
293/******/ configurable: false,
294/******/ enumerable: true,
295/******/ get: getter
296/******/ });
297/******/ }
298/******/ };
299/******/
300/******/ // getDefaultExport function for compatibility with non-harmony modules
301/******/ __webpack_require__.n = function(module) {
302/******/ var getter = module && module.__esModule ?
303/******/ function getDefault() { return module['default']; } :
304/******/ function getModuleExports() { return module; };
305/******/ __webpack_require__.d(getter, 'a', getter);
306/******/ return getter;
307/******/ };
308/******/
309/******/ // Object.prototype.hasOwnProperty.call
310/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
311/******/
312/******/ // __webpack_public_path__
313/******/ __webpack_require__.p = "";
314/******/
315/******/ // Load entry module and return exports
316/******/ return __webpack_require__(__webpack_require__.s = 0);
317/******/ })
318/************************************************************************/
319/******/ ([
320/* 0 */
321/***/ (function(module, exports, __webpack_require__) {
322
323var Slider = __webpack_require__(1);
324
325if (window && !window.G2) {
326 console.err('Please load the G2 script first!');
327}
328
329module.exports = Slider;
330
331/***/ }),
332/* 1 */
333/***/ (function(module, exports, __webpack_require__) {
334
335/**
336 * @fileOverview G2's plugin for datazoom.
337 * @author sima.zhang
338 */
339var Range = __webpack_require__(2);
340
341var G2 = window && window.G2;
342var Chart = G2.Chart,
343 Util = G2.Util,
344 G = G2.G,
345 Global = G2.Global;
346var Canvas = G.Canvas;
347var DomUtil = Util.DomUtil;
348
349var isNumber = function isNumber(val) {
350 return typeof val === 'number';
351};
352
353var Slider =
354/*#__PURE__*/
355function () {
356 var _proto = Slider.prototype;
357
358 _proto._initProps = function _initProps() {
359 this.height = 26;
360 this.width = 'auto'; // 默认自适应
361
362 this.padding = Global.plotCfg.padding;
363 this.container = null;
364 this.xAxis = null;
365 this.yAxis = null; // 选中区域的样式
366
367 this.fillerStyle = {
368 fill: '#BDCCED',
369 fillOpacity: 0.3
370 }; // 滑动条背景样式
371
372 this.backgroundStyle = {
373 stroke: '#CCD6EC',
374 fill: '#CCD6EC',
375 fillOpacity: 0.3,
376 lineWidth: 1
377 };
378 this.range = [0, 100];
379 this.layout = 'horizontal'; // 文本颜色
380
381 this.textStyle = {
382 fill: '#545454'
383 }; // 滑块的样式
384
385 this.handleStyle = {
386 img: 'https://gw.alipayobjects.com/zos/rmsportal/QXtfhORGlDuRvLXFzpsQ.png',
387 width: 5
388 }; // 背景图表的配置,如果为 false 则表示不渲染
389
390 this.backgroundChart = {
391 type: ['area'],
392 // 图表的类型,可以是字符串也可是是数组
393 color: '#CCD6EC'
394 };
395 };
396
397 function Slider(cfg) {
398 this._initProps();
399
400 Util.deepMix(this, cfg);
401 var container = this.container;
402
403 if (!container) {
404 throw new Error('Please specify the container for the Slider!');
405 }
406
407 if (Util.isString(container)) {
408 this.domContainer = document.getElementById(container);
409 } else {
410 this.domContainer = container;
411 }
412
413 this.handleStyle = Util.mix({
414 width: this.height,
415 height: this.height
416 }, this.handleStyle);
417
418 if (this.width === 'auto') {
419 // 宽度自适应
420 window.addEventListener('resize', Util.wrapBehavior(this, '_initForceFitEvent'));
421 }
422 }
423
424 _proto._initForceFitEvent = function _initForceFitEvent() {
425 var timer = setTimeout(Util.wrapBehavior(this, 'forceFit'), 200);
426 clearTimeout(this.resizeTimer);
427 this.resizeTimer = timer;
428 };
429
430 _proto.forceFit = function forceFit() {
431 if (!this || this.destroyed) {
432 return;
433 }
434
435 var width = DomUtil.getWidth(this.domContainer);
436 var height = this.height;
437
438 if (width !== this.domWidth) {
439 var canvas = this.canvas;
440 canvas.changeSize(width, height); // 改变画布尺寸
441
442 this.bgChart && this.bgChart.changeWidth(width);
443 canvas.clear();
444
445 this._initWidth();
446
447 this._initSlider(); // 初始化滑动条
448
449
450 this._bindEvent();
451
452 canvas.draw();
453 }
454 };
455
456 _proto._initWidth = function _initWidth() {
457 var width;
458
459 if (this.width === 'auto') {
460 width = DomUtil.getWidth(this.domContainer);
461 } else {
462 width = this.width;
463 }
464
465 this.domWidth = width;
466 var padding = Util.toAllPadding(this.padding);
467
468 if (this.layout === 'horizontal') {
469 this.plotWidth = width - padding[1] - padding[3];
470 this.plotPadding = padding[3];
471 this.plotHeight = this.height;
472 } else if (this.layout === 'vertical') {
473 this.plotWidth = this.width;
474 this.plotHeight = this.height - padding[0] - padding[2];
475 this.plotPadding = padding[0];
476 }
477 };
478
479 _proto.render = function render() {
480 this._initWidth();
481
482 this._initCanvas(); // 初始化 canvas
483
484
485 this._initBackground(); // 初始化背景图表
486
487
488 this._initSlider(); // 初始化滑动条
489
490
491 this._bindEvent();
492
493 this.canvas.draw();
494 };
495
496 _proto.changeData = function changeData(data) {
497 this.data = data;
498 this.repaint();
499 };
500
501 _proto.destroy = function destroy() {
502 clearTimeout(this.resizeTimer);
503 var rangeElement = this.rangeElement;
504 rangeElement.off('sliderchange');
505 this.bgChart && this.bgChart.destroy();
506 this.canvas.destroy();
507 var container = this.domContainer;
508
509 while (container.hasChildNodes()) {
510 container.removeChild(container.firstChild);
511 }
512
513 window.removeEventListener('resize', Util.getWrapBehavior(this, '_initForceFitEvent'));
514 this.destroyed = true;
515 };
516
517 _proto.clear = function clear() {
518 this.canvas.clear();
519 this.bgChart && this.bgChart.destroy();
520 this.bgChart = null;
521 this.scale = null;
522 this.canvas.draw();
523 };
524
525 _proto.repaint = function repaint() {
526 this.clear();
527 this.render();
528 };
529
530 _proto._initCanvas = function _initCanvas() {
531 var width = this.domWidth;
532 var height = this.height;
533 var canvas = new Canvas({
534 width: width,
535 height: height,
536 containerDOM: this.domContainer,
537 capture: false
538 });
539 var node = canvas.get('el');
540 node.style.position = 'absolute';
541 node.style.top = 0;
542 node.style.left = 0;
543 node.style.zIndex = 3;
544 this.canvas = canvas;
545 };
546
547 _proto._initBackground = function _initBackground() {
548 var _Util$deepMix;
549
550 var data = this.data;
551 var xAxis = this.xAxis;
552 var yAxis = this.yAxis;
553 var scales = Util.deepMix((_Util$deepMix = {}, _Util$deepMix["" + xAxis] = {
554 range: [0, 1]
555 }, _Util$deepMix), this.scales); // 用户列定义
556
557 if (!data) {
558 // 没有数据,则不创建
559 throw new Error('Please specify the data!');
560 }
561
562 if (!xAxis) {
563 throw new Error('Please specify the xAxis!');
564 }
565
566 if (!yAxis) {
567 throw new Error('Please specify the yAxis!');
568 }
569
570 var backgroundChart = this.backgroundChart;
571 var type = backgroundChart.type;
572 var color = backgroundChart.color;
573
574 if (!Util.isArray(type)) {
575 type = [type];
576 }
577
578 var padding = Util.toAllPadding(this.padding);
579 var bgChart = new Chart({
580 container: this.container,
581 width: this.domWidth,
582 height: this.height,
583 padding: [0, padding[1], 0, padding[3]],
584 animate: false
585 });
586 bgChart.source(data);
587 bgChart.scale(scales);
588 bgChart.axis(false);
589 bgChart.tooltip(false);
590 bgChart.legend(false);
591 Util.each(type, function (eachType) {
592 bgChart[eachType]().position(xAxis + '*' + yAxis).color(color).opacity(1);
593 });
594 bgChart.render();
595 this.bgChart = bgChart;
596 this.scale = this.layout === 'horizontal' ? bgChart.getXScale() : bgChart.getYScales()[0];
597
598 if (this.layout === 'vertical') {
599 bgChart.destroy();
600 }
601 };
602
603 _proto._initRange = function _initRange() {
604 var startRadio = this.startRadio;
605 var endRadio = this.endRadio;
606 var start = this.start;
607 var end = this.end;
608 var scale = this.scale;
609 var min = 0;
610 var max = 1; // startRadio 优先级高于 start
611
612 if (isNumber(startRadio)) {
613 min = startRadio;
614 } else if (start) {
615 min = scale.scale(scale.translate(start));
616 } // endRadio 优先级高于 end
617
618
619 if (isNumber(endRadio)) {
620 max = endRadio;
621 } else if (end) {
622 max = scale.scale(scale.translate(end));
623 }
624
625 var minSpan = this.minSpan,
626 maxSpan = this.maxSpan;
627 var totalSpan = 0;
628
629 if (scale.type === 'time' || scale.type === 'timeCat') {
630 // 时间类型已排序
631 var values = scale.values;
632 var firstValue = values[0];
633 var lastValue = values[values.length - 1];
634 totalSpan = lastValue - firstValue;
635 } else if (scale.isLinear) {
636 totalSpan = scale.max - scale.min;
637 }
638
639 if (totalSpan && minSpan) {
640 this.minRange = minSpan / totalSpan * 100;
641 }
642
643 if (totalSpan && maxSpan) {
644 this.maxRange = maxSpan / totalSpan * 100;
645 }
646
647 var range = [min * 100, max * 100];
648 this.range = range;
649 return range;
650 };
651
652 _proto._getHandleValue = function _getHandleValue(type) {
653 var value;
654 var range = this.range;
655 var min = range[0] / 100;
656 var max = range[1] / 100;
657 var scale = this.scale;
658
659 if (type === 'min') {
660 value = this.start ? this.start : scale.invert(min);
661 } else {
662 value = this.end ? this.end : scale.invert(max);
663 }
664
665 return value;
666 };
667
668 _proto._initSlider = function _initSlider() {
669 var canvas = this.canvas;
670
671 var range = this._initRange();
672
673 var scale = this.scale;
674 var rangeElement = canvas.addGroup(Range, {
675 middleAttr: this.fillerStyle,
676 range: range,
677 minRange: this.minRange,
678 maxRange: this.maxRange,
679 layout: this.layout,
680 width: this.plotWidth,
681 height: this.plotHeight,
682 backgroundStyle: this.backgroundStyle,
683 textStyle: this.textStyle,
684 handleStyle: this.handleStyle,
685 minText: scale.getText(this._getHandleValue('min')),
686 maxText: scale.getText(this._getHandleValue('max'))
687 });
688
689 if (this.layout === 'horizontal') {
690 rangeElement.translate(this.plotPadding, 0);
691 } else if (this.layout === 'vertical') {
692 rangeElement.translate(0, this.plotPadding);
693 }
694
695 this.rangeElement = rangeElement;
696 };
697
698 _proto._bindEvent = function _bindEvent() {
699 var self = this;
700 var rangeElement = self.rangeElement;
701 rangeElement.on('sliderchange', function (ev) {
702 var range = ev.range;
703 var minRatio = range[0] / 100;
704 var maxRatio = range[1] / 100;
705
706 self._updateElement(minRatio, maxRatio);
707 });
708 };
709
710 _proto._updateElement = function _updateElement(minRatio, maxRatio) {
711 var scale = this.scale;
712 var rangeElement = this.rangeElement;
713 var minTextElement = rangeElement.get('minTextElement');
714 var maxTextElement = rangeElement.get('maxTextElement');
715 var min = scale.invert(minRatio);
716 var max = scale.invert(maxRatio);
717 var minText = scale.getText(min);
718 var maxText = scale.getText(max);
719 minTextElement.attr('text', minText);
720 maxTextElement.attr('text', maxText);
721 this.start = minText;
722 this.end = maxText;
723
724 if (this.onChange) {
725 this.onChange({
726 startText: minText,
727 endText: maxText,
728 startValue: min,
729 endValue: max,
730 startRadio: minRatio,
731 endRadio: maxRatio
732 });
733 }
734 };
735
736 return Slider;
737}();
738
739module.exports = Slider;
740
741/***/ }),
742/* 2 */
743/***/ (function(module, exports) {
744
745function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
746
747/**
748 * @fileOverview The class of slider
749 * @author sima.zhang
750 */
751var G2 = window && window.G2;
752var Util = G2.Util,
753 G = G2.G;
754var Group = G.Group;
755var DomUtil = Util.DomUtil;
756var OFFSET = 5;
757
758var Range =
759/*#__PURE__*/
760function (_Group) {
761 _inheritsLoose(Range, _Group);
762
763 function Range() {
764 return _Group.apply(this, arguments) || this;
765 }
766
767 var _proto = Range.prototype;
768
769 _proto.getDefaultCfg = function getDefaultCfg() {
770 return {
771 /**
772 * 范围
773 * @type {Array}
774 */
775 range: null,
776
777 /**
778 * 中滑块属性
779 * @type {ATTRS}
780 */
781 middleAttr: null,
782
783 /**
784 * 背景
785 * @type {G-Element}
786 */
787 backgroundElement: null,
788
789 /**
790 * 下滑块
791 * @type {G-Element}
792 */
793 minHandleElement: null,
794
795 /**
796 * 上滑块
797 * @type {G-Element}
798 */
799 maxHandleElement: null,
800
801 /**
802 * 中块
803 * @type {G-Element}
804 */
805 middleHandleElement: null,
806
807 /**
808 * 当前的激活的元素
809 * @type {G-Element}
810 */
811 currentTarget: null,
812
813 /**
814 * 布局方式: horizontal,vertical
815 * @type {String}
816 */
817 layout: 'vertical',
818
819 /**
820 * 宽
821 * @type {Number}
822 */
823 width: null,
824
825 /**
826 * 高
827 * @type {Number}
828 */
829 height: null,
830
831 /**
832 * 当前的PageX
833 * @type {Number}
834 */
835 pageX: null,
836
837 /**
838 * 当前的PageY
839 * @type {Number}
840 */
841 pageY: null
842 };
843 };
844
845 _proto._initHandle = function _initHandle(type) {
846 var handle = this.addGroup();
847 var layout = this.get('layout');
848 var handleStyle = this.get('handleStyle');
849 var img = handleStyle.img;
850 var iconWidth = handleStyle.width;
851 var iconHeight = handleStyle.height;
852 var text;
853 var handleIcon;
854 var triggerCursor;
855
856 if (layout === 'horizontal') {
857 var _iconWidth = handleStyle.width;
858 triggerCursor = 'ew-resize';
859 handleIcon = handle.addShape('Image', {
860 attrs: {
861 x: -_iconWidth / 2,
862 y: 0,
863 width: _iconWidth,
864 height: iconHeight,
865 img: img,
866 cursor: triggerCursor
867 }
868 });
869 text = handle.addShape('Text', {
870 attrs: Util.mix({
871 x: type === 'min' ? -(_iconWidth / 2 + OFFSET) : _iconWidth / 2 + OFFSET,
872 y: iconHeight / 2,
873 textAlign: type === 'min' ? 'end' : 'start',
874 textBaseline: 'middle',
875 text: type === 'min' ? this.get('minText') : this.get('maxText'),
876 cursor: triggerCursor
877 }, this.get('textStyle'))
878 });
879 } else {
880 triggerCursor = 'ns-resize';
881 handleIcon = handle.addShape('Image', {
882 attrs: {
883 x: 0,
884 y: -iconHeight / 2,
885 width: iconWidth,
886 height: iconHeight,
887 img: img,
888 cursor: triggerCursor
889 }
890 });
891 text = handle.addShape('Text', {
892 attrs: Util.mix({
893 x: iconWidth / 2,
894 y: type === 'min' ? iconHeight / 2 + OFFSET : -(iconHeight / 2 + OFFSET),
895 textAlign: 'center',
896 textBaseline: 'middle',
897 text: type === 'min' ? this.get('minText') : this.get('maxText'),
898 cursor: triggerCursor
899 }, this.get('textStyle'))
900 });
901 }
902
903 this.set(type + 'TextElement', text);
904 this.set(type + 'IconElement', handleIcon);
905 return handle;
906 };
907
908 _proto._initSliderBackground = function _initSliderBackground() {
909 var backgroundElement = this.addGroup();
910 backgroundElement.initTransform();
911 backgroundElement.translate(0, 0);
912 backgroundElement.addShape('Rect', {
913 attrs: Util.mix({
914 x: 0,
915 y: 0,
916 width: this.get('width'),
917 height: this.get('height')
918 }, this.get('backgroundStyle'))
919 });
920 return backgroundElement;
921 };
922
923 _proto._beforeRenderUI = function _beforeRenderUI() {
924 var backgroundElement = this._initSliderBackground();
925
926 var minHandleElement = this._initHandle('min');
927
928 var maxHandleElement = this._initHandle('max');
929
930 var middleHandleElement = this.addShape('rect', {
931 attrs: this.get('middleAttr')
932 });
933 this.set('middleHandleElement', middleHandleElement);
934 this.set('minHandleElement', minHandleElement);
935 this.set('maxHandleElement', maxHandleElement);
936 this.set('backgroundElement', backgroundElement);
937 backgroundElement.set('zIndex', 0);
938 middleHandleElement.set('zIndex', 1);
939 minHandleElement.set('zIndex', 2);
940 maxHandleElement.set('zIndex', 2);
941 middleHandleElement.attr('cursor', 'move');
942 this.sort();
943 };
944
945 _proto._renderUI = function _renderUI() {
946 if (this.get('layout') === 'horizontal') {
947 this._renderHorizontal();
948 } else {
949 this._renderVertical();
950 }
951 };
952
953 _proto._transform = function _transform(layout) {
954 var range = this.get('range');
955 var minRatio = range[0] / 100;
956 var maxRatio = range[1] / 100;
957 var width = this.get('width');
958 var height = this.get('height');
959 var minHandleElement = this.get('minHandleElement');
960 var maxHandleElement = this.get('maxHandleElement');
961 var middleHandleElement = this.get('middleHandleElement');
962
963 if (minHandleElement.resetMatrix) {
964 minHandleElement.resetMatrix();
965 maxHandleElement.resetMatrix();
966 } else {
967 minHandleElement.initTransform();
968 maxHandleElement.initTransform();
969 }
970
971 if (layout === 'horizontal') {
972 middleHandleElement.attr({
973 x: width * minRatio,
974 y: 0,
975 width: (maxRatio - minRatio) * width,
976 height: height
977 });
978 minHandleElement.translate(minRatio * width, 0);
979 maxHandleElement.translate(maxRatio * width, 0);
980 } else {
981 middleHandleElement.attr({
982 x: 0,
983 y: height * (1 - maxRatio),
984 width: width,
985 height: (maxRatio - minRatio) * height
986 });
987 minHandleElement.translate(0, (1 - minRatio) * height);
988 maxHandleElement.translate(0, (1 - maxRatio) * height);
989 }
990 };
991
992 _proto._renderHorizontal = function _renderHorizontal() {
993 this._transform('horizontal');
994 };
995
996 _proto._renderVertical = function _renderVertical() {
997 this._transform('vertical');
998 };
999
1000 _proto._bindUI = function _bindUI() {
1001 this.on('mousedown', Util.wrapBehavior(this, '_onMouseDown'));
1002 };
1003
1004 _proto._isElement = function _isElement(target, name) {
1005 // 判断是否是该元素
1006 var element = this.get(name);
1007
1008 if (target === element) {
1009 return true;
1010 }
1011
1012 if (element.isGroup) {
1013 var elementChildren = element.get('children');
1014 return elementChildren.indexOf(target) > -1;
1015 }
1016
1017 return false;
1018 };
1019
1020 _proto._getRange = function _getRange(diff, range) {
1021 var rst = diff + range;
1022 rst = rst > 100 ? 100 : rst;
1023 rst = rst < 0 ? 0 : rst;
1024 return rst;
1025 };
1026
1027 _proto._limitRange = function _limitRange(diff, limit, range) {
1028 range[0] = this._getRange(diff, range[0]);
1029 range[1] = range[0] + limit;
1030
1031 if (range[1] > 100) {
1032 range[1] = 100;
1033 range[0] = range[1] - limit;
1034 }
1035 };
1036
1037 _proto._updateStatus = function _updateStatus(dim, ev) {
1038 var totalLength = dim === 'x' ? this.get('width') : this.get('height');
1039 dim = Util.upperFirst(dim);
1040 var range = this.get('range');
1041 var page = this.get('page' + dim);
1042 var currentTarget = this.get('currentTarget');
1043 var rangeStash = this.get('rangeStash');
1044 var layout = this.get('layout');
1045 var sign = layout === 'vertical' ? -1 : 1;
1046 var currentPage = ev['page' + dim];
1047 var diffPage = currentPage - page;
1048 var diffRange = diffPage / totalLength * 100 * sign;
1049 var diffStashRange;
1050 var minRange = this.get('minRange');
1051 var maxRange = this.get('maxRange');
1052
1053 if (range[1] <= range[0]) {
1054 if (this._isElement(currentTarget, 'minHandleElement') || this._isElement(currentTarget, 'maxHandleElement')) {
1055 range[0] = this._getRange(diffRange, range[0]);
1056 range[1] = this._getRange(diffRange, range[0]);
1057 }
1058 } else {
1059 if (this._isElement(currentTarget, 'minHandleElement')) {
1060 range[0] = this._getRange(diffRange, range[0]);
1061
1062 if (minRange) {
1063 // 设置了最小范围
1064 if (range[1] - range[0] <= minRange) {
1065 this._limitRange(diffRange, minRange, range);
1066 }
1067 }
1068
1069 if (maxRange) {
1070 // 设置了最大范围
1071 if (range[1] - range[0] >= maxRange) {
1072 this._limitRange(diffRange, maxRange, range);
1073 }
1074 }
1075 }
1076
1077 if (this._isElement(currentTarget, 'maxHandleElement')) {
1078 range[1] = this._getRange(diffRange, range[1]);
1079
1080 if (minRange) {
1081 // 设置了最小范围
1082 if (range[1] - range[0] <= minRange) {
1083 this._limitRange(diffRange, minRange, range);
1084 }
1085 }
1086
1087 if (maxRange) {
1088 // 设置了最大范围
1089 if (range[1] - range[0] >= maxRange) {
1090 this._limitRange(diffRange, maxRange, range);
1091 }
1092 }
1093 }
1094 }
1095
1096 if (this._isElement(currentTarget, 'middleHandleElement')) {
1097 diffStashRange = rangeStash[1] - rangeStash[0];
1098
1099 this._limitRange(diffRange, diffStashRange, range);
1100 }
1101
1102 this.emit('sliderchange', {
1103 range: range
1104 });
1105 this.set('page' + dim, currentPage);
1106
1107 this._renderUI();
1108
1109 this.get('canvas').draw(); // need delete
1110
1111 return;
1112 };
1113
1114 _proto._onMouseDown = function _onMouseDown(ev) {
1115 var currentTarget = ev.currentTarget;
1116 var originEvent = ev.event;
1117 var range = this.get('range');
1118 originEvent.stopPropagation();
1119 originEvent.preventDefault();
1120 this.set('pageX', originEvent.pageX);
1121 this.set('pageY', originEvent.pageY);
1122 this.set('currentTarget', currentTarget);
1123 this.set('rangeStash', [range[0], range[1]]);
1124
1125 this._bindCanvasEvents();
1126 };
1127
1128 _proto._bindCanvasEvents = function _bindCanvasEvents() {
1129 var containerDOM = this.get('canvas').get('containerDOM');
1130 this.onMouseMoveListener = DomUtil.addEventListener(containerDOM, 'mousemove', Util.wrapBehavior(this, '_onCanvasMouseMove'));
1131 this.onMouseUpListener = DomUtil.addEventListener(containerDOM, 'mouseup', Util.wrapBehavior(this, '_onCanvasMouseUp')); // @2018-06-06 by blue.lb 添加mouseleave事件监听,让用户在操作出滑块区域后有一个“正常”的效果,可以正常重新触发滑块的操作流程
1132
1133 this.onMouseLeaveListener = DomUtil.addEventListener(containerDOM, 'mouseleave', Util.wrapBehavior(this, '_onCanvasMouseUp'));
1134 };
1135
1136 _proto._onCanvasMouseMove = function _onCanvasMouseMove(ev) {
1137 var layout = this.get('layout');
1138
1139 if (layout === 'horizontal') {
1140 this._updateStatus('x', ev);
1141 } else {
1142 this._updateStatus('y', ev);
1143 }
1144 };
1145
1146 _proto._onCanvasMouseUp = function _onCanvasMouseUp() {
1147 this._removeDocumentEvents();
1148 };
1149
1150 _proto._removeDocumentEvents = function _removeDocumentEvents() {
1151 this.onMouseMoveListener.remove();
1152 this.onMouseUpListener.remove();
1153 this.onMouseLeaveListener.remove();
1154 };
1155
1156 return Range;
1157}(Group);
1158
1159module.exports = Range;
1160
1161/***/ })
1162/******/ ]);
1163});
1164
1165/***/ }),
1166/* 3 */
1167/***/ (function(module, exports, __webpack_require__) {
1168
1169"use strict";
1170
1171
1172Object.defineProperty(exports, "__esModule", {
1173 value: true
1174});
1175
1176var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
1177
1178var _react = __webpack_require__(1);
1179
1180var _react2 = _interopRequireDefault(_react);
1181
1182function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1183
1184function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1185
1186function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
1187
1188function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
1189
1190var ErrorBoundary = function (_React$Component) {
1191 _inherits(ErrorBoundary, _React$Component);
1192
1193 function ErrorBoundary(props) {
1194 _classCallCheck(this, ErrorBoundary);
1195
1196 var _this = _possibleConstructorReturn(this, (ErrorBoundary.__proto__ || Object.getPrototypeOf(ErrorBoundary)).call(this, props));
1197
1198 _this.state = { hasError: false };
1199 return _this;
1200 }
1201
1202 _createClass(ErrorBoundary, [{
1203 key: 'componentDidCatch',
1204 value: function componentDidCatch(error, info) {
1205 this.setState({ hasError: true });
1206 }
1207 }, {
1208 key: 'unstable_handleError',
1209 value: function unstable_handleError(error, info) {
1210 this.setState({ hasError: true });
1211 }
1212 }, {
1213 key: 'render',
1214 value: function render() {
1215 if (this.state.hasError) {
1216 return _react2.default.createElement(
1217 'h1',
1218 null,
1219 'Slider error.'
1220 );
1221 }
1222 return this.props.children;
1223 }
1224 }]);
1225
1226 return ErrorBoundary;
1227}(_react2.default.Component);
1228
1229exports.default = ErrorBoundary;
1230
1231/***/ }),
1232/* 4 */
1233/***/ (function(module, exports, __webpack_require__) {
1234
1235__webpack_require__(0);
1236module.exports = __webpack_require__(0);
1237
1238
1239/***/ })
1240/******/ ]);
1241});
\No newline at end of file