@plotdb/chart 0.0.2 → 0.0.3
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/dist/chart.js +15 -11
- package/dist/chart.min.js +1 -1
- package/package.json +13 -7
- package/src/chart.ls +7 -4
- package/web/src/pug/base.pug +2 -1
- package/web/src/pug/block/line/0.0.1/index.ls +53 -16
- package/web/src/pug/block/taiwancounty/0.0.1/index.ls +74 -0
- package/web/src/pug/block/taiwancounty/0.0.1/index.pug +64 -0
- package/web/src/pug/block/worldmap/0.0.1/index.ls +0 -2
- package/web/src/pug/index.pug +4 -5
- package/web/static/assets/custom-lib/d3/d3-array.v2.js +1182 -0
- package/web/static/assets/custom-lib/d3/d3-array.v3.js +1273 -0
- package/web/static/assets/custom-lib/d3/d3-array.v3.min.js +1273 -0
- package/web/static/assets/custom-lib/d3/d3-geo.v2.js +3127 -0
- package/web/static/assets/custom-lib/d3/d3-geo.v2.min.js +2 -0
- package/web/static/assets/custom-lib/d3/d3.v6.js +19708 -0
- package/web/static/block/line/0.0.1/index.html +81 -50
- package/web/static/block/taiwancounty/0.0.1/index.html +202 -0
- package/web/static/index.html +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Change Logs
|
|
2
2
|
|
|
3
|
+
# v0.0.3
|
|
4
|
+
|
|
5
|
+
- upgrade @plotdb/block and related modules. add @loadingio/vscroll
|
|
6
|
+
- support Promise-based sample function
|
|
7
|
+
- change context of `sample` so we can access `cfg` directly in `sample`
|
|
8
|
+
- add taiwancounty chart
|
|
9
|
+
|
|
10
|
+
|
|
3
11
|
## v0.0.2
|
|
4
12
|
|
|
5
13
|
- use `palette` instead of `pal` in all charts, configurations and utils
|
package/dist/chart.js
CHANGED
|
@@ -298,23 +298,27 @@
|
|
|
298
298
|
return this$.tick();
|
|
299
299
|
});
|
|
300
300
|
return p = Promise.resolve().then(function(){
|
|
301
|
-
var
|
|
301
|
+
var defcfg, ret;
|
|
302
|
+
defcfg = defaultConfig(this$.mod.config || {});
|
|
303
|
+
withDefault(this$.cfg, defcfg);
|
|
302
304
|
if (this$.raw && Array.isArray(this$.raw)) {
|
|
303
305
|
return;
|
|
304
306
|
}
|
|
305
|
-
if (this$.useSample) {
|
|
306
|
-
|
|
307
|
-
? this$.mod.sample() || {}
|
|
308
|
-
: {}).raw;
|
|
309
|
-
this$.binding = ref$.binding;
|
|
307
|
+
if (!this$.useSample || !this$.mod.sample) {
|
|
308
|
+
return;
|
|
310
309
|
}
|
|
310
|
+
ret = this$.mod.sample.apply(this$);
|
|
311
|
+
return ret.then
|
|
312
|
+
? ret.then()
|
|
313
|
+
: Promise.resolve(ret);
|
|
314
|
+
}).then(function(it){
|
|
315
|
+
var ref$;
|
|
316
|
+
return this$.raw = (ref$ = it || {}).raw, this$.binding = ref$.binding, this$;
|
|
317
|
+
}).then(function(){
|
|
318
|
+
var ref$, _resizeLock;
|
|
311
319
|
if (!this$.raw) {
|
|
312
|
-
|
|
320
|
+
this$.raw = [];
|
|
313
321
|
}
|
|
314
|
-
}).then(function(){
|
|
315
|
-
var defcfg, ref$, _resizeLock;
|
|
316
|
-
defcfg = defaultConfig(this$.mod.config || {});
|
|
317
|
-
withDefault(this$.cfg, defcfg);
|
|
318
322
|
if (this$.layoutOpt) {
|
|
319
323
|
if (!(typeof layout != 'undefined' && layout !== null)) {
|
|
320
324
|
console.warn("[@plotdb/chart] layout-opt is set yet @plotdb/layout is not found.");
|
package/dist/chart.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){var svgns,parent,aniloop,visibilityObserver,resizeObserver,withDefault,defaultConfig,chart;svgns="http://www.w3.org/2000/svg";parent=function(n,s,e){var m;m=n;while(n&&n!==e){n=n.parentNode}if(n!==e){return null}if(!s){return n}n=m;while(n&&n!==e&&(!n.matches||n.matches&&!n.matches(s))){n=n.parentNode}if(n===e&&(!e.matches||!e.matches(s))){return null}return n};aniloop=function(){this.running=false;this.time={now:0,last:0};this.fps(60);this.evtHandler={};return this};aniloop.prototype=import$(Object.create(Object.prototype),{on:function(n,cb){var this$=this;return(Array.isArray(n)?n:[n]).map(function(n){var ref$;return((ref$=this$.evtHandler)[n]||(ref$[n]=[])).push(cb)})},fire:function(n){var v,res$,i$,to$,ref$,len$,cb,results$=[];res$=[];for(i$=1,to$=arguments.length;i$<to$;++i$){res$.push(arguments[i$])}v=res$;for(i$=0,len$=(ref$=this.evtHandler[n]||[]).length;i$<len$;++i$){cb=ref$[i$];results$.push(cb.apply(this,v))}return results$},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(it){if(it!=null){this.running=!it}if(this.running){return this.pause()}else{return this.run()}},pause:function(){return this.running=false},render:function(){return this.fire("tick",this.time.now)},run:function(fps){var this$=this;if(fps!=null){this.fps(fps)}if(this.running){return}this.running=true;return requestAnimationFrame(function(t){return this$.handler(this$.time.last=t,true)})},throttle:function(v){v==null&&(v=true);return this.isThrottled=v},fps:function(it){if(!(it!=null)){return this._fps_val}this._fps_val=it>.01?it:.01;return this._fps_delay=1e3/this._fps_val},handler:function(t,force){var delay,ref$,this$=this;force==null&&(force=false);if(!this.running){return}this.time.now=t;delay=this.isThrottled?(ref$=this._fps_delay)>1e3?ref$:1e3:this._fps_delay;if(force||this.time.now-this.time.last>=delay){this.time.last=t;this.render()}return requestAnimationFrame(function(t){return this$.handler(t,false)})}});visibilityObserver={list:[],init:function(){var ref$,h,vc,this$=this;this.inited=true;ref$=document.hidden!=null?["hidden","visibilitychange"]:document.msHidden!=null?["hidden","visibilitychange"]:document.webkiHidden!=null?["webkitHidden","webkitvisibilitychange"]:["hidden","visibilitychange"],h=ref$[0],vc=ref$[1];return document.addEventListener(vc,debounce(150,function(){var th;th=!!document[h];return this$.list.map(function(it){return it.throttle(th)})},false))},add:function(aniloop){if(!this.inited){this.init()}return this.list.push(aniloop)}};resizeObserver={wm:new WeakMap,ro:new ResizeObserver(function(list){return list.map(function(n){var ret;ret=resizeObserver.wm.get(n.target);return ret._resize()})}),add:function(node,obj){this.wm.set(node,obj);return this.ro.observe(node)},delete:function(it){this.ro.unobserve(it);return this.wm["delete"](it)}};withDefault=function(cfg,defcfg){var _;cfg==null&&(cfg={});defcfg==null&&(defcfg={});defcfg=JSON.parse(JSON.stringify(defcfg));_=function(cfg,defcfg){var k,v;for(k in defcfg){v=defcfg[k];if(!(cfg[k]!=null)){cfg[k]=v}else if(typeof cfg[k]==="object"&&typeof v==="object"){withDefault(cfg[k],defcfg[k])}}return cfg};return _(cfg,defcfg)};defaultConfig=function(cfg){var _;_=function(meta,ret){var ctrls,that,id,v;ret==null&&(ret={});ctrls=(that=meta.child)?that:meta;for(id in meta){v=meta[id];if(!v.type){_(v,ret[id]||(ret[id]={}))}else if(v["default"]){ret[id]=v["default"]}}return ret};return _(cfg)};chart=function(opt){var this$=this;opt==null&&(opt={});this.root=typeof opt.root==="string"?document.querySelector(opt.root):opt.root;this.useSample=opt.useSample!=null?opt.useSample:true;this.autoSelect=opt.autoSelect!=null?opt.autoSelect:true;this.forceInit=opt.forceInit?opt.forceInit:false;this.prepareSvg=opt.prepareSvg!=null?opt.prepareSvg:true;this.layoutOpt=opt.layout!=null?opt.layout:true;this.delayRender=opt.delayRender||false;this.dataAccessor=opt.dataAccessor!=null?opt.dataAccessor:function(it){if(it){return it.data._raw}else{return null}};this.raw=opt.raw||null;this.mod=opt.mod||{};this.cfg=opt.config||{};this.seed=opt.seed||Math.random();this.binding=opt.binding||{};this.evtHandler={};this.init=proxise.once(function(){return this$._init()});this._resize=null;if(this.autoSelect){this.root.addEventListener("click",this._select=function(e){var p;if(!(p=parent(e.target,".data",this$.root))){return}return this$.fire("select",[{data:this$.dataAccessor(p),node:p}])});this.root.addEventListener("mouseover",this._hover=function(e){var p;if(!(p=ld$.parent(e.target,".data",this$.root))){return}return this$.fire("hover",[{data:this$.dataAccessor(p),node:p}])})}return this};chart.prototype=import$(Object.create(Object.prototype),{_init:function(){var layoutRoot,ref$,r,p,this$=this;if(window.getComputedStyle(this.root).position==="static"){this.root.style.position="relative"}layoutRoot=this.layoutOpt?typeof this.layoutOpt!=="object"?this.root.querySelector(".pdl-layout"):typeof this.layoutOpt.root==="string"?this.root.querySelector(this.layoutOpt.root):this.layoutOpt.root?this.layoutOpt.root:null:null;if(this.prepareSvg&&!(this.svg=this.root.querySelector("svg"))){this.svg=document.createElementNS(svgns,"svg");ref$=this.svg.style;ref$.width="100%";ref$.height="100%";if(this.layoutOpt){if(!layoutRoot){console.error("[@plotdb/chart] layout enabled yet layout root isn't configured properly. ")}r=layoutRoot.querySelector("[data-type=render]");if(!r){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.")}}(r||this.root).appendChild(this.svg)}this._aniloop=new aniloop;visibilityObserver.add(this._aniloop);this._aniloop.on("tick",function(){return this$.tick()});return p=Promise.resolve().then(function(){var ref$;if(this$.raw&&Array.isArray(this$.raw)){return}if(this$.useSample){this$.raw=(ref$=this$.mod.sample?this$.mod.sample()||{}:{}).raw;this$.binding=ref$.binding}if(!this$.raw){return this$.raw=[]}}).then(function(){var defcfg,ref$,_resizeLock;defcfg=defaultConfig(this$.mod.config||{});withDefault(this$.cfg,defcfg);if(this$.layoutOpt){if(!(typeof layout!="undefined"&&layout!==null)){console.warn("[@plotdb/chart] layout-opt is set yet @plotdb/layout is not found.")}else{if(!layoutRoot){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")}this$.layout=new layout(typeof this$.layoutOpt==="object"?(ref$=import$({},this$.layoutOpt),ref$.watchResize=false,ref$):{root:layoutRoot,watchResize:false})}}_resizeLock=proxise(function(){resizeObserver.add(this$.root,this$);return null});if(this$.forceInit&&!this$.root.offsetParent||window.getComputedStyle(this$.root).display==="none"){return}this$._resize=function(){return _resizeLock.resolve()};return _resizeLock()}).then(function(){return this$._resize=function(){}}).then(function(){var init,layoutLock;init=function(){if(this$.mod.init){return this$.mod.init.apply(this$)}};if(!this$.layout){return init()}layoutLock=proxise(function(){Promise.resolve(this$.layout.init(init));return null});this$._layout=function(){return layoutLock.resolve()};this$.layout.on("render",function(){return this$._layout()});return layoutLock()}).then(function(){this$._layout=function(){};Promise.resolve().then(function(){if(!this$.delayRender){return}this$.renderLock=proxise(function(){});return this$.renderLock()}).then(function(){this$._resize=function(){this$.resize();return this$.render()};this$._layout=function(){this$.parse();this$.bind();this$.resize();return this$.render()};this$.parse();this$.bind();this$.resize();return this$.render()})})},parse:function(){var this$=this;this.data=this.raw.map(function(r,i){var ret,k,v;ret={};(function(){var ref$,results$=[];for(k in ref$=this.binding){v=ref$[k];results$.push({k:k,v:v})}return results$}).call(this$).map(function(arg$){var k,v,ref$,ref1$,t;k=arg$.k,v=arg$.v;if(!v){return}ret[k]=((ref$=(ref1$=this$.mod).dimension||(ref1$.dimension={}))[k]||(ref$[k]={})).multiple?v.map(function(it){return r[it.key]}):r[v.key];t=((ref$=(ref1$=this$.mod).dimension||(ref1$.dimension={}))[k]||(ref$[k]={})).type;if(/[RIT]/.exec(t)&&!/[CN]/.exec(t)){return ret[k]=Array.isArray(ret[k])?ret[k].map(function(it){return parseFloat(it)}):parseFloat(ret[k])}});ret._raw=r;ret._idx=i;return ret});if(this.mod.parse){return this.mod.parse.apply(this)}},bind:function(){if(this.mod.bind){return this.mod.bind.apply(this)}},start:function(){this._aniloop.run();if(this.mod.start){return this.mod.start.apply(this)}},stop:function(){this._aniloop.pause();if(this.mod.stop){return this.mod.stop.apply(this)}},resize:function(){if(this.layout){this.layout.update(false)}this.box=this.root.getBoundingClientRect();if(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 this$=this;return Promise.resolve().then(function(){if(this$._select){this$.root.removeEventListener("click",this$._select)}if(this$._hover){this$.root.removeEventListener("mouseover",this$._hover)}resizeObserver["delete"](this$.root);if(this$.layout){this$.layout.destroy()}this$.stop();if(this$.mod.destroy){return this$.mod.destroy.apply(this$)}})},config:function(opt){if(!(opt!=null&&opt)){return this.cfg}return import$(this.cfg,opt)},setBind:function(n,b){this.binding[n]=b;this.parse();this.bind();this.resize();return this.render()},setRaw:function(raw,binding,reinit){var ref$;reinit==null&&(reinit=false);if(!Array.isArray(raw)){ref$=raw,raw=ref$.raw,binding=ref$.binding,reinit=ref$.reinit}if(raw!=null){this.raw=raw}if(binding!=null){this.binding=binding}if(this.renderLock){this.renderLock.resolve();return this.renderLock=null}else{if(reinit&&this.mod.init){this.mod.init.apply(this)}this.parse();this.bind();this.resize();return this.render()}},on:function(n,cb){var this$=this;return(Array.isArray(n)?n:[n]).map(function(n){var ref$;return((ref$=this$.evtHandler)[n]||(ref$[n]=[])).push(cb)})},fire:function(n){var v,res$,i$,to$,ref$,len$,cb,results$=[];res$=[];for(i$=1,to$=arguments.length;i$<to$;++i$){res$.push(arguments[i$])}v=res$;for(i$=0,len$=(ref$=this.evtHandler[n]||[]).length;i$<len$;++i$){cb=ref$[i$];results$.push(cb.apply(this,v))}return results$},filter:function(filters,internal){var bs,k,ref$,v,u;filters==null&&(filters={});internal==null&&(internal=false);bs=[];for(k in ref$=this.binding){v=ref$[k];u=Array.isArray(v)?v:[v];u=u.map(fn$);bs=bs.concat(u)}for(k in filters){v=filters[k];bs.filter(fn1$).map(fn2$)}if(internal){this.fire("filter",filters)}if(this.mod.filter){this.mod.filter.apply(this,[filters,internal])}this.parse();this.bind();this.resize();return this.render();function fn$(v){return{k:k,v:v}}function fn1$(it){return it.k===k}function fn2$(it){return it.v.filter=v}}});if(typeof module!="undefined"&&module!==null){module.exports=chart}else if(typeof window!="undefined"&&window!==null){window.chart=chart}function import$(obj,src){var own={}.hasOwnProperty;for(var key in src)if(own.call(src,key))obj[key]=src[key];return obj}}).call(this);
|
|
1
|
+
(function(){var svgns,parent,aniloop,visibilityObserver,resizeObserver,withDefault,defaultConfig,chart;svgns="http://www.w3.org/2000/svg";parent=function(n,s,e){var m;m=n;while(n&&n!==e){n=n.parentNode}if(n!==e){return null}if(!s){return n}n=m;while(n&&n!==e&&(!n.matches||n.matches&&!n.matches(s))){n=n.parentNode}if(n===e&&(!e.matches||!e.matches(s))){return null}return n};aniloop=function(){this.running=false;this.time={now:0,last:0};this.fps(60);this.evtHandler={};return this};aniloop.prototype=import$(Object.create(Object.prototype),{on:function(n,cb){var this$=this;return(Array.isArray(n)?n:[n]).map(function(n){var ref$;return((ref$=this$.evtHandler)[n]||(ref$[n]=[])).push(cb)})},fire:function(n){var v,res$,i$,to$,ref$,len$,cb,results$=[];res$=[];for(i$=1,to$=arguments.length;i$<to$;++i$){res$.push(arguments[i$])}v=res$;for(i$=0,len$=(ref$=this.evtHandler[n]||[]).length;i$<len$;++i$){cb=ref$[i$];results$.push(cb.apply(this,v))}return results$},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(it){if(it!=null){this.running=!it}if(this.running){return this.pause()}else{return this.run()}},pause:function(){return this.running=false},render:function(){return this.fire("tick",this.time.now)},run:function(fps){var this$=this;if(fps!=null){this.fps(fps)}if(this.running){return}this.running=true;return requestAnimationFrame(function(t){return this$.handler(this$.time.last=t,true)})},throttle:function(v){v==null&&(v=true);return this.isThrottled=v},fps:function(it){if(!(it!=null)){return this._fps_val}this._fps_val=it>.01?it:.01;return this._fps_delay=1e3/this._fps_val},handler:function(t,force){var delay,ref$,this$=this;force==null&&(force=false);if(!this.running){return}this.time.now=t;delay=this.isThrottled?(ref$=this._fps_delay)>1e3?ref$:1e3:this._fps_delay;if(force||this.time.now-this.time.last>=delay){this.time.last=t;this.render()}return requestAnimationFrame(function(t){return this$.handler(t,false)})}});visibilityObserver={list:[],init:function(){var ref$,h,vc,this$=this;this.inited=true;ref$=document.hidden!=null?["hidden","visibilitychange"]:document.msHidden!=null?["hidden","visibilitychange"]:document.webkiHidden!=null?["webkitHidden","webkitvisibilitychange"]:["hidden","visibilitychange"],h=ref$[0],vc=ref$[1];return document.addEventListener(vc,debounce(150,function(){var th;th=!!document[h];return this$.list.map(function(it){return it.throttle(th)})},false))},add:function(aniloop){if(!this.inited){this.init()}return this.list.push(aniloop)}};resizeObserver={wm:new WeakMap,ro:new ResizeObserver(function(list){return list.map(function(n){var ret;ret=resizeObserver.wm.get(n.target);return ret._resize()})}),add:function(node,obj){this.wm.set(node,obj);return this.ro.observe(node)},delete:function(it){this.ro.unobserve(it);return this.wm["delete"](it)}};withDefault=function(cfg,defcfg){var _;cfg==null&&(cfg={});defcfg==null&&(defcfg={});defcfg=JSON.parse(JSON.stringify(defcfg));_=function(cfg,defcfg){var k,v;for(k in defcfg){v=defcfg[k];if(!(cfg[k]!=null)){cfg[k]=v}else if(typeof cfg[k]==="object"&&typeof v==="object"){withDefault(cfg[k],defcfg[k])}}return cfg};return _(cfg,defcfg)};defaultConfig=function(cfg){var _;_=function(meta,ret){var ctrls,that,id,v;ret==null&&(ret={});ctrls=(that=meta.child)?that:meta;for(id in meta){v=meta[id];if(!v.type){_(v,ret[id]||(ret[id]={}))}else if(v["default"]){ret[id]=v["default"]}}return ret};return _(cfg)};chart=function(opt){var this$=this;opt==null&&(opt={});this.root=typeof opt.root==="string"?document.querySelector(opt.root):opt.root;this.useSample=opt.useSample!=null?opt.useSample:true;this.autoSelect=opt.autoSelect!=null?opt.autoSelect:true;this.forceInit=opt.forceInit?opt.forceInit:false;this.prepareSvg=opt.prepareSvg!=null?opt.prepareSvg:true;this.layoutOpt=opt.layout!=null?opt.layout:true;this.delayRender=opt.delayRender||false;this.dataAccessor=opt.dataAccessor!=null?opt.dataAccessor:function(it){if(it){return it.data._raw}else{return null}};this.raw=opt.raw||null;this.mod=opt.mod||{};this.cfg=opt.config||{};this.seed=opt.seed||Math.random();this.binding=opt.binding||{};this.evtHandler={};this.init=proxise.once(function(){return this$._init()});this._resize=null;if(this.autoSelect){this.root.addEventListener("click",this._select=function(e){var p;if(!(p=parent(e.target,".data",this$.root))){return}return this$.fire("select",[{data:this$.dataAccessor(p),node:p}])});this.root.addEventListener("mouseover",this._hover=function(e){var p;if(!(p=ld$.parent(e.target,".data",this$.root))){return}return this$.fire("hover",[{data:this$.dataAccessor(p),node:p}])})}return this};chart.prototype=import$(Object.create(Object.prototype),{_init:function(){var layoutRoot,ref$,r,p,this$=this;if(window.getComputedStyle(this.root).position==="static"){this.root.style.position="relative"}layoutRoot=this.layoutOpt?typeof this.layoutOpt!=="object"?this.root.querySelector(".pdl-layout"):typeof this.layoutOpt.root==="string"?this.root.querySelector(this.layoutOpt.root):this.layoutOpt.root?this.layoutOpt.root:null:null;if(this.prepareSvg&&!(this.svg=this.root.querySelector("svg"))){this.svg=document.createElementNS(svgns,"svg");ref$=this.svg.style;ref$.width="100%";ref$.height="100%";if(this.layoutOpt){if(!layoutRoot){console.error("[@plotdb/chart] layout enabled yet layout root isn't configured properly. ")}r=layoutRoot.querySelector("[data-type=render]");if(!r){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.")}}(r||this.root).appendChild(this.svg)}this._aniloop=new aniloop;visibilityObserver.add(this._aniloop);this._aniloop.on("tick",function(){return this$.tick()});return p=Promise.resolve().then(function(){var defcfg,ret;defcfg=defaultConfig(this$.mod.config||{});withDefault(this$.cfg,defcfg);if(this$.raw&&Array.isArray(this$.raw)){return}if(!this$.useSample||!this$.mod.sample){return}ret=this$.mod.sample.apply(this$);return ret.then?ret.then():Promise.resolve(ret)}).then(function(it){var ref$;return this$.raw=(ref$=it||{}).raw,this$.binding=ref$.binding,this$}).then(function(){var ref$,_resizeLock;if(!this$.raw){this$.raw=[]}if(this$.layoutOpt){if(!(typeof layout!="undefined"&&layout!==null)){console.warn("[@plotdb/chart] layout-opt is set yet @plotdb/layout is not found.")}else{if(!layoutRoot){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")}this$.layout=new layout(typeof this$.layoutOpt==="object"?(ref$=import$({},this$.layoutOpt),ref$.watchResize=false,ref$):{root:layoutRoot,watchResize:false})}}_resizeLock=proxise(function(){resizeObserver.add(this$.root,this$);return null});if(this$.forceInit&&!this$.root.offsetParent||window.getComputedStyle(this$.root).display==="none"){return}this$._resize=function(){return _resizeLock.resolve()};return _resizeLock()}).then(function(){return this$._resize=function(){}}).then(function(){var init,layoutLock;init=function(){if(this$.mod.init){return this$.mod.init.apply(this$)}};if(!this$.layout){return init()}layoutLock=proxise(function(){Promise.resolve(this$.layout.init(init));return null});this$._layout=function(){return layoutLock.resolve()};this$.layout.on("render",function(){return this$._layout()});return layoutLock()}).then(function(){this$._layout=function(){};Promise.resolve().then(function(){if(!this$.delayRender){return}this$.renderLock=proxise(function(){});return this$.renderLock()}).then(function(){this$._resize=function(){this$.resize();return this$.render()};this$._layout=function(){this$.parse();this$.bind();this$.resize();return this$.render()};this$.parse();this$.bind();this$.resize();return this$.render()})})},parse:function(){var this$=this;this.data=this.raw.map(function(r,i){var ret,k,v;ret={};(function(){var ref$,results$=[];for(k in ref$=this.binding){v=ref$[k];results$.push({k:k,v:v})}return results$}).call(this$).map(function(arg$){var k,v,ref$,ref1$,t;k=arg$.k,v=arg$.v;if(!v){return}ret[k]=((ref$=(ref1$=this$.mod).dimension||(ref1$.dimension={}))[k]||(ref$[k]={})).multiple?v.map(function(it){return r[it.key]}):r[v.key];t=((ref$=(ref1$=this$.mod).dimension||(ref1$.dimension={}))[k]||(ref$[k]={})).type;if(/[RIT]/.exec(t)&&!/[CN]/.exec(t)){return ret[k]=Array.isArray(ret[k])?ret[k].map(function(it){return parseFloat(it)}):parseFloat(ret[k])}});ret._raw=r;ret._idx=i;return ret});if(this.mod.parse){return this.mod.parse.apply(this)}},bind:function(){if(this.mod.bind){return this.mod.bind.apply(this)}},start:function(){this._aniloop.run();if(this.mod.start){return this.mod.start.apply(this)}},stop:function(){this._aniloop.pause();if(this.mod.stop){return this.mod.stop.apply(this)}},resize:function(){if(this.layout){this.layout.update(false)}this.box=this.root.getBoundingClientRect();if(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 this$=this;return Promise.resolve().then(function(){if(this$._select){this$.root.removeEventListener("click",this$._select)}if(this$._hover){this$.root.removeEventListener("mouseover",this$._hover)}resizeObserver["delete"](this$.root);if(this$.layout){this$.layout.destroy()}this$.stop();if(this$.mod.destroy){return this$.mod.destroy.apply(this$)}})},config:function(opt){if(!(opt!=null&&opt)){return this.cfg}return import$(this.cfg,opt)},setBind:function(n,b){this.binding[n]=b;this.parse();this.bind();this.resize();return this.render()},setRaw:function(raw,binding,reinit){var ref$;reinit==null&&(reinit=false);if(!Array.isArray(raw)){ref$=raw,raw=ref$.raw,binding=ref$.binding,reinit=ref$.reinit}if(raw!=null){this.raw=raw}if(binding!=null){this.binding=binding}if(this.renderLock){this.renderLock.resolve();return this.renderLock=null}else{if(reinit&&this.mod.init){this.mod.init.apply(this)}this.parse();this.bind();this.resize();return this.render()}},on:function(n,cb){var this$=this;return(Array.isArray(n)?n:[n]).map(function(n){var ref$;return((ref$=this$.evtHandler)[n]||(ref$[n]=[])).push(cb)})},fire:function(n){var v,res$,i$,to$,ref$,len$,cb,results$=[];res$=[];for(i$=1,to$=arguments.length;i$<to$;++i$){res$.push(arguments[i$])}v=res$;for(i$=0,len$=(ref$=this.evtHandler[n]||[]).length;i$<len$;++i$){cb=ref$[i$];results$.push(cb.apply(this,v))}return results$},filter:function(filters,internal){var bs,k,ref$,v,u;filters==null&&(filters={});internal==null&&(internal=false);bs=[];for(k in ref$=this.binding){v=ref$[k];u=Array.isArray(v)?v:[v];u=u.map(fn$);bs=bs.concat(u)}for(k in filters){v=filters[k];bs.filter(fn1$).map(fn2$)}if(internal){this.fire("filter",filters)}if(this.mod.filter){this.mod.filter.apply(this,[filters,internal])}this.parse();this.bind();this.resize();return this.render();function fn$(v){return{k:k,v:v}}function fn1$(it){return it.k===k}function fn2$(it){return it.v.filter=v}}});if(typeof module!="undefined"&&module!==null){module.exports=chart}else if(typeof window!="undefined"&&window!==null){window.chart=chart}function import$(obj,src){var own={}.hasOwnProperty;for(var key in src)if(own.call(src,key))obj[key]=src[key];return obj}}).call(this);
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "@plotdb/chart",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "plotdb charts",
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.3",
|
|
7
7
|
"homepage": "https://github.com/plotdb/chart",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
@@ -21,15 +21,18 @@
|
|
|
21
21
|
"@loadingio/bootstrap.ext": "^0.0.1",
|
|
22
22
|
"@loadingio/ldquery": "^2.2.0",
|
|
23
23
|
"@loadingio/loading.css": "^2.0.1",
|
|
24
|
+
"@loadingio/vscroll": "^0.0.6",
|
|
24
25
|
"@plotdb/layout": "^0.0.10",
|
|
25
26
|
"@plotdb/pdmap-world": "^0.0.3",
|
|
26
27
|
"@plotdb/sheet": "^0.1.7",
|
|
28
|
+
"bootstrap.native": "^3.0.15",
|
|
27
29
|
"@zbryikt/template": "^2.3.22",
|
|
28
30
|
"bootstrap": "^4.5.2",
|
|
29
31
|
"fedep": "^0.0.16",
|
|
30
32
|
"ldloader": "^2.0.1",
|
|
31
33
|
"ldview": "^0.2.3",
|
|
32
34
|
"livescript": "^1.6.0",
|
|
35
|
+
"pdmaptw": "0.0.4",
|
|
33
36
|
"uglify-js": "^3.2.0",
|
|
34
37
|
"uglifycss": "^0.0.29"
|
|
35
38
|
},
|
|
@@ -37,11 +40,13 @@
|
|
|
37
40
|
"root": "web/static/assets/lib",
|
|
38
41
|
"modules": [
|
|
39
42
|
"bootstrap",
|
|
43
|
+
"bootstrap.native",
|
|
40
44
|
"@loadingio/bootstrap.ext",
|
|
41
45
|
"@loadingio/ldquery",
|
|
42
46
|
"@loadingio/loading.css",
|
|
43
47
|
"@loadingio/ldcolorpicker",
|
|
44
48
|
"@loadingio/debounce.js",
|
|
49
|
+
"@loadingio/vscroll",
|
|
45
50
|
"@plotdb/pdmap-world",
|
|
46
51
|
"@plotdb/block",
|
|
47
52
|
"@plotdb/csscope",
|
|
@@ -51,6 +56,7 @@
|
|
|
51
56
|
"@plotdb/konfig",
|
|
52
57
|
"@zbryikt/voronoijs",
|
|
53
58
|
"choosefont.js",
|
|
59
|
+
"pdmaptw",
|
|
54
60
|
"proxise",
|
|
55
61
|
"ldloader",
|
|
56
62
|
"ldcover",
|
|
@@ -64,20 +70,20 @@
|
|
|
64
70
|
"dependencies": {
|
|
65
71
|
"@loadingio/debounce.js": "^0.0.1",
|
|
66
72
|
"@loadingio/ldcolorpicker": "^2.0.4",
|
|
67
|
-
"@plotdb/block": "^
|
|
68
|
-
"@plotdb/csscope": "^
|
|
69
|
-
"@plotdb/konfig": "^
|
|
70
|
-
"@plotdb/rescope": "^
|
|
73
|
+
"@plotdb/block": "^3.0.1",
|
|
74
|
+
"@plotdb/csscope": "^3.0.1",
|
|
75
|
+
"@plotdb/konfig": "^2.0.2",
|
|
76
|
+
"@plotdb/rescope": "^4.0.2",
|
|
71
77
|
"@zbryikt/voronoijs": "^0.0.1",
|
|
72
78
|
"choosefont.js": "^0.0.1",
|
|
73
79
|
"ldcolor": "^0.0.4",
|
|
74
80
|
"ldcover": "^2.0.0",
|
|
75
81
|
"ldpalettepicker": "^3.1.3",
|
|
76
82
|
"ldslider": "^2.0.6",
|
|
77
|
-
"proxise": "^0.1.
|
|
83
|
+
"proxise": "^0.1.6",
|
|
78
84
|
"wrap-svg-text": "^0.0.6"
|
|
79
85
|
},
|
|
80
86
|
"peerDependencies": {
|
|
81
|
-
"proxise": "^0.1.
|
|
87
|
+
"proxise": "^0.1.6"
|
|
82
88
|
}
|
|
83
89
|
}
|
package/src/chart.ls
CHANGED
|
@@ -167,13 +167,16 @@ chart.prototype = Object.create(Object.prototype) <<< do
|
|
|
167
167
|
visibilityObserver.add @_aniloop
|
|
168
168
|
@_aniloop.on \tick, ~> @tick!
|
|
169
169
|
p = Promise.resolve!
|
|
170
|
-
.then ~>
|
|
171
|
-
if @raw and Array.isArray(@raw) => return
|
|
172
|
-
if @use-sample => @ <<< (if @mod.sample => @mod.sample! or {} else {}){raw, binding}
|
|
173
|
-
if !@raw => @raw = []
|
|
174
170
|
.then ~>
|
|
175
171
|
defcfg = default-config(@mod.config or {})
|
|
176
172
|
with-default @cfg, defcfg
|
|
173
|
+
if @raw and Array.isArray(@raw) => return
|
|
174
|
+
if !@use-sample or !@mod.sample => return
|
|
175
|
+
ret = @mod.sample.apply @
|
|
176
|
+
return if ret.then => ret.then! else Promise.resolve ret
|
|
177
|
+
.then ~> @ <<<(it or {}){raw, binding}
|
|
178
|
+
.then ~>
|
|
179
|
+
if !@raw => @raw = []
|
|
177
180
|
if @layout-opt =>
|
|
178
181
|
if !(layout?) => console.warn "[@plotdb/chart] layout-opt is set yet @plotdb/layout is not found."
|
|
179
182
|
else
|
package/web/src/pug/base.pug
CHANGED
|
@@ -7,12 +7,13 @@ html
|
|
|
7
7
|
head
|
|
8
8
|
block prehead
|
|
9
9
|
+css("/assets/lib/bootstrap/main/css/bootstrap.min.css")
|
|
10
|
-
+css("/assets/lib/bootstrap.
|
|
10
|
+
+css("/assets/lib/@loadingio/bootstrap.ext/main/index.min.css")
|
|
11
11
|
+css("/assets/lib/@loadingio/loading.css/main/loading.min.css")
|
|
12
12
|
+css("/css/index.css")
|
|
13
13
|
block head
|
|
14
14
|
body
|
|
15
15
|
block body
|
|
16
|
+
+script("/assets/lib/bootstrap.native/main/bootstrap-native-v4.min.js")
|
|
16
17
|
+script("https://polyfill.io/v3/polyfill.min.js?features=ResizeObserver")
|
|
17
18
|
+script("/assets/lib/@loadingio/ldquery/main/ldq.min.js")
|
|
18
19
|
+script("/assets/lib/ldview/main/index.min.js")
|
|
@@ -18,15 +18,19 @@ mod = ({context, t}) ->
|
|
|
18
18
|
{d3,chart,axis,format} = context
|
|
19
19
|
sample-count = 4
|
|
20
20
|
sample: ->
|
|
21
|
-
raw: [0 to
|
|
21
|
+
raw: [0 to 30].map (val) ~>
|
|
22
22
|
ret = {}
|
|
23
|
-
[1 to sample-count].map (i) -> ret["val#i"] = Math.random! * (10 - Math.abs(10 - val)) + val
|
|
23
|
+
[1 to sample-count].map (i) -> ret["val#i"] = (i * Math.random! * (10 - Math.abs(10 - val)) + val) >? 0
|
|
24
24
|
ret.order = val
|
|
25
25
|
ret
|
|
26
26
|
binding:
|
|
27
27
|
value: [1 to sample-count].map -> {key: "val#it"}
|
|
28
28
|
order: {key: \order}
|
|
29
|
-
config:
|
|
29
|
+
config:
|
|
30
|
+
mode: type: \choice, values: <[line area streamgraph bump]>, default: \line
|
|
31
|
+
stack: type: \boolean
|
|
32
|
+
line: type: \choice, values: <[curve linear]>, default: \linear
|
|
33
|
+
show-dot: type: \boolean, default: true
|
|
30
34
|
dimension:
|
|
31
35
|
value: {type: \R, name: "y axis", multiple: true}
|
|
32
36
|
order: {type: \ON, name: "x axis"}
|
|
@@ -39,7 +43,6 @@ mod = ({context, t}) ->
|
|
|
39
43
|
!isNaN(it.y1)
|
|
40
44
|
.x ~> @scale.x it.x
|
|
41
45
|
.y ~> @scale.y it.y1
|
|
42
|
-
#.curve d3.curveCatmullRom
|
|
43
46
|
@area = d3.area!
|
|
44
47
|
.defined ~>
|
|
45
48
|
!isNaN(it.y1) and !isNaN(it.y0)
|
|
@@ -107,7 +110,7 @@ mod = ({context, t}) ->
|
|
|
107
110
|
binds = @binding.value.map((b,i) -> {b, i}).filter (d,i) ~> @legend.is-selected d.b.key
|
|
108
111
|
|
|
109
112
|
# if bump
|
|
110
|
-
if @cfg.bump =>
|
|
113
|
+
if @cfg.mode == \bump =>
|
|
111
114
|
@parsed = []
|
|
112
115
|
dd = @data.map (d) ~>
|
|
113
116
|
ret = {} <<< d
|
|
@@ -123,13 +126,45 @@ mod = ({context, t}) ->
|
|
|
123
126
|
ret.original-value = v.map -> it.v
|
|
124
127
|
ret
|
|
125
128
|
|
|
129
|
+
dd = dd or @data
|
|
130
|
+
|
|
131
|
+
if @cfg.mode == \streamgraph =>
|
|
132
|
+
sums = dd.map (d) ->
|
|
133
|
+
sum = 0
|
|
134
|
+
for i from 0 til d.value.length => sum += d.value[i]
|
|
135
|
+
sum
|
|
136
|
+
[smin, smax] = [Math.min.apply(Math, sums), Math.max.apply(Math, sums)]
|
|
137
|
+
else
|
|
138
|
+
[sums, smin, smax] = [dd.map(-> 0), 0, 0]
|
|
139
|
+
@parsed = []
|
|
140
|
+
line0 = dd.map -> 0
|
|
141
|
+
for i from 0 til binds.length =>
|
|
142
|
+
[p,b] = [(if i > 0 => binds[i - 1] else null), binds[i]]
|
|
143
|
+
line1 = dd.map (d,j) -> d.value[b.i] + line0[j]
|
|
144
|
+
@parsed.push {
|
|
145
|
+
pts: (dd or @data).map (d,j) ->
|
|
146
|
+
data: d
|
|
147
|
+
y0: line0[j] - (sums[j] / 2) + (smax - smin) / 2
|
|
148
|
+
y1: line1[j] - (sums[j] / 2) + (smax - smin) / 2
|
|
149
|
+
x: d._order
|
|
150
|
+
v: if d.original-value => d.original-value[i] else d.value[i]
|
|
151
|
+
bind: b.b
|
|
152
|
+
color: b.b.name or b.b.key
|
|
153
|
+
}
|
|
154
|
+
if (@cfg.stack and @cfg.mode != \bump) or (@cfg.mode in <[streamgraph area]>) => line0 = line1
|
|
155
|
+
/*
|
|
126
156
|
@parsed = binds.map (b,i) ~>
|
|
127
157
|
pts: (dd or @data).map (d,j) ->
|
|
128
|
-
|
|
158
|
+
data: d
|
|
159
|
+
y0: 0
|
|
160
|
+
y1: d.value[b.i]
|
|
161
|
+
x: d._order
|
|
162
|
+
v: if d.original-value => d.original-value[i] else d.value[i]
|
|
129
163
|
bind: b.b
|
|
130
164
|
color: b.b.name or b.b.key
|
|
131
|
-
|
|
165
|
+
*/
|
|
132
166
|
# if stacked
|
|
167
|
+
/*
|
|
133
168
|
if @cfg.stack =>
|
|
134
169
|
ys = @data.map -> it.value.reduce(((a,b)-> a + b),0)
|
|
135
170
|
@parsed = []
|
|
@@ -144,8 +179,10 @@ mod = ({context, t}) ->
|
|
|
144
179
|
v: if d.original-value => d.original-value[i] else d.value[i]
|
|
145
180
|
bind: b
|
|
146
181
|
color: b.name or b.key
|
|
147
|
-
|
|
182
|
+
*/
|
|
148
183
|
resize: ->
|
|
184
|
+
@line.curve if @cfg.line == \curve => d3.curveCatmullRom else d3.curveLinear
|
|
185
|
+
@area.curve if @cfg.line == \curve => d3.curveCatmullRom else d3.curveLinear
|
|
149
186
|
@tip.toggle(if @cfg.{}tip.enabled? => @cfg.tip.enabled else true)
|
|
150
187
|
[miny,maxy] = [0,0]
|
|
151
188
|
for i from 0 til @parsed.length =>
|
|
@@ -158,14 +195,14 @@ mod = ({context, t}) ->
|
|
|
158
195
|
|
|
159
196
|
@extent =
|
|
160
197
|
x: d3.extent @data, -> (it._order)
|
|
161
|
-
y: [(if @cfg.bump => miny >? 1 else miny), if maxy == miny => miny + 1 else maxy]
|
|
198
|
+
y: [(if @cfg.mode == \bump => miny >? 1 else miny), if maxy == miny => miny + 1 else maxy]
|
|
162
199
|
|
|
163
200
|
@scale.x.domain @extent.x
|
|
164
|
-
@scale.y.domain (if @cfg.bump => [@extent.y.1, @extent.y.0] else @extent.y)
|
|
201
|
+
@scale.y.domain (if @cfg.mode == \bump => [@extent.y.1, @extent.y.0] else @extent.y)
|
|
165
202
|
|
|
166
203
|
[w,h] = [@box.width, @box.height]
|
|
167
204
|
max-tick = Math.ceil(@layout.get-box \yaxis .height / 40) >? 2
|
|
168
|
-
yticks = if @cfg.bump => [1 to ((@parsed.length or 1) >? 1)]
|
|
205
|
+
yticks = if @cfg.mode == \bump => [1 to ((@parsed.length or 1) >? 1)]
|
|
169
206
|
else @scale.y.ticks((@cfg.{}yaxis.tick-count or 4) <? max-tick)
|
|
170
207
|
yfmt = chart.utils.format.auto yticks
|
|
171
208
|
|
|
@@ -175,7 +212,7 @@ mod = ({context, t}) ->
|
|
|
175
212
|
@yaxis.config @cfg.yaxis
|
|
176
213
|
@yaxis.ticks yticks
|
|
177
214
|
@yaxis.scale @scale.y
|
|
178
|
-
if @cfg.bump =>
|
|
215
|
+
if @cfg.mode == \bump =>
|
|
179
216
|
@yaxis.caption t \rank
|
|
180
217
|
else
|
|
181
218
|
if @parsed.length > 1 =>
|
|
@@ -217,7 +254,7 @@ mod = ({context, t}) ->
|
|
|
217
254
|
..enter!append \path .attr \class, \data
|
|
218
255
|
.attr \fill, \none
|
|
219
256
|
.attr \d, (d,i) ~>
|
|
220
|
-
if @cfg.
|
|
257
|
+
if @cfg.mode in <[streamgraph area]> => @area d.pts
|
|
221
258
|
else @line d.pts
|
|
222
259
|
.attr \stroke, (d,i) ~> @tint.get d.color
|
|
223
260
|
.attr \stroke-width, 1
|
|
@@ -225,12 +262,12 @@ mod = ({context, t}) ->
|
|
|
225
262
|
.transition!duration 150
|
|
226
263
|
.style \opacity, (d,i) ~> if @legend.is-selected(d.bind.key) => 1 else 0.3
|
|
227
264
|
.attr \d, (d,i) ~>
|
|
228
|
-
if @cfg.
|
|
265
|
+
if @cfg.mode in <[streamgraph area]> => @area d.pts
|
|
229
266
|
else @line d.pts
|
|
230
267
|
.attr \stroke, (d,i) ~> @tint.get d.color
|
|
231
|
-
.attr \fill, (d,i) ~> if @cfg.
|
|
268
|
+
.attr \fill, (d,i) ~> if @cfg.mode in <[streamgraph area]> => @tint.get(d.color) else \none
|
|
232
269
|
.attr \fill-opacity, ~> \0.5
|
|
233
|
-
@g.view.selectAll \g.dot .data(@parsed, -> it.bind.key)
|
|
270
|
+
@g.view.selectAll \g.dot .data((if @cfg.show-dot => @parsed else []), -> it.bind.key)
|
|
234
271
|
..exit!remove!
|
|
235
272
|
..enter!append \g .attr \class, \dot
|
|
236
273
|
@g.view.selectAll \g.dot
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
<-(->it!) _
|
|
2
|
+
|
|
3
|
+
block-factory =
|
|
4
|
+
pkg:
|
|
5
|
+
name: 'taiwancounty', version: '0.0.1'
|
|
6
|
+
extend: {name: "base", version: "0.0.1"}
|
|
7
|
+
dependencies: [
|
|
8
|
+
{url: "https://d3js.org/topojson.v2.min.js", async: false}
|
|
9
|
+
{url: "https://d3js.org/d3-geo.v2.min.js", async: false}
|
|
10
|
+
{name: "pdmaptw", version: "local", path: "index.min.js", async: false}
|
|
11
|
+
{name: "pdmaptw", version: "local", path: "county.map.js"}
|
|
12
|
+
]
|
|
13
|
+
init: ({root, context, pubsub}) ->
|
|
14
|
+
pubsub.fire \init, mod: mod {context} .then ~> it.0
|
|
15
|
+
|
|
16
|
+
mod = ({context}) ->
|
|
17
|
+
{chart, d3, ldcolor, pdmaptw, topojson} = context
|
|
18
|
+
sample: ->
|
|
19
|
+
pdmaptw.get('county').then ({meta, topo}) ->
|
|
20
|
+
raw: meta.name.map -> {val: Math.random!, name: pdmaptw.normalize it}
|
|
21
|
+
binding: color: {key: \val}, name: {key: \name}
|
|
22
|
+
config:
|
|
23
|
+
palette: type: \palette
|
|
24
|
+
dimension:
|
|
25
|
+
name: {type: \N, name: "國家"}
|
|
26
|
+
color: {type: \R, name: "顏色"}
|
|
27
|
+
init: ->
|
|
28
|
+
@g = @layout.get-group \view
|
|
29
|
+
@obj = new pdmaptw {root: @g, type: \county}
|
|
30
|
+
@scale = scale = {color: d3.interpolateTurbo}
|
|
31
|
+
@legend = new chart.utils.legend do
|
|
32
|
+
root: @root
|
|
33
|
+
name: \legend
|
|
34
|
+
layout: @layout
|
|
35
|
+
shape: (d) -> d3.select(@).attr \fill, scale.color d.key
|
|
36
|
+
@tip = new chart.utils.tip {
|
|
37
|
+
root: @root,
|
|
38
|
+
accessor: ({evt}) ~>
|
|
39
|
+
if !(evt.target and data = d3.select(evt.target).datum!) => return null
|
|
40
|
+
return {name: data.data.name, value: data.data.color}
|
|
41
|
+
range: ~> return @layout.get-node \view .getBoundingClientRect!
|
|
42
|
+
}
|
|
43
|
+
@obj.init!then ~> @obj.fit {node: @g, box: @layout.get-node(\view).getBoundingClientRect!}
|
|
44
|
+
|
|
45
|
+
parse: ->
|
|
46
|
+
@extent = c: [undefined, undefined]
|
|
47
|
+
d3.select @svg .selectAll \path .each (d,i) ~>
|
|
48
|
+
d.data = @data.filter(-> it.name == d.properties.name).0 or {}
|
|
49
|
+
if !(@extent.c.0?) or d.data.color < @extent.c.0 => @extent.c.0 = d.data.color
|
|
50
|
+
if !(@extent.c.1?) or d.data.color > @extent.c.1 => @extent.c.1 = d.data.color
|
|
51
|
+
|
|
52
|
+
resize: ->
|
|
53
|
+
@tip.toggle(if @cfg.{}tip.enabled? => @cfg.tip.enabled else true)
|
|
54
|
+
@obj.fit @layout.get-box \view
|
|
55
|
+
pal = if @cfg.palette => @cfg.palette.colors else <[#f00 #999 #00f]>
|
|
56
|
+
len = pal.length
|
|
57
|
+
@ticks = d3.quantize((~> (1 - it) * (@extent.c.1 - @extent.c.0) + @extent.c.0), len).map ~>
|
|
58
|
+
{key: it, text: d3.format(@cfg.legend-format or '.2f')(it) + (if @binding.color.unit => that else '')}
|
|
59
|
+
@ticks.sort (a,b) -> a.key - b.key
|
|
60
|
+
if @cfg.palette =>
|
|
61
|
+
@scale.color = d3.scaleLinear!
|
|
62
|
+
.domain @ticks.map(-> it.key)
|
|
63
|
+
.range pal.map -> ldcolor.web(it.value or it)
|
|
64
|
+
@legend.data @ticks
|
|
65
|
+
@obj.fit {node: @g, box: @layout.get-box(\view)}
|
|
66
|
+
|
|
67
|
+
render: ->
|
|
68
|
+
d3.select @svg .selectAll \path
|
|
69
|
+
.transition!duration 350
|
|
70
|
+
.attr \fill, (d,i) ~> @scale.color d.data.color
|
|
71
|
+
.attr \fill-opacity, (d,i) ~> if @cfg.dim-empty => (if d.data.color? => 1 else 0.2) else 1
|
|
72
|
+
@legend.render!
|
|
73
|
+
|
|
74
|
+
return block-factory
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
div
|
|
2
|
+
div(plug="layout")
|
|
3
|
+
.pdl-layout
|
|
4
|
+
div(data-type="layout")
|
|
5
|
+
.pdl-cell(data-name="view")
|
|
6
|
+
.pdl-cell(data-name="legend") 123
|
|
7
|
+
div(data-type="render")
|
|
8
|
+
style(type="text/css"): :stylus
|
|
9
|
+
.pdl-layout > div[data-type=layout]
|
|
10
|
+
display: grid
|
|
11
|
+
grid-template-columns: 1fr fit-content(5em)
|
|
12
|
+
script(type="@plotdb/block"): include:lsc index.ls
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
//-div: script(type="@plotdb/block"): :lsc
|
|
16
|
+
{
|
|
17
|
+
pkg:
|
|
18
|
+
name: 'taiwantown', version: '0.0.1'
|
|
19
|
+
dependencies: [
|
|
20
|
+
{url: "https://d3js.org/d3.v4.js", async: false}
|
|
21
|
+
"https://d3js.org/d3-format.v2.min.js"
|
|
22
|
+
"https://d3js.org/d3-array.v2.min.js"
|
|
23
|
+
"https://d3js.org/topojson.v2.min.js"
|
|
24
|
+
{url: "https://d3js.org/d3-color.v1.min.js", async: false}
|
|
25
|
+
{url: "https://d3js.org/d3-interpolate.v1.min.js", async: false}
|
|
26
|
+
{url: "https://d3js.org/d3-scale-chromatic.v1.min.js", async: false}
|
|
27
|
+
"/js/map.list.js"
|
|
28
|
+
"https://cdn.jsdelivr.net/npm/pdmaptw@0.0.2/dist/pdmaptw.min.js"
|
|
29
|
+
]
|
|
30
|
+
init: ({root, context}) ->
|
|
31
|
+
counties = context.counties.map (d,i) -> {val: Math.random!, county: d}
|
|
32
|
+
towns = context.towns.map (d,i) -> {val: Math.random!, town: d}
|
|
33
|
+
c = new chart do
|
|
34
|
+
root: root
|
|
35
|
+
raw: towns
|
|
36
|
+
mod: @mod({context})
|
|
37
|
+
binding: do
|
|
38
|
+
color: {name: \val}
|
|
39
|
+
name: {name: \town}
|
|
40
|
+
c.init!then -> c.render!
|
|
41
|
+
@c = c
|
|
42
|
+
|
|
43
|
+
interface: -> @c
|
|
44
|
+
|
|
45
|
+
mod: ({context}) ->
|
|
46
|
+
return do
|
|
47
|
+
init: ->
|
|
48
|
+
@obj = context.pdmaptw.create do
|
|
49
|
+
root: @svg
|
|
50
|
+
type: \town
|
|
51
|
+
baseurl: 'https://cdn.jsdelivr.net/npm/pdmaptw@0.0.2/dist'
|
|
52
|
+
@obj.init!then ~> @obj.fit!
|
|
53
|
+
parse: ->
|
|
54
|
+
d3.select @svg .selectAll \path .each (d,i) ~>
|
|
55
|
+
d.data = @data.filter(-> it.name == d.properties.name).0 or {}
|
|
56
|
+
resize: -> #@obj.fit!
|
|
57
|
+
render: ->
|
|
58
|
+
@color = d3.interpolateTurbo
|
|
59
|
+
if config.pal => @color = d3.interpolateDiscrete config.pal
|
|
60
|
+
d3.select @svg .selectAll \path
|
|
61
|
+
.transition!duration 350
|
|
62
|
+
.attr \fill, (d,i) ~> @color d.data.color
|
|
63
|
+
|
|
64
|
+
}
|
|
@@ -55,7 +55,6 @@ mod = ({context}) ->
|
|
|
55
55
|
.filter -> it.c
|
|
56
56
|
.map -> it.c <<< {value: it.v.color, data: it.v}
|
|
57
57
|
geo-data.map (d) -> d.data = d.properties.data or {}
|
|
58
|
-
|
|
59
58
|
@extent = c: d3.extent(geo-data, -> it.properties.value)
|
|
60
59
|
|
|
61
60
|
resize: ->
|
|
@@ -74,7 +73,6 @@ mod = ({context}) ->
|
|
|
74
73
|
|
|
75
74
|
render: ->
|
|
76
75
|
@legend.render!
|
|
77
|
-
|
|
78
76
|
d3.select @g .selectAll \path
|
|
79
77
|
.transition!duration 350
|
|
80
78
|
.attr \fill, (d,i) ~> @scale.color d.properties.value
|
package/web/src/pug/index.pug
CHANGED
|
@@ -41,12 +41,11 @@ block script
|
|
|
41
41
|
+script("https://polyfill.io/v3/polyfill.min.js?features=ResizeObserver")
|
|
42
42
|
+script("/assets/lib/proxise/main/proxise.js")
|
|
43
43
|
+script("/assets/lib/@loadingio/debounce.js/main/debounce.min.js")
|
|
44
|
-
+script("/assets/lib/@plotdb/csscope/main/
|
|
45
|
-
+script("/assets/lib/@plotdb/rescope/main/
|
|
46
|
-
+script("/assets/lib/@plotdb/block/main/
|
|
47
|
-
+script("/assets/lib/@plotdb/konfig/main/
|
|
44
|
+
+script("/assets/lib/@plotdb/csscope/main/index.min.js")
|
|
45
|
+
+script("/assets/lib/@plotdb/rescope/main/index.min.js")
|
|
46
|
+
+script("/assets/lib/@plotdb/block/main/index.min.js")
|
|
47
|
+
+script("/assets/lib/@plotdb/konfig/main/index.min.js")
|
|
48
48
|
+script("/assets/lib/@plotdb/konfig/main/konfig.widget.bootstrap.js")
|
|
49
49
|
+script("/assets/lib/ldpalettepicker/main/ldpp.min.js")
|
|
50
50
|
+script("/assets/lib/ldpalettepicker/main/all.palettes.js")
|
|
51
|
-
//+script("/assets/block/cache.js")
|
|
52
51
|
script: include:lsc index.ls
|