UNPKG

basb-cli

Version:
2 lines (1 loc) 9.78 kB
import{bA as e,e as t,d as r,bR as n,b1 as o,bS as s,bh as i,m as u,$ as a,bT as h,D as p,_ as c,Y as l,bU as f,Z as b,bV as d,bQ as M,aJ as y,aN as v}from"./index.js";import{B as g}from"./brushHelper.js";import{c as m,a as T,r as V}from"./visualSolution.js";import{B as x,T as O,r as B}from"./featureManager.js";import"./interactionMutex.js";import"./cursorHelper.js";import"./VisualMapping.js";var C=["rect","polygon","keep","clear"];function S(n,o){var s=e(n?n.brush:[]);if(s.length){var i=[];t(s,(function(e){var t=e.hasOwnProperty("toolbox")?e.toolbox:[];t instanceof Array&&(i=i.concat(t))}));var u=n&&n.toolbox;r(u)&&(u=u[0]),u||(u={feature:{}},n.toolbox=[u]);var a=u.feature||(u.feature={}),h=a.brush||(a.brush={}),p=h.type||(h.type=[]);p.push.apply(p,i),function(e){var r={};t(e,(function(e){r[e]=1})),e.length=0,t(r,(function(t,r){e.push(r)}))}(p),o&&!p.length&&p.push.apply(p,C)}}var I={lineX:A(0),lineY:A(1),rect:{point:function(e,t,r){return e&&r.boundingRect.contain(e[0],e[1])},rect:function(e,t,r){return e&&r.boundingRect.intersect(e)}},polygon:{point:function(e,t,r){return e&&r.boundingRect.contain(e[0],e[1])&&n(r.range,e[0],e[1])},rect:function(e,t,r){var i=r.range;if(!e||i.length<=1)return!1;var u=e.x,a=e.y,h=e.width,p=e.height,c=i[0];return!!(n(i,u,a)||n(i,u+h,a)||n(i,u,a+p)||n(i,u+h,a+p)||o.create(e).contain(c[0],c[1])||s(u,a,u+h,a,i)||s(u,a,u,a+p,i)||s(u+h,a,u+h,a+p,i)||s(u,a+p,u+h,a+p,i))||void 0}}};function A(e){var t=["x","y"],r=["width","height"];return{point:function(t,r,n){if(t){var o=n.range;return _(t[e],o)}},rect:function(n,o,s){if(n){var i=s.range,u=[n[t[e]],n[t[e]]+n[r[e]]];return u[1]<u[0]&&u.reverse(),_(u[0],i)||_(u[1],i)||_(i[0],u)||_(i[1],u)}}}}function _(e,t){return t[0]<=e&&e<=t[1]}var k=["inBrush","outOfBrush"],H="__ecBrushSelect",w="__ecInBrushSelectEvent";function R(e){e.eachComponent({mainType:"brush"},(function(t){(t.brushTargetManager=new x(t.option,e)).setInputRanges(t.areas,e)}))}function D(e,n,o){var s,c,l=[];e.eachComponent({mainType:"brush"},(function(e){o&&"takeGlobalCursor"===o.type&&e.setBrushOption("brush"===o.key?o.brushOption:{brushType:!1})})),R(e),e.eachComponent({mainType:"brush"},(function(n,o){var h={brushId:n.id,brushIndex:o,brushName:n.name,areas:i(n.areas),selected:[]};l.push(h);var f=n.option,b=f.brushLink,d=[],M=[],y=[],v=!1;o||(s=f.throttleType,c=f.throttleDelay);var g=u(n.areas,(function(e){var t=z[e.brushType],r=a({boundingRect:t?t(e):void 0},e);return r.selectors=function(e){var t=e.brushType,r={point:function(n){return I[t].point(n,r,e)},rect:function(n){return I[t].rect(n,r,e)}};return r}(r),r})),V=m(n.option,k,(function(e){e.mappingMethod="fixed"}));function x(e){return"all"===b||!!d[e]}function O(e){return!!e.length}r(b)&&t(b,(function(e){d[e]=1})),e.eachSeries((function(o,s){var i=y[s]=[];"parallel"===o.subType?function(e,t){var r=e.coordinateSystem;v=v||r.hasAxisBrushed(),x(t)&&r.eachActiveState(e.getData(),(function(e,t){"active"===e&&(M[t]=1)}))}(o,s):function(o,s,i){if(!o.brushSelector||function(e,t){var n=e.option.seriesIndex;return null!=n&&"all"!==n&&(r(n)?p(n,t)<0:t!==n)}(n,s))return;if(t(g,(function(t){n.brushTargetManager.controlSeries(t,o,e)&&i.push(t),v=v||O(i)})),x(s)&&O(i)){var u=o.getData();u.each((function(e){j(o,i,u,e)&&(M[e]=1)}))}}(o,s,i)})),e.eachSeries((function(e,t){var r={seriesId:e.id,seriesIndex:t,seriesName:e.name,dataIndex:[]};h.selected.push(r);var n=y[t],o=e.getData(),s=x(t)?function(e){return M[e]?(r.dataIndex.push(o.getRawIndex(e)),"inBrush"):"outOfBrush"}:function(t){return j(e,n,o,t)?(r.dataIndex.push(o.getRawIndex(t)),"inBrush"):"outOfBrush"};(x(t)?v:O(n))&&T(k,V,o,s)}))})),function(e,t,r,n,o){if(!o)return;var s=e.getZr();if(s[w])return;s[H]||(s[H]=E);var i=h(s,H,r,t);i(e,n)}(n,s,c,l,o)}function E(e,t){if(!e.isDisposed()){var r=e.getZr();r[w]=!0,e.dispatchAction({type:"brushSelect",batch:t}),r[w]=!1}}function j(e,t,r,n){for(var o=0,s=t.length;o<s;o++){var i=t[o];if(e.brushSelector(n,r,i.selectors,i))return!0}}var z={rect:function(e){return L(e.range)},polygon:function(e){for(var t,r=e.range,n=0,o=r.length;n<o;n++){t=t||[[1/0,-1/0],[1/0,-1/0]];var s=r[n];s[0]<t[0][0]&&(t[0][0]=s[0]),s[0]>t[0][1]&&(t[0][1]=s[0]),s[1]<t[1][0]&&(t[1][0]=s[1]),s[1]>t[1][1]&&(t[1][1]=s[1])}return t&&L(t)}};function L(e){return new o(e[0][0],e[1][0],e[0][1]-e[0][0],e[1][1]-e[1][0])}var P=function(e){function t(){var r=null!==e&&e.apply(this,arguments)||this;return r.type=t.type,r}return c(t,e),t.prototype.init=function(e,t){this.ecModel=e,this.api=t,this.model,(this._brushController=new g(t.getZr())).on("brush",l(this._onBrush,this)).mount()},t.prototype.render=function(e,t,r,n){this.model=e,this._updateController(e,t,r,n)},t.prototype.updateTransform=function(e,t,r,n){R(t),this._updateController(e,t,r,n)},t.prototype.updateVisual=function(e,t,r,n){this.updateTransform(e,t,r,n)},t.prototype.updateView=function(e,t,r,n){this._updateController(e,t,r,n)},t.prototype._updateController=function(e,t,r,n){(!n||n.$from!==e.id)&&this._brushController.setPanels(e.brushTargetManager.makePanelOpts(r)).enableBrush(e.brushOption).updateCovers(e.areas.slice())},t.prototype.dispose=function(){this._brushController.dispose()},t.prototype._onBrush=function(e){var t=this.model.id,r=this.model.brushTargetManager.setOutputRanges(e.areas,this.ecModel);(!e.isEnd||e.removeOnClick)&&this.api.dispatchAction({type:"brush",brushId:t,areas:i(r),$from:t}),e.isEnd&&this.api.dispatchAction({type:"brushEnd",brushId:t,areas:i(r),$from:t})},t.type="brush",t}(f);function Z(e,t){return M({brushType:e.brushType,brushMode:e.brushMode,transformable:e.transformable,brushStyle:new y(e.brushStyle).getItemStyle(),removeOnClick:e.removeOnClick,z:e.z},t,!0)}var Y=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.type=n.type,t.areas=[],t.brushOption={},t}return c(n,e),n.prototype.optionUpdated=function(e,t){var r=this.option;!t&&V(r,e,["inBrush","outOfBrush"]);var n=r.inBrush=r.inBrush||{};r.outOfBrush=r.outOfBrush||{color:"#ddd"},n.hasOwnProperty("liftZ")||(n.liftZ=5)},n.prototype.setAreas=function(e){b(r(e)),t(e,(function(e){b(e.brushType,"Illegal areas")})),e&&(this.areas=u(e,(function(e){return Z(this.option,e)}),this))},n.prototype.setBrushOption=function(e){this.brushOption=Z(this.option,e),this.brushType=this.brushOption.brushType},n.type="brush",n.dependencies=["geo","grid","xAxis","yAxis","parallel","series"],n.defaultOption={seriesIndex:"all",brushType:"rect",brushMode:"single",transformable:!0,brushStyle:{borderWidth:1,color:"rgba(210,219,238,0.3)",borderColor:"#D2DBEE"},throttleType:"fixRate",throttleDelay:0,removeOnClick:!0,z:1e4},n}(d),U=["rect","polygon","lineX","lineY","keep","clear"],$=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return c(r,e),r.prototype.render=function(e,r,n){var o,s,i;r.eachComponent({mainType:"brush"},(function(e){o=e.brushType,s=e.brushOption.brushMode||"single",i=i||!!e.areas.length})),this._brushType=o,this._brushMode=s,t(e.get("type",!0),(function(t){e.setIconStatus(t,("keep"===t?"multiple"===s:"clear"===t?i:t===o)?"emphasis":"normal")}))},r.prototype.updateView=function(e,t,r){this.render(e,t,r)},r.prototype.getIcons=function(){var e=this.model,r=e.get("icon",!0),n={};return t(e.get("type",!0),(function(e){r[e]&&(n[e]=r[e])})),n},r.prototype.onclick=function(e,t,r){var n=this._brushType,o=this._brushMode;"clear"===r?(t.dispatchAction({type:"axisAreaSelect",intervals:[]}),t.dispatchAction({type:"brush",command:"clear",areas:[]})):t.dispatchAction({type:"takeGlobalCursor",key:"brush",brushOption:{brushType:"keep"===r?n:n!==r&&r,brushMode:"keep"===r?"multiple"===o?"single":"multiple":o}})},r.getDefaultOption=function(e){return{show:!0,type:U.slice(),icon:{rect:"M7.3,34.7 M0.4,10V-0.2h9.8 M89.6,10V-0.2h-9.8 M0.4,60v10.2h9.8 M89.6,60v10.2h-9.8 M12.3,22.4V10.5h13.1 M33.6,10.5h7.8 M49.1,10.5h7.8 M77.5,22.4V10.5h-13 M12.3,31.1v8.2 M77.7,31.1v8.2 M12.3,47.6v11.9h13.1 M33.6,59.5h7.6 M49.1,59.5 h7.7 M77.5,47.6v11.9h-13",polygon:"M55.2,34.9c1.7,0,3.1,1.4,3.1,3.1s-1.4,3.1-3.1,3.1 s-3.1-1.4-3.1-3.1S53.5,34.9,55.2,34.9z M50.4,51c1.7,0,3.1,1.4,3.1,3.1c0,1.7-1.4,3.1-3.1,3.1c-1.7,0-3.1-1.4-3.1-3.1 C47.3,52.4,48.7,51,50.4,51z M55.6,37.1l1.5-7.8 M60.1,13.5l1.6-8.7l-7.8,4 M59,19l-1,5.3 M24,16.1l6.4,4.9l6.4-3.3 M48.5,11.6 l-5.9,3.1 M19.1,12.8L9.7,5.1l1.1,7.7 M13.4,29.8l1,7.3l6.6,1.6 M11.6,18.4l1,6.1 M32.8,41.9 M26.6,40.4 M27.3,40.2l6.1,1.6 M49.9,52.1l-5.6-7.6l-4.9-1.2",lineX:"M15.2,30 M19.7,15.6V1.9H29 M34.8,1.9H40.4 M55.3,15.6V1.9H45.9 M19.7,44.4V58.1H29 M34.8,58.1H40.4 M55.3,44.4 V58.1H45.9 M12.5,20.3l-9.4,9.6l9.6,9.8 M3.1,29.9h16.5 M62.5,20.3l9.4,9.6L62.3,39.7 M71.9,29.9H55.4",lineY:"M38.8,7.7 M52.7,12h13.2v9 M65.9,26.6V32 M52.7,46.3h13.2v-9 M24.9,12H11.8v9 M11.8,26.6V32 M24.9,46.3H11.8v-9 M48.2,5.1l-9.3-9l-9.4,9.2 M38.9-3.9V12 M48.2,53.3l-9.3,9l-9.4-9.2 M38.9,62.3V46.4",keep:"M4,10.5V1h10.3 M20.7,1h6.1 M33,1h6.1 M55.4,10.5V1H45.2 M4,17.3v6.6 M55.6,17.3v6.6 M4,30.5V40h10.3 M20.7,40 h6.1 M33,40h6.1 M55.4,30.5V40H45.2 M21,18.9h62.9v48.6H21V18.9z",clear:"M22,14.7l30.9,31 M52.9,14.7L22,45.7 M4.7,16.8V4.2h13.1 M26,4.2h7.8 M41.6,4.2h7.8 M70.3,16.8V4.2H57.2 M4.7,25.9v8.6 M70.3,25.9v8.6 M4.7,43.2v12.6h13.1 M26,55.8h7.8 M41.6,55.8h7.8 M70.3,43.2v12.6H57.2"},title:e.getLocaleModel().get(["toolbox","brush","title"])}},r}(O);function N(e){e.registerComponentView(P),e.registerComponentModel(Y),e.registerPreprocessor(S),e.registerVisual(e.PRIORITY.VISUAL.BRUSH,D),e.registerAction({type:"brush",event:"brush",update:"updateVisual"},(function(e,t){t.eachComponent({mainType:"brush",query:e},(function(t){t.setAreas(e.areas)}))})),e.registerAction({type:"brushSelect",event:"brushSelected",update:"none"},v),e.registerAction({type:"brushEnd",event:"brushEnd",update:"none"},v),B("brush",$)}export{N as install};