diff --git a/c3.js b/c3.js
index 07f2d13..7284e13 100644
--- a/c3.js
+++ b/c3.js
@@ -116,7 +116,10 @@
text += "
" + name + " | " + value + " |
";
}
return text + "";
- });
+ }),
+ __tooltip_init_show = getConfig(['tooltip','init','show'], false),
+ __tooltip_init_x = getConfig(['tooltip','init','x'], 0),
+ __tooltip_init_position = getConfig(['tooltip','init','position'], {top:'0px',left:'50px'});
/*-- Set Variables --*/
@@ -419,6 +422,11 @@
//-- Data --//
+ function addName (data) {
+ var name = __data_names[data.id];
+ data.name = isDefined(name) ? name : data.id;
+ return data;
+ }
function convertRowsToData (rows) {
var keys = rows[0], new_row = {}, new_rows = [], i, j;
for (i = 1; i < rows.length; i++) {
@@ -786,6 +794,7 @@
var targets = c3.data.targets = convertDataToTargets(data);
var rectX, rectW;
var grid, xgridLine;
+ var i;
// TODO: set names if names not specified
@@ -872,15 +881,9 @@
.on('mouseover', function(d,i) {
if (dragging) return; // do nothing if dragging
- var selectedData = c3.data.targets.map(function(d){ return d.values[i]; });
- var j, newData, name;
+ var selectedData = c3.data.targets.map(function(d){ return addName(d.values[i]); });
+ var j, newData;
- // Add id,name to selectedData
- for (j = 0; j < selectedData.length; j++) {
- if (isUndefined(selectedData[j])) continue;
- name = __data_names[selectedData[j].id];
- selectedData[j].name = isDefined(name) ? name : selectedData[j].id;
- }
// Sort selectedData as names order
if (Object.keys(__data_names).length > 0) {
newData = [];
@@ -1129,6 +1132,23 @@
// Draw with targets
redraw({withTransition:false});
+
+ // Show tooltip if needed
+ if (__tooltip_init_show) {
+ if (isTimeSeries && typeof __tooltip_init_x == 'string') {
+ __tooltip_init_x = parseDate(__tooltip_init_x);
+ for (i = 0; i < targets[0].values.length; i++) {
+ if ((targets[0].values[i].x - __tooltip_init_x) == 0) break;
+ }
+ __tooltip_init_x = i;
+ }
+ tooltip.html(__tooltip_contents(targets.map(function(d){
+ return addName(d.values[__tooltip_init_x]);
+ })));
+ tooltip.style("top", __tooltip_init_position.top)
+ .style("left", __tooltip_init_position.left)
+ .style("visibility", "visible");
+ }
}
function redraw (options) {
diff --git a/c3.min.js b/c3.min.js
index 0511e49..7f027d8 100644
--- a/c3.min.js
+++ b/c3.min.js
@@ -1,57 +1,58 @@
-(function(Ka){function gb(){function n(c,i){c.attr("transform",function(c){return"translate("+(i(c)+E)+",0)"})}function c(c,i){c.attr("transform",function(c){return"translate(0,"+i(c)+")"})}function i(v){v.each(function(){for(var i=d3.select(this),v=l.domain(),k=[],x=Math.ceil(v[0]);xa.length?a.length:10);d=f.append("g").attr("clip-path",
-Da).attr("class","grid");rb&&d.append("g").attr("class","xgrids");Va&&(g=d.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(Va).enter().append("g").attr("class","xgrid-line"),g.append("line").attr("class",function(a){return""+a["class"]}),g.append("text").attr("class",function(a){return""+a["class"]}).attr("text-anchor","end").attr("transform",e?"":"rotate(-90)").attr("dx",e?0:-p.top).attr("dy",-6).text(function(a){return a.text}));Yb&&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:p.top).attr("y2",e?-10:u);sb&&d.append("g").attr("class","ygrids");Wa&&d.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(Wa).enter().append("line").attr("class",function(a){return"ygrid-line "+a["class"]});f.append("g").attr("clip-path",Da).attr("class","regions");f.append("g").attr("clip-path",Da).attr("class","chart");f.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).selectAll(".event-rects").data(a).enter().append("rect").attr("class",
-function(a,b){return"event-rect event-rect-"+b}).style("cursor",function(){return V&&aa?"pointer":null}).on("mouseover",function(a,b){if(!Ea){var d=h.data.targets.map(function(a){return a.values[b]}),g,c;for(g=0;gr[g].indexOf(a.id)))for(c=0;c",d,c,e;for(d=0;d"+e+" | "+
-c+" | ";return b+""}),Gb=n.bindto.replace("#","")+"-clip",Da="url(#"+Gb+")",H="timeseries"===Eb,wa="categorized"===Eb,Ya=null,Ea=!1,ca=ra?40:0,Hb,db=[[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()}]];Hb=function(a){for(var b=db.length-1,d=db[b];!d[1](a);)d=db[--b];return d[0](a)};var p={top:0,right:vb&&!e?50:1,bottom:20+Cb+ca,left:40},Ib=Ga-Cb-ca,fc=Ga-ca,s=dc-p.left-p.right,u=Ga-p.top-p.bottom,qa=Ga-Ib-(20+ca),ha=d3.time.format(ec).parse,Jb=e?0:u,Kb=e?s:1,q=Na(e?10:0,e?u:s),D=ka(Jb,Kb),ga=ka(Jb,Kb),I=Na(0,s),Pa=ka(qa,10),Oa=ka(qa,10),w=wa?gb():d3.svg.axis(),oa=d3.svg.axis(),
-$a=d3.svg.axis(),ja=wa?gb():d3.svg.axis();w.scale(q).orient(e?"left":"bottom");oa.scale(D).orient(e?"bottom":"left");$a.scale(ga).orient(e?"top":"right");ja.scale(I).orient("bottom");H&&w.tickFormat(Hb);wa?(w.categories(Ha).tickCentered(Fb),ja.categories(Ha).tickCentered(Fb)):(w.tickOffset=function(){return 0},ja.tickOffset=function(){return 0});if(wa){var Ia=q,Lb=I,Mb=Object.keys(q),xa,Ja,q=function(a){return Ia(a)+w.tickOffset()},I=function(a){return Lb(a)+ja.tickOffset()};for(Ja=0;Ja=h;h+=diffx2)j+=m(b[f-1],b[f],h,k)}}b=j}else b=eb(a.values);return b}b=q(a.values[0].x);a=A(a.id)(a.values[0].value);return e?"M "+a+" "+b:"M "+b+" "+a};var yb,gc=d3.svg.line().x(function(a){return I(a.x)}).y(function(a){return Q(a.id)(a.value)});
-yb=function(a){return Sa(a)?gc(a.values):"M "+I(a.values[0].x)+" "+Q(a.id)(a.values[0].value)};var cb=function(a){return"start"in a?q(H?ha(a.start):a.start):0},zb=function(a){var b=cb(a),a=("end"in a?q(H?ha(a.end):a.end):s)-b;return 0>a?0:a},N,fb=[],Nb=null!==Db?Db:"#1f77b4 #ff7f0e #2ca02c #d62728 #9467bd #8c564b #e377c2 #7f7f7f #bcbd22 #17becf".split(" ");N=function(a){if(a in Bb)return Bb[a];0<=fb.indexOf(a)||fb.push(a);return Nb[fb.indexOf(a)%Nb.length]};var da=d3.select(n.bindto).append("svg").attr("width",
-s+p.left+p.right).attr("height",u+p.top+p.bottom);da.append("defs");da.select("defs").append("clipPath").attr("id",Gb).append("rect").attr("y",p.top).attr("width",s).attr("height",u-p.top);da.select("defs").append("clipPath").attr("id","xaxis-clip").append("rect").attr("x",-1).attr("y",-1).attr("width",s+2).attr("height",40);da.select("defs").append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-39).attr("y",p.top-1).attr("width",40).attr("height",u-p.top+2);var f=da.append("g").attr("transform",
-"translate("+p.left+","+p.top+")"),O=null;pa&&(O=da.append("g").attr("transform","translate(40,"+Ib+")"));var ua=null;ra&&(ua=da.append("g").attr("transform","translate(40,"+fc+")"));var Fa=d3.select(n.bindto).style("position","relative").append("div").style("position","absolute").style("width","30%").style("z-index","10").style("visibility","hidden"),ia=d3.svg.brush().x(I).on("brush",function(){P({withTransition:!1,withY:!1,withSubchart:!1})}),Ba=null,Qa=null;h.focus=function(a){h.defocus();d3.selectAll(va(a)).filter(function(a){return Ma(a.id)}).classed("focused",
-!0).transition().duration(100).style("opacity",1)};h.defocus=function(a){d3.selectAll(va(a)).filter(function(a){return Ma(a.id)}).classed("focused",!1).transition().duration(100).style("opacity",0.3)};h.revert=function(a){d3.selectAll(va(a)).filter(function(a){return Ma(a.id)}).classed("focused",!1).transition().duration(100).style("opacity",1)};h.show=function(a){d3.selectAll(va(a)).transition().style("opacity",1)};h.hide=function(a){d3.selectAll(va(a)).transition().style("opacity",0)};h.load=function(a){l(a.done)&&
-(a.done=function(){});var b;if(b="cacheIds"in a)a:{b=a.cacheIds;for(var d=0;db.classes.indexOf(a)})});return J};
-h.data.get=function(a){a=h.data.getAsTarget(a);return i(a)?a.values.map(function(a){return a.value}):void 0};h.data.getAsTarget=function(a){var b=k(function(b){return b.id==a});return 0s[c].indexOf(f.id)))for(e=0;e=d;d+=diffx2)qa+=h(a[f-1],a[f],d,m);return qa}function Ua(a){var b=l.data.targets=ma(a),c,e;p.domain(d3.extent(a.map(function(a){return a.x})));
+A.domain(R(b,"y"));ia.domain(R(b,"y2"));C.domain(p.domain());Pa.domain(A.domain());Oa.domain(ia.domain());x.ticks(10>a.length?a.length:10);c=h.append("g").attr("clip-path",Ha).attr("class","grid");rb&&c.append("g").attr("class","xgrids");Va&&(e=c.append("g").attr("class","xgrid-lines").selectAll(".xgrid-line").data(Va).enter().append("g").attr("class","xgrid-line"),e.append("line").attr("class",function(a){return""+a["class"]}),e.append("text").attr("class",function(a){return""+a["class"]}).attr("text-anchor",
+"end").attr("transform",g?"":"rotate(-90)").attr("dx",g?0:-q.top).attr("dy",-6).text(function(a){return a.text}));Wb&&c.append("g").attr("class","xgrid-focus").append("line").attr("class","xgrid-focus").attr("x1",g?0:-10).attr("x2",g?t:-10).attr("y1",g?-10:q.top).attr("y2",g?-10:u);sb&&c.append("g").attr("class","ygrids");Wa&&c.append("g").attr("class","ygrid-lines").selectAll("ygrid-line").data(Wa).enter().append("line").attr("class",function(a){return"ygrid-line "+a["class"]});h.append("g").attr("clip-path",
+Ha).attr("class","regions");h.append("g").attr("clip-path",Ha).attr("class","chart");h.select(".chart").append("g").attr("class","event-rects").style("fill-opacity",0).selectAll(".event-rects").data(a).enter().append("rect").attr("class",function(a,b){return"event-rect event-rect-"+b}).style("cursor",function(a){return V&&ba?"pointer":null}).on("mouseover",function(a,b){if(!Ia){var c=l.data.targets.map(function(a){return M(a.values[b])}),e,d;if(0",c,d,f;for(c=0;c"+f+" | "+
+d+" | ";return b+""}),Zb=d(["tooltip","init","show"],!1),la=d(["tooltip","init","x"],0),yb=d(["tooltip","init","position"],{top:"0px",left:"50px"}),Eb=v.bindto.replace("#","")+"-clip",Ha="url(#"+Eb+")",z="timeseries"===Cb,Ba="categorized"===Cb,Ya=null,Ia=!1,da=wa?40:0,hc=function(a){return function(b){for(var c=a.length-1,d=a[c];!d[1](b);)d=a[--c];return d[0](b)}}([[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()}]]),q={top:0,right:wb&&!g?50:1,bottom:20+Bb+da,left:40},Fb=Ja-Bb-da,ic=Ja-da,t=dc-q.left-q.right,u=Ja-q.top-q.bottom,va=Ja-Fb-(20+da),aa=d3.time.format(ec).parse,
+Gb=g?0:u,Hb=g?t:1,p=Ma(g?10:0,g?u:t),A=na(Gb,Hb),ia=na(Gb,Hb),C=Ma(0,t),Pa=na(va,10),Oa=na(va,10),x=Ba?db():d3.svg.axis(),ta=d3.svg.axis(),$a=d3.svg.axis(),ka=Ba?db():d3.svg.axis();x.scale(p).orient(g?"left":"bottom");ta.scale(A).orient(g?"bottom":"left");$a.scale(ia).orient(g?"top":"right");ka.scale(C).orient("bottom");z&&x.tickFormat(hc);Ba?(x.categories(Ka).tickCentered(Db),ka.categories(Ka).tickCentered(Db)):(x.tickOffset=function(){return 0},ka.tickOffset=function(){return 0});Ba&&function(){var a=
+p,b=C,c=Object.keys(p),d,f;p=function(b){return a(b)+x.tickOffset()};C=function(a){return b(a)+ka.tickOffset()};for(f=0;fa?0:
+a},N=function(a,b){var c=[],d=null!==b?b:"#1f77b4 #ff7f0e #2ca02c #d62728 #9467bd #8c564b #e377c2 #7f7f7f #bcbd22 #17becf".split(" ");return function(b){if(b in a)return a[b];0<=c.indexOf(b)||c.push(b);return d[c.indexOf(b)%d.length]}}(fc,gc),ea=d3.select(v.bindto).append("svg").attr("width",t+q.left+q.right).attr("height",u+q.top+q.bottom);ea.append("defs");ea.select("defs").append("clipPath").attr("id",Eb).append("rect").attr("y",q.top).attr("width",t).attr("height",u-q.top);ea.select("defs").append("clipPath").attr("id",
+"xaxis-clip").append("rect").attr("x",-1).attr("y",-1).attr("width",t+2).attr("height",40);ea.select("defs").append("clipPath").attr("id","yaxis-clip").append("rect").attr("x",-39).attr("y",q.top-1).attr("width",40).attr("height",u-q.top+2);var h=ea.append("g").attr("transform","translate("+q.left+","+q.top+")"),I=null;ua&&(I=ea.append("g").attr("transform","translate(40,"+Fb+")"));var za=null;wa&&(za=ea.append("g").attr("transform","translate(40,"+ic+")"));var ja=d3.select(v.bindto).style("position",
+"relative").append("div").style("position","absolute").style("width","30%").style("z-index","10").style("visibility","hidden"),ha=d3.svg.brush().x(C).on("brush",function(){J({withTransition:!1,withY:!1,withSubchart:!1})}),Ga=null,Qa=null;l.focus=function(a){l.defocus();d3.selectAll(Aa(a)).filter(function(a){return P(a.id)}).classed("focused",!0).transition().duration(100).style("opacity",1)};l.defocus=function(a){d3.selectAll(Aa(a)).filter(function(a){return P(a.id)}).classed("focused",!1).transition().duration(100).style("opacity",
+0.3)};l.revert=function(a){d3.selectAll(Aa(a)).filter(function(a){return P(a.id)}).classed("focused",!1).transition().duration(100).style("opacity",1)};l.show=function(a){d3.selectAll(Aa(a)).transition().style("opacity",1)};l.hide=function(a){d3.selectAll(Aa(a)).transition().style("opacity",0)};l.load=function(a){r(a.done)&&(a.done=function(){});if("cacheIds"in a&&ga(a.cacheIds))xa(fa(a.cacheIds),a.done);else if("data"in a)xa(ma(data),a.done);else if("url"in a)d3.csv(a.url,function(b,c){xa(ma(c),
+a.done)});else if("rows"in a)xa(ma(E(a.rows)),a.done);else if("columns"in a)xa(ma(k(a.columns)),a.done);else throw Error("url or rows or columns is required.");};l.unload=function(a){l.data.targets=l.data.targets.filter(function(b){return b.id!=a});d3.selectAll(".target-"+a).transition().style("opacity",0).remove();wa&&(d3.selectAll(".legend-item-"+a).remove(),bb(l.data.targets));0b.classes.indexOf(a)})});return D};l.data.get=function(a){a=l.data.getAsTarget(a);return n(a)?a.values.map(function(a){return a.value}):void 0};l.data.getAsTarget=function(a){var b=y(function(b){return b.id==a});return 0