Browse Source

Fix y tick format option

pull/18/head
Masayuki Tanaka 11 years ago
parent
commit
dc9b274279
  1. 8
      c3.js
  2. 32
      c3.min.js

8
c3.js

@ -88,7 +88,7 @@
// not used
//__axis_y_rescale = getConfig(['axis', 'y', 'rescale'], true),
__axis_y_inner = getConfig(['axis', 'y', 'inner'], false),
__axis_y_format = getConfig(['axis', 'y', 'format'], function (d) { return d; }),
__axis_y_tick_format = getConfig(['axis', 'y', 'tick', 'format'], function (d) { return d; }),
__axis_y_padding = getConfig(['axis', 'y', 'padding'], null),
__axis_y_ticks = getConfig(['axis', 'y', 'ticks'], 10),
__axis_y2_show = getConfig(['axis', 'y2', 'show'], false),
@ -99,7 +99,7 @@
// __axis_y2_label = getConfig(['axis', 'y2', 'text'], null),
// __axis_y2_rescale = getConfig(['axis', 'y2', 'rescale'], true),
__axis_y2_inner = getConfig(['axis', 'y2', 'inner'], false),
__axis_y2_format = getConfig(['axis', 'y2', 'format'], function (d) { return d; }),
__axis_y2_tick_format = getConfig(['axis', 'y2', 'tick', 'format'], function (d) { return d; }),
__axis_y2_padding = getConfig(['axis', 'y2', 'padding'], null),
__axis_y2_ticks = getConfig(['axis', 'y2', 'ticks'], 10),
__axis_rotated = getConfig(['axis', 'rotated'], false);
@ -1082,8 +1082,8 @@
// Set axes attrs
xAxis.ticks(data.length < 10 ? data.length : 10);
yAxis.ticks(__axis_y_ticks).outerTickSize(0).tickFormat(__axis_y_format);
yAxis2.ticks(__axis_y2_ticks).outerTickSize(0).tickFormat(__axis_y2_format);
yAxis.ticks(__axis_y_ticks).outerTickSize(0).tickFormat(__axis_y_tick_format);
yAxis2.ticks(__axis_y2_ticks).outerTickSize(0).tickFormat(__axis_y2_tick_format);
// Save original x domain for zoom update
orgXDomain = x.domain();

32
c3.min.js vendored

