UNPKG

15.8 kBJavaScriptView Raw
1!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):"object"==typeof exports?exports.BizChartsPluginSlider=e(require("react")):t.BizChartsPluginSlider=e(t.React)}(this,function(t){return function(t){function e(n){if(i[n])return i[n].exports;var r=i[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,e),r.l=!0,r.exports}var i={};return e.m=t,e.c=i,e.i=function(t){return t},e.d=function(t,i,n){e.o(t,i)||Object.defineProperty(t,i,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var i=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(i,"a",i),i},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=4)}([function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{default:t}}function r(t,e){var i={};for(var n in t)0>e.indexOf(n)&&Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=t[n]);return i}function a(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function s(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function o(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function h(t,e){if(t.onChange!==e.onChange)return!0;for(var i=0;v.length>i;i+=1){var n=v[i];if(!window.G2.Util.isEqual(t[n],e[n]))return!0}return!1}var l=Object.assign||function(t){for(var e=1;arguments.length>e;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},u=function(){function t(t,e){for(var i=0;e.length>i;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}(),d=i(2),c=n(d),f=i(1),g=n(f),p=i(3),m=n(p),v=["width","height","padding","xAis","yAxis","start","end","fillerStyle","backgroundStyle","scales","textStyle","handleStyle","backgroundChart"],y=function(t){function e(){a(this,e);var t=s(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return t.refHandle=function(e){t.container||(t.container=e)},t.reBuild=!1,t}return o(e,t),u(e,[{key:"componentDidMount",value:function(){this.createG2Instance().render()}},{key:"componentWillReceiveProps",value:function(t){var e=this.props,i=e.data,n=r(e,["data"]),a=t.data,s=r(t,["data"]);i!==a&&(this.slider.changeData(a),this.slider.repaint()),h(n,s)&&(this.reBuild=!0)}},{key:"componentDidUpdate",value:function(){if(this.reBuild){this.slider.destroy();this.createG2Instance().render(),this.reBuild=!1}}},{key:"componentWillUnmount",value:function(){this.slider.destroy()}},{key:"createG2Instance",value:function(){return this.slider=new c.default(l({container:this.container},this.props))}},{key:"render",value:function(){return g.default.createElement("div",{ref:this.refHandle})}}]),e}(f.Component);e.default=function(t){function e(){return a(this,e),s(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return o(e,t),u(e,[{key:"render",value:function(){return g.default.createElement(m.default,null,g.default.createElement(y,this.props))}}]),e}(f.Component),t.exports=e.default},function(e,i){e.exports=t},function(t,e,i){!function(e,i){t.exports=i()}(0,function(){return function(t){function e(n){if(i[n])return i[n].exports;var r=i[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,e),r.l=!0,r.exports}var i={};return e.m=t,e.c=i,e.d=function(t,i,n){e.o(t,i)||Object.defineProperty(t,i,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var i=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(i,"a",i),i},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,i){var n=i(1);window&&!window.G2&&console.err("Please load the G2 script first!"),t.exports=n},function(t,e,i){var n=i(2),r=window&&window.G2,a=r.Chart,s=r.Util,o=r.G,h=r.Global,l=o.Canvas,u=s.DomUtil,d=function(t){return"number"==typeof t};t.exports=function(){function t(t){this._initProps(),s.deepMix(this,t);var e=this.container;if(!e)throw Error("Please specify the container for the Slider!");this.domContainer=s.isString(e)?document.getElementById(e):e,this.handleStyle=s.mix({width:this.height,height:this.height},this.handleStyle),"auto"===this.width&&window.addEventListener("resize",s.wrapBehavior(this,"_initForceFitEvent"))}var e=t.prototype;return e._initProps=function(){this.height=26,this.width="auto",this.padding=h.plotCfg.padding,this.container=null,this.xAxis=null,this.yAxis=null,this.fillerStyle={fill:"#BDCCED",fillOpacity:.3},this.backgroundStyle={stroke:"#CCD6EC",fill:"#CCD6EC",fillOpacity:.3,lineWidth:1},this.range=[0,100],this.layout="horizontal",this.textStyle={fill:"#545454"},this.handleStyle={img:"https://gw.alipayobjects.com/zos/rmsportal/QXtfhORGlDuRvLXFzpsQ.png",width:5},this.backgroundChart={type:["area"],color:"#CCD6EC"}},e._initForceFitEvent=function(){var t=setTimeout(s.wrapBehavior(this,"forceFit"),200);clearTimeout(this.resizeTimer),this.resizeTimer=t},e.forceFit=function(){if(this&&!this.destroyed){var t=u.getWidth(this.domContainer),e=this.height;if(t!==this.domWidth){var i=this.canvas;i.changeSize(t,e),this.bgChart&&this.bgChart.changeWidth(t),i.clear(),this._initWidth(),this._initSlider(),this._bindEvent(),i.draw()}}},e._initWidth=function(){var t;t="auto"===this.width?u.getWidth(this.domContainer):this.width,this.domWidth=t;var e=s.toAllPadding(this.padding);"horizontal"===this.layout?(this.plotWidth=t-e[1]-e[3],this.plotPadding=e[3],this.plotHeight=this.height):"vertical"===this.layout&&(this.plotWidth=this.width,this.plotHeight=this.height-e[0]-e[2],this.plotPadding=e[0])},e.render=function(){this._initWidth(),this._initCanvas(),this._initBackground(),this._initSlider(),this._bindEvent(),this.canvas.draw()},e.changeData=function(t){this.data=t,this.repaint()},e.destroy=function(){clearTimeout(this.resizeTimer),this.rangeElement.off("sliderchange"),this.bgChart&&this.bgChart.destroy(),this.canvas.destroy();for(var t=this.domContainer;t.hasChildNodes();)t.removeChild(t.firstChild);window.removeEventListener("resize",s.getWrapBehavior(this,"_initForceFitEvent")),this.destroyed=!0},e.clear=function(){this.canvas.clear(),this.bgChart&&this.bgChart.destroy(),this.bgChart=null,this.scale=null,this.canvas.draw()},e.repaint=function(){this.clear(),this.render()},e._initCanvas=function(){var t=this.domWidth,e=this.height,i=new l({width:t,height:e,containerDOM:this.domContainer,capture:!1}),n=i.get("el");n.style.position="absolute",n.style.top=0,n.style.left=0,n.style.zIndex=3,this.canvas=i},e._initBackground=function(){var t,e=this.data,i=this.xAxis,n=this.yAxis,r=s.deepMix((t={},t[""+i]={range:[0,1]},t),this.scales);if(!e)throw Error("Please specify the data!");if(!i)throw Error("Please specify the xAxis!");if(!n)throw Error("Please specify the yAxis!");var o=this.backgroundChart,h=o.type,l=o.color;s.isArray(h)||(h=[h]);var u=s.toAllPadding(this.padding),d=new a({container:this.container,width:this.domWidth,height:this.height,padding:[0,u[1],0,u[3]],animate:!1});d.source(e),d.scale(r),d.axis(!1),d.tooltip(!1),d.legend(!1),s.each(h,function(t){d[t]().position(i+"*"+n).color(l).opacity(1)}),d.render(),this.bgChart=d,this.scale="horizontal"===this.layout?d.getXScale():d.getYScales()[0],"vertical"===this.layout&&d.destroy()},e._initRange=function(){var t=this.startRadio,e=this.endRadio,i=this.start,n=this.end,r=this.scale,a=0,s=1;d(t)?a=t:i&&(a=r.scale(r.translate(i))),d(e)?s=e:n&&(s=r.scale(r.translate(n)));var o=this.minSpan,h=this.maxSpan,l=0;if("time"===r.type||"timeCat"===r.type){var u=r.values;l=u[u.length-1]-u[0]}else r.isLinear&&(l=r.max-r.min);l&&o&&(this.minRange=o/l*100),l&&h&&(this.maxRange=h/l*100);var c=[100*a,100*s];return this.range=c,c},e._getHandleValue=function(t){var e=this.range,i=e[0]/100,n=e[1]/100,r=this.scale;return"min"===t?this.start?this.start:r.invert(i):this.end?this.end:r.invert(n)},e._initSlider=function(){var t=this.canvas,e=this._initRange(),i=this.scale,r=t.addGroup(n,{middleAttr:this.fillerStyle,range:e,minRange:this.minRange,maxRange:this.maxRange,layout:this.layout,width:this.plotWidth,height:this.plotHeight,backgroundStyle:this.backgroundStyle,textStyle:this.textStyle,handleStyle:this.handleStyle,minText:i.getText(this._getHandleValue("min")),maxText:i.getText(this._getHandleValue("max"))});"horizontal"===this.layout?r.translate(this.plotPadding,0):"vertical"===this.layout&&r.translate(0,this.plotPadding),this.rangeElement=r},e._bindEvent=function(){var t=this;t.rangeElement.on("sliderchange",function(e){var i=e.range;t._updateElement(i[0]/100,i[1]/100)})},e._updateElement=function(t,e){var i=this.scale,n=this.rangeElement,r=n.get("minTextElement"),a=n.get("maxTextElement"),s=i.invert(t),o=i.invert(e),h=i.getText(s),l=i.getText(o);r.attr("text",h),a.attr("text",l),this.start=h,this.end=l,this.onChange&&this.onChange({startText:h,endText:l,startValue:s,endValue:o,startRadio:t,endRadio:e})},t}()},function(t,e){function i(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}var n=window&&window.G2,r=n.Util,a=n.G,s=a.Group,o=r.DomUtil;t.exports=function(t){function e(){return t.apply(this,arguments)||this}i(e,t);var n=e.prototype;return n.getDefaultCfg=function(){return{range:null,middleAttr:null,backgroundElement:null,minHandleElement:null,maxHandleElement:null,middleHandleElement:null,currentTarget:null,layout:"vertical",width:null,height:null,pageX:null,pageY:null}},n._initHandle=function(t){var e,i,n,a=this.addGroup(),s=this.get("layout"),o=this.get("handleStyle"),h=o.img,l=o.width,u=o.height;if("horizontal"===s){var d=o.width;n="ew-resize",i=a.addShape("Image",{attrs:{x:-d/2,y:0,width:d,height:u,img:h,cursor:n}}),e=a.addShape("Text",{attrs:r.mix({x:"min"===t?-(d/2+5):d/2+5,y:u/2,textAlign:"min"===t?"end":"start",textBaseline:"middle",text:this.get("min"===t?"minText":"maxText"),cursor:n},this.get("textStyle"))})}else n="ns-resize",i=a.addShape("Image",{attrs:{x:0,y:-u/2,width:l,height:u,img:h,cursor:n}}),e=a.addShape("Text",{attrs:r.mix({x:l/2,y:"min"===t?u/2+5:-(u/2+5),textAlign:"center",textBaseline:"middle",text:this.get("min"===t?"minText":"maxText"),cursor:n},this.get("textStyle"))});return this.set(t+"TextElement",e),this.set(t+"IconElement",i),a},n._initSliderBackground=function(){var t=this.addGroup();return t.initTransform(),t.translate(0,0),t.addShape("Rect",{attrs:r.mix({x:0,y:0,width:this.get("width"),height:this.get("height")},this.get("backgroundStyle"))}),t},n._beforeRenderUI=function(){var t=this._initSliderBackground(),e=this._initHandle("min"),i=this._initHandle("max"),n=this.addShape("rect",{attrs:this.get("middleAttr")});this.set("middleHandleElement",n),this.set("minHandleElement",e),this.set("maxHandleElement",i),this.set("backgroundElement",t),t.set("zIndex",0),n.set("zIndex",1),e.set("zIndex",2),i.set("zIndex",2),n.attr("cursor","move"),this.sort()},n._renderUI=function(){"horizontal"===this.get("layout")?this._renderHorizontal():this._renderVertical()},n._transform=function(t){var e=this.get("range"),i=e[0]/100,n=e[1]/100,r=this.get("width"),a=this.get("height"),s=this.get("minHandleElement"),o=this.get("maxHandleElement"),h=this.get("middleHandleElement");s.resetMatrix?(s.resetMatrix(),o.resetMatrix()):(s.initTransform(),o.initTransform()),"horizontal"===t?(h.attr({x:r*i,y:0,width:(n-i)*r,height:a}),s.translate(i*r,0),o.translate(n*r,0)):(h.attr({x:0,y:a*(1-n),width:r,height:(n-i)*a}),s.translate(0,(1-i)*a),o.translate(0,(1-n)*a))},n._renderHorizontal=function(){this._transform("horizontal")},n._renderVertical=function(){this._transform("vertical")},n._bindUI=function(){this.on("mousedown",r.wrapBehavior(this,"_onMouseDown"))},n._isElement=function(t,e){var i=this.get(e);if(t===i)return!0;if(i.isGroup){return i.get("children").indexOf(t)>-1}return!1},n._getRange=function(t,e){var i=t+e;return i=i>100?100:i,i=0>i?0:i},n._limitRange=function(t,e,i){i[0]=this._getRange(t,i[0]),(i[1]=i[0]+e)>100&&(i[1]=100,i[0]=i[1]-e)},n._updateStatus=function(t,e){var i=this.get("x"===t?"width":"height");t=r.upperFirst(t);var n,a=this.get("range"),s=this.get("page"+t),o=this.get("currentTarget"),h=this.get("rangeStash"),l=this.get("layout"),u="vertical"===l?-1:1,d=e["page"+t],c=d-s,f=c/i*100*u,g=this.get("minRange"),p=this.get("maxRange");a[1]>a[0]?(this._isElement(o,"minHandleElement")&&(a[0]=this._getRange(f,a[0]),g&&(a[1]-a[0]>g||this._limitRange(f,g,a)),p&&(p>a[1]-a[0]||this._limitRange(f,p,a))),this._isElement(o,"maxHandleElement")&&(a[1]=this._getRange(f,a[1]),g&&(a[1]-a[0]>g||this._limitRange(f,g,a)),p&&(p>a[1]-a[0]||this._limitRange(f,p,a)))):(this._isElement(o,"minHandleElement")||this._isElement(o,"maxHandleElement"))&&(a[0]=this._getRange(f,a[0]),a[1]=this._getRange(f,a[0])),this._isElement(o,"middleHandleElement")&&(n=h[1]-h[0],this._limitRange(f,n,a)),this.emit("sliderchange",{range:a}),this.set("page"+t,d),this._renderUI(),this.get("canvas").draw()},n._onMouseDown=function(t){var e=t.currentTarget,i=t.event,n=this.get("range");i.stopPropagation(),i.preventDefault(),this.set("pageX",i.pageX),this.set("pageY",i.pageY),this.set("currentTarget",e),this.set("rangeStash",[n[0],n[1]]),this._bindCanvasEvents()},n._bindCanvasEvents=function(){var t=this.get("canvas").get("containerDOM");this.onMouseMoveListener=o.addEventListener(t,"mousemove",r.wrapBehavior(this,"_onCanvasMouseMove")),this.onMouseUpListener=o.addEventListener(t,"mouseup",r.wrapBehavior(this,"_onCanvasMouseUp")),this.onMouseLeaveListener=o.addEventListener(t,"mouseleave",r.wrapBehavior(this,"_onCanvasMouseUp"))},n._onCanvasMouseMove=function(t){"horizontal"===this.get("layout")?this._updateStatus("x",t):this._updateStatus("y",t)},n._onCanvasMouseUp=function(){this._removeDocumentEvents()},n._removeDocumentEvents=function(){this.onMouseMoveListener.remove(),this.onMouseUpListener.remove(),this.onMouseLeaveListener.remove()},e}(s)}])})},function(t,e,i){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function a(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}Object.defineProperty(e,"__esModule",{value:!0});var s=function(){function t(t,e){for(var i=0;e.length>i;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}(),o=i(1),h=function(t){return t&&t.__esModule?t:{default:t}}(o);e.default=function(t){function e(t){n(this,e);var i=r(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return i.state={hasError:!1},i}return a(e,t),s(e,[{key:"componentDidCatch",value:function(t,e){this.setState({hasError:!0})}},{key:"unstable_handleError",value:function(t,e){this.setState({hasError:!0})}},{key:"render",value:function(){return this.state.hasError?h.default.createElement("h1",null,"Slider error."):this.props.children}}]),e}(h.default.Component)},function(t,e,i){i(0),t.exports=i(0)}])});
\No newline at end of file