Browse Source

Fix legend position on Firefox

pull/57/head
Masayuki Tanaka 11 years ago
parent
commit
ac30d1ffb0
  1. 11
      c3.js
  2. 8
      c3.min.js

11
c3.js

@ -2760,9 +2760,10 @@
yForLegendText = function (d, i) { return yForLegend(d, i) + 9; };
xForLegendRect = function (d, i) { return xForLegend(d, i) - 4; };
yForLegendRect = function (d, i) { return yForLegend(d, i) - 7; };
updateSizes = function (offsetWidth, offsetHeight) {
var width = Math.ceil((offsetWidth + paddingRight) / 10) * 10,
height = Math.ceil((offsetHeight + paddingTop) / 10) * 10;
updateSizes = function (textElement) {
var box = textElement.getBBox(),
width = Math.ceil((box.width + paddingRight) / 10) * 10,
height = Math.ceil((box.height + paddingTop) / 10) * 10;
if (width > item_width) {
item_width = width;
if (! isLegendRight) {
@ -2796,7 +2797,7 @@
});
l.append('text')
.text(function (d) { return isDefined(__data_names[d]) ? __data_names[d] : d; })
.each(function () { updateSizes(this.offsetWidth, this.offsetHeight); })
.each(function () { updateSizes(this); })
.style("pointer-events", "none")
.attr('x', isLegendRight ? xForLegendText : -200)
.attr('y', isLegendRight ? -200 : yForLegend);
@ -2818,7 +2819,7 @@
legend.selectAll('text')
.data(ids)
.each(function () { updateSizes(this.offsetWidth, this.offsetHeight); })
.each(function () { updateSizes(this); })
.transition().duration(withTransition ? 250 : 0)
.attr('x', xForLegendText)
.attr('y', yForLegendText);

8
c3.min.js vendored

@ -69,10 +69,10 @@ b=l.select(".chart-arcs").selectAll(".chart-arc").data(Sb(a)).enter().append("g"
"middle").style("pointer-events","none");Ha&&(b=G.select(".chart-bars").selectAll(".chart-bar").data(a),b=b.enter().append("g").attr("class",function(a){return"chart-bar target target-"+a.id}),b.append("g").attr("class",Rc).style("fill",function(a){return I(a.id)}),b=G.select(".chart-lines").selectAll(".chart-line").data(a),b=b.enter().append("g").attr("class",function(a){return"chart-line target target-"+a.id}),b.append("path").attr("class",Qc).style("opacity",0).style("stroke",function(a){return I(a.id)}));
ia&&xb(a);p.selectAll(".target").transition().style("opacity",1)}function db(a,b){f.data.targets.forEach(function(b){for(var d=0;d<a.length;d++)if(b.id===a[d].id){b.values=a[d].values;a.splice(d,1);break}});f.data.targets=f.data.targets.concat(a);ud(f.data.targets);V({withUpdateOrgXDomain:!0,withUpdateXDomain:!0});b()}function oc(a){var b=p.selectAll(".legend-item"),c=function(b){return!a||b===a};b.filter(function(a){return!c(a)}).transition().duration(100).style("opacity",0.3);b.filter(c).transition().duration(100).style("opacity",
1)}function $e(a){var b=p.selectAll(".legend-item"),c=function(b){return!a||b===a};b.filter(function(a){return!c(a)}).transition().duration(100).style("opacity",1);b.filter(c).transition().duration(100).style("opacity",0.3)}function pc(){p.selectAll(".legend-item").transition().duration(100).style("opacity",1)}function xb(a,b){var c=Xa(a),d,e,h,l,m,n,p,q=0,r=0,s,u,t;b=w(b)?{}:b;t=y(b.withTransition)?b.withTransition:!0;x?(e=function(){return 0.2*Qa},m=function(a,b){return s+q*b}):(e=function(a,b){return s+
r*b},m=function(){return 0.2*sa});h=function(a,b){return e(a,b)+14};n=function(a,b){return m(a,b)+9};l=function(a,b){return e(a,b)-4};p=function(a,b){return m(a,b)-7};u=function(b,c){var d=10*Math.ceil((b+30)/10),g=10*Math.ceil((c+4)/10);d>r&&(r=d,x||(s=(Qa-r*Object.keys(a).length)/2));g>q&&(q=g,x&&(s=(sa-q*Object.keys(a).length)/2))};d=Ia.selectAll(".legend-item").data(c).enter().append("g").attr("class",function(a){return"legend-item legend-item-"+a}).style("cursor","pointer").on("click",function(a){af(a)}).on("mouseover",
function(a){oc(a);f.focus(a)}).on("mouseout",function(){pc();f.revert()});d.append("text").text(function(a){return y(Va[a])?Va[a]:a}).each(function(){u(this.offsetWidth,this.offsetHeight)}).style("pointer-events","none").attr("x",x?h:-200).attr("y",x?-200:m);d.append("rect").attr("class","legend-item-event").style("fill-opacity",0).attr("x",x?l:-200).attr("y",x?-200:p).attr("width",r+14).attr("height",24);d.append("rect").attr("class","legend-item-tile").style("pointer-events","none").style("fill",
function(a){return I(a)}).attr("x",x?h:-200).attr("y",x?-200:n).attr("width",10).attr("height",10);Ia.selectAll("text").data(c).each(function(){u(this.offsetWidth,this.offsetHeight)}).transition().duration(t?250:0).attr("x",h).attr("y",n);Ia.selectAll("rect.legend-item-event").data(c).transition().duration(t?250:0).attr("x",l).attr("y",p);Ia.selectAll("rect.legend-item-tile").data(c).transition().duration(t?250:0).attr("x",e).attr("y",m)}function yb(a){return a?"-"+a.replace(/\./g,"\\."):""}function ka(a){return".target"+
yb(a)}function qc(a){return Oc(a.id)}function rc(a){return"data"in a&&Oc(a.data.id)}var f={data:{}},rb={},da="_expanded_",na="_selected_",nc="_included_",ya=d(["bindto"],"#chart"),Pa=d(["size","width"],null),Hb=d(["size","height"],null),gb=d(["padding","left"],null),zc=d(["padding","right"],null),ea=d(["zoom","enabled"],!1),Bd=d(["zoom","extent"],null),Oe=d(["zoom","privileged"],!1),Ie=d(["onenter"],function(){}),Je=d(["onleave"],function(){}),Ue=d(["transition","duration"],350);if(!("data"in fa))throw Error("data is required in config");
r*b},m=function(){return 0.2*sa});h=function(a,b){return e(a,b)+14};n=function(a,b){return m(a,b)+9};l=function(a,b){return e(a,b)-4};p=function(a,b){return m(a,b)-7};u=function(b){var c=b.getBBox();b=10*Math.ceil((c.width+30)/10);c=10*Math.ceil((c.height+4)/10);b>r&&(r=b,x||(s=(Qa-r*Object.keys(a).length)/2));c>q&&(q=c,x&&(s=(sa-q*Object.keys(a).length)/2))};d=Ia.selectAll(".legend-item").data(c).enter().append("g").attr("class",function(a){return"legend-item legend-item-"+a}).style("cursor","pointer").on("click",
function(a){af(a)}).on("mouseover",function(a){oc(a);f.focus(a)}).on("mouseout",function(){pc();f.revert()});d.append("text").text(function(a){return y(Va[a])?Va[a]:a}).each(function(){u(this)}).style("pointer-events","none").attr("x",x?h:-200).attr("y",x?-200:m);d.append("rect").attr("class","legend-item-event").style("fill-opacity",0).attr("x",x?l:-200).attr("y",x?-200:p).attr("width",r+14).attr("height",24);d.append("rect").attr("class","legend-item-tile").style("pointer-events","none").style("fill",
function(a){return I(a)}).attr("x",x?h:-200).attr("y",x?-200:n).attr("width",10).attr("height",10);Ia.selectAll("text").data(c).each(function(){u(this)}).transition().duration(t?250:0).attr("x",h).attr("y",n);Ia.selectAll("rect.legend-item-event").data(c).transition().duration(t?250:0).attr("x",l).attr("y",p);Ia.selectAll("rect.legend-item-tile").data(c).transition().duration(t?250:0).attr("x",e).attr("y",m)}function yb(a){return a?"-"+a.replace(/\./g,"\\."):""}function ka(a){return".target"+yb(a)}
function qc(a){return Oc(a.id)}function rc(a){return"data"in a&&Oc(a.data.id)}var f={data:{}},rb={},da="_expanded_",na="_selected_",nc="_included_",ya=d(["bindto"],"#chart"),Pa=d(["size","width"],null),Hb=d(["size","height"],null),gb=d(["padding","left"],null),zc=d(["padding","right"],null),ea=d(["zoom","enabled"],!1),Bd=d(["zoom","extent"],null),Oe=d(["zoom","privileged"],!1),Ie=d(["onenter"],function(){}),Je=d(["onleave"],function(){}),Ue=d(["transition","duration"],350);if(!("data"in fa))throw Error("data is required in config");
var ua=d(["data","x"],null),ba=d(["data","xs"],null),$b=d(["data","x_format"],"%Y-%m-%d"),je=d(["data","id_converter"],function(a){return a}),Va=d(["data","names"],{}),u=d(["data","groups"],[]),Dc=d(["data","axes"],{}),Mc=d(["data","type"],null),z=d(["data","types"],{}),Ca=d(["data","labels"],{}),Ea=d(["data","order"],null),Cd=d(["data","regions"],{}),bf=d(["data","colors"],{}),la=d(["data","selection","enabled"],!1),wa=d(["data","selection","grouped"],!1),ma=d(["data","selection","isselectable"],
function(){return!0}),Ha=d(["subchart","show"],!1),Eb=Ha?d(["subchart","size","height"],60):0,cf=d(["color","pattern"],null),ia=d(["legend","show"],!0),df=d(["legend","position"],"bottom"),af=d(["legend","item","onclick"],function(){}),h=d(["axis","rotated"],!1),sc=d(["axis","x","type"],"indexed"),Sa=d(["axis","x","categories"],[]),Pd=d(["axis","x","tick","centered"],!1),nb=d(["axis","x","tick","format"],null),Sd=d(["axis","x","tick","culling"],h||"categorized"===sc?!1:!0),Ec=d(["axis","x","tick",
"count"],10),wb=d(["axis","x","default"],null),Ke=d(["axis","x","label"],null),$d=d(["axis","y","max"],null),Yd=d(["axis","y","min"],null),be=d(["axis","y","center"],null),Le=d(["axis","y","label"],null),hb=d(["axis","y","inner"],!1),Rb=d(["axis","y","tick","format"],null),Ta=d(["axis","y","padding"],null),Ld=d(["axis","y","ticks"],10),fb=d(["axis","y2","show"],!1),Zd=d(["axis","y2","max"],null),Xd=d(["axis","y2","min"],null),ae=d(["axis","y2","center"],null),Ib=d(["axis","y2","inner"],!1),Nd=d(["axis",

Loading…
Cancel
Save