@plotdb/chart 2.0.0 → 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 +30 -0
- package/README.md +8 -7
- package/index.js +10 -0
- package/index.min.js +1 -1
- 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/utils/tip.js +1 -1
- package/utils/tip.min.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
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
|
+
|
|
26
|
+
## v2.0.1
|
|
27
|
+
|
|
28
|
+
- update documentation
|
|
29
|
+
- upgrade dependencies
|
|
30
|
+
- use `ctx()` to replace `setCtx()` in `utils/tip.ls`
|
|
31
|
+
|
|
32
|
+
|
|
3
33
|
## v2.0.0
|
|
4
34
|
|
|
5
35
|
- further minimize generated js file with mangling and compression
|
package/README.md
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
# @plotdb/chart
|
|
2
2
|
|
|
3
|
-
charting framework. In `@plotdb/chart`, charts are separated into
|
|
3
|
+
charting framework. In `@plotdb/chart`, charts are separated into 3 parts:
|
|
4
4
|
|
|
5
|
-
- chart
|
|
6
|
-
- chart
|
|
5
|
+
- chart class - define how a chart works, and provide an interface for controlling charts.
|
|
6
|
+
- chart mod - specific chart definition and implementation.
|
|
7
|
+
- chart data - data, config, binding and other metadata.
|
|
7
8
|
|
|
8
|
-
Chart
|
|
9
|
+
Chart class provides:
|
|
9
10
|
|
|
10
11
|
- chart lifecycle control - initing, resizing, rendering, destroying, etc
|
|
11
12
|
- animation loop control.
|
|
12
13
|
- rendering management for container resizing / visibility changing.
|
|
13
14
|
- utility modules for common charting components.
|
|
14
15
|
|
|
15
|
-
Chart
|
|
16
|
+
Chart mod includes:
|
|
16
17
|
|
|
17
18
|
- the actual code for chart rendering
|
|
18
19
|
- definition of user configurable options
|
|
19
20
|
- accepted data formats
|
|
20
21
|
- other metadata and dependencies
|
|
21
22
|
|
|
22
|
-
While not in spec and not necessary, chart
|
|
23
|
+
While not in spec and not necessary, chart mod can be encapsulated in `@plotdb/block`.
|
|
23
24
|
|
|
24
25
|
|
|
25
26
|
## Usage
|
|
@@ -41,7 +42,7 @@ then, create and initialize a chart object:
|
|
|
41
42
|
c.init().then(function() { ... });
|
|
42
43
|
|
|
43
44
|
|
|
44
|
-
For more detail about chart module object, chart object constructor option and api interface, check `doc/
|
|
45
|
+
For more detail about chart module object, chart object constructor option and api interface, check `doc/index.md`.
|
|
45
46
|
|
|
46
47
|
|
|
47
48
|
|
package/index.js
CHANGED
|
@@ -594,6 +594,16 @@
|
|
|
594
594
|
function fn2$(it){
|
|
595
595
|
return it.v.filter = v;
|
|
596
596
|
}
|
|
597
|
+
},
|
|
598
|
+
sample: function(){
|
|
599
|
+
if (this.mod.sample) {
|
|
600
|
+
return this.mod.sample.apply(this);
|
|
601
|
+
} else {
|
|
602
|
+
return {
|
|
603
|
+
raw: [],
|
|
604
|
+
binding: {}
|
|
605
|
+
};
|
|
606
|
+
}
|
|
597
607
|
}
|
|
598
608
|
});
|
|
599
609
|
if (typeof module != 'undefined' && module !== null) {
|
package/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){var n,i,o,s,u,a,t;function l(t,e){var n,r={}.hasOwnProperty;for(n in e)r.call(e,n)&&(t[n]=e[n]);return t}n=function(t,e,n){for(var r=t;t&&t!==n;)t=t.parentNode;if(t!==n)return null;if(!e)return t;for(t=r;t&&t!==n&&(!t.matches||t.matches&&!t.matches(e));)t=t.parentNode;return t!==n||n.matches&&n.matches(e)?t:null},(i=function(){return this.running=!1,this.time={now:0,last:0},this.fps(60),this.evtHandler={},this}).prototype=l(Object.create(Object.prototype),{on:function(t,n){var r=this;return(Array.isArray(t)?t:[t]).map(function(t){var e;return((e=r.evtHandler)[t]||(e[t]=[])).push(n)})},fire:function(t){for(var e,n,r,i,o=[],s=[],u=1,a=arguments.length;u<a;++u)s.push(arguments[u]);for(e=s,u=0,r=(n=this.evtHandler[t]||[]).length;u<r;++u)i=n[u],o.push(i.apply(this,e));return o},reset:function(){return this.time={now:0}},setTime:function(t){return this.time.now=t},getTime:function(){return this.time.now},isRunning:function(){return this.running},toggle:function(t){return null!=t&&(this.running=!t),this.running?this.pause():this.run()},pause:function(){return this.running=!1},render:function(){return this.fire("tick",this.time.now)},run:function(t){var e=this;if(null!=t&&this.fps(t),!this.running)return this.running=!0,requestAnimationFrame(function(t){return e.handler(e.time.last=t,!0)})},throttle:function(t){return this.isThrottled=t=null==t?!0:t},fps:function(t){return null==t?this._fps_val:(this._fps_val=.01<t?t:.01,this._fps_delay=1e3/this._fps_val)},handler:function(t,e){var n,r=this;if(null==e&&(e=!1),this.running)return this.time.now=t,n=this.isThrottled?1e3<(n=this._fps_delay)?n:1e3:this._fps_delay,(e||this.time.now-this.time.last>=n)&&(this.time.last=t,this.render()),requestAnimationFrame(function(t){return r.handler(t,!1)})}}),o={list:[],init:function(){var t,n,r=this;return this.inited=!0,t=null==document.hidden&&null==document.msHidden&&null!=document.webkiHidden?["webkitHidden","webkitvisibilitychange"]:["hidden","visibilitychange"],n=t[0],document.addEventListener(t[1],debounce(150,function(){var e=!!document[n];return r.list.map(function(t){return t.throttle(e)})},!1))},add:function(t){return this.inited||this.init(),this.list.push(t)}},s={wm:new WeakMap,ro:new ResizeObserver(function(t){return t.map(function(t){return s.wm.get(t.target)._resize()})}),add:function(t,e){return this.wm.set(t,e),this.ro.observe(t)},delete:function(t){return this.ro.unobserve(t),this.wm.delete(t)}},u=function(t,e){return null==e&&(e={}),function(t,e){var n,r;for(n in e)r=e[n],null==t[n]?t[n]=r:"object"==typeof t[n]&&"object"==typeof r&&u(t[n],e[n]);return t}(t=null==t?{}:t,e=JSON.parse(JSON.stringify(e)))},a=function(t){var o=function(t,e){var n,r,i;for(r in null==e&&(e={}),n=t.child,t)(i=t[r]).type?i.default&&(e[r]=i.default):o(i,e[r]||(e[r]={}));return e};return o(t)},(t=function(t){var e=this;return this.root="string"==typeof(t=null==t?{}:t).root?document.querySelector(t.root):t.root,this.useSample=null==t.useSample||t.useSample,this.autoSelect=null==t.autoSelect||t.autoSelect,this.forceInit=t.forceInit||!1,this.prepareSvg=null==t.prepareSvg||t.prepareSvg,this.layoutOpt=null==t.layout||t.layout,this.delayRender=t.delayRender||!1,this.dataAccessor=null!=t.dataAccessor?t.dataAccessor:function(t){return t?t.data._raw:null},this.raw=t.raw||null,this.mod=t.mod||{},this.cfg=t.config||{},this.seed=t.seed||Math.random(),this.binding=t.binding||{},this.evtHandler={},this.init=proxise.once(function(){return e._init()}),this._resize=null,this.autoSelect&&(this.root.addEventListener("click",this._select=function(t){if(t=n(t.target,".data",e.root))return e.fire("select",[{data:e.dataAccessor(t),node:t}])}),this.root.addEventListener("mouseover",this._hover=function(t){if(t=ld$.parent(t.target,".data",e.root))return e.fire("hover",[{data:e.dataAccessor(t),node:t}])})),this}).prototype=l(Object.create(Object.prototype),{_init:function(){var n,t,e,r=this;return"static"===window.getComputedStyle(this.root).position&&(this.root.style.position="relative"),n=this.layoutOpt?"object"!=typeof this.layoutOpt?this.root.querySelector(".pdl-layout"):"string"==typeof this.layoutOpt.root?this.root.querySelector(this.layoutOpt.root):this.layoutOpt.root||null:null,this.prepareSvg&&!(this.svg=this.root.querySelector("svg"))&&(this.svg=document.createElementNS("http://www.w3.org/2000/svg","svg"),(t=this.svg.style).width="100%",t.height="100%",this.layoutOpt&&(n||console.error("[@plotdb/chart] layout enabled yet layout root isn't configured properly. "),(e=n.querySelector("[data-type=render]"))||console.warn("[@plotdb/chart] prepareSvg and layout is configured at the same time,\nyet render container for layout is not found. svg is thus appended in the root.")),(e||this.root).appendChild(this.svg)),this._aniloop=new i,o.add(this._aniloop),this._aniloop.on("tick",function(){return r.tick()}),Promise.resolve().then(function(){var t=a(r.mod.config||{});if(u(r.cfg,t),(!r.raw||!Array.isArray(r.raw))&&r.useSample&&r.mod.sample)return(t=r.mod.sample.apply(r)).then?t.then():Promise.resolve(t)}).then(function(t){return r.raw=(t=t||{}).raw,r.binding=t.binding,r}).then(function(){var t,e;if(r.raw||(r.raw=[]),r.layoutOpt&&("undefined"==typeof layout||null===layout?console.warn("[@plotdb/chart] layout-opt is set yet @plotdb/layout is not found."):(n||(console.error("[@plotdb/chart] cannot determine root node for @plotdb/layout."),console.error("[@plotdb/chart] config layout properly or disable layout by setting layout to false")),r.layout=new layout("object"==typeof r.layoutOpt?((t=l({},r.layoutOpt)).watchResize=!1,t):{root:n,watchResize:!1}))),e=proxise(function(){return s.add(r.root,r),null}),(!r.forceInit||r.root.offsetParent)&&"none"!==window.getComputedStyle(r.root).display)return r._resize=function(){return e.resolve()},e()}).then(function(){return r._resize=function(){}}).then(function(){var t,e=function(){if(r.mod.init)return r.mod.init.apply(r)};return r.layout?(t=proxise(function(){return Promise.resolve(r.layout.init(e)),null}),r._layout=function(){return t.resolve()},r.layout.on("render",function(){return r._layout()}),t()):e()}).then(function(){r._layout=function(){},Promise.resolve().then(function(){if(r.delayRender)return r.renderLock=proxise(function(){}),r.renderLock()}).then(function(){return r._resize=function(){return r.resize(),r.render()},r._layout=function(){return r.parse(),r.bind(),r.resize(),r.render()},r.parse(),r.bind(),r.resize(),r.render()})})},parse:function(){var s=this;if(this.data=this.raw.map(function(i,t){var n,r,o={};return function(){var t,e=[];for(n in t=this.binding)r=t[n],e.push({k:n,v:r});return e}.call(s).map(function(t){var e,n=t.k,r=t.v;if(r)return o[n]=((t=(e=s.mod).dimension||(e.dimension={}))[n]||(t[n]={})).multiple?(r.map?r:[r]).map(function(t){return i[t.key]}):i[r.key],t=((t=(e=s.mod).dimension||(e.dimension={}))[n]||(t[n]={})).type,/[RIT]/.exec(t)&&!/[CN]/.exec(t)?o[n]=Array.isArray(o[n])?o[n].map(function(t){return parseFloat(t)}):parseFloat(o[n]):void 0}),o._raw=i,o._idx=t,o}),this.mod.parse)return this.mod.parse.apply(this)},bind:function(){if(this.mod.bind)return this.mod.bind.apply(this)},start:function(){if(this._aniloop.run(),this.mod.start)return this.mod.start.apply(this)},stop:function(){if(this._aniloop.pause(),this.mod.stop)return this.mod.stop.apply(this)},resize:function(){if(this.layout&&this.layout.update(!1),this.box=this.root.getBoundingClientRect(),this.mod.resize)return this.mod.resize.apply(this)},tick:function(){if(this.mod.tick)return this.mod.tick.apply(this)},render:function(){if(this.mod.render)return this.mod.render.apply(this)},destroy:function(){var t=this;return Promise.resolve().then(function(){if(t._select&&t.root.removeEventListener("click",t._select),t._hover&&t.root.removeEventListener("mouseover",t._hover),s.delete(t.root),t.layout&&t.layout.destroy(),t.stop(),t.mod.destroy)return t.mod.destroy.apply(t)})},config:function(t){return null!=t&&t?l(this.cfg,t):this.cfg},setBind:function(t,e){return this.binding[t]=e,this.parse(),this.bind(),this.resize(),this.render()},setRaw:function(t,e,n){var r;return null==n&&(n=!1),Array.isArray(t)||(t=(r=t).raw,e=r.binding,n=r.reinit),null!=t&&(this.raw=t),null!=e&&(this.binding=e),this.renderLock?(this.renderLock.resolve(),this.renderLock=null):(n&&this.mod.init&&this.mod.init.apply(this),this.parse(),this.bind(),this.resize(),this.render())},on:function(t,n){var r=this;return(Array.isArray(t)?t:[t]).map(function(t){var e;return((e=r.evtHandler)[t]||(e[t]=[])).push(n)})},fire:function(t){for(var e,n,r,i,o=[],s=[],u=1,a=arguments.length;u<a;++u)s.push(arguments[u]);for(e=s,u=0,r=(n=this.evtHandler[t]||[]).length;u<r;++u)i=n[u],o.push(i.apply(this,e));return o},filter:function(t,e){var n,r,i,o,s;for(r in null==t&&(t={}),null==e&&(e=!1),n=[],i=this.binding)o=i[r],s=(s=Array.isArray(o)?o:[o]).map(u),n=n.concat(s);for(r in t)o=t[r],n.filter(a).map(l);return e&&this.fire("filter",t),this.mod.filter&&this.mod.filter.apply(this,[t,e]),this.parse(),this.bind(),this.resize(),this.render();function u(t){return{k:r,v:t}}function a(t){return t.k===r}function l(t){return t.v.filter=o}}}),"undefined"!=typeof module&&null!==module?module.exports=t:"undefined"!=typeof window&&null!==window&&(window.chart=t)}.call(this);
|
|
1
|
+
!function(){var n,i,o,s,u,a,t;function l(t,e){var n,r={}.hasOwnProperty;for(n in e)r.call(e,n)&&(t[n]=e[n]);return t}n=function(t,e,n){for(var r=t;t&&t!==n;)t=t.parentNode;if(t!==n)return null;if(!e)return t;for(t=r;t&&t!==n&&(!t.matches||t.matches&&!t.matches(e));)t=t.parentNode;return t!==n||n.matches&&n.matches(e)?t:null},(i=function(){return this.running=!1,this.time={now:0,last:0},this.fps(60),this.evtHandler={},this}).prototype=l(Object.create(Object.prototype),{on:function(t,n){var r=this;return(Array.isArray(t)?t:[t]).map(function(t){var e;return((e=r.evtHandler)[t]||(e[t]=[])).push(n)})},fire:function(t){for(var e,n,r,i,o=[],s=[],u=1,a=arguments.length;u<a;++u)s.push(arguments[u]);for(e=s,u=0,r=(n=this.evtHandler[t]||[]).length;u<r;++u)i=n[u],o.push(i.apply(this,e));return o},reset:function(){return this.time={now:0}},setTime:function(t){return this.time.now=t},getTime:function(){return this.time.now},isRunning:function(){return this.running},toggle:function(t){return null!=t&&(this.running=!t),this.running?this.pause():this.run()},pause:function(){return this.running=!1},render:function(){return this.fire("tick",this.time.now)},run:function(t){var e=this;if(null!=t&&this.fps(t),!this.running)return this.running=!0,requestAnimationFrame(function(t){return e.handler(e.time.last=t,!0)})},throttle:function(t){return this.isThrottled=t=null==t?!0:t},fps:function(t){return null==t?this._fps_val:(this._fps_val=.01<t?t:.01,this._fps_delay=1e3/this._fps_val)},handler:function(t,e){var n,r=this;if(null==e&&(e=!1),this.running)return this.time.now=t,n=this.isThrottled?1e3<(n=this._fps_delay)?n:1e3:this._fps_delay,(e||this.time.now-this.time.last>=n)&&(this.time.last=t,this.render()),requestAnimationFrame(function(t){return r.handler(t,!1)})}}),o={list:[],init:function(){var t,n,r=this;return this.inited=!0,t=null==document.hidden&&null==document.msHidden&&null!=document.webkiHidden?["webkitHidden","webkitvisibilitychange"]:["hidden","visibilitychange"],n=t[0],document.addEventListener(t[1],debounce(150,function(){var e=!!document[n];return r.list.map(function(t){return t.throttle(e)})},!1))},add:function(t){return this.inited||this.init(),this.list.push(t)}},s={wm:new WeakMap,ro:new ResizeObserver(function(t){return t.map(function(t){return s.wm.get(t.target)._resize()})}),add:function(t,e){return this.wm.set(t,e),this.ro.observe(t)},delete:function(t){return this.ro.unobserve(t),this.wm.delete(t)}},u=function(t,e){return null==e&&(e={}),function(t,e){var n,r;for(n in e)r=e[n],null==t[n]?t[n]=r:"object"==typeof t[n]&&"object"==typeof r&&u(t[n],e[n]);return t}(t=null==t?{}:t,e=JSON.parse(JSON.stringify(e)))},a=function(t){var o=function(t,e){var n,r,i;for(r in null==e&&(e={}),n=t.child,t)(i=t[r]).type?i.default&&(e[r]=i.default):o(i,e[r]||(e[r]={}));return e};return o(t)},(t=function(t){var e=this;return this.root="string"==typeof(t=null==t?{}:t).root?document.querySelector(t.root):t.root,this.useSample=null==t.useSample||t.useSample,this.autoSelect=null==t.autoSelect||t.autoSelect,this.forceInit=t.forceInit||!1,this.prepareSvg=null==t.prepareSvg||t.prepareSvg,this.layoutOpt=null==t.layout||t.layout,this.delayRender=t.delayRender||!1,this.dataAccessor=null!=t.dataAccessor?t.dataAccessor:function(t){return t?t.data._raw:null},this.raw=t.raw||null,this.mod=t.mod||{},this.cfg=t.config||{},this.seed=t.seed||Math.random(),this.binding=t.binding||{},this.evtHandler={},this.init=proxise.once(function(){return e._init()}),this._resize=null,this.autoSelect&&(this.root.addEventListener("click",this._select=function(t){if(t=n(t.target,".data",e.root))return e.fire("select",[{data:e.dataAccessor(t),node:t}])}),this.root.addEventListener("mouseover",this._hover=function(t){if(t=ld$.parent(t.target,".data",e.root))return e.fire("hover",[{data:e.dataAccessor(t),node:t}])})),this}).prototype=l(Object.create(Object.prototype),{_init:function(){var n,t,e,r=this;return"static"===window.getComputedStyle(this.root).position&&(this.root.style.position="relative"),n=this.layoutOpt?"object"!=typeof this.layoutOpt?this.root.querySelector(".pdl-layout"):"string"==typeof this.layoutOpt.root?this.root.querySelector(this.layoutOpt.root):this.layoutOpt.root||null:null,this.prepareSvg&&!(this.svg=this.root.querySelector("svg"))&&(this.svg=document.createElementNS("http://www.w3.org/2000/svg","svg"),(t=this.svg.style).width="100%",t.height="100%",this.layoutOpt&&(n||console.error("[@plotdb/chart] layout enabled yet layout root isn't configured properly. "),(e=n.querySelector("[data-type=render]"))||console.warn("[@plotdb/chart] prepareSvg and layout is configured at the same time,\nyet render container for layout is not found. svg is thus appended in the root.")),(e||this.root).appendChild(this.svg)),this._aniloop=new i,o.add(this._aniloop),this._aniloop.on("tick",function(){return r.tick()}),Promise.resolve().then(function(){var t=a(r.mod.config||{});if(u(r.cfg,t),(!r.raw||!Array.isArray(r.raw))&&r.useSample&&r.mod.sample)return(t=r.mod.sample.apply(r)).then?t.then():Promise.resolve(t)}).then(function(t){return r.raw=(t=t||{}).raw,r.binding=t.binding,r}).then(function(){var t,e;if(r.raw||(r.raw=[]),r.layoutOpt&&("undefined"==typeof layout||null===layout?console.warn("[@plotdb/chart] layout-opt is set yet @plotdb/layout is not found."):(n||(console.error("[@plotdb/chart] cannot determine root node for @plotdb/layout."),console.error("[@plotdb/chart] config layout properly or disable layout by setting layout to false")),r.layout=new layout("object"==typeof r.layoutOpt?((t=l({},r.layoutOpt)).watchResize=!1,t):{root:n,watchResize:!1}))),e=proxise(function(){return s.add(r.root,r),null}),(!r.forceInit||r.root.offsetParent)&&"none"!==window.getComputedStyle(r.root).display)return r._resize=function(){return e.resolve()},e()}).then(function(){return r._resize=function(){}}).then(function(){var t,e=function(){if(r.mod.init)return r.mod.init.apply(r)};return r.layout?(t=proxise(function(){return Promise.resolve(r.layout.init(e)),null}),r._layout=function(){return t.resolve()},r.layout.on("render",function(){return r._layout()}),t()):e()}).then(function(){r._layout=function(){},Promise.resolve().then(function(){if(r.delayRender)return r.renderLock=proxise(function(){}),r.renderLock()}).then(function(){return r._resize=function(){return r.resize(),r.render()},r._layout=function(){return r.parse(),r.bind(),r.resize(),r.render()},r.parse(),r.bind(),r.resize(),r.render()})})},parse:function(){var s=this;if(this.data=this.raw.map(function(i,t){var n,r,o={};return function(){var t,e=[];for(n in t=this.binding)r=t[n],e.push({k:n,v:r});return e}.call(s).map(function(t){var e,n=t.k,r=t.v;if(r)return o[n]=((t=(e=s.mod).dimension||(e.dimension={}))[n]||(t[n]={})).multiple?(r.map?r:[r]).map(function(t){return i[t.key]}):i[r.key],t=((t=(e=s.mod).dimension||(e.dimension={}))[n]||(t[n]={})).type,/[RIT]/.exec(t)&&!/[CN]/.exec(t)?o[n]=Array.isArray(o[n])?o[n].map(function(t){return parseFloat(t)}):parseFloat(o[n]):void 0}),o._raw=i,o._idx=t,o}),this.mod.parse)return this.mod.parse.apply(this)},bind:function(){if(this.mod.bind)return this.mod.bind.apply(this)},start:function(){if(this._aniloop.run(),this.mod.start)return this.mod.start.apply(this)},stop:function(){if(this._aniloop.pause(),this.mod.stop)return this.mod.stop.apply(this)},resize:function(){if(this.layout&&this.layout.update(!1),this.box=this.root.getBoundingClientRect(),this.mod.resize)return this.mod.resize.apply(this)},tick:function(){if(this.mod.tick)return this.mod.tick.apply(this)},render:function(){if(this.mod.render)return this.mod.render.apply(this)},destroy:function(){var t=this;return Promise.resolve().then(function(){if(t._select&&t.root.removeEventListener("click",t._select),t._hover&&t.root.removeEventListener("mouseover",t._hover),s.delete(t.root),t.layout&&t.layout.destroy(),t.stop(),t.mod.destroy)return t.mod.destroy.apply(t)})},config:function(t){return null!=t&&t?l(this.cfg,t):this.cfg},setBind:function(t,e){return this.binding[t]=e,this.parse(),this.bind(),this.resize(),this.render()},setRaw:function(t,e,n){var r;return null==n&&(n=!1),Array.isArray(t)||(t=(r=t).raw,e=r.binding,n=r.reinit),null!=t&&(this.raw=t),null!=e&&(this.binding=e),this.renderLock?(this.renderLock.resolve(),this.renderLock=null):(n&&this.mod.init&&this.mod.init.apply(this),this.parse(),this.bind(),this.resize(),this.render())},on:function(t,n){var r=this;return(Array.isArray(t)?t:[t]).map(function(t){var e;return((e=r.evtHandler)[t]||(e[t]=[])).push(n)})},fire:function(t){for(var e,n,r,i,o=[],s=[],u=1,a=arguments.length;u<a;++u)s.push(arguments[u]);for(e=s,u=0,r=(n=this.evtHandler[t]||[]).length;u<r;++u)i=n[u],o.push(i.apply(this,e));return o},filter:function(t,e){var n,r,i,o,s;for(r in null==t&&(t={}),null==e&&(e=!1),n=[],i=this.binding)o=i[r],s=(s=Array.isArray(o)?o:[o]).map(u),n=n.concat(s);for(r in t)o=t[r],n.filter(a).map(l);return e&&this.fire("filter",t),this.mod.filter&&this.mod.filter.apply(this,[t,e]),this.parse(),this.bind(),this.resize(),this.render();function u(t){return{k:r,v:t}}function a(t){return t.k===r}function l(t){return t.v.filter=o}},sample:function(){return this.mod.sample?this.mod.sample.apply(this):{raw:[],binding:{}}}}),"undefined"!=typeof module&&null!==module?module.exports=t:"undefined"!=typeof window&&null!==window&&(window.chart=t)}.call(this);
|
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
|
+
{"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);
|
package/utils/tip.js
CHANGED
package/utils/tip.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){var t,e=function(t){var e,i=this;return this.root="string"==typeof(t=null==t?{}:t).root?document.querySelector(t.root):t.root,this.tip="string"==typeof t.node?this.root.querySelector(t.node):t.node,this.margin=null!=t.margin?t.margin:10,this.type="over"===t.type?"over":"move",this.accessor=t.accessor,this.range=t.range,this.zmgr=t.zmgr,this._z=0,this.enabled=!0,this.tip||(this.tip=document.createElement("div"),this.tip.innerHTML='<div ld="name" style="font-size:.85em"></div>\n<div ld="value" style="font-weight:bold;font-size:1.1em;line-height:1.2em"></div>',this.root.appendChild(this.tip),(e=this.tip.style).padding=".4em .5em",e.background="#13171a",e.color="#fff",e.borderRadius="3px",e.boxShadow="0 2px 4px rgba(0,0,0,.3)",e.lineHeight="1.2em",e.fontSize=".9em",e.maxWidth="10em",e.wordBreak="break-all"),(e=this.tip.style).position="absolute",e.zIndex=1,e.top=0,e.left=0,e.pointerEvents="none",e.userSelect="none",e.opacity=0,e.transition="opacity .15s ease-in-out"+("over"===this.type?", transform .15s ease-in-out":""),this.view=new ldview({root:this.tip,text:t.view||{name:function(t){t=t.ctx;return t?t.name:""},value:function(t){t=t.ctx;return t?t.value:""}}}),this.hide=debounce(3e3,function(){if(this.tip.style.opacity=0,this.zmgr)return this.zmgr.remove(this._z)}),this._evthdr={},this.accessor&&(this.root.addEventListener("over"===this.type?"mouseover":"mousemove",this._evthdr.over=function(t){var e;if(t.target&&(e=i.accessor({evt:t})))return i.render({data:e,node:t.target,evt:t})}),this.root.addEventListener("mouseout",this._evthdr.out=function(){return i.hide().now()})),this};e.prototype=((t=Object.create(Object.prototype)).destroy=function(){if(this._evthdr.over&&this.root.removeEventListener("over"===this.type?"mouseover":"mousemove",this._evthdr.over),this._evthdr.out)return this.root.removeEventListener("mouseout",this._evthdr.out)},t.toggle=function(t){return null==t?this.enabled:this.enabled=t},t.render=function(t){var e,i,n,o,r,h,s,d,a;if(null==t&&(t={}),this.enabled)return this.view.
|
|
1
|
+
!function(){var t,e=function(t){var e,i=this;return this.root="string"==typeof(t=null==t?{}:t).root?document.querySelector(t.root):t.root,this.tip="string"==typeof t.node?this.root.querySelector(t.node):t.node,this.margin=null!=t.margin?t.margin:10,this.type="over"===t.type?"over":"move",this.accessor=t.accessor,this.range=t.range,this.zmgr=t.zmgr,this._z=0,this.enabled=!0,this.tip||(this.tip=document.createElement("div"),this.tip.innerHTML='<div ld="name" style="font-size:.85em"></div>\n<div ld="value" style="font-weight:bold;font-size:1.1em;line-height:1.2em"></div>',this.root.appendChild(this.tip),(e=this.tip.style).padding=".4em .5em",e.background="#13171a",e.color="#fff",e.borderRadius="3px",e.boxShadow="0 2px 4px rgba(0,0,0,.3)",e.lineHeight="1.2em",e.fontSize=".9em",e.maxWidth="10em",e.wordBreak="break-all"),(e=this.tip.style).position="absolute",e.zIndex=1,e.top=0,e.left=0,e.pointerEvents="none",e.userSelect="none",e.opacity=0,e.transition="opacity .15s ease-in-out"+("over"===this.type?", transform .15s ease-in-out":""),this.view=new ldview({root:this.tip,text:t.view||{name:function(t){t=t.ctx;return t?t.name:""},value:function(t){t=t.ctx;return t?t.value:""}}}),this.hide=debounce(3e3,function(){if(this.tip.style.opacity=0,this.zmgr)return this.zmgr.remove(this._z)}),this._evthdr={},this.accessor&&(this.root.addEventListener("over"===this.type?"mouseover":"mousemove",this._evthdr.over=function(t){var e;if(t.target&&(e=i.accessor({evt:t})))return i.render({data:e,node:t.target,evt:t})}),this.root.addEventListener("mouseout",this._evthdr.out=function(){return i.hide().now()})),this};e.prototype=((t=Object.create(Object.prototype)).destroy=function(){if(this._evthdr.over&&this.root.removeEventListener("over"===this.type?"mouseover":"mousemove",this._evthdr.over),this._evthdr.out)return this.root.removeEventListener("mouseout",this._evthdr.out)},t.toggle=function(t){return null==t?this.enabled:this.enabled=t},t.render=function(t){var e,i,n,o,r,h,s,d,a;if(null==t&&(t={}),this.enabled)return this.view.ctx(t.data),this.view.render(),e=this.root.getBoundingClientRect(),h=null!=t.node?((s=t.node.getBoundingClientRect()).x=s.x-e.x,s.y=s.y-e.y,s):null!=t.box?t.box:{x:t.x,y:t.y,width:t.width,height:t.height},i=this.tip.getBoundingClientRect(),o=(n=[t.evt.clientX-e.x,t.evt.clientY-e.y])[0],a=n[1],d=this.margin,r=(n=[h.x+(null!=h.width?h.width/2:0),h.y+(null!=h.height?h.height/2:0)])[0],s=n[1],t=(n=[o-i.width/2,a-i.height/2])[0],h=n[1],t=(n=[t+(r<o?1:-1)*(d+i.width/2),h+(s<a?1:-1)*(d+i.height/2)])[0],h=n[1],t=(n=[((n=(t>(a=(s=this.range?this.range():e).x-e.x)?t:a)+i.width)<(d=s.width+s.x-e.x)?n:d)-i.width,((n=(h>(a=s.y-e.y)?h:a)+i.height)<(d=s.height+s.y-e.y)?n:d)-i.height])[0],h=n[1],(n=this.tip.style).transform="translate("+t+"px,"+h+"px)",n.opacity=1,n.zIndex=this._z=this.zmgr?this.zmgr.add(10):10,this.hide()},t),"undefined"!=typeof chart&&null!==chart&&((chart.utils||(chart.utils={})).tip=e)}.call(this);
|