Skip to content

Commit

Permalink
viewbox & optional nested svg
Browse files Browse the repository at this point in the history
  • Loading branch information
sheppard committed Jan 16, 2015
1 parent de7d826 commit 9787f86
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions js/wq/chart.js
Expand Up @@ -38,6 +38,8 @@ chart.base = function() {
'padding': {'left': 10, 'right': 10, 'top': 10, 'bottom': 10},
'xaxis': {'bottom': 20}
},
viewBox=true,
nestedSvg=false,
renderBackground = false,
xscale = null,
xscalefn = d3.scale.linear,
Expand Down Expand Up @@ -185,6 +187,9 @@ chart.base = function() {

// Plot using given selection (usually one object, but wrapped as array)
function plot(sel) {
if (nestedSvg) {
sel = _selectOrAppend(sel, 'svg', nestedSvg);
}
sel.each(_plot);
}

Expand All @@ -197,6 +202,15 @@ chart.base = function() {
var svg = d3.select(this);
var uid = svg.attr('data-uid') || Math.round(Math.random() * 1000000);
svg.attr('data-uid', uid);
var vbstr;
if (viewBox) {
if (viewBox === true) {
vbstr = "0 0 " + width + " " + height;
} else {
vbstr = viewBox;
}
svg.attr("viewBox", vbstr);
}
var cwidth = width - padding - padding;
var cheight = height - padding - padding;
var margins = plot.getMargins();
Expand Down Expand Up @@ -458,6 +472,26 @@ chart.base = function() {
height = val;
return plot;
};
plot.viewBox = function(val) {
if (!arguments.length) return viewBox;
viewBox = val;
return plot;
};
plot.nestedSvg = function(val) {
if (!arguments.length) return nestedSvg;
nestedSvg = val;
return plot;
};
plot.outerFill = function(val) {
if (!arguments.length) return outerFill;
outerFill = val;
return plot;
};
plot.innerFill = function(val) {
if (!arguments.length) return innerFill;
innerFill = val;
return plot;
};
plot.legend = function(val) {
if (!arguments.length) return legend;
legend = val || {};
Expand Down

0 comments on commit 9787f86

Please sign in to comment.