@plotdb/chart 2.1.36 → 2.1.37
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.
- package/CHANGELOG.md +8 -0
- package/package.json +1 -1
- package/utils/axis.js +16 -5
- package/utils/axis.min.js +1 -1
- package/utils/config.js +29 -0
- package/utils/config.min.js +1 -1
- package/utils/legend.js +1 -0
- package/utils/legend.min.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
# Change Logs
|
|
2
2
|
|
|
3
|
+
## v2.1.37
|
|
4
|
+
|
|
5
|
+
- support configurable axis caption position
|
|
6
|
+
- support centered axis configuration
|
|
7
|
+
- legend: reset container's height before accessing parent's height to prevent incorrect size calculation
|
|
8
|
+
|
|
9
|
+
|
|
3
10
|
## v2.1.36
|
|
4
11
|
|
|
5
12
|
- bar chart: fix bug: incorrect palette binding
|
|
6
13
|
- curved bar: tweak layout, config and dynamic
|
|
14
|
+
- base chart: check resize function existence before calling it
|
|
7
15
|
|
|
8
16
|
|
|
9
17
|
## v2.1.35
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"author":"zbryikt","name":"@plotdb/chart","license":"MIT","description":"plotdb charts","style":"index.min.css","browser":"index.min.js","main":"index.min.js","version":"2.1.
|
|
1
|
+
{"author":"zbryikt","name":"@plotdb/chart","license":"MIT","description":"plotdb charts","style":"index.min.css","browser":"index.min.js","main":"index.min.js","version":"2.1.37","homepage":"https://github.com/plotdb/chart","repository":{"type":"git","url":"https://github.com/plotdb/chart"},"engines":{"node":">=10.14.1","npm":">=6.4.1"},"scripts":{"start":"npx server -r web -o true -p 3457"},"devDependencies":{"@loadingio/bootstrap.ext":"^0.0.9","@loadingio/ldquery":"^3.0.4","@loadingio/loading.css":"^3.1.0","@loadingio/vscroll":"^0.0.11","@plotdb/layout":"^0.0.12","@plotdb/pdmap-world":"^0.0.5","@plotdb/semver":"^0.0.3","@plotdb/sheet":"^0.5.8","@xlfont/choose":"^0.0.16","@xlfont/load":"^2.1.2","@zbryikt/template":"^2.3.45","bootstrap":"^4.6.1","bootstrap.native":"^3.0.15","fedep":"^1.1.11","jsdom":"^22.1.0","ldbutton":"^2.0.1","ldfile":"^2.0.1","ldiconfont":"^0.2.4","ldloader":"^3.0.2","ldview":"^1.4.0","livescript":"^1.6.0","pdmaptw":"2.2.1","uglify-js":"^3.13.1","uglifycss":"^0.0.29","zmgr":"^2.2.3"},"frontendDependencies":{"root":"web/static/assets/lib","modules":["bootstrap","bootstrap.native","@loadingio/bootstrap.ext","@loadingio/ldquery","@loadingio/loading.css","@loadingio/ldcolorpicker","@loadingio/debounce.js","@loadingio/vscroll","@plotdb/pdmap-world","@plotdb/block","@plotdb/csscope","@plotdb/rescope","@plotdb/layout","@plotdb/sheet","@plotdb/konfig","@plotdb/semver","@xlfont/choose","@xlfont/load","@zbryikt/voronoijs","d3","d3-array","d3-axis","d3-brush","d3-color","d3-dispatch","d3-drag","d3-ease","d3-force","d3-force-boundary","d3-format","d3-hierarchy","d3-interpolate","d3-path","d3-quadtree","d3-random","d3-scale-chromatic","d3-selection","d3-shape","d3-timer","d3-transition","choosefont.js","pdmaptw","proxise","ldiconfont","ldloader","ldbutton","ldcover","ldcolor","ldfile","ldslider","wrap-svg-text","ldpalettepicker","zmgr","ldview"]},"dependencies":{"@loadingio/debounce.js":"^1.0.1","@loadingio/ldcolorpicker":"^3.0.5","@plotdb/block":"^5.2.2","@plotdb/csscope":"^5.0.3","@plotdb/konfig":"^4.8.12","@plotdb/rescope":"^5.0.9","@zbryikt/voronoijs":"^1.0.0","choosefont.js":"^0.0.1","d3":"^4.13.0","d3-array":"^3.1.1","d3-axis":"^3.0.0","d3-brush":"^3.0.0","d3-color":"^3.1.0","d3-dispatch":"^3.0.1","d3-drag":"^3.0.0","d3-ease":"^3.0.1","d3-force":"^3.0.0","d3-force-boundary":"^0.0.2","d3-format":"^3.1.0","d3-hierarchy":"^3.1.1","d3-interpolate":"^3.0.1","d3-path":"^3.0.1","d3-quadtree":"^3.0.1","d3-random":"^3.0.1","d3-scale-chromatic":"^3.0.0","d3-selection":"^3.0.0","d3-shape":"^3.1.0","d3-timer":"^3.0.1","d3-transition":"^3.0.1","ldcolor":"^1.1.3","ldcover":"^3.5.1","ldpalettepicker":"^4.0.4","ldslider":"^3.1.1","proxise":"^1.0.1","wrap-svg-text":"^0.0.7"}}
|
package/utils/axis.js
CHANGED
|
@@ -163,7 +163,7 @@
|
|
|
163
163
|
});
|
|
164
164
|
},
|
|
165
165
|
render: function(){
|
|
166
|
-
var n, isHorizon, wrap, ticks, ref$, fontSize, box, this$ = this;
|
|
166
|
+
var n, isHorizon, wrap, ticks, ref$, fontSize, box, mm3, md3, x$, yoff, this$ = this;
|
|
167
167
|
n = this._n;
|
|
168
168
|
isHorizon = this.dir < 2;
|
|
169
169
|
wrap = n.wrap;
|
|
@@ -242,12 +242,19 @@
|
|
|
242
242
|
return a._c - b._c;
|
|
243
243
|
});
|
|
244
244
|
n.domain.style.stroke = this.cfg.baseline.show ? this.cfg.baseline.color : 'none';
|
|
245
|
+
mm3 = (this.cfg.caption.position || 0) % 3;
|
|
246
|
+
md3 = Math.floor((this.cfg.caption.position || 0) / 3);
|
|
247
|
+
x$ = n.label;
|
|
248
|
+
x$.setAttribute('text-anchor', ['start', 'middle', 'end'][mm3]);
|
|
249
|
+
x$.setAttribute('dominant-baseline', ['baseline', 'hanging'][md3]);
|
|
245
250
|
if (isHorizon) {
|
|
246
251
|
n.domain.setAttribute('d', "M0 0L" + box.width + " 0Z");
|
|
247
252
|
n.label.setAttribute('x', box.width / 2);
|
|
253
|
+
n.label.setAttribute('x', [2, box.width / 2, box.width - 2][mm3]);
|
|
248
254
|
} else {
|
|
249
255
|
n.domain.setAttribute('d', "M0 0L0 " + box.height + "Z");
|
|
250
|
-
|
|
256
|
+
yoff = [2, box.height / 2, box.height - 2][mm3];
|
|
257
|
+
n.label.setAttribute("transform", "translate(0," + yoff + ") rotate(90)");
|
|
251
258
|
}
|
|
252
259
|
ticks.map(function(o){
|
|
253
260
|
return o.box = o.n.t.getBBox();
|
|
@@ -321,7 +328,7 @@
|
|
|
321
328
|
return !overlap;
|
|
322
329
|
};
|
|
323
330
|
bfs = function(maxlv){
|
|
324
|
-
var ref$, lc, fifo, L, R, D, M, size, delta, box;
|
|
331
|
+
var ref$, lc, fifo, L, R, D, M, mm3, md3, size, delta, box, xoff, yoff;
|
|
325
332
|
maxlv == null && (maxlv = 1);
|
|
326
333
|
ref$ = [
|
|
327
334
|
{
|
|
@@ -362,19 +369,23 @@
|
|
|
362
369
|
this$._n.label.style.fontSize = this$.cfg.caption.font.size ? this$.cfg.caption.font.size + "" || '' : void 8;
|
|
363
370
|
this$._n.label.setAttribute('class', (this$.cfg.caption.font.family || {}).className || '');
|
|
364
371
|
this$.caption();
|
|
372
|
+
mm3 = (this$.cfg.caption.position || 0) % 3;
|
|
373
|
+
md3 = Math.floor((this$.cfg.caption.position || 0) / 3);
|
|
365
374
|
size = Math.max.apply(Math, [0].concat(lc.picked.map(function(it){
|
|
366
375
|
return it.sizeAlt;
|
|
367
376
|
})));
|
|
368
377
|
delta = this$.cfg.tick.inner + this$.cfg.label.padding + this$.cfg.caption.padding + size;
|
|
369
378
|
if (this$.dir < 2) {
|
|
370
|
-
this$._n.label.setAttribute('y', delta);
|
|
379
|
+
this$._n.label.setAttribute('y', [-2, delta][md3]);
|
|
371
380
|
return this$._n.layout.style.height = (delta + this$._n.label.getBoundingClientRect().height) + "px";
|
|
372
381
|
} else {
|
|
373
382
|
this$._n.label.setAttribute('x', 0);
|
|
374
383
|
this$._n.label.setAttribute('y', 0);
|
|
375
384
|
this$._n.layout.style.width = (delta + this$._n.label.getBoundingClientRect().width) + "px";
|
|
376
385
|
box = this$._n.layout.getBoundingClientRect();
|
|
377
|
-
|
|
386
|
+
xoff = [2, -delta - 2][md3];
|
|
387
|
+
yoff = [2, box.height / 2, box.height - 2][mm3];
|
|
388
|
+
this$._n.label.setAttribute('transform', "translate(" + xoff + "," + yoff + ") rotate(90)");
|
|
378
389
|
return this$._n.root.setAttribute('transform', "translate(" + (box.width - 1) + ",0)");
|
|
379
390
|
}
|
|
380
391
|
};
|
package/utils/axis.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){var s,t;function c(t,e){var n,i={}.hasOwnProperty;for(n in e)i.call(e,n)&&(t[n]=e[n]);return t}s=function(t){return document.createElementNS("http://www.w3.org/2000/svg",t)},(t=function(t){var e,n=this;return this.dir={bottom:0,left:2}[(t=null==t?{}:t).direction||"bottom"],this.name=t.name||"axis",this.layout=t.layout||new layout({root:this.root}),this._ticks=[],this._scale=t.scale||function(t){return t},this._format=chart.utils.format.simple,this._config(t.cfg),this._map={},this._n=e={root:s("g"),layout:this.layout.getNode(this.name),render:this.layout.getGroup(this.name),wrap:null,domain:s("path")},e.render.appendChild(e.root),e.root.appendChild(e.domain),e.label=s("text"),e.label.textContent="",(t=e.label).setAttribute("dominant-baseline","hanging"),t.setAttribute("text-anchor","middle"),e.root.appendChild(e.label),this.wrapper(),(e=this.layout).on("update",function(){return n.update()}),e.on("render",function(){return n.render()}),this}).prototype=c(Object.create(Object.prototype),{wrapper:function(){var t,e=this._n;return e.wrap&&e.wrap.parentNode&&e.wrap.parentNode.removeChild(e.wrap),e.wrap=document.createElement("div"),c(((t=e.wrap.style).visibility="hidden",t.position="absolute",t.top=0,t.left=0,t.pointerEvents="none",t.userSelect="none",t.zIndex=0,t.wordBreak="break-all",t.lineHeight=".95em",t),this.dir<2&&null!=this.cfg.textWidth?{whiteSpace:"wrap",width:(1<(t=this.cfg.textWidth)?t:1)+"em"}:{whiteSpace:"pre",width:"4em"}),e.layout.appendChild(e.wrap)},_config:function(e){var t,n=this;return null==e&&(e={}),this.cfg={tick:{inner:8},baseline:{},label:{padding:1},caption:{padding:1},enabled:e.enabled},["tick","baseline","label","caption"].map(function(t){return c(n.cfg[t],e[t]||{})}),(t=this.cfg.label).font||(t.font={}),(t=this.cfg.caption).font||(t.font={}),this.format(this.cfg.label.format)},config:function(t){return null==t?this.cfg:(this._config(t),this.wrapper())},format:function(t){return null==t?this._format:this._format="string"==typeof t?chart.utils.format.from(t):t||chart.utils.format.simple},scale:function(t){return null!=t?this._scale=t:this._scale},caption:function(t){return arguments.length&&(this._caption=t),!this.cfg.enabled||null!=this.cfg.caption.show&&!this.cfg.caption.show?this._n.label.textContent="":this._n.label.textContent=this.cfg.caption.text||this._caption||""},update:function(){},ticks:function(n){var t,e,i,a=this,
|
|
1
|
+
!function(){var s,t;function c(t,e){var n,i={}.hasOwnProperty;for(n in e)i.call(e,n)&&(t[n]=e[n]);return t}s=function(t){return document.createElementNS("http://www.w3.org/2000/svg",t)},(t=function(t){var e,n=this;return this.dir={bottom:0,left:2}[(t=null==t?{}:t).direction||"bottom"],this.name=t.name||"axis",this.layout=t.layout||new layout({root:this.root}),this._ticks=[],this._scale=t.scale||function(t){return t},this._format=chart.utils.format.simple,this._config(t.cfg),this._map={},this._n=e={root:s("g"),layout:this.layout.getNode(this.name),render:this.layout.getGroup(this.name),wrap:null,domain:s("path")},e.render.appendChild(e.root),e.root.appendChild(e.domain),e.label=s("text"),e.label.textContent="",(t=e.label).setAttribute("dominant-baseline","hanging"),t.setAttribute("text-anchor","middle"),e.root.appendChild(e.label),this.wrapper(),(e=this.layout).on("update",function(){return n.update()}),e.on("render",function(){return n.render()}),this}).prototype=c(Object.create(Object.prototype),{wrapper:function(){var t,e=this._n;return e.wrap&&e.wrap.parentNode&&e.wrap.parentNode.removeChild(e.wrap),e.wrap=document.createElement("div"),c(((t=e.wrap.style).visibility="hidden",t.position="absolute",t.top=0,t.left=0,t.pointerEvents="none",t.userSelect="none",t.zIndex=0,t.wordBreak="break-all",t.lineHeight=".95em",t),this.dir<2&&null!=this.cfg.textWidth?{whiteSpace:"wrap",width:(1<(t=this.cfg.textWidth)?t:1)+"em"}:{whiteSpace:"pre",width:"4em"}),e.layout.appendChild(e.wrap)},_config:function(e){var t,n=this;return null==e&&(e={}),this.cfg={tick:{inner:8},baseline:{},label:{padding:1},caption:{padding:1},enabled:e.enabled},["tick","baseline","label","caption"].map(function(t){return c(n.cfg[t],e[t]||{})}),(t=this.cfg.label).font||(t.font={}),(t=this.cfg.caption).font||(t.font={}),this.format(this.cfg.label.format)},config:function(t){return null==t?this.cfg:(this._config(t),this.wrapper())},format:function(t){return null==t?this._format:this._format="string"==typeof t?chart.utils.format.from(t):t||chart.utils.format.simple},scale:function(t){return null!=t?this._scale=t:this._scale},caption:function(t){return arguments.length&&(this._caption=t),!this.cfg.enabled||null!=this.cfg.caption.show&&!this.cfg.caption.show?this._n.label.textContent="":this._n.label.textContent=this.cfg.caption.text||this._caption||""},update:function(){},ticks:function(n){var t,e,i,a=this,o={},r=this._n.layout.getBoundingClientRect()[this.dir<2?"width":"height"],r=Math.round(r/25),l=1<(t=Math.round(n.length/(1<r?r:1)))?t:1;for(e in this._ticks=n.filter(function(t,e){return!(e%l)||e===n.length-1}).map(function(t){var e,n;return o[(t="object"!=typeof t?{v:t}:t).v]=c((e=a._map)[n=t.v]||(e[n]={}),t)}),t=this._map)i=t[e],o[e]||i.n.g.parentNode.removeChild(i.n.g);return this._map=o,this._ticks.filter(function(t){return!t.n}).map(function(t){if(t.n={g:s("g"),p:s("path"),t:s("g")},t.n.g.appendChild(t.n.p),t.n.g.appendChild(t.n.t),a._n.root.appendChild(t.n.g),isNaN(+t.v))return t.t=t.v})},render:function(){var i,t,a,e,n,o,r,l=this,s=this._n,c=this.dir<2,h=s.wrap;return h.style.fontSize=this.cfg.label.font.size?this.cfg.label.font.size+""||"":void 0,h.setAttribute("class",(this.cfg.label.font.family||{}).className||""),i=this._ticks,null==this.cfg.enabled||this.cfg.enabled?(c?((t=s.layout.style).height="",t.paddingTop="",t.paddingBottom=""):((t=s.layout.style).width="",t.paddingLeft="",t.paddingRight=""),s.domain.style.display="",i.map(function(t){return t.n.g.style.display=""}),a=getComputedStyle(h).fontSize,e=s.layout.getBoundingClientRect(),(t=s.domain.style).strokeWidth=1,t.stroke="currentColor",t.fill="none",i.map(function(t,e){var n=e?e===i.length-1?2:1:0;return t._c=null!=t.c?t.c:l._scale(t.v)+(l._scale.bandwidth?l._scale.bandwidth()/2:0),t._t=null!=t.t?t.t:l._format(t.v),(e=t.n.p.style).strokeWidth=1,e.stroke="currentColor",e.fill="none",h.textContent=t._t,h.style.textAlign=c?["left","center","right"][n]:["right","left"][l.dir-2],t.n.tt=wrapSvgText({node:h}),t.n.t.style.fontSize=a,t.n.t.style.fill=l.cfg.label.color,t.n.t.textContent="",t.n.t.appendChild(t.n.tt),t.n.t.setAttribute("class",(l.cfg.label.font||{}).className||"")}),i.sort(function(t,e){return t._c-e._c}),s.domain.style.stroke=this.cfg.baseline.show?this.cfg.baseline.color:"none",r=(this.cfg.caption.position||0)%3,n=Math.floor((this.cfg.caption.position||0)/3),(o=s.label).setAttribute("text-anchor",["start","middle","end"][r]),o.setAttribute("dominant-baseline",["baseline","hanging"][n]),c?(s.domain.setAttribute("d","M0 0L"+e.width+" 0Z"),s.label.setAttribute("x",e.width/2),s.label.setAttribute("x",[2,e.width/2,e.width-2][r])):(s.domain.setAttribute("d","M0 0L0 "+e.height+"Z"),r=[2,e.height/2,e.height-2][r],s.label.setAttribute("transform","translate(0,"+r+") rotate(90)")),i.map(function(t){return t.box=t.n.t.getBBox()}),this.adjust()):(c?((t=s.layout.style).height="0px",t.paddingTop="0",t.paddingBottom="0"):((t=s.layout.style).width="0px",t.paddingLeft="0",t.paddingRight="0"),s.domain.style.display="none",void i.map(function(t){return t.n.g.style.display="none"}))},adjust:function(){var u=this,f=this._ticks,d=this.dir<2,p=function(t,e,n){var i,a,o,r,l,s,c,h;if(!n.checked[t])return n.checked[t]=!0,i=f[t],r=t?t===f.length-1?2:1:0,h=[i._c,i._t][0],o={x:-(a=i.box).x,y:-a.y},r=!u._scale.bandwidth&&(null!=u.cfg.tick.boundaryOffset?!!u.cfg.tick.boundaryOffset:u.dir<2)?r/2:.5,d?o.x-=a.width*r:o.y-=a.height*r,i.n.tt.setAttribute("transform","translate("+o.x+","+o.y+")"),(a={size:a[d?"width":"height"],sizeAlt:a[d?"height":"width"],lv:e,tick:i,idx:t}).coord=h-a.size*r,d?(i.n.g.setAttribute("transform","translate("+h+",0)"),i.n.p.setAttribute("d","M0 0L0 "+u.cfg.tick.inner),i.n.t.setAttribute("transform","translate(0,"+(u.cfg.tick.inner+u.cfg.label.padding)+")")):(i.n.g.setAttribute("transform","translate(0,"+h+")"),i.n.p.setAttribute("d","M0 0L-"+u.cfg.tick.inner+" 0"),i.n.t.setAttribute("transform","translate("+(-u.cfg.tick.inner-a.sizeAlt-1-u.cfg.label.padding)+",0)")),h=[a.coord,a.coord+a.size],s=(h=[(l=h[0])-2,h[1]+2])[0],c=h[1],h=n.picked.filter(function(t){var e=[t.coord,t.coord+t.size],t=e[0];return(e=[t-2,e[1]+2])[0]<l&&l<e[1]||s<t&&t<c}).length,i.n.t.style.opacity=h?0:1,i.n.p.style.stroke=u.cfg.tick.color||"",n.picked.push(a),!h};return function(t){var e,n,i,a,o,r,l,s,c,h,d;for(null==t&&(t=1),e=[{checked:{},picked:[],node:u._n.wrap},[]],n=e[0],i=e[1],n.fontSize=getComputedStyle(n.node).fontSize,f.map(function(t){return t.n.t.style.opacity=0}),f.length&&(i.push([0,f.length-1,0]),[0,f.length-1].map(function(t){return p(t,0,n)}));i.length;)a=(e=i.splice(0,1)[0])[0],o=e[1],t<=(r=e[2])||(l=Math.floor((a+o)/2),p(l,r,n),a+1<l&&i.push([a,l,r+1]),l+1<o&&i.push([l,o,r+1]));return u._n.label.style.fill=u.cfg.caption.color,u._n.label.style.fontSize=u.cfg.caption.font.size?u.cfg.caption.font.size+""||"":void 0,u._n.label.setAttribute("class",(u.cfg.caption.font.family||{}).className||""),u.caption(),d=(u.cfg.caption.position||0)%3,s=Math.floor((u.cfg.caption.position||0)/3),h=Math.max.apply(Math,[0].concat(n.picked.map(function(t){return t.sizeAlt}))),c=u.cfg.tick.inner+u.cfg.label.padding+u.cfg.caption.padding+h,u.dir<2?(u._n.label.setAttribute("y",[-2,c][s]),u._n.layout.style.height=c+u._n.label.getBoundingClientRect().height+"px"):(u._n.label.setAttribute("x",0),u._n.label.setAttribute("y",0),u._n.layout.style.width=c+u._n.label.getBoundingClientRect().width+"px",d=[2,(h=u._n.layout.getBoundingClientRect()).height/2,h.height-2][d],u._n.label.setAttribute("transform","translate("+[2,-c-2][s]+","+d+") rotate(90)"),u._n.root.setAttribute("transform","translate("+(h.width-1)+",0)"))}(5)}}),"undefined"!=typeof chart&&null!==chart&&((chart.utils||(chart.utils={})).axis=t)}.call(this);
|
package/utils/config.js
CHANGED
|
@@ -113,6 +113,10 @@
|
|
|
113
113
|
type: 'boolean',
|
|
114
114
|
'default': true
|
|
115
115
|
},
|
|
116
|
+
center: {
|
|
117
|
+
type: 'boolean',
|
|
118
|
+
'default': false
|
|
119
|
+
},
|
|
116
120
|
tick: {
|
|
117
121
|
inner: {
|
|
118
122
|
type: 'number',
|
|
@@ -190,6 +194,31 @@
|
|
|
190
194
|
max: 100,
|
|
191
195
|
step: 0.5
|
|
192
196
|
},
|
|
197
|
+
position: {
|
|
198
|
+
type: 'choice',
|
|
199
|
+
'default': 4,
|
|
200
|
+
values: [
|
|
201
|
+
{
|
|
202
|
+
name: 'in / start',
|
|
203
|
+
value: 0
|
|
204
|
+
}, {
|
|
205
|
+
name: 'in / middle',
|
|
206
|
+
value: 1
|
|
207
|
+
}, {
|
|
208
|
+
name: 'in / end',
|
|
209
|
+
value: 2
|
|
210
|
+
}, {
|
|
211
|
+
name: 'out / start',
|
|
212
|
+
value: 3
|
|
213
|
+
}, {
|
|
214
|
+
name: 'out / middle',
|
|
215
|
+
value: 4
|
|
216
|
+
}, {
|
|
217
|
+
name: 'out / end',
|
|
218
|
+
value: 5
|
|
219
|
+
}
|
|
220
|
+
]
|
|
221
|
+
},
|
|
193
222
|
font: font
|
|
194
223
|
}
|
|
195
224
|
}
|
package/utils/config.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){var e;e={from:function(e){var l=this,
|
|
1
|
+
!function(){var e;e={from:function(e){var l=this,n=function(e,t){var a,o;for(a in t.preset&&function(e,t){var a,o={}.hasOwnProperty;for(a in t)o.call(t,a)&&(e[a]=t[a])}(e,JSON.parse(JSON.stringify(l.preset[t.preset]))),t)o=t[a],"preset"!==a&&("string"==typeof o?e[a]=JSON.parse(JSON.stringify(l.preset[o]))||{}:n(e[a]||(e[a]={}),o));return e};return n({},e)},preset:{default:{margin:{type:"number"},font:e={family:{type:"font"},size:{type:"quantity",default:"1em",units:[{name:"em",max:10,step:.01,default:1},{name:"px",max:256,step:1,default:16}]}},color:{type:"color",default:"currentColor"},palette:{type:"palette"},background:{type:"color",default:"transparent"}},font:e,tip:{enabled:{type:"boolean",default:!0},format:{type:"format",default:".3s"}},label:{format:{type:"format",default:".3s"}},legend:{selectable:{type:"boolean",default:!0},enabled:{type:"boolean",default:!0},position:{type:"choice",values:["bottom","right"],default:"right"},sort:{direction:{type:"choice",values:["asc","desc"],default:"desc"},mode:{type:"choice",values:["label","value","none"],default:"value"}}},axis:{enabled:{type:"boolean",default:!0},center:{type:"boolean",default:!1},tick:{inner:{type:"number",name:"Inner Tick Size",default:8,min:0,max:40,step:.1},color:{type:"color",default:"currentColor"},count:{type:"number",default:4,min:1,max:40},boundaryOffset:{type:"boolean",default:!0}},baseline:{show:{type:"boolean",default:!0},color:{type:"color",default:"currentColor"}},label:{color:{type:"color",default:"currentColor"},format:{type:"format",default:".3s"},direction:{type:"choice",default:"horizontal",values:["horizontal","vertical"]},padding:{type:"number",default:1,min:0,max:100,step:.5},font:e},caption:{color:{type:"color",default:"currentColor"},text:{type:"text",default:""},show:{type:"boolean",default:!0},padding:{type:"number",default:1,min:0,max:100,step:.5},position:{type:"choice",default:4,values:[{name:"in / start",value:0},{name:"in / middle",value:1},{name:"in / end",value:2},{name:"out / start",value:3},{name:"out / middle",value:4},{name:"out / end",value:5}]},font:e}}}},"undefined"!=typeof chart&&null!==chart&&((chart.utils||(chart.utils={})).config=e)}.call(this);
|
package/utils/legend.js
CHANGED
|
@@ -206,6 +206,7 @@
|
|
|
206
206
|
node = this.layout.getNode(this.name).querySelector('.pdlg');
|
|
207
207
|
if (node) {
|
|
208
208
|
if (this.dir === 'vertical') {
|
|
209
|
+
node.style.height = 'fit-content';
|
|
209
210
|
node.style.height = getComputedStyle(node.parentNode).height;
|
|
210
211
|
} else {
|
|
211
212
|
node.style.height = '';
|
package/utils/legend.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){var o,t;o="http://www.w3.org/2000/svg",(t=function(a){var t,e,n,i,l=this;return 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}),(n=this.layout).on("update",function(){return l.update()}),n.on("render",function(){return l.render()}),this.id=Math.random().toString(36).substring(2),i=this.layout.getNode(this.name),t=this.layout.getGroup(this.name),i.querySelector("[ld-each=legend]")||(i.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(o,"g"),n=document.createElementNS(o,"g"),i=document.createElementNS(o,"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._func=[{key:"all",type:"func",text:"全選"},{key:"none",type:"func",text:"全不選"}],this.view={layout:new ldview({root:this.layout.getNode(this.name),initRender:!1,handler:{legend:{list:function(){var n,t=l._data.map(function(t){return t}),i=l.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(l.cfg.selectable?l._func:[])},key:function(t){return t.key},view:{handler:{shape:function(t){var e=t.node,t=t.ctx;return e.setAttribute("data-name",l._name(t,"shape"))},text:function(t){var e=t.node,t=t.ctx;return e.setAttribute("data-name",l._name(t,"text")),e.innerText=t.text}}}}}}),render:new ldview({root:this.layout.getGroup(this.name),initRender:!1,handler:{legend:{list:function(){return l._data.concat(l.cfg.selectable?l._func:[])},key:function(t){return t.key},view:{action:{click:{"@":function(t){t.node;var e,n=t.ctx;if(l.cfg.selectable){if("func"===n.type)for(e in l._picked)l._picked[e]="all"===n.key;else l._picked[n.key]=!l._picked[n.key];return l.view.render.render("legend"),l.fire("select",l._picked)}}}},handler:{"@":function(t){var e=t.node,t=t.ctx;return e.style.opacity=!l.cfg.selectable||"func"===t.type||l._picked[t.key]?1:.3},shape:function(t){var e,n,i=t.node,r=t.ctx;if("func"!==r.type)return i.querySelector("circle")||i.appendChild(document.createElementNS(o,"circle")),e=i.querySelector("circle"),n=l.layout.getBox(l._name(r,"shape")),t=l.layout.getBox(l.name),e.setAttribute("cx",".5em"),e.setAttribute("cy",".5em"),e.setAttribute("r",".5em"),e.setAttribute("transform","translate("+(n.x-t.x)+", "+(n.y-t.y)+")"),"function"==typeof a.shape?a.shape.call(e,r):void 0;i.style.display="none"},text:function(t){var e=t.node,n=t.ctx,i=l.layout.getNode(l._name(n,"text")),t=l.layout.getBox(l._name(n,"text")),n=l.layout.getBox(l.name);return e.setAttribute("transform","translate("+(t.x-n.x)+", "+(t.y-n.y)+")"),e.textContent="",i=wrapSvgText({node:i,useRange:!0}),e.appendChild(i)}}}}}})},this.update(),this}).prototype=function(t,e){var n,i={}.hasOwnProperty;for(n in e)i.call(e,n)&&(t[n]=e[n]);return t}(Object.create(Object.prototype),{_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,(t=this.layout.getNode(this.name).querySelector(".pdlg"))&&("vertical"===this.dir?t.style.height=getComputedStyle(t.parentNode).height:t.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=[],o=1,d=arguments.length;o<d;++o)l.push(arguments[o]);for(e=l,o=0,i=(n=this.evtHandler[t]||[]).length;o<i;++o)r=n[o],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]}}),"undefined"!=typeof chart&&null!==chart&&((chart.utils||(chart.utils={})).legend=t)}.call(this);
|
|
1
|
+
!function(){var o,t;o="http://www.w3.org/2000/svg",(t=function(a){var t,e,n,i,l=this;return 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}),(n=this.layout).on("update",function(){return l.update()}),n.on("render",function(){return l.render()}),this.id=Math.random().toString(36).substring(2),i=this.layout.getNode(this.name),t=this.layout.getGroup(this.name),i.querySelector("[ld-each=legend]")||(i.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(o,"g"),n=document.createElementNS(o,"g"),i=document.createElementNS(o,"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._func=[{key:"all",type:"func",text:"全選"},{key:"none",type:"func",text:"全不選"}],this.view={layout:new ldview({root:this.layout.getNode(this.name),initRender:!1,handler:{legend:{list:function(){var n,t=l._data.map(function(t){return t}),i=l.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(l.cfg.selectable?l._func:[])},key:function(t){return t.key},view:{handler:{shape:function(t){var e=t.node,t=t.ctx;return e.setAttribute("data-name",l._name(t,"shape"))},text:function(t){var e=t.node,t=t.ctx;return e.setAttribute("data-name",l._name(t,"text")),e.innerText=t.text}}}}}}),render:new ldview({root:this.layout.getGroup(this.name),initRender:!1,handler:{legend:{list:function(){return l._data.concat(l.cfg.selectable?l._func:[])},key:function(t){return t.key},view:{action:{click:{"@":function(t){t.node;var e,n=t.ctx;if(l.cfg.selectable){if("func"===n.type)for(e in l._picked)l._picked[e]="all"===n.key;else l._picked[n.key]=!l._picked[n.key];return l.view.render.render("legend"),l.fire("select",l._picked)}}}},handler:{"@":function(t){var e=t.node,t=t.ctx;return e.style.opacity=!l.cfg.selectable||"func"===t.type||l._picked[t.key]?1:.3},shape:function(t){var e,n,i=t.node,r=t.ctx;if("func"!==r.type)return i.querySelector("circle")||i.appendChild(document.createElementNS(o,"circle")),e=i.querySelector("circle"),n=l.layout.getBox(l._name(r,"shape")),t=l.layout.getBox(l.name),e.setAttribute("cx",".5em"),e.setAttribute("cy",".5em"),e.setAttribute("r",".5em"),e.setAttribute("transform","translate("+(n.x-t.x)+", "+(n.y-t.y)+")"),"function"==typeof a.shape?a.shape.call(e,r):void 0;i.style.display="none"},text:function(t){var e=t.node,n=t.ctx,i=l.layout.getNode(l._name(n,"text")),t=l.layout.getBox(l._name(n,"text")),n=l.layout.getBox(l.name);return e.setAttribute("transform","translate("+(t.x-n.x)+", "+(t.y-n.y)+")"),e.textContent="",i=wrapSvgText({node:i,useRange:!0}),e.appendChild(i)}}}}}})},this.update(),this}).prototype=function(t,e){var n,i={}.hasOwnProperty;for(n in e)i.call(e,n)&&(t[n]=e[n]);return t}(Object.create(Object.prototype),{_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,(t=this.layout.getNode(this.name).querySelector(".pdlg"))&&("vertical"===this.dir?(t.style.height="fit-content",t.style.height=getComputedStyle(t.parentNode).height):t.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=[],o=1,d=arguments.length;o<d;++o)l.push(arguments[o]);for(e=l,o=0,i=(n=this.evtHandler[t]||[]).length;o<i;++o)r=n[o],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]}}),"undefined"!=typeof chart&&null!==chart&&((chart.utils||(chart.utils={})).legend=t)}.call(this);
|