From 7ef93c7b2132963a77e78eda6454e964a066dd6e Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Sun, 27 Oct 2013 16:44:00 +0900 Subject: [PATCH] Fix trivial --- c3.js | 40 ++++++++--------- c3.min.js | 126 +++++++++++++++++++++++++++--------------------------- 2 files changed, 82 insertions(+), 84 deletions(-) diff --git a/c3.js b/c3.js index af4ece7..222bdfa 100644 --- a/c3.js +++ b/c3.js @@ -250,17 +250,6 @@ }; })(); - // For region - var regionStart = function (d) { - return ('start' in d) ? x(isTimeSeries ? parseDate(d.start) : d.start) : 0; - }; - var regionWidth = function (d) { - var start = regionStart(d), - end = ('end' in d) ? x(isTimeSeries ? parseDate(d.end) : d.end) : width, - w = end - start; - return (w < 0) ? 0 : w; - }; - // Define color var color = generateColor(__data_colors, __color_pattern); @@ -366,6 +355,12 @@ function getY (min, max) { return d3.scale.linear().range([min, max]); } + function getYScale (id) { + return getAxisId(id) === 'y2' ? y2 : y; + } + function getSubYScale (id) { + return getAxisId(id) === 'y2' ? subY2 : subY; + } //-- Axis --// @@ -385,6 +380,9 @@ function getYAxis (scale, orient) { return d3.svg.axis().scale(scale).orient(orient); } + function getAxisId (id) { + return id in __data_axes ? __data_axes[id] : 'y'; + } //-- Domain --// @@ -469,17 +467,17 @@ return targets; } - //-- Axis --// + //-- Regions --// - function getAxisId (id) { - return id in __data_axes ? __data_axes[id] : 'y'; - } - function getYScale (id) { - return getAxisId(id) === 'y2' ? y2 : y; - } - function getSubYScale (id) { - return getAxisId(id) === 'y2' ? subY2 : subY; - } + function regionStart (d) { + return ('start' in d) ? x(isTimeSeries ? parseDate(d.start) : d.start) : 0; + }; + function regionWidth (d) { + var start = regionStart(d), + end = ('end' in d) ? x(isTimeSeries ? parseDate(d.end) : d.end) : width, + w = end - start; + return (w < 0) ? 0 : w; + }; //-- Data --// diff --git a/c3.min.js b/c3.min.js index bcf17f4..6817b53 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,63 +1,63 @@ -(function(xb){function ic(){function h(b,Na){b.attr("transform",function(b){return"translate("+(Na(b)+S)+",0)"})}function r(b,h){b.attr("transform",function(b){return"translate(0,"+h(b)+")"})}function Oa(b){var h=b[0];b=b[b.length-1];return hu[d].indexOf(f.id)))for(b=0;b=g;g+=diffx2)p+=b(a[f-1],a[f],g,t);return p}function nb(a){var c=k.data.targets=U(a),d,b;m.domain(d3.extent(a.map(function(a){return a.x})));z.domain(F(c,"y"));P.domain(F(c,"y2"));W.domain(m.domain());Qa.domain(z.domain());Ra.domain(P.domain());L.ticks(10>a.length?a.length:10);fa.ticks(Ic).outerTickSize(0).tickFormat(Jc); -Sa.ticks(Kc).outerTickSize(0).tickFormat(Lc);za=m.domain();C.x(W);pa&&Ha.x(m);g.append("g").attr("class","x axis").attr("clip-path",e?"":"url(#xaxis-clip)").attr("transform",H.x).call(e?fa:L);g.append("g").attr("class","y axis").attr("clip-path",e?"url(#yaxis-clip)":"").call(e?L:fa).append("text").attr("transform","rotate(-90)").attr("dy","1.4em").attr("dx","-.8em").style("text-anchor","end").text(Mc);Eb&&g.append("g").attr("class","y2 axis").attr("transform",H.y2).call(Sa);if(pa)g.append("rect").attr("class", -"zoom-rect").attr("width",s).attr("height",q).style("opacity",0).call(Ha).on("dblclick.zoom",null);d=g.append("g").attr("clip-path",Ia).attr("class","grid");Zb&&d.append("g").attr("class","xgrids");ob&&(b=d.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(ob).enter().append("g").attr("class","xgrid-line"),b.append("line").attr("class",function(a){return""+a["class"]}),b.append("text").attr("class",function(a){return""+a["class"]}).attr("text-anchor","end").attr("transform",e? -"":"rotate(-90)").attr("dx",e?0:-v).attr("dy",-6).text(function(a){return a.text}));Nc&&d.append("g").attr("class","xgrid-focus").append("line").attr("class","xgrid-focus").attr("x1",e?0:-10).attr("x2",e?s:-10).attr("y1",e?-10:v).attr("y2",e?-10:q);$b&&d.append("g").attr("class","ygrids");pb&&d.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(pb).enter().append("line").attr("class",function(a){return"ygrid-line "+a["class"]});g.append("g").attr("clip-path",Ia).attr("class","regions"); -g.append("g").attr("clip-path",Ia).attr("class","chart");g.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).selectAll(".event-rects").data(a).enter().append("rect").attr("class",function(a,c){return"event-rect event-rect-"+c}).style("cursor",function(a){return $&&ha?"pointer":null}).on("mouseover",function(a,c){if(!Ya){var d=k.data.targets.map(function(a){return va(a.values[c])}),b,l;if(0",b,e,f;for(b=0;b"+f+""+e+"";return c+""}),Pc=b(["tooltip","init","show"],!1),sa=b(["tooltip","init","x"],0),ec=b(["tooltip","init","position"],{top:"0px",left:"50px"}), -vb=ya.replace("#","")+"-clip",Ia="url(#"+vb+")",B="timeseries"===hc,oa="categorized"===hc,sb=null,Ya=!1,rb=!1,da=ra?40:0,oc=function(a){return function(c){for(var b=a.length-1,e=a[b];!e[1](c);)e=a[--b];return e[0](c)}}([[d3.time.format("%Y/%-m/%-d"),function(){return!0}],[d3.time.format("%-m/%-d"),function(a){return a.getMonth()}],[d3.time.format("%-m/%-d"),function(a){return 1!=a.getDate()}],[d3.time.format("%-m/%-d"),function(a){return a.getDay()&&1!=a.getDate()}],[d3.time.format("%I %p"),function(a){return a.getHours()}], -[d3.time.format("%I:%M"),function(a){return a.getMinutes()}],[d3.time.format(":%S"),function(a){return a.getSeconds()}],[d3.time.format(".%L"),function(a){return a.getMilliseconds()}]]),ga=d3.time.format(Vc).parse,Bb,Gb,Db,Pa,Fb,Hb,s,q,ea,bb,na,Ib,Jb,eb,fb,m,z,P,W,Qa,Ra,L,fa,Sa,Aa,kc=e?"left":"bottom",lc=e?db?"top":"bottom":db?"right":"left",mc=e?cb?"bottom":"top":cb?"left":"right",nc="bottom";O();S();var H={main:function(){return"translate("+G+","+v+")"},context:function(){return"translate("+E+","+ -ua+")"},legend:function(){return"translate("+Oa+","+yb+")"},y2:function(){return"translate("+(e?0:s)+","+(e?10:0)+")"},x:function(){return"translate(0,"+q+")"},subx:function(){return"translate(0,"+ea+")"}},Rc=function(){var a=d3.svg.line().x(e?function(a){return x(a.id)(a.value)}:Xa).y(e?Xa:function(a){return x(a.id)(a.value)});return function(c){var b;if(lb(c))return"spline"===Z["string"===typeof c?c:c.id]?a.interpolate("cardinal"):a.interpolate("linear"),0a?0:a},Q=function(a,c){var b=[],e=null!==c?c:"#1f77b4 #ff7f0e #2ca02c #d62728 #9467bd #8c564b #e377c2 #7f7f7f #bcbd22 #17becf".split(" "); -return function(c){if(c in a)return a[c];0<=b.indexOf(c)||b.push(c);return e[b.indexOf(c)%e.length]}}(Wc,Xc),$a=d3.select(ya).append("svg").attr("width",s+G+A).attr("height",q+v+V),wb=$a.append("defs");wb.append("clipPath").attr("id",vb).append("rect").attr("y",v).attr("width",s).attr("height",q-v);wb.append("clipPath").attr("id","xaxis-clip").append("rect").attr("x",-1).attr("y",-1).attr("width",s+2).attr("height",40);wb.append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-G+1).attr("y", -v-1).attr("width",G).attr("height",q-v+2);var g=$a.append("g").attr("transform",H.main),y=null;qa&&(y=$a.append("g").attr("transform",H.context));var ta=null;ra&&(ta=$a.append("g").attr("transform",H.legend));var ia=d3.select(ya).style("position","relative").append("div").style("position","absolute").style("width","30%").style("z-index","10").style("visibility","hidden"),C=d3.svg.brush().on("brush",function(){D({withTransition:!1,withY:!1,withSubchart:!1})}),Ha=d3.behavior.zoom().on("zoom",pa?Tc: -null),Wa=null,hb=null,za;k.focus=function(a){k.defocus();d3.selectAll(Ma(a)).filter(function(a){return ib(a.id)}).classed("focused",!0).transition().duration(100).style("opacity",1)};k.defocus=function(a){d3.selectAll(Ma(a)).filter(function(a){return ib(a.id)}).classed("focused",!1).transition().duration(100).style("opacity",0.3)};k.revert=function(a){d3.selectAll(Ma(a)).filter(function(a){return ib(a.id)}).classed("focused",!1).transition().duration(100).style("opacity",1)};k.show=function(a){d3.selectAll(Ma(a)).transition().style("opacity", -1)};k.hide=function(a){d3.selectAll(Ma(a)).transition().style("opacity",0)};k.load=function(a){r(a.done)&&(a.done=function(){});if("cacheIds"in a&&ka(a.cacheIds))Ka(N(a.cacheIds),a.done);else if("data"in a)Ka(U(data),a.done);else if("url"in a)d3.csv(a.url,function(c,b){Ka(U(b),a.done)});else if("rows"in a)Ka(U(wa(a.rows)),a.done);else if("columns"in a)Ka(U(ca(a.columns)),a.done);else throw Error("url or rows or columns is required.");};k.unload=function(a){k.data.targets=k.data.targets.filter(function(c){return c.id!= -a});d3.selectAll(".target-"+a).transition().style("opacity",0).remove();ra&&(d3.selectAll(".legend-item-"+a).remove(),Za(k.data.targets));0b.classes.indexOf(a)})});return I};k.data.get=function(a){a= -k.data.getAsTarget(a);return h(a)?a.values.map(function(a){return a.value}):void 0};k.data.getAsTarget=function(a){var b=Ta(function(b){return b.id==a});return 0a?0:a}function aa(a){var c=Da[a.id];a.name=l(c)?c:a.id;return a}function va(a){var c=a[0],d={},m=[],f,b;for(f=1;fw[d].indexOf(f.id)))for(b=0;b=g;g+=diffx2)p+=b(a[f-1],a[f],g,t);return p}function ob(a){var c=k.data.targets=ba(a),d,b;r.domain(d3.extent(a.map(function(a){return a.x}))); +y.domain(B(c,"y"));O.domain(B(c,"y2"));U.domain(r.domain());Pa.domain(y.domain());Qa.domain(O.domain());M.ticks(10>a.length?a.length:10);ea.ticks(Ic).outerTickSize(0).tickFormat(Jc);Ra.ticks(Kc).outerTickSize(0).tickFormat(Lc);ya=r.domain();E.x(U);oa&&Ga.x(r);g.append("g").attr("class","x axis").attr("clip-path",e?"":"url(#xaxis-clip)").attr("transform",I.x).call(e?ea:M);g.append("g").attr("class","y axis").attr("clip-path",e?"url(#yaxis-clip)":"").call(e?M:ea).append("text").attr("transform","rotate(-90)").attr("dy", +"1.4em").attr("dx","-.8em").style("text-anchor","end").text(Mc);Gb&&g.append("g").attr("class","y2 axis").attr("transform",I.y2).call(Ra);if(oa)g.append("rect").attr("class","zoom-rect").attr("width",n).attr("height",u).style("opacity",0).call(Ga).on("dblclick.zoom",null);d=g.append("g").attr("clip-path",Ha).attr("class","grid");ac&&d.append("g").attr("class","xgrids");pb&&(b=d.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(pb).enter().append("g").attr("class","xgrid-line"), +b.append("line").attr("class",function(a){return""+a["class"]}),b.append("text").attr("class",function(a){return""+a["class"]}).attr("text-anchor","end").attr("transform",e?"":"rotate(-90)").attr("dx",e?0:-v).attr("dy",-6).text(function(a){return a.text}));Nc&&d.append("g").attr("class","xgrid-focus").append("line").attr("class","xgrid-focus").attr("x1",e?0:-10).attr("x2",e?n:-10).attr("y1",e?-10:v).attr("y2",e?-10:u);bc&&d.append("g").attr("class","ygrids");qb&&d.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(qb).enter().append("line").attr("class", +function(a){return"ygrid-line "+a["class"]});g.append("g").attr("clip-path",Ha).attr("class","regions");g.append("g").attr("clip-path",Ha).attr("class","chart");g.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).selectAll(".event-rects").data(a).enter().append("rect").attr("class",function(a,c){return"event-rect event-rect-"+c}).style("cursor",function(a){return Y&&ga?"pointer":null}).on("mouseover",function(a,c){if(!Ya){var d=k.data.targets.map(function(a){return aa(a.values[c])}), +b,m;if(0",b,e,f;for(b=0;b"+f+""+e+"";return c+""}),Pc=b(["tooltip","init", +"show"],!1),ra=b(["tooltip","init","x"],0),gc=b(["tooltip","init","position"],{top:"0px",left:"50px"}),vb=xa.replace("#","")+"-clip",Ha="url(#"+vb+")",D="timeseries"===ic,na="categorized"===ic,tb=null,Ya=!1,sb=!1,ca=qa?40:0,oc=function(a){return function(c){for(var b=a.length-1,e=a[b];!e[1](c);)e=a[--b];return e[0](c)}}([[d3.time.format("%Y/%-m/%-d"),function(){return!0}],[d3.time.format("%-m/%-d"),function(a){return a.getMonth()}],[d3.time.format("%-m/%-d"),function(a){return 1!=a.getDate()}],[d3.time.format("%-m/%-d"), +function(a){return a.getDay()&&1!=a.getDate()}],[d3.time.format("%I %p"),function(a){return a.getHours()}],[d3.time.format("%I:%M"),function(a){return a.getMinutes()}],[d3.time.format(":%S"),function(a){return a.getSeconds()}],[d3.time.format(".%L"),function(a){return a.getMilliseconds()}]]),fa=d3.time.format(Vc).parse,Db,Ib,Fb,Oa,Hb,Jb,n,u,da,bb,ma,Kb,Lb,eb,fb,r,y,O,U,Pa,Qa,M,ea,Ra,za,kc=e?"left":"bottom",lc=e?db?"top":"bottom":db?"right":"left",mc=e?cb?"bottom":"top":cb?"left":"right",nc="bottom"; +N();R();var I={main:function(){return"translate("+H+","+v+")"},context:function(){return"translate("+G+","+ta+")"},legend:function(){return"translate("+Na+","+yb+")"},y2:function(){return"translate("+(e?0:n)+","+(e?10:0)+")"},x:function(){return"translate(0,"+u+")"},subx:function(){return"translate(0,"+da+")"}},Rc=function(){var a=d3.svg.line().x(e?function(a){return h(a.id)(a.value)}:Xa).y(e?Xa:function(a){return h(a.id)(a.value)});return function(c){var b;if(mb(c))return"spline"===X["string"=== +typeof c?c:c.id]?a.interpolate("cardinal"):a.interpolate("linear"),0b.classes.indexOf(a)})});return J};k.data.get=function(a){a= +k.data.getAsTarget(a);return l(a)?a.values.map(function(a){return a.value}):void 0};k.data.getAsTarget=function(a){var b=Sa(function(b){return b.id==a});return 0