@plotdb/chart 3.11.0 → 3.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- !function(){var c,d;c="http://www.w3.org/2000/svg",(d=function(a){var t,e,n,i,r,l,s,o,u=this;if(null==a&&(a={}),this._data=a.data||[],this.name=a.name||"legend",this.cfg=a.cfg||{},this.root="string"==typeof a.root?document.querySelector(a.root):a.root,this.dir=a.direction||"vertical",this.evtHandler={},this._picked=Object.fromEntries(this._data.map(function(t){return[t.key,!0]})),this.layout=a.layout||new layout({root:this.root}),(e=this.layout).on("update",function(){return u.update()}),e.on("render",function(){return u.render()}),this.id=Math.random().toString(36).substring(2),e=this.layout.getNode(this.name),t=this.layout.getGroup(this.name),e.querySelector("[ld-each=legend]")||(e.innerHTML='<div class="pdlg '+this.dir+'">\n <div ld-each="legend">\n <div class="pdl-cell" ld="shape" data-only></div>\n <div class="pdl-cell" ld="text" data-only></div>\n </div>\n</div>'),t.querySelector("[ld-each=legend]")||(e=document.createElementNS(c,"g"),n=document.createElementNS(c,"g"),i=document.createElementNS(c,"g"),e.classList.add("pdlg-g"),e.setAttribute("ld-each","legend"),n.setAttribute("ld","shape"),i.setAttribute("ld","text"),e.appendChild(n),e.appendChild(i),t.appendChild(e)),this._i18n=a.i18n||("undefined"!=typeof block&&null!==block&&block.i18n&&block.i18n.module?block.i18n.module:null),this._t=a.t||null,this._i18n){if(r=this._i18n.addResourceBundle)for(l in s=d.i18n){o=s[l];try{r.call(this._i18n,l,d.i18nNs,o,!0,!1)}catch(t){}}this._i18n.on&&this._i18n.on("languageChanged",this._lngHandler=function(){return u._relocalize()})}return this._func=[{key:"all",type:"func",text:this._text("all")},{key:"none",type:"func",text:this._text("none")}],this.view={layout:new ldview({root:this.layout.getNode(this.name),initRender:!1,handler:{legend:{list:function(){var n,t=u._data.map(function(t){return t}),i=u.cfg.sort||{};return"none"!==i.mode&&(n="desc"===i.direction?1:-1,t.sort(function(t,e){return"value"===i.mode?n*(e.value-t.value):n*(t.text<e.text?1:t.text>e.text?-1:0)})),t.concat(u._actions()?u._func:[])},key:function(t){return t.key},view:{handler:{shape:function(t){return t.node.setAttribute("data-name",u._name(t.ctx,"shape"))},text:function(t){var e=t.node,t=t.ctx;return e.setAttribute("data-name",u._name(t,"text")),e.innerText=t.text}}}}}}),render:new ldview({root:this.layout.getGroup(this.name),initRender:!1,handler:{legend:{list:function(){return u._data.concat(u._actions()?u._func:[])},key:function(t){return t.key},view:{action:{click:{"@":function(t){t.node;var e,n=t.ctx;if(u.cfg.selectable){if("func"===n.type)for(e in u._picked)u._picked[e]="all"===n.key;else u._picked[n.key]=!u._picked[n.key];return u.view.render.render("legend"),u.fire("select",u._picked)}}}},handler:{"@":function(t){var e=t.node,t=t.ctx;return e.style.opacity=!u.cfg.selectable||"func"===t.type||u._picked[t.key]?1:.3},shape:function(t){var e,n,i,r=t.node,t=t.ctx;if("func"!==t.type)return r.querySelector("circle")||r.appendChild(document.createElementNS(c,"circle")),e=r.querySelector("circle"),n=u.layout.getBox(u._name(t,"shape")),i=u.layout.getBox(u.name),e.setAttribute("cx",".5em"),e.setAttribute("cy",".5em"),e.setAttribute("r",".5em"),e.setAttribute("transform","translate("+(n.x-i.x)+", "+(n.y-i.y)+")"),"function"==typeof a.shape?a.shape.call(e,t):void 0;r.style.display="none"},text:function(t){var e=t.node,t=t.ctx,n=u.layout.getNode(u._name(t,"text")),t=u.layout.getBox(u._name(t,"text")),i=u.layout.getBox(u.name);return e.setAttribute("transform","translate("+(t.x-i.x)+", "+(t.y-i.y)+")"),e.textContent="",t=wrapSvgText({node:n,useRange:!0}),e.appendChild(t)}}}}}})},this.update(),this}).i18nNs="@plotdb/chart.legend",d.i18n={en:{all:"Select All",none:"Select None"},"zh-TW":{all:"全選",none:"全不選"},"zh-CN":{all:"全选",none:"全不选"},ja:{all:"すべて選択",none:"すべて解除"}},d.prototype=((t,e)=>{var n,i={}.hasOwnProperty;for(n in e)i.call(e,n)&&(t[n]=e[n]);return t})(Object.create(Object.prototype),{_text:function(t){var e,n;return this._t&&(e=this._t("legend."+t))&&e!=="legend."+t||(n=d.i18nNs+":"+t,this._i18n&&this._i18n.t&&(e=this._i18n.t(n))&&e!==n&&e!==t)?e:(n=(n=this._i18n?this._i18n.language||this._i18n.lng:null)||("undefined"!=typeof document&&null!==document?document.documentElement.lang:"")||"en",(d.i18n[n]||d.i18n[n.split("-")[0]]||(/^zh/i.exec(n)?d.i18n[/cn|hans|sg/i.exec(n)?"zh-CN":"zh-TW"]:void 0)||d.i18n.en)[t])},_relocalize:function(){var e=this;if(this._func.map(function(t){return t.text=e._text(t.key)}),this._actions())return this.view.layout.render("legend"),this.layout.update(!1),this.view.render.render()},destroy:function(){return this._i18n&&this._lngHandler&&this._i18n.off&&this._i18n.off("languageChanged",this._lngHandler),this._lngHandler=null},_actions:function(){return!(!this.cfg.selectable||null!=this.cfg.actions&&!this.cfg.actions)},_name:function(t,e){return"pdlg-"+(e=null==e?"s":e)+"-"+this.id+"-"+(t.type||"")+"-"+t.key},enabled:function(){return this._data&&this._data.length&&(!(null!=this.cfg.enabled)||this.cfg.enabled)},update:function(){var t=this.enabled()?"":"0px",e=this.layout.getNode(this.name).style;return e.width=t,e.height=t,e.padding=t,e.margin=t,(e=this.layout.getNode(this.name).querySelector(".pdlg"))&&("vertical"===this.dir?(e.style.height="fit-content",e.style.height=getComputedStyle(e.parentNode).height):e.style.height=""),this.view.layout.render()},render:function(){var t=this.enabled();if(this.layout.getGroup(this.name).style.display=t?"":"none",t)return this.view.render.render()},config:function(t){var e,n=this;return null==t?this.cfg:(this.cfg.selectable!==t.selectable&&(this._picked=null,this._updatePicked()),this.cfg=t,this.dir="bottom"===this.cfg.position?"horizontal":"vertical",e=this.layout.getNode(this.name).querySelector(".pdlg"),["horizontal","vertical"].map(function(t){return e.classList.toggle(t,n.dir===t)}))},_updatePicked:function(){var e=this;return null==this._picked&&(this._picked=Object.fromEntries(this._data.map(function(t){return[t.key,!0]}))),this._data.map(function(t){if(null==e._picked[t.key])return e._picked[t.key]=!0})},data:function(t){var n;return arguments.length?(n={},t.map(function(t,e){return n[t.key]=e}),this._data=t.filter(function(t,e){return n[t.key]===e}),this._range=this._data.filter(function(t){return t.ext}),this._updatePicked(),this.update(),this.layout.update(!1),this.view.render.render()):this._data},on:function(t,n){var i=this;return(Array.isArray(t)?t:[t]).map(function(t){var e;return((e=i.evtHandler)[t]||(e[t]=[])).push(n)})},fire:function(t){for(var e,n,i,r,a=[],l=[],s=1,o=arguments.length;s<o;++s)l.push(arguments[s]);for(e=l,s=0,i=(n=this.evtHandler[t]||[]).length;s<i;++s)r=n[s],a.push(r.apply(this,e));return a},isSelected:function(e){var n=this;return this._range&&this._range.length?!!this._range.filter(function(t){return e>=t.ext[0]&&e<t.ext[1]&&n._picked[t.key]}).length:!!this._picked[e]},mode:function(){return"shrink"===((this.cfg.subset||{}).mode||"shrink")?"shrink":"dim"},opacity:function(){var t;return null!=(t=(this.cfg.subset||{}).opacity)?t:.2},isVisible:function(t){return"shrink"!==this.mode()||this.isSelected(t)},select:function(t){var e;return null==t?this._picked=Object.fromEntries(this._data.map(function(t){return[t.key,!0]})):(e=Object.fromEntries(t.map(function(t){return[t,!0]})),this._picked=Object.fromEntries(this._data.map(function(t){return[t.key,!!e[t.key]]}))),this.view.render.render("legend"),this},selected:function(){var e=this,t=this._data.filter(function(t){return!!e._picked[t.key]}).map(function(t){return t.key});return t.length===this._data.length?null:t}}),"undefined"!=typeof chart&&null!==chart&&((chart.utils||(chart.utils={})).legend=d)}.call(this);
1
+ !function(){var u,c;u="http://www.w3.org/2000/svg",(c=function(a){var t,e,n,i,r,s,l,o,h=this;if(null==a&&(a={}),this._data=a.data||[],this.name=a.name||"legend",this.cfg=a.cfg||{},this.root="string"==typeof a.root?document.querySelector(a.root):a.root,this.dir=a.direction||"vertical",this.evtHandler={},this._picked=Object.fromEntries(this._data.map(function(t){return[t.key,!0]})),this.layout=a.layout||new layout({root:this.root}),(e=this.layout).on("update",function(){return h.update()}),e.on("render",function(){return h.render()}),this.id=Math.random().toString(36).substring(2),this._anchor=null,this._pos={},e=this.layout.getNode(this.name),t=this.layout.getGroup(this.name),e.querySelector("[ld-each=legend]")||(e.innerHTML='<div class="pdlg '+this.dir+'">\n <div ld-each="legend">\n <div class="pdl-cell" ld="shape" data-only></div>\n <div class="pdl-cell" ld="text" data-only></div>\n </div>\n</div>'),t.querySelector("[ld-each=legend]")||(e=document.createElementNS(u,"g"),n=document.createElementNS(u,"g"),i=document.createElementNS(u,"g"),e.classList.add("pdlg-g"),e.setAttribute("ld-each","legend"),n.setAttribute("ld","shape"),i.setAttribute("ld","text"),e.appendChild(n),e.appendChild(i),t.appendChild(e)),this._i18n=a.i18n||("undefined"!=typeof block&&null!==block&&block.i18n&&block.i18n.module?block.i18n.module:null),this._t=a.t||null,this._i18n){if(r=this._i18n.addResourceBundle)for(s in l=c.i18n){o=l[s];try{r.call(this._i18n,s,c.i18nNs,o,!0,!1)}catch(t){}}this._i18n.on&&this._i18n.on("languageChanged",this._lngHandler=function(){return h._relocalize()})}return this._func=[{key:"all",type:"func",text:this._text("all")},{key:"none",type:"func",text:this._text("none")}],this.view={layout:new ldview({root:this.layout.getNode(this.name),initRender:!1,handler:{legend:{list:function(){var n,t=h._data.map(function(t){return t}),i=h.cfg.sort||{};return"none"!==i.mode&&(n="desc"===i.direction?1:-1,t.sort(function(t,e){return"value"===i.mode?n*(e.value-t.value):n*(t.text<e.text?1:t.text>e.text?-1:0)})),t.concat(h._actions()?h._func:[])},key:function(t){return t.key},view:{handler:{shape:function(t){return t.node.setAttribute("data-name",h._name(t.ctx,"shape"))},text:function(t){var e=t.node,t=t.ctx;return e.setAttribute("data-name",h._name(t,"text")),e.innerText=t.text}}}}}}),render:new ldview({root:this.layout.getGroup(this.name),initRender:!1,handler:{legend:{list:function(){return h._data.concat(h._actions()?h._func:[])},key:function(t){return t.key},view:{action:{click:{"@":function(t){t.node;var e,n=t.ctx;if(h.cfg.selectable){if("func"===n.type)for(e in h._picked)h._picked[e]="all"===n.key;else h._picked[n.key]=!h._picked[n.key];return h.view.render.render("legend"),h.fire("select",h._picked)}}}},handler:{"@":function(t){var e=t.node,t=t.ctx;return e.style.opacity=!h.cfg.selectable||"func"===t.type||h._picked[t.key]?1:.3,h._direct()&&(t=h._pos[t.key])?e.setAttribute("transform","translate(0,"+t.dy+")"):e.removeAttribute("transform")},shape:function(t){var e,n,i,r=t.node,t=t.ctx;if("func"!==t.type)return r.querySelector("circle")||r.appendChild(document.createElementNS(u,"circle")),e=r.querySelector("circle"),n=h.layout.getBox(h._name(t,"shape")),i=h.layout.getBox(h.name),e.setAttribute("cx",".5em"),e.setAttribute("cy",".5em"),e.setAttribute("r",".5em"),e.setAttribute("transform","translate("+(n.x-i.x)+", "+(n.y-i.y)+")"),"function"==typeof a.shape?a.shape.call(e,t):void 0;r.style.display="none"},text:function(t){var e=t.node,t=t.ctx,n=h.layout.getNode(h._name(t,"text")),t=h.layout.getBox(h._name(t,"text")),i=h.layout.getBox(h.name);return e.setAttribute("transform","translate("+(t.x-i.x)+", "+(t.y-i.y)+")"),e.textContent="",t=wrapSvgText({node:n,useRange:!0}),e.appendChild(t)}}}}}})},this.update(),this}).i18nNs="@plotdb/chart.legend",c.i18n={en:{all:"Select All",none:"Select None"},"zh-TW":{all:"全選",none:"全不選"},"zh-CN":{all:"全选",none:"全不选"},ja:{all:"すべて選択",none:"すべて解除"}},c.prototype=((t,e)=>{var n,i={}.hasOwnProperty;for(n in e)i.call(e,n)&&(t[n]=e[n]);return t})(Object.create(Object.prototype),{_text:function(t){var e,n;return this._t&&(e=this._t("legend."+t))&&e!=="legend."+t||(n=c.i18nNs+":"+t,this._i18n&&this._i18n.t&&(e=this._i18n.t(n))&&e!==n&&e!==t)?e:(n=(n=this._i18n?this._i18n.language||this._i18n.lng:null)||("undefined"!=typeof document&&null!==document?document.documentElement.lang:"")||"en",(c.i18n[n]||c.i18n[n.split("-")[0]]||(/^zh/i.exec(n)?c.i18n[/cn|hans|sg/i.exec(n)?"zh-CN":"zh-TW"]:void 0)||c.i18n.en)[t])},_relocalize:function(){var e=this;if(this._func.map(function(t){return t.text=e._text(t.key)}),this._actions())return this.view.layout.render("legend"),this.layout.update(!1),this.view.render.render()},destroy:function(){return this._i18n&&this._lngHandler&&this._i18n.off&&this._i18n.off("languageChanged",this._lngHandler),this._lngHandler=null},_actions:function(){return!(!this.cfg.selectable||null!=this.cfg.actions&&!this.cfg.actions||this._direct())},_direct:function(){return"direct"===this.cfg.mode&&!!this._anchor&&"vertical"===this.dir},anchor:function(t){return arguments.length?(this._anchor=t,this):this._anchor},_solve:function(){var i,r,t,a,s=this;if(this._pos={},this._direct()&&(i=this.layout.getBox(this.name),r=[],this._data.map(function(t){var e=s.layout.getBox(s._name(t,"text")),n=function(){try{return this._anchor(t)}catch(t){return null}}.call(s);return r.push({d:t,nbox:e,y:n})}),(t=r.filter(function(t){return null!=t.y&&!isNaN(t.y)})).length))return a=chart.utils.labels.place(t.map(function(t){return{y:t.y-t.nbox.height/2,height:t.nbox.height}}),{top:0,bottom:i.height,gap:2}),t.map(function(t,e){var n=t.nbox.y-i.y;return s._pos[t.d.key]={dy:a[e].y-n,y:a[e].y,h:t.nbox.height,moved:a[e].moved,anchor:t.y}})},_leads:function(){var e,t,n,i,r,a,s=[],l=this.layout.getGroup(this.name);if(this._lead||(this._lead=document.createElementNS(u,"g"),this._lead.setAttribute("data-type","leader"),this._lead.style.pointerEvents="none"),this._direct()){for(e in l.insertBefore(this._lead,l.firstChild),this._lead.textContent="",t=this._pos)(r=t[e]).moved&&this._data.filter(o)[0]&&(n=document.createElementNS(u,"path"),i=(r=[r.anchor,r.y+r.h/2])[0],r=r[1],a=this._shapeX(),n.setAttribute("d","M0 "+i+" L"+a/2+" "+i+" L"+a/2+" "+r+" L"+a+" "+r),n.setAttribute("fill","none"),n.setAttribute("stroke","currentColor"),n.setAttribute("stroke-width",1),n.setAttribute("opacity",this._picked[e]?.35:.12),s.push(this._lead.appendChild(n)));return s}function o(t){return t.key===e}this._lead.parentNode&&this._lead.parentNode.removeChild(this._lead)},_shapeX:function(){var t,e=this._data[0];return e?(t=this.layout.getBox(this.name),this.layout.getBox(this._name(e,"shape")).x-t.x):0},_name:function(t,e){return"pdlg-"+(e=null==e?"s":e)+"-"+this.id+"-"+(t.type||"")+"-"+t.key},enabled:function(){return this._data&&this._data.length&&(!(null!=this.cfg.enabled)||this.cfg.enabled)},update:function(){var t=this.enabled()?"":"0px",e=this.layout.getNode(this.name).style;return e.width=t,e.height=t,e.padding=t,e.margin=t,(e=this.layout.getNode(this.name).querySelector(".pdlg"))&&("vertical"===this.dir?(e.style.height="fit-content",e.style.height=getComputedStyle(e.parentNode).height):e.style.height=""),this.view.layout.render()},render:function(){var t=this.enabled();if(this.layout.getGroup(this.name).style.display=t?"":"none",t)return this._solve(),this.view.render.render(),this._leads()},config:function(t){var e,n=this;return null==t?this.cfg:(this.cfg.selectable!==t.selectable&&(this._picked=null,this._updatePicked()),this.cfg=t,this.dir="bottom"===this.cfg.position?"horizontal":"vertical",e=this.layout.getNode(this.name).querySelector(".pdlg"),["horizontal","vertical"].map(function(t){return e.classList.toggle(t,n.dir===t)}))},_updatePicked:function(){var e=this;return null==this._picked&&(this._picked=Object.fromEntries(this._data.map(function(t){return[t.key,!0]}))),this._data.map(function(t){if(null==e._picked[t.key])return e._picked[t.key]=!0})},data:function(t){var n;return arguments.length?(n={},t.map(function(t,e){return n[t.key]=e}),this._data=t.filter(function(t,e){return n[t.key]===e}),this._range=this._data.filter(function(t){return t.ext}),this._updatePicked(),this.update(),this.layout.update(!1),this.view.render.render()):this._data},on:function(t,n){var i=this;return(Array.isArray(t)?t:[t]).map(function(t){var e;return((e=i.evtHandler)[t]||(e[t]=[])).push(n)})},fire:function(t){for(var e,n,i,r,a=[],s=[],l=1,o=arguments.length;l<o;++l)s.push(arguments[l]);for(e=s,l=0,i=(n=this.evtHandler[t]||[]).length;l<i;++l)r=n[l],a.push(r.apply(this,e));return a},isSelected:function(e){var n=this;return this._range&&this._range.length?!!this._range.filter(function(t){return e>=t.ext[0]&&e<t.ext[1]&&n._picked[t.key]}).length:!!this._picked[e]},mode:function(){return"shrink"===((this.cfg.subset||{}).mode||"shrink")?"shrink":"dim"},opacity:function(){var t;return null!=(t=(this.cfg.subset||{}).opacity)?t:.2},isVisible:function(t){return"shrink"!==this.mode()||this.isSelected(t)},select:function(t){var e;return null==t?this._picked=Object.fromEntries(this._data.map(function(t){return[t.key,!0]})):(e=Object.fromEntries(t.map(function(t){return[t,!0]})),this._picked=Object.fromEntries(this._data.map(function(t){return[t.key,!!e[t.key]]}))),this.view.render.render("legend"),this},selected:function(){var e=this,t=this._data.filter(function(t){return!!e._picked[t.key]}).map(function(t){return t.key});return t.length===this._data.length?null:t}}),"undefined"!=typeof chart&&null!==chart&&((chart.utils||(chart.utils={})).legend=c)}.call(this);