@plotdb/chart 2.0.1 → 2.1.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 +23 -0
- package/package.json +1 -1
- package/utils/config.js +6 -0
- package/utils/config.min.js +1 -1
- package/utils/legend.css +1 -0
- package/utils/legend.js +18 -3
- package/utils/legend.min.css +1 -1
- package/utils/legend.min.js +1 -1
- package/utils/tick.js +97 -0
- package/utils/tick.min.js +1 -0
- package/utils/tint.js +73 -7
- package/utils/tint.min.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Change Logs
|
|
2
2
|
|
|
3
|
+
## v2.1.0
|
|
4
|
+
|
|
5
|
+
- bar & pie chart: also support `C` as name field type
|
|
6
|
+
- make wordcloud work. also support font picker
|
|
7
|
+
- voronoi-treemap: fix rendering issue when there is no data
|
|
8
|
+
- support sunburst
|
|
9
|
+
- `chart.utils.tint`: support discrete and continuous value mode
|
|
10
|
+
- `chart.utils.legend`: prevent label wrapping
|
|
11
|
+
- add `chart.utils.tick`, helper for generating ticks.
|
|
12
|
+
- rewrite `taiwancounty` for better color mapping and labeling
|
|
13
|
+
- fix bug: line chart: prevent exception when order is not bound
|
|
14
|
+
- line chart: support additional mode:
|
|
15
|
+
- layered area chart
|
|
16
|
+
- full stacked area chart
|
|
17
|
+
- multiple area chart
|
|
18
|
+
- bubble chart:
|
|
19
|
+
- support pie bubble
|
|
20
|
+
- support legend toggling
|
|
21
|
+
- tweak label
|
|
22
|
+
- tweak coloring
|
|
23
|
+
- curve bar: support additional configuration
|
|
24
|
+
|
|
25
|
+
|
|
3
26
|
## v2.0.1
|
|
4
27
|
|
|
5
28
|
- update documentation
|
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.0
|
|
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.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"},"devDependencies":{"@loadingio/bootstrap.ext":"^0.0.9","@loadingio/ldquery":"^3.0.4","@loadingio/loading.css":"^3.1.0","@loadingio/vscroll":"^0.0.8","@plotdb/layout":"^0.0.12","@plotdb/pdmap-world":"^0.0.5","@plotdb/semver":"^0.0.3","@plotdb/sheet":"^0.2.0","@zbryikt/template":"^2.3.38","bootstrap":"^4.6.1","bootstrap.native":"^3.0.15","fedep":"^1.1.7","ldiconfont":"^0.2.3","ldbutton":"^2.0.1","ldloader":"^3.0.1","ldview":"^1.2.1","livescript":"^1.6.0","pdmaptw":"2.1.0","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","@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","ldslider","wrap-svg-text","ldpalettepicker","zmgr","ldview"]},"dependencies":{"@loadingio/debounce.js":"^1.0.1","@loadingio/ldcolorpicker":"^3.0.0","@plotdb/block":"^4.6.1","@plotdb/csscope":"^4.0.6","@plotdb/konfig":"^4.2.7","@plotdb/rescope":"^4.1.6","@zbryikt/voronoijs":"^1.0.0","d3":"^4.13.0","d3-array":"^3.1.1","d3-axis":"^3.0.0","d3-brush":"^3.0.0","d3-color":"^3.0.1","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","choosefont.js":"^0.0.1","ldcolor":"^1.0.0","ldcover":"^3.2.1","ldpalettepicker":"^4.0.1","ldslider":"^3.0.4","proxise":"^1.0.1","wrap-svg-text":"^0.0.7"}}
|
package/utils/config.js
CHANGED
package/utils/config.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){var
|
|
1
|
+
!function(){var e={preset:{default:{margin:{type:"number"},font:{size:{type:"number",min:1,max:256,step:1,default:16}},color:{type:"color"},palette:{type:"palette"},background:{type:"color"}},legend:{selectable:{type:"boolean",default:!0}}}};"undefined"!=typeof chart&&null!==chart&&((chart.utils||(chart.utils={})).config=e)}.call(this);
|
package/utils/legend.css
CHANGED
package/utils/legend.js
CHANGED
|
@@ -202,6 +202,10 @@
|
|
|
202
202
|
if (!(cfg != null)) {
|
|
203
203
|
return this.cfg;
|
|
204
204
|
}
|
|
205
|
+
if (this.cfg.selectable !== cfg.selectable) {
|
|
206
|
+
this._picked = null;
|
|
207
|
+
this._updatePicked();
|
|
208
|
+
}
|
|
205
209
|
this.cfg = cfg;
|
|
206
210
|
this.dir = this.cfg.position === 'bottom' ? 'horizontal' : 'vertical';
|
|
207
211
|
node = this.layout.getNode(this.name).querySelector('.pdlg');
|
|
@@ -209,6 +213,19 @@
|
|
|
209
213
|
return node.classList.toggle(it, this$.dir === it);
|
|
210
214
|
});
|
|
211
215
|
},
|
|
216
|
+
_updatePicked: function(){
|
|
217
|
+
var this$ = this;
|
|
218
|
+
if (!(this._picked != null)) {
|
|
219
|
+
this._picked = Object.fromEntries(this._data.map(function(d){
|
|
220
|
+
return [d.key, true];
|
|
221
|
+
}));
|
|
222
|
+
}
|
|
223
|
+
return this._data.map(function(d){
|
|
224
|
+
if (!(this$._picked[d.key] != null)) {
|
|
225
|
+
return this$._picked[d.key] = true;
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
},
|
|
212
229
|
data: function(data){
|
|
213
230
|
var hash;
|
|
214
231
|
data == null && (data = []);
|
|
@@ -219,9 +236,7 @@
|
|
|
219
236
|
this._data = data.filter(function(d, i){
|
|
220
237
|
return hash[d.key] === i;
|
|
221
238
|
});
|
|
222
|
-
this.
|
|
223
|
-
return [d.key, true];
|
|
224
|
-
}));
|
|
239
|
+
this._updatePicked();
|
|
225
240
|
this.update();
|
|
226
241
|
this.layout.update(false);
|
|
227
242
|
return this.view.render.render();
|
package/utils/legend.min.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.pdlg{height:100%;width:100%;display:flex;align-items:start;justify-content:center}.pdlg>div{display:flex;align-items:center;line-height:1em}.pdlg>div [ld=shape]{display:inline-block;width:1em;height:1em;margin-right:.5em;background:#999;flex:0 0 auto;line-height:1em}.pdlg>div [ld=text]{color:#999;padding-right:.25em;line-height:1.2em}.pdlg.vertical{flex-direction:column;align-items:start}.pdlg.vertical>div{margin-bottom:.5em}.pdlg.horizontal>div{margin-right:.5em}g.pdlg-g{cursor:pointer;transition:opacity .15s ease-in-out}
|
|
1
|
+
.pdlg{height:100%;width:100%;display:flex;align-items:start;justify-content:center}.pdlg>div{display:flex;align-items:center;line-height:1em}.pdlg>div [ld=shape]{display:inline-block;width:1em;height:1em;margin-right:.5em;background:#999;flex:0 0 auto;line-height:1em}.pdlg>div [ld=text]{color:#999;padding-right:.25em;line-height:1.2em;white-space:pre}.pdlg.vertical{flex-direction:column;align-items:start}.pdlg.vertical>div{margin-bottom:.5em}.pdlg.horizontal>div{margin-right:.5em}g.pdlg-g{cursor:pointer;transition:opacity .15s ease-in-out}
|
package/utils/legend.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){var
|
|
1
|
+
!function(){var d,e;d="http://www.w3.org/2000/svg",(e=function(a){var e,t,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(e){return[e.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),e=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>'),e.querySelector("[ld-each=legend]")||(t=document.createElementNS(d,"g"),n=document.createElementNS(d,"g"),i=document.createElementNS(d,"g"),t.classList.add("pdlg-g"),t.setAttribute("ld-each","legend"),n.setAttribute("ld","shape"),i.setAttribute("ld","text"),t.appendChild(n),t.appendChild(i),e.appendChild(t)),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(){return l._data.concat(l.cfg.selectable?l._func:[])},key:function(e){return e.key},view:{handler:{shape:function(e){var t=e.node,e=e.ctx;return t.setAttribute("data-name",l._name(e,"shape"))},text:function(e){var t=e.node,e=e.ctx;return t.setAttribute("data-name",l._name(e,"text")),t.innerText=e.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(e){return e.key},view:{action:{click:{"@":function(e){e.node;var t,n=e.ctx;if(l.cfg.selectable){if("func"===n.type)for(t in l._picked)l._picked[t]="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(e){var t=e.node,e=e.ctx;return t.style.opacity=!l.cfg.selectable||"func"===e.type||l._picked[e.key]?1:.3},shape:function(e){var t,n,i=e.node,r=e.ctx;if("func"!==r.type)return i.querySelector("circle")||i.appendChild(document.createElementNS(d,"circle")),t=i.querySelector("circle"),n=l.layout.getBox(l._name(r,"shape")),e=l.layout.getBox(l.name),t.setAttribute("cx",".5em"),t.setAttribute("cy",".5em"),t.setAttribute("r",".5em"),t.setAttribute("transform","translate("+(n.x-e.x)+", "+(n.y-e.y)+")"),"function"==typeof a.shape?a.shape.call(t,r):void 0;i.style.display="none"},text:function(e){var t=e.node,n=e.ctx,i=l.layout.getNode(l._name(n,"text")),e=l.layout.getBox(l._name(n,"text")),n=l.layout.getBox(l.name);return t.setAttribute("transform","translate("+(e.x-n.x)+", "+(e.y-n.y)+")"),t.textContent="",i=wrapSvgText({node:i,useRange:!0}),t.appendChild(i)}}}}}})},this.update(),this}).prototype=function(e,t){var n,i={}.hasOwnProperty;for(n in t)i.call(t,n)&&(e[n]=t[n]);return e}(Object.create(Object.prototype),{_name:function(e,t){return"pdlg-"+(t=null==t?"s":t)+"-"+this.id+"-"+(e.type||"")+"-"+e.key},enabled:function(){return this._data&&this._data.length&&(!(null!=this.cfg.enabled)||this.cfg.enabled)},update:function(){var e=this.enabled()?"":"0px",t=this.layout.getNode("legend").style;return t.width=e,t.height=e,t.padding=e,t.margin=e,this.view.layout.render()},render:function(){var e=this.enabled();if(this.layout.getGroup(this.name).style.display=e?"":"none",e)return this.view.render.render()},config:function(e){var t,n=this;return null==e?this.cfg:(this.cfg.selectable!==e.selectable&&(this._picked=null,this._updatePicked()),this.cfg=e,this.dir="bottom"===this.cfg.position?"horizontal":"vertical",t=this.layout.getNode(this.name).querySelector(".pdlg"),["horizontal","vertical"].map(function(e){return t.classList.toggle(e,n.dir===e)}))},_updatePicked:function(){var t=this;return null==this._picked&&(this._picked=Object.fromEntries(this._data.map(function(e){return[e.key,!0]}))),this._data.map(function(e){if(null==t._picked[e.key])return t._picked[e.key]=!0})},data:function(e){var n={};return(e=null==e?[]:e).map(function(e,t){return n[e.key]=t}),this._data=e.filter(function(e,t){return n[e.key]===t}),this._updatePicked(),this.update(),this.layout.update(!1),this.view.render.render()},on:function(e,n){var i=this;return(Array.isArray(e)?e:[e]).map(function(e){var t;return((t=i.evtHandler)[e]||(t[e]=[])).push(n)})},fire:function(e){for(var t,n,i,r,a=[],l=[],d=1,c=arguments.length;d<c;++d)l.push(arguments[d]);for(t=l,d=0,i=(n=this.evtHandler[e]||[]).length;d<i;++d)r=n[d],a.push(r.apply(this,t));return a},isSelected:function(e){return!!this._picked[e]}}),"undefined"!=typeof chart&&null!==chart&&((chart.utils||(chart.utils={})).legend=e)}.call(this);
|
package/utils/tick.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
(function(){
|
|
2
|
+
var tick;
|
|
3
|
+
tick = function(o){
|
|
4
|
+
var ext, len, ticks, extent, g, s, i$, ref$, len$, i, step, base, lg, fmt, unit, labels, to$, t1, t2;
|
|
5
|
+
o == null && (o = {});
|
|
6
|
+
ext = o.extent || [0, 1];
|
|
7
|
+
len = o.len || 3;
|
|
8
|
+
ext = ext.map(function(it){
|
|
9
|
+
if (!isNaN(it)) {
|
|
10
|
+
return it;
|
|
11
|
+
} else {
|
|
12
|
+
return 0;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
if (ext[0] > ext[1]) {
|
|
16
|
+
ext = [ext[1], ext[0]];
|
|
17
|
+
}
|
|
18
|
+
if (o.pretty != null && !o.pretty) {
|
|
19
|
+
ticks = (function(){
|
|
20
|
+
var i$, to$, results$ = [];
|
|
21
|
+
for (i$ = 0, to$ = len; i$ < to$; ++i$) {
|
|
22
|
+
results$.push(i$);
|
|
23
|
+
}
|
|
24
|
+
return results$;
|
|
25
|
+
}()).map(function(i){
|
|
26
|
+
var ref$;
|
|
27
|
+
return ext[0] + (ext[1] - ext[0]) * i / ((ref$ = len - 1) > 1 ? ref$ : 1);
|
|
28
|
+
});
|
|
29
|
+
extent = [ticks[0], ticks[len - 1]];
|
|
30
|
+
} else {
|
|
31
|
+
g = (ext[1] - ext[0]) / (len + 1);
|
|
32
|
+
s = Math.floor(Math.log((ext[1] - ext[0] || 1) / (len + 1)) / Math.LN10);
|
|
33
|
+
for (i$ = 0, len$ = (ref$ = [10, 20, 25, 50, 100]).length; i$ < len$; ++i$) {
|
|
34
|
+
i = ref$[i$];
|
|
35
|
+
if ((step = i * Math.pow(10, s - 1)) > g) {
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
base = step * Math.floor(ext[0] / step);
|
|
40
|
+
ticks = (function(){
|
|
41
|
+
var i$, to$, results$ = [];
|
|
42
|
+
for (i$ = 0, to$ = len; i$ <= to$; ++i$) {
|
|
43
|
+
results$.push(i$);
|
|
44
|
+
}
|
|
45
|
+
return results$;
|
|
46
|
+
}()).map(function(i){
|
|
47
|
+
return base + step * i;
|
|
48
|
+
});
|
|
49
|
+
extent = [ticks[0], ticks[len]];
|
|
50
|
+
}
|
|
51
|
+
if (lg = o.legend) {
|
|
52
|
+
fmt = lg.format || function(it){
|
|
53
|
+
return it;
|
|
54
|
+
};
|
|
55
|
+
unit = lg.unit || '';
|
|
56
|
+
if (lg.range) {
|
|
57
|
+
labels = [];
|
|
58
|
+
for (i$ = 0, to$ = ticks.length - 1; i$ < to$; ++i$) {
|
|
59
|
+
i = i$;
|
|
60
|
+
ref$ = [ticks[i], ticks[i + 1]], t1 = ref$[0], t2 = ref$[1];
|
|
61
|
+
labels.push({
|
|
62
|
+
key: (t1 + t2) / 2,
|
|
63
|
+
text: lg.text
|
|
64
|
+
? lg.text(t1, t2)
|
|
65
|
+
: fmt(t1) + " - " + fmt(t2) + unit
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
labels = ticks.map(function(it){
|
|
70
|
+
return {
|
|
71
|
+
key: it,
|
|
72
|
+
text: lg.text
|
|
73
|
+
? lg.text(it)
|
|
74
|
+
: fmt(it) + "" + unit
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
labels.sort(function(a, b){
|
|
79
|
+
if (a.key < b.key) {
|
|
80
|
+
return 1;
|
|
81
|
+
} else if (a.key > b.key) {
|
|
82
|
+
return -1;
|
|
83
|
+
} else {
|
|
84
|
+
return 0;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
ticks: ticks,
|
|
90
|
+
extent: extent,
|
|
91
|
+
labels: labels
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
if (typeof chart != 'undefined' && chart !== null) {
|
|
95
|
+
(chart.utils || (chart.utils = {})).tick = tick;
|
|
96
|
+
}
|
|
97
|
+
}).call(this);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(){var t=function(t){var n,e,r,u,o,a,f,i,l,c,h,s,p,y,k,x,g,m=(t=null==t?{}:t).extent||[0,1],M=t.len||3;if((m=m.map(function(t){return isNaN(t)?0:t}))[0]>m[1]&&(m=[m[1],m[0]]),null==t.pretty||t.pretty){for(r=(m[1]-m[0])/(M+1),u=Math.floor(Math.log((m[1]-m[0]||1)/(M+1))/Math.LN10),o=0,f=(a=[10,20,25,50,100]).length;o<f&&(i=a[o],!((l=i*Math.pow(10,u-1))>r));++o);c=l*Math.floor(m[0]/l),e=[(n=function(){for(var t=[],n=0,e=M;n<=e;++n)t.push(n);return t}().map(function(t){return c+l*t}))[0],n[M]]}else e=[(n=function(){for(var t=[],n=0,e=M;n<e;++n)t.push(n);return t}().map(function(t){return m[0]+(m[1]-m[0])*t/(1<(t=M-1)?t:1)}))[0],n[M-1]];if(h=t.legend){if(s=h.format||function(t){return t},p=h.unit||"",h.range)for(y=[],o=0,k=n.length-1;o<k;++o)x=(a=[n[i=o],n[i+1]])[0],g=a[1],y.push({key:(x+g)/2,text:h.text?h.text(x,g):s(x)+" - "+s(g)+p});else y=n.map(function(t){return{key:t,text:h.text?h.text(t):s(t)+""+p}});y.sort(function(t,n){return t.key<n.key?1:t.key>n.key?-1:0})}return{ticks:n,extent:e,labels:y}};"undefined"!=typeof chart&&null!==chart&&((chart.utils||(chart.utils={})).tick=t)}.call(this);
|
package/utils/tint.js
CHANGED
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
this.nmap = [];
|
|
8
8
|
this.wm = new WeakMap();
|
|
9
9
|
this.count = 0;
|
|
10
|
+
this._ext = opt.extent || [0, 1];
|
|
10
11
|
this.set(opt.palette) || opt.colors;
|
|
12
|
+
this.mode(opt.mode) || 0;
|
|
11
13
|
return this;
|
|
12
14
|
};
|
|
13
15
|
tint['default'] = ['#e15c64', '#f7b26a', '#f3ed9d', '#a4bd81', '#a0d7d2', '#8db1da', '#daaedb'];
|
|
@@ -62,7 +64,48 @@
|
|
|
62
64
|
});
|
|
63
65
|
});
|
|
64
66
|
},
|
|
65
|
-
|
|
67
|
+
mode: function(m){
|
|
68
|
+
if (arguments.length === 0) {
|
|
69
|
+
return this._m;
|
|
70
|
+
}
|
|
71
|
+
return this._m = m;
|
|
72
|
+
},
|
|
73
|
+
extent: function(v){
|
|
74
|
+
var e;
|
|
75
|
+
if (arguments.length === 0) {
|
|
76
|
+
return this._ext;
|
|
77
|
+
}
|
|
78
|
+
this._ext = e = [v[0], v[1]].map(function(it){
|
|
79
|
+
if (it != null) {
|
|
80
|
+
return it;
|
|
81
|
+
} else {
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
if (e[0] > e[1]) {
|
|
86
|
+
return this._ext = [e[1], e[0]];
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
get: function(d, v, i){
|
|
90
|
+
v == null && (v = 0);
|
|
91
|
+
switch (this._m) {
|
|
92
|
+
case 1:
|
|
93
|
+
return this._vd(d, v);
|
|
94
|
+
case 2:
|
|
95
|
+
return this._vc(d, v);
|
|
96
|
+
default:
|
|
97
|
+
return this._d(d, v, i);
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
_v: function(c, v){
|
|
101
|
+
if (v > 0) {
|
|
102
|
+
c = ldcolor.lighter(c, v);
|
|
103
|
+
} else if (v < 0) {
|
|
104
|
+
c = ldcolor.darker(c, -v);
|
|
105
|
+
}
|
|
106
|
+
return ldcolor.web(c);
|
|
107
|
+
},
|
|
108
|
+
_d: function(data, variant, idx){
|
|
66
109
|
var val, seg, pos, ref$, fz, fm, c1, c2, h, s, l, ret;
|
|
67
110
|
variant == null && (variant = 0);
|
|
68
111
|
if (idx != null) {
|
|
@@ -111,12 +154,30 @@
|
|
|
111
154
|
} else {
|
|
112
155
|
ret = this.colors[val];
|
|
113
156
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
157
|
+
return this._v(ret, variant);
|
|
158
|
+
},
|
|
159
|
+
_vd: function(data, variant){
|
|
160
|
+
var ext, v, ref$, ref1$;
|
|
161
|
+
ext = this._ext || [0, 1];
|
|
162
|
+
v = (ref$ = (ref1$ = (data - ext[0]) / (ext[1] - ext[0] || 1)) > 0 ? ref1$ : 0) < 1 ? ref$ : 1;
|
|
163
|
+
return this._v(this.colors[Math.floor((ref$ = v * (this.len || 1)) < (ref1$ = this.len - 1) ? ref$ : ref1$)], variant);
|
|
164
|
+
},
|
|
165
|
+
_vc: function(data, variant){
|
|
166
|
+
var ext, v, ref$, ref1$, i, i1, i2, c1, c2, pos, h, s, l;
|
|
167
|
+
ext = this._ext || [0, 1];
|
|
168
|
+
v = (ref$ = (ref1$ = (data - ext[0]) / (ext[1] - ext[0] || 1)) > 0 ? ref1$ : 0) < 1 ? ref$ : 1;
|
|
169
|
+
i = v * (this.len || 1);
|
|
170
|
+
ref$ = [(ref$ = Math.floor(pos)) < (ref1$ = this.len - 1) ? ref$ : ref1$, (ref$ = Math.floor(pos) + 1) < (ref1$ = this.len - 1) ? ref$ : ref1$], i1 = ref$[0], i2 = ref$[1];
|
|
171
|
+
ref$ = [this.colors[i1], this.colors[i2]], c1 = ref$[0], c2 = ref$[1];
|
|
172
|
+
pos = i - i1;
|
|
173
|
+
ref$ = ['h', 's', 'l'].map(function(k){
|
|
174
|
+
return pos * (c2[k] - c1[k]) + c1[k];
|
|
175
|
+
}), h = ref$[0], s = ref$[1], l = ref$[2];
|
|
176
|
+
return this._v({
|
|
177
|
+
h: h,
|
|
178
|
+
s: s,
|
|
179
|
+
l: l
|
|
180
|
+
}, variant);
|
|
120
181
|
},
|
|
121
182
|
text: function(v, opt){
|
|
122
183
|
var hcl;
|
|
@@ -127,6 +188,11 @@
|
|
|
127
188
|
: opt.textLight || '#fff');
|
|
128
189
|
}
|
|
129
190
|
});
|
|
191
|
+
tint.mode = {
|
|
192
|
+
ordinal: 0,
|
|
193
|
+
discrete: 1,
|
|
194
|
+
continuous: 2
|
|
195
|
+
};
|
|
130
196
|
if (typeof chart != 'undefined' && chart !== null) {
|
|
131
197
|
(chart.utils || (chart.utils = {})).tint = tint;
|
|
132
198
|
}
|
package/utils/tint.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){var s;(s=function(t){return this.isUnique=null==(t=null==t?{}:t).unique||t.unique,this.map={},this.nmap=[],this.wm=new WeakMap,this.count=0,this.set(t.palette)||t.colors,this}).default=["#e15c64","#f7b26a","#f3ed9d","#a4bd81","#a0d7d2","#8db1da","#daaedb"],s.prototype=function(t,
|
|
1
|
+
!function(){var s;(s=function(t){return this.isUnique=null==(t=null==t?{}:t).unique||t.unique,this.map={},this.nmap=[],this.wm=new WeakMap,this.count=0,this._ext=t.extent||[0,1],this.set(t.palette)||t.colors,this.mode(t.mode),this}).default=["#e15c64","#f7b26a","#f3ed9d","#a4bd81","#a0d7d2","#8db1da","#daaedb"],s.prototype=function(t,n){var i,s={}.hasOwnProperty;for(i in n)s.call(n,i)&&(t[i]=n[i]);return t}(Object.create(Object.prototype),{set:function(t,n){var i=this;return null==t&&(t=[]),null==n&&(n=!1),this.colors=Array.isArray(t)&&t.length?t:t.colors&&Array.isArray(t.colors)?t.colors:s.default,this.nmap=t.maps||[],this.colors=this.colors.map(function(t){return t.value||t}),1===this.colors.length&&this.colors.push(ldcolor.complement(this.colors[0])),this.colors=this.colors.map(function(t){return ldcolor.hsl(t)}),this.len=2<(t=this.colors.length)?t:2,n?this.reset():this.nmap.map(function(t,n){return(Array.isArray(t)?t:[t]).map(function(t){return i.get(t,0,n)})})},unique:function(t){return null!=t?this.isUnique=!!t:this.isUnique},reset:function(){var i=this;return this.map={},this.wm=new WeakMap,this.count=0,(this.nmap||[]).map(function(t,n){return(Array.isArray(t)?t:[t]).map(function(t){return i.get(t,0,n)})})},mode:function(t){return 0===arguments.length?this._m:this._m=t},extent:function(t){var n;return 0===arguments.length?this._ext:(this._ext=n=[t[0],t[1]].map(function(t){return null!=t?t:0}),n[0]>n[1]?this._ext=[n[1],n[0]]:void 0)},get:function(t,n,i){switch(null==n&&(n=0),this._m){case 1:return this._vd(t,n);case 2:return this._vc(t,n);default:return this._d(t,n,i)}},_v:function(t,n){return 0<n?t=ldcolor.lighter(t,n):n<0&&(t=ldcolor.darker(t,-n)),ldcolor.web(t)},_d:function(t,n,i){var s,r,e,o,l,h,u,c;if(null==n&&(n=0),null!=i?(this.count<i&&(this.count=i+1),s=i%this.len,"object"==typeof t?this.wm.set(t,s):this.map[t]=s):("object"==typeof t?null==(s=this.wm.get(t))&&this.wm.set(t,s=this.count++):null==(s=this.map[t])&&(this.map[t]=s=this.count++),this.isUnique||(s%=this.len)),s>=this.len){for(c=s%(this.len-1),r=Math.floor(s/(this.len-1)),o=(e=[0,1])[0],l=e[1];0<r;)o=(e=[2*o,2*l])[0],l=e[1],r%2&&(o+=1),r>>=1;r=o/l,e=[this.colors[c],this.colors[1+c]],h=e[0],u=e[1],c={h:(e=["h","s","l"].map(function(t){return r*(u[t]-h[t])+h[t]}))[0],s:e[1],l:e[2]}}else c=this.colors[s];return this._v(c,n)},_vd:function(t,n){var i,s=this._ext||[0,1],s=(t=0<(i=(t-s[0])/(s[1]-s[0]||1))?i:0)<1?t:1;return this._v(this.colors[Math.floor((t=s*(this.len||1))<(i=this.len-1)?t:i)],n)},_vc:function(t,n){var i,s,r,e=this._ext||[0,1],t=((o=0<(l=(t-e[0])/(e[1]-e[0]||1))?l:0)<1?o:1)*(this.len||1),o=[(o=Math.floor(void 0))<(l=this.len-1)?o:l,(o=Math.floor(void 0)+1)<(l=this.len-1)?o:l],e=o[0],l=o[1];return o=[this.colors[e],this.colors[l]],i=o[0],s=o[1],r=t-e,t=(o=["h","s","l"].map(function(t){return r*(s[t]-i[t])+i[t]}))[0],e=o[1],o=o[2],this._v({h:t,s:e,l:o},n)},text:function(t,n){return null==n&&(n={}),t=ldcolor.hcl(this.get(t)),ldcolor.web(50<t.l?n.textDark||"#000":n.textLight||"#fff")}}),s.mode={ordinal:0,discrete:1,continuous:2},"undefined"!=typeof chart&&null!==chart&&((chart.utils||(chart.utils={})).tint=s)}.call(this);
|