Made the line edge clipping optional, defaulting to false. But is still required for the lineWithFocus example

master-patched
Bob Monteverde 12 years ago
parent 6b450b1585
commit d22eb5a396

@ -619,6 +619,7 @@ nv.models.line = function() {
getX = function(d) { return d.x },
getY = function(d) { return d.y },
interactive = true,
clipEdge = false,
clipVoronoi = true,
xDomain, yDomain;
@ -664,7 +665,7 @@ nv.models.line = function() {
.attr('height', availableHeight);
gEnter
.attr('clip-path', 'url(#chart-clip-path-' + id + ')');
.attr('clip-path', clipEdge ? 'url(#chart-clip-path-' + id + ')' : '');
var shiftWrap = gEnter.append('g').attr('class', 'shiftWrap');
@ -873,6 +874,12 @@ nv.models.line = function() {
return chart;
};
chart.clipEdge = function(_) {
if (!arguments.length) return clipEdge;
clipEdge = _;
return chart;
};
chart.clipVoronoi= function(_) {
if (!arguments.length) return clipVoronoi;
clipVoronoi = _;
@ -923,7 +930,7 @@ nv.models.lineWithFocus = function() {
xAxis2 = nv.models.xaxis().scale(x2),
yAxis2 = nv.models.yaxis().scale(y2),
legend = nv.models.legend().height(30),
focus = nv.models.line(),
focus = nv.models.line().clipEdge(true),
context = nv.models.line().dotRadius(.1).interactive(false),
dispatch = d3.dispatch('tooltipShow', 'tooltipHide'),
brush = d3.svg.brush()
@ -2082,17 +2089,25 @@ nv.models.stackedArea = function() {
//compute the data based on offset and order (calc's y0 for every point)
dataCopy = d3.layout.stack().offset(offset).order(order).values(function(d){ return d.values })(dataCopy);
dataCopy = d3.layout.stack()
.offset(offset)
.order(order)
.values(function(d){ return d.values })
.y(getY)
(dataCopy);
x .domain(xDomain || d3.extent(d3.merge(seriesData), getX))
.range([0, availableWidth]);
y .domain(yDomain || [0, d3.max(dataCopy, function(d) { return d3.max(d.values, function(d) { return d.y0 + d.y }) }) ])
y .domain(yDomain || [0, d3.max(dataCopy, function(d) {
return d3.max(d.values, function(d) { return d.y0 + d.y })
}) ])
.range([availableHeight, 0]);
lines
//.interactive(false)
//.interactive(false) //if we were to turn off interactive, the whole line chart should be removed
.width(availableWidth)
.height(availableHeight)
.xDomain(x.domain())
@ -2102,10 +2117,7 @@ nv.models.stackedArea = function() {
return d.color || color[i % 10];
}).filter(function(d,i) { return !data[i].disabled }));
// Select the wrapper g, if it exists.
var wrap = d3.select(this).selectAll('g.d3stackedarea').data([dataCopy]);
// Create the skeletal chart on first load.
var gEnter = wrap.enter().append('g').attr('class', 'd3stackedarea').append('g');
gEnter.append('g').attr('class', 'areaWrap');
@ -2115,11 +2127,13 @@ nv.models.stackedArea = function() {
var g = wrap.select('g')
.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
var linesWrap = g.select('.linesWrap')
.datum(dataCopy.filter(function(d) { return !d.disabled }))
d3.transition(linesWrap).call(lines);
var area = d3.svg.area()
.x(function(d) { return x(getX(d)) })
.y0(function(d) { return y(d.y0) })
@ -2148,6 +2162,17 @@ nv.models.stackedArea = function() {
return chart;
}
chart.x = function(_) {
if (!arguments.length) return getX;
getX = d3.functor(_);
return chart;
};
chart.y = function(_) {
if (!arguments.length) return getY;
getY = d3.functor(_);
return chart;
}
chart.margin = function(_) {
if (!arguments.length) return margin;
@ -2215,8 +2240,8 @@ nv.models.stackedArea = function() {
nv.models.stackedAreaWithLegend = function() {
var margin = {top: 30, right: 20, bottom: 50, left: 60},
width = 960,
height = 500,
getWidth = function() { return 960 },
getHeight = function() { return 500 },
dotRadius = function() { return 2.5 },
color = d3.scale.category10().range(),
dispatch = d3.dispatch('tooltipShow', 'tooltipHide');
@ -2231,6 +2256,7 @@ nv.models.stackedAreaWithLegend = function() {
controls = nv.models.legend().height(30),
stacked = nv.models.stackedArea();
//TODO: let user select default
var controlsData = [
{ key: 'Stacked' },
{ key: 'Stream', disabled: true },
@ -2238,9 +2264,13 @@ nv.models.stackedAreaWithLegend = function() {
];
function chart(selection) {
selection.each(function(data) {
var width = getWidth(),
height = getHeight(),
availableWidth = width - margin.left - margin.right,
availableHeight = height - margin.top - margin.bottom;
var series = data.filter(function(d) { return !d.disabled })
//.map(function(d) { return d.values });
.reduce(function(prev, curr, index) { //sum up all the y's
@ -2252,18 +2282,18 @@ nv.models.stackedAreaWithLegend = function() {
}, []);
x .domain(d3.extent(d3.merge(series), getX ))
.range([0, width - margin.left - margin.right]);
x .domain(d3.extent(d3.merge(series), function(d) { return d.x } ))
.range([0, availableWidth]);
y .domain(stacked.offset() == 'zero' ?
[0, d3.max(d3.merge(series), getY )] :
[0, d3.max(series, function(d) { return d.y } )] :
[0, 1] // 0 - 100%
)
.range([height - margin.top - margin.bottom, 0]);
.range([availableHeight, 0]);
stacked
.width(width - margin.left - margin.right)
.height(height - margin.top - margin.bottom)
.width(availableWidth)
.height(availableHeight)
var wrap = d3.select(this).selectAll('g.wrap').data([data]);
@ -2280,15 +2310,14 @@ nv.models.stackedAreaWithLegend = function() {
d.disabled = !d.disabled;
if (d.disabled)
d.values.map(function(p) { p._y = p.y; p.y = 0; return p });
d.values.map(function(p) { p._y = p.y; p.y = 0; return p }); //TODO: need to use value from getY, not always d.y
else
d.values.map(function(p) { p.y = p._y; return p });
d.values.map(function(p) { p.y = p._y; return p }); // ....
if (!data.filter(function(d) { return !d.disabled }).length) {
data.map(function(d) {
d.disabled = false;
d.values.map(function(p) { p.y = p._y; return p });
//wrap.selectAll('.series').classed('disabled', false);
d.values.map(function(p) { p.y = p._y; return p }); // ....
return d;
});
}
@ -2321,7 +2350,7 @@ nv.models.stackedAreaWithLegend = function() {
});
/*
/*
legend.dispatch.on('legendMouseover', function(d, i) {
d.hover = true;
selection.transition().call(chart)
@ -2331,7 +2360,7 @@ nv.models.stackedAreaWithLegend = function() {
d.hover = false;
selection.transition().call(chart)
});
*/
*/
stacked.dispatch.on('pointMouseover.tooltip', function(e) {
dispatch.tooltipShow({
@ -2357,28 +2386,20 @@ nv.models.stackedAreaWithLegend = function() {
legend.width(width/2 - margin.right);
controls
.width(280)
.color(['#666', '#666', '#666']);
g.select('.legendWrap')
.datum(data)
.attr('transform', 'translate(' + (width/2 - margin.left) + ',' + (-margin.top) +')')
.call(legend);
controls.width(280).color(['#444', '#444', '#444']);
g.select('.controlsWrap')
.datum(controlsData)
.attr('transform', 'translate(0,' + (-margin.top) +')')
.call(controls);
var stackedWrap = g.select('.stackedWrap')
.datum(data);
//.datum(data.filter(function(d) { return !d.disabled }))
d3.transition(stackedWrap).call(stacked);
@ -2386,23 +2407,22 @@ nv.models.stackedAreaWithLegend = function() {
.domain(x.domain())
.range(x.range())
.ticks( width / 100 )
.tickSize(-(height - margin.top - margin.bottom), 0);
.tickSize(-availableHeight, 0);
g.select('.x.axis')
.attr('transform', 'translate(0,' + y.range()[0] + ')');
.attr('transform', 'translate(0,' + availableHeight + ')');
d3.transition(g.select('.x.axis'))
.call(xAxis);
yAxis
.domain(y.domain())
.range(y.range())
.ticks( stacked.offset() == 'wiggle' ? 0 : height / 36 )
.tickSize(-(width - margin.right - margin.left), 0)
.ticks(stacked.offset() == 'wiggle' ? 0 : height / 36)
.tickSize(-availableWidth, 0)
.tickFormat(stacked.offset() == 'zero' ? d3.format(',.2f') : d3.format('%')); //TODO: stacked format should be set by caller
d3.transition(g.select('.y.axis'))
.call(yAxis);
});
return chart;
@ -2412,15 +2432,15 @@ nv.models.stackedAreaWithLegend = function() {
chart.x = function(_) {
if (!arguments.length) return getX;
getX = _;
stacked.x(_);
getX = d3.functor(_);
stacked.x(getX);
return chart;
};
chart.y = function(_) {
if (!arguments.length) return getY;
getY = _;
stacked.y(_);
getY = d3.functor(_);
stacked.y(getY);
return chart;
};
@ -2431,14 +2451,14 @@ nv.models.stackedAreaWithLegend = function() {
};
chart.width = function(_) {
if (!arguments.length) return width;
width = _;
if (!arguments.length) return getWidth;
getWidth = d3.functor(_);
return chart;
};
chart.height = function(_) {
if (!arguments.length) return height;
height = _;
if (!arguments.length) return getHeight;
getHeight = d3.functor(_);
return chart;
};
@ -2450,18 +2470,9 @@ nv.models.stackedAreaWithLegend = function() {
};
chart.stacked = stacked;
// Expose the x-axis' tickFormat method.
//chart.xAxis = {};
//d3.rebind(chart.xAxis, xAxis, 'tickFormat');
chart.xAxis = xAxis;
// Expose the y-axis' tickFormat method.
//chart.yAxis = {};
//d3.rebind(chart.yAxis, yAxis, 'tickFormat');
chart.yAxis = yAxis;
return chart;
}

4
nv.d3.min.js vendored

File diff suppressed because one or more lines are too long

@ -12,6 +12,7 @@ nv.models.line = function() {
getX = function(d) { return d.x },
getY = function(d) { return d.y },
interactive = true,
clipEdge = false,
clipVoronoi = true,
xDomain, yDomain;
@ -57,7 +58,7 @@ nv.models.line = function() {
.attr('height', availableHeight);
gEnter
.attr('clip-path', 'url(#chart-clip-path-' + id + ')');
.attr('clip-path', clipEdge ? 'url(#chart-clip-path-' + id + ')' : '');
var shiftWrap = gEnter.append('g').attr('class', 'shiftWrap');
@ -266,6 +267,12 @@ nv.models.line = function() {
return chart;
};
chart.clipEdge = function(_) {
if (!arguments.length) return clipEdge;
clipEdge = _;
return chart;
};
chart.clipVoronoi= function(_) {
if (!arguments.length) return clipVoronoi;
clipVoronoi = _;

@ -21,7 +21,7 @@ nv.models.lineWithFocus = function() {
xAxis2 = nv.models.xaxis().scale(x2),
yAxis2 = nv.models.yaxis().scale(y2),
legend = nv.models.legend().height(30),
focus = nv.models.line(),
focus = nv.models.line().clipEdge(true),
context = nv.models.line().dotRadius(.1).interactive(false),
dispatch = d3.dispatch('tooltipShow', 'tooltipHide'),
brush = d3.svg.brush()

Loading…
Cancel
Save