@plotdb/chart 3.4.0 → 3.5.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.
- package/CHANGELOG.md +10 -0
- package/package.json +1 -1
- package/utils/legend.js +71 -3
- package/utils/legend.min.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Change Logs
|
|
2
2
|
|
|
3
|
+
## v3.5.0
|
|
4
|
+
|
|
5
|
+
- legend: "select all / select none" text is now translated instead of hard-coded Chinese.
|
|
6
|
+
it uses the `i18n` / `t` constructor options if given, otherwise `block.i18n.module` from
|
|
7
|
+
`@plotdb/block`, so existing blocks follow the page language without changes. built-in
|
|
8
|
+
resources ( `en`, `zh-TW`, `zh-CN`, `ja` ) are in `chart.utils.legend.i18n` and are added under
|
|
9
|
+
the `@plotdb/chart.legend` namespace. legend re-renders on `languageChanged`.
|
|
10
|
+
- legend: add `destroy()` to stop listening to language change.
|
|
11
|
+
|
|
12
|
+
|
|
3
13
|
## v3.4.0
|
|
4
14
|
|
|
5
15
|
- axis: `label.strategy: ends` no longer insists on perfectly equal gaps. keeping both ends
|
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":"3.
|
|
1
|
+
{"author":"zbryikt","name":"@plotdb/chart","license":"MIT","description":"plotdb charts","style":"index.min.css","browser":"index.min.js","main":"index.min.js","version":"3.5.0","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.12","@loadingio/ldquery":"^3.0.6","@loadingio/loading.css":"^3.2.1","@loadingio/vscroll":"^0.0.11","@plotdb/layout":"^0.0.12","@plotdb/pdmap-world":"^0.0.5","@plotdb/semver":"^0.0.3","@plotdb/sheet":"^0.7.0","@xlfont/choose":"^0.0.32","@xlfont/load":"^2.1.5","@zbryikt/template":"^2.4.3","bootstrap":"^4.6.1","bootstrap.native":"^3.0.15","fedep":"^1.9.0","jsdom":"^22.1.0","ldbutton":"^2.0.5","ldfile":"^2.0.1","ldiconfont":"^0.2.8","ldloader":"^3.0.3","ldview":"^1.5.1","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":"^7.9.0","d3-force-boundary":"^0.0.2","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/legend.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
var svgns, legend;
|
|
3
3
|
svgns = "http://www.w3.org/2000/svg";
|
|
4
4
|
legend = function(opt){
|
|
5
|
-
var x$, nodeLayout, nodeRender, gl, gs, gt, this$ = this;
|
|
5
|
+
var x$, nodeLayout, nodeRender, gl, gs, gt, add, lng, ref$, res, this$ = this;
|
|
6
6
|
opt == null && (opt = {});
|
|
7
7
|
this._data = opt.data || [];
|
|
8
8
|
this.name = opt.name || 'legend';
|
|
@@ -43,15 +43,32 @@
|
|
|
43
43
|
gl.appendChild(gt);
|
|
44
44
|
nodeRender.appendChild(gl);
|
|
45
45
|
}
|
|
46
|
+
this._i18n = opt.i18n || ((typeof block != 'undefined' && block !== null) && block.i18n && block.i18n.module ? block.i18n.module : null);
|
|
47
|
+
this._t = opt.t || null;
|
|
48
|
+
if (this._i18n) {
|
|
49
|
+
if (add = this._i18n.addResourceBundle) {
|
|
50
|
+
for (lng in ref$ = legend.i18n) {
|
|
51
|
+
res = ref$[lng];
|
|
52
|
+
try {
|
|
53
|
+
add.call(this._i18n, lng, legend.i18nNs, res, true, false);
|
|
54
|
+
} catch (e$) {}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (this._i18n.on) {
|
|
58
|
+
this._i18n.on('languageChanged', this._lngHandler = function(){
|
|
59
|
+
return this$._relocalize();
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
46
63
|
this._func = [
|
|
47
64
|
{
|
|
48
65
|
key: "all",
|
|
49
66
|
type: "func",
|
|
50
|
-
text:
|
|
67
|
+
text: this._text('all')
|
|
51
68
|
}, {
|
|
52
69
|
key: "none",
|
|
53
70
|
type: "func",
|
|
54
|
-
text:
|
|
71
|
+
text: this._text('none')
|
|
55
72
|
}
|
|
56
73
|
];
|
|
57
74
|
this.view = {
|
|
@@ -187,7 +204,58 @@
|
|
|
187
204
|
this.update();
|
|
188
205
|
return this;
|
|
189
206
|
};
|
|
207
|
+
legend.i18nNs = "@plotdb/chart.legend";
|
|
208
|
+
legend.i18n = {
|
|
209
|
+
en: {
|
|
210
|
+
all: "Select All",
|
|
211
|
+
none: "Select None"
|
|
212
|
+
},
|
|
213
|
+
"zh-TW": {
|
|
214
|
+
all: "全選",
|
|
215
|
+
none: "全不選"
|
|
216
|
+
},
|
|
217
|
+
"zh-CN": {
|
|
218
|
+
all: "全选",
|
|
219
|
+
none: "全不选"
|
|
220
|
+
},
|
|
221
|
+
ja: {
|
|
222
|
+
all: "すべて選択",
|
|
223
|
+
none: "すべて解除"
|
|
224
|
+
}
|
|
225
|
+
};
|
|
190
226
|
legend.prototype = import$(Object.create(Object.prototype), {
|
|
227
|
+
_text: function(key){
|
|
228
|
+
var r, k, lng, res;
|
|
229
|
+
if (this._t && (r = this._t("legend." + key)) && r !== "legend." + key) {
|
|
230
|
+
return r;
|
|
231
|
+
}
|
|
232
|
+
k = legend.i18nNs + ":" + key;
|
|
233
|
+
if (this._i18n && this._i18n.t && (r = this._i18n.t(k)) && r !== k && r !== key) {
|
|
234
|
+
return r;
|
|
235
|
+
}
|
|
236
|
+
lng = this._i18n ? this._i18n.language || this._i18n.lng : null;
|
|
237
|
+
lng = lng || (typeof document != 'undefined' && document !== null ? document.documentElement.lang : '') || 'en';
|
|
238
|
+
res = legend.i18n[lng] || legend.i18n[lng.split('-')[0]] || (/^zh/i.exec(lng) ? legend.i18n[/cn|hans|sg/i.exec(lng) ? 'zh-CN' : 'zh-TW'] : void 8) || legend.i18n.en;
|
|
239
|
+
return res[key];
|
|
240
|
+
},
|
|
241
|
+
_relocalize: function(){
|
|
242
|
+
var this$ = this;
|
|
243
|
+
this._func.map(function(f){
|
|
244
|
+
return f.text = this$._text(f.key);
|
|
245
|
+
});
|
|
246
|
+
if (!this.cfg.selectable) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
this.view.layout.render('legend');
|
|
250
|
+
this.layout.update(false);
|
|
251
|
+
return this.view.render.render();
|
|
252
|
+
},
|
|
253
|
+
destroy: function(){
|
|
254
|
+
if (this._i18n && this._lngHandler && this._i18n.off) {
|
|
255
|
+
this._i18n.off('languageChanged', this._lngHandler);
|
|
256
|
+
}
|
|
257
|
+
return this._lngHandler = null;
|
|
258
|
+
},
|
|
191
259
|
_name: function(ctx, type){
|
|
192
260
|
type == null && (type = "s");
|
|
193
261
|
return "pdlg-" + type + "-" + this.id + "-" + (ctx.type || '') + "-" + ctx.key;
|
package/utils/legend.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){var
|
|
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.cfg.selectable?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.cfg.selectable?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.cfg.selectable)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},_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);
|