@ -55,19 +55,19 @@ a}).transition().duration(100).style("opacity",0.3);h.focus(a)}).on("mouseout",f
10);e.append("text").text(function(a){return n(Ka[a])?Ka[a]:a}).attr("x",-200).attr("y",function(){return ma/2});za.selectAll("rect.legend-item-event").data(d).transition().duration(k?250:0).attr("x",function(a,b){return g+Ua*b});za.selectAll("rect.legend-item-tile").data(d).transition().duration(k?250:0).attr("x",function(a,b){return g+Ua*b});za.selectAll("text").data(d).transition().duration(k?250:0).attr("x",function(a,b){return g+Ua*b+14})}function Va(a){return n(a)?".target-"+a:".target"}var h=
{data:{}},eb={},Z="_expanded_",ja="_selected_",Kb="_included_",wa=e(["bindto"],"#chart"),Ya=e(["size","width"],null),Yb=e(["size","height"],null),Ub=e(["padding","left"],null),Sb=e(["padding","right"],null),ra=e(["zoom","enabled"],!1),Lc=e(["zoom","extent"],null),Cd=e(["zoom","privileged"],!1),vd=e(["onenter"],function(){}),wd=e(["onleave"],function(){});if(!("data"in $))throw Error("data is required in config");var qa=e(["data","x"],null),X=e(["data","xs"],null),xb=e(["data","x_format"],"%Y-%m-%d"),
gd=e(["data","id_converter"],function(a){return a}),Ka=e(["data","names"],{}),t=e(["data","groups"],[]),ac=e(["data","axes"],{}),ha=e(["data","types"],{}),Mc=e(["data","regions"],{}),Ld=e(["data","colors"],{}),ia=e(["data","selection","enabled"],!1),sa=e(["data","selection","grouped"],!1),ta=e(["data","selection","isselectable"],function(){return!0}),ya=e(["subchart","show"],!1),Qb=ya?e(["subchart","size","height"],60):0,Md=e(["color","pattern"],null),Aa=e(["legend","show"],!0),Ua=e(["legend","item",
"width"],80),Kd=e(["legend","item","onclick"],function(){}),Nc=e(["axis","x","type"],"indexed"),Ga=e(["axis","x","categories"],[]),Vc=e(["axis","x","tick","centered"],!1),cb=e(["axis","x","tick","format"],null),jb=e(["axis","x","default"],null),xd=e(["axis","x","label"],null),ad=e(["axis","y","max"],null),Zc=e(["axis","y","min"],null),cd=e(["axis","y","center"],null),yd=e(["axis","y","label"],null),ob=e(["axis","y","inner"],!1),sd=e(["axis","y","format"],function(a){return a}),Ia=e(["axis","y","padding"],
null),rd=e(["axis","y","ticks"],10),Tb=e(["axis","y2","show"],!1),$c=e(["axis","y2","max"],null),Yc=e(["axis","y2","min"],null),bd=e(["axis","y2","center"],null),nb=e(["axis","y2","inner"],!1),ud=e(["axis","y2","format"],function(a){return a}),Ja=e(["axis","y2","padding"],null),td=e(["axis","y2","ticks"],10),g=e(["axis","rotated"],!1),Dc=e(["grid","x","show"],!1),Gd=e(["grid","x","type"],"tick"),Eb=e(["grid","x","lines"],null),Ec=e(["grid","y","show"],!1),Fb=e(["grid","y","lines"],null),Bb=e(["point",
"show"],!0)?e(["point","r"],2.5):0,zd=e(["point","focus","line","enabled"],!0),Gb=e(["point","focus","expand","enabled"],!0),Hb=e(["point","focus","expand","r"],Gb?4:Bb),Pa=e(["point","focus","select","r"],8),Fd=e(["point","onclick"],function(){}),nd=e(["point","onselected"],function(){}),od=e(["point","onunselected"],function(){}),K=e(["regions"],[]),mc=e(["tooltip","contents"],function(a){var b="<table class='-tooltip'><tr><th colspan='2'>"+I()(a[0].x)+"</th></tr>",c,e,g;for(c=0;c<a.length;c++)n(a[c])?
(e=n(a[c].value)?(Math.round(100*a[c].value)/100).toFixed(2):"-",g=a[c].name):g=e="-",b+="<tr class='-tooltip-name-"+a[c].id+"'><td class='name'><span style='background-color:"+Y(a[c].id)+"'></span>"+g+"</td><td class='value'>"+e+"</td></tr>";return b+"</table>"}),Dd=e(["tooltip","init","show"],!1),Ba=e(["tooltip","init","x"],0),Gc=e(["tooltip","init","position"],{top:"0px",left:"50px"}),Db=wa.replace("#","")+"-clip",Ra="url(#"+Db+")",A="timeseries"===Nc,ea="categorized"===Nc,rb=!A&&(qa||X),Jb=null,
Sa=!1,Ib=!1,ma=Aa?40:0,Y=function(a,b){var c=[],e=null!==b?b:"#1f77b4 #ff7f0e #2ca02c #d62728 #9467bd #8c564b #e377c2 #7f7f7f #bcbd22 #17becf".split(" ");return function(b){if(b in a)return a[b];-1===c.indexOf(b)&&c.push(b);return e[c.indexOf(b)%e.length]}}(Ld,Md),Wc=function(){var a=[[c.time.format("%Y/%-m/%-d"),function(){return!0}],[c.time.format("%-m/%-d"),function(a){return a.getMonth()}],[c.time.format("%-m/%-d"),function(a){return 1!==a.getDate()}],[c.time.format("%-m/%-d"),function(a){return a.getDay()&&
1!==a.getDate()}],[c.time.format("%I %p"),function(a){return a.getHours()}],[c.time.format("%I:%M"),function(a){return a.getMinutes()}],[c.time.format(":%S"),function(a){return a.getSeconds()}],[c.time.format(".%L"),function(a){return a.getMilliseconds()}]];return function(b){for(var c=a.length-1,e=a[c];!e[1](b);)e=a[--c];return e[0](b)}}(),Pb,Wb,Rb,Za,Vb,Xb,q,p,na,mb,va,Zb,$b,pb,qb,m,u,V,da,$a,ab,z,oa,bb,Fa,Rc=g?"left":"bottom",Sc=g?ob?"top":"bottom":ob?"right":"left",Tc=g?nb?"bottom":"top":nb?"left":
"right",Uc="bottom",J={main:function(){return"translate("+y+","+r+")"},context:function(){return"translate("+l+","+Ca+")"},legend:function(){return"translate("+Nb+","+Mb+")"},y2:function(){return"translate("+(g?0:q)+","+(g?10:0)+")"},x:function(){return"translate(0,"+p+")"},subx:function(){return"translate(0,"+na+")"}},Hd=function(){var a=c.svg.line().x(g?function(a){return E(a.id)(a.value)}:gb).y(g?gb:function(a){return E(a.id)(a.value)});return function(b){var c=Ac(b.values),e;if(wb(b))return"spline"===
ha["string"===typeof b?b:b.id]?a.interpolate("cardinal"):a.interpolate("linear"),Mc[b.id]?qd(c,m,E(b.id),Mc[b.id]):a(c);e=m(c[0].x);b=E(b.id)(c[0].value);return g?"M "+b+" "+e:"M "+e+" "+b}}(),Id=function(){var a=c.svg.line().x(function(a){return da(a.x)}).y(function(a){return T(a.id)(a.value)});return function(b){var c=Ac(b.values);return wb(b)?a(c):"M "+da(c[0].x)+" "+T(b.id)(c[0].value)}}(),G=c.svg.brush().on("brush",function(){C({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0})}),
B=c.behavior.zoom().on("zoomstart",function(){B.altDomain=c.event.sourceEvent.altKey?m.orgDomain():null}).on("zoom",ra?Jd:null);G.update=function(){v&&v.select(".x.brush").call(this);return this};B.orgScaleExtent=function(){var a=Lc?Lc:[1,10];return[a[0],Math.max(Na()/a[1],a[1])]};B.updateScaleExtent=function(){var a=m.orgDomain(),a=(a[1]-a[0])/(W[1]-W[0]),b=this.orgScaleExtent();this.scaleExtent([b[0]*a,b[1]*a]);return this};var Qa,ib,k,v,za,P,hb,xa=null,Ma=null,W;h.focus=function(a){h.defocus();
c.selectAll(Va(a)).filter(function(a){return tb(a.id)}).classed("focused",!0).transition().duration(100).style("opacity",1)};h.defocus=function(a){c.selectAll(Va(a)).filter(function(a){return tb(a.id)}).classed("focused",!1).transition().duration(100).style("opacity",0.3)};h.revert=function(a){c.selectAll(Va(a)).filter(function(a){return tb(a.id)}).classed("focused",!1).transition().duration(100).style("opacity",1)};h.show=function(a){c.selectAll(Va(a)).transition().style("opacity",1)};h.hide=function(a){c.selectAll(Va(a)).transition().style("opacity",
0)};h.unzoom=function(){G.clear().update();C({withUpdateXDomain:!0})};h.load=function(a){s(a.done)&&(a.done=function(){});"categories"in a&&ea&&(Ga=a.categories,z.categories(Ga));if("cacheIds"in a&&Wa(a.cacheIds))Ta(Xa(a.cacheIds),a.done);else if("data"in a)Ta(La(a.data),a.done);else if("url"in a)c.csv(a.url,function(b,c){Ta(La(c),a.done)});else if("rows"in a)Ta(La(dc(a.rows)),a.done);else if("columns"in a)Ta(La(ec(a.columns)),a.done);else throw Error("url or rows or columns is required.");};h.unload=
function(a){h.data.targets=h.data.targets.filter(function(b){return b.id!==a});c.selectAll(".target-"+a).transition().style("opacity",0).remove();Aa&&(c.selectAll(".legend-item-"+a).remove(),kb(h.data.targets));0<h.data.targets.length&&C()};h.selected=function(a){a=n(a)?"-"+a:"";return c.merge(k.selectAll(".-shapes"+a).selectAll(".-shape").filter(function(){return c.select(this).classed(ja)}).map(function(a){return a.map(function(a){return a.__data__})}))};h.select=function(a,b,d){ia&&k.selectAll(".-shapes").selectAll(".-shape").each(function(e,
g){var h="circle"===this.nodeName?wc:pd,k="circle"===this.nodeName?yb:yc;0<=b.indexOf(g)?ta(e)&&(sa||s(a)||0<=a.indexOf(e.id))&&h(c.select(this).classed(ja,!0),e,g):n(d)&&d&&k(c.select(this).classed(ja,!1),e,g)})};h.unselect=function(a,b){ia&&k.selectAll(".-shapes").selectAll(".-shape").each(function(d,e){var g="circle"===this.nodeName?yb:yc;(s(b)||0<=b.indexOf(e))&&ta(d)&&(sa||s(a)||0<=a.indexOf(d.id))&&g(c.select(this).classed(ja,!1),d,e)})};h.toLine=function(a){vb(a,"line");C()};h.toSpline=function(a){vb(a,
"spline");C()};h.toBar=function(a){vb(a,"bar");C()};h.groups=function(a){if(s(a))return t;t=a;C();return t};h.regions=function(a){if(s(a))return K;K=a;C();return K};h.regions.add=function(a){if(s(a))return K;K=K.concat(a);C();return K};h.regions.remove=function(a,b){var d=[].concat(a);b=n(b)?b:{};d.forEach(function(a){var d=c.selectAll("."+a);n(b.duration)&&(d=d.transition().duration(b.duration).style("fill-opacity",0));d.remove();K=K.filter(function(b){return 0>b.classes.indexOf(a)})});return K};
h.data.get=function(a){a=h.data.getAsTarget(a);return n(a)?a.values.map(function(a){return a.value}):void 0};h.data.getAsTarget=function(a){var b=db(function(b){return b.id===a});return 0<b.length?b[0]:void 0};h.destroy=function(){h.data.targets=void 0;h.data.x={};hb.html("");Q.onresize=null};if("url"in $.data)c.csv($.data.url,function(a,b){Cb(b)});else if("rows"in $.data)Cb(dc($.data.rows));else if("columns"in $.data)Cb(ec($.data.columns));else throw Error("url or rows or columns is required.");
return h}})(window);
"width"],80),Kd=e(["legend","item","onclick"],function(){}),Nc=e(["axis","x","type"],"indexed"),Ga=e(["axis","x","categories"],[]),Vc=e(["axis","x","tick","centered"],!1),cb=e(["axis","x","tick","format"],null),jb=e(["axis","x","default"],null),xd=e(["axis","x","label"],null),ad=e(["axis","y","max"],null),Zc=e(["axis","y","min"],null),cd=e(["axis","y","center"],null),yd=e(["axis","y","label"],null),ob=e(["axis","y","inner"],!1),sd=e(["axis","y","tick","format"],function(a){return a}),Ia=e(["axis",
"y","padding"],null),rd=e(["axis","y","ticks"],10),Tb=e(["axis","y2","show"],!1),$c=e(["axis","y2","max"],null),Yc=e(["axis","y2","min"],null),bd=e(["axis","y2","center"],null),nb=e(["axis","y2","inner"],!1),ud=e(["axis","y2","tick","format"],function(a){return a}),Ja=e(["axis","y2","padding"],null),td=e(["axis","y2","ticks"],10),g=e(["axis","rotated"],!1),Dc=e(["grid","x","show"],!1),Gd=e(["grid","x","type"],"tick"),Eb=e(["grid","x","lines"],null),Ec=e(["grid","y","show"],!1),Fb=e(["grid","y","lines"],
null),Bb=e(["point","show"],!0)?e(["point","r"],2.5):0,zd=e(["point","focus","line","enabled"],!0),Gb=e(["point","focus","expand","enabled"],!0),Hb=e(["point","focus","expand","r"],Gb?4:Bb),Pa=e(["point","focus","select","r"],8),Fd=e(["point","onclick"],function(){}),nd=e(["point","onselected"],function(){}),od=e(["point","onunselected"],function(){}),K=e(["regions"],[]),mc=e(["tooltip","contents"],function(a){var b="<table class='-tooltip'><tr><th colspan='2'>"+I()(a[0].x)+"</th></tr>",c,e,g;for(c=
0;c<a.length;c++)n(a[c])?(e=n(a[c].value)?(Math.round(100*a[c].value)/100).toFixed(2):"-",g=a[c].name):g=e="-",b+="<tr class='-tooltip-name-"+a[c].id+"'><td class='name'><span style='background-color:"+Y(a[c].id)+"'></span>"+g+"</td><td class='value'>"+e+"</td></tr>";return b+"</table>"}),Dd=e(["tooltip","init","show"],!1),Ba=e(["tooltip","init","x"],0),Gc=e(["tooltip","init","position"],{top:"0px",left:"50px"}),Db=wa.replace("#","")+"-clip",Ra="url(#"+Db+")",A="timeseries"===Nc,ea="categorized"===
Nc,rb=!A&&(qa||X),Jb=null,Sa=!1,Ib=!1,ma=Aa?40:0,Y=function(a,b){var c=[],e=null!==b?b:"#1f77b4 #ff7f0e #2ca02c #d62728 #9467bd #8c564b #e377c2 #7f7f7f #bcbd22 #17becf".split(" ");return function(b){if(b in a)return a[b];-1===c.indexOf(b)&&c.push(b);return e[c.indexOf(b)%e.length]}}(Ld,Md),Wc=function(){var a=[[c.time.format("%Y/%-m/%-d"),function(){return!0}],[c.time.format("%-m/%-d"),function(a){return a.getMonth()}],[c.time.format("%-m/%-d"),function(a){return 1!==a.getDate()}],[c.time.format("%-m/%-d"),
function(a){return a.getDay()&&1!==a.getDate()}],[c.time.format("%I %p"),function(a){return a.getHours()}],[c.time.format("%I:%M"),function(a){return a.getMinutes()}],[c.time.format(":%S"),function(a){return a.getSeconds()}],[c.time.format(".%L"),function(a){return a.getMilliseconds()}]];return function(b){for(var c=a.length-1,e=a[c];!e[1](b);)e=a[--c];return e[0](b)}}(),Pb,Wb,Rb,Za,Vb,Xb,q,p,na,mb,va,Zb,$b,pb,qb,m,u,V,da,$a,ab,z,oa,bb,Fa,Rc=g?"left":"bottom",Sc=g?ob?"top":"bottom":ob?"right":"left",
Tc=g?nb?"bottom":"top":nb?"left":"right",Uc="bottom",J={main:function(){return"translate("+y+","+r+")"},context:function(){return"translate("+l+","+Ca+")"},legend:function(){return"translate("+Nb+","+Mb+")"},y2:function(){return"translate("+(g?0:q)+","+(g?10:0)+")"},x:function(){return"translate(0,"+p+")"},subx:function(){return"translate(0,"+na+")"}},Hd=function(){var a=c.svg.line().x(g?function(a){return E(a.id)(a.value)}:gb).y(g?gb:function(a){return E(a.id)(a.value)});return function(b){var c=
Ac(b.values),e;if(wb(b))return"spline"===ha["string"===typeof b?b:b.id]?a.interpolate("cardinal"):a.interpolate("linear"),Mc[b.id]?qd(c,m,E(b.id),Mc[b.id]):a(c);e=m(c[0].x);b=E(b.id)(c[0].value);return g?"M "+b+" "+e:"M "+e+" "+b}}(),Id=function(){var a=c.svg.line().x(function(a){return da(a.x)}).y(function(a){return T(a.id)(a.value)});return function(b){var c=Ac(b.values);return wb(b)?a(c):"M "+da(c[0].x)+" "+T(b.id)(c[0].value)}}(),G=c.svg.brush().on("brush",function(){C({withTransition:!1,withY:!1,
withSubchart:!1,withUpdateXDomain:!0})}),B=c.behavior.zoom().on("zoomstart",function(){B.altDomain=c.event.sourceEvent.altKey?m.orgDomain():null}).on("zoom",ra?Jd:null);G.update=function(){v&&v.select(".x.brush").call(this);return this};B.orgScaleExtent=function(){var a=Lc?Lc:[1,10];return[a[0],Math.max(Na()/a[1],a[1])]};B.updateScaleExtent=function(){var a=m.orgDomain(),a=(a[1]-a[0])/(W[1]-W[0]),b=this.orgScaleExtent();this.scaleExtent([b[0]*a,b[1]*a]);return this};var Qa,ib,k,v,za,P,hb,xa=null,
Ma=null,W;h.focus=function(a){h.defocus();c.selectAll(Va(a)).filter(function(a){return tb(a.id)}).classed("focused",!0).transition().duration(100).style("opacity",1)};h.defocus=function(a){c.selectAll(Va(a)).filter(function(a){return tb(a.id)}).classed("focused",!1).transition().duration(100).style("opacity",0.3)};h.revert=function(a){c.selectAll(Va(a)).filter(function(a){return tb(a.id)}).classed("focused",!1).transition().duration(100).style("opacity",1)};h.show=function(a){c.selectAll(Va(a)).transition().style("opacity",
1)};h.hide=function(a){c.selectAll(Va(a)).transition().style("opacity",0)};h.unzoom=function(){G.clear().update();C({withUpdateXDomain:!0})};h.load=function(a){s(a.done)&&(a.done=function(){});"categories"in a&&ea&&(Ga=a.categories,z.categories(Ga));if("cacheIds"in a&&Wa(a.cacheIds))Ta(Xa(a.cacheIds),a.done);else if("data"in a)Ta(La(a.data),a.done);else if("url"in a)c.csv(a.url,function(b,c){Ta(La(c),a.done)});else if("rows"in a)Ta(La(dc(a.rows)),a.done);else if("columns"in a)Ta(La(ec(a.columns)),
a.done);else throw Error("url or rows or columns is required.");};h.unload=function(a){h.data.targets=h.data.targets.filter(function(b){return b.id!==a});c.selectAll(".target-"+a).transition().style("opacity",0).remove();Aa&&(c.selectAll(".legend-item-"+a).remove(),kb(h.data.targets));0<h.data.targets.length&&C()};h.selected=function(a){a=n(a)?"-"+a:"";return c.merge(k.selectAll(".-shapes"+a).selectAll(".-shape").filter(function(){return c.select(this).classed(ja)}).map(function(a){return a.map(function(a){return a.__data__})}))};
h.select=function(a,b,d){ia&&k.selectAll(".-shapes").selectAll(".-shape").each(function(e,g){var h="circle"===this.nodeName?wc:pd,k="circle"===this.nodeName?yb:yc;0<=b.indexOf(g)?ta(e)&&(sa||s(a)||0<=a.indexOf(e.id))&&h(c.select(this).classed(ja,!0),e,g):n(d)&&d&&k(c.select(this).classed(ja,!1),e,g)})};h.unselect=function(a,b){ia&&k.selectAll(".-shapes").selectAll(".-shape").each(function(d,e){var g="circle"===this.nodeName?yb:yc;(s(b)||0<=b.indexOf(e))&&ta(d)&&(sa||s(a)||0<=a.indexOf(d.id))&&g(c.select(this).classed(ja,
!1),d,e)})};h.toLine=function(a){vb(a,"line");C()};h.toSpline=function(a){vb(a,"spline");C()};h.toBar=function(a){vb(a,"bar");C()};h.groups=function(a){if(s(a))return t;t=a;C();return t};h.regions=function(a){if(s(a))return K;K=a;C();return K};h.regions.add=function(a){if(s(a))return K;K=K.concat(a);C();return K};h.regions.remove=function(a,b){var d=[].concat(a);b=n(b)?b:{};d.forEach(function(a){var d=c.selectAll("."+a);n(b.duration)&&(d=d.transition().duration(b.duration).style("fill-opacity",0));
d.remove();K=K.filter(function(b){return 0>b.classes.indexOf(a)})});return K};h.data.get=function(a){a=h.data.getAsTarget(a);return n(a)?a.values.map(function(a){return a.value}):void 0};h.data.getAsTarget=function(a){var b=db(function(b){return b.id===a});return 0<b.length?b[0]:void 0};h.destroy=function(){h.data.targets=void 0;h.data.x={};hb.html("");Q.onresize=null};if("url"in $.data)c.csv($.data.url,function(a,b){Cb(b)});else if("rows"in $.data)Cb(dc($.data.rows));else if("columns"in $.data)Cb(ec($.data.columns));
else throw Error("url or rows or columns is required.");return h}})(window);

Loading…
Cancel
Save