Cleaning up scatterChart, fixed a few issues that had no tickets

master-patched
Bob Monteverde 12 years ago
parent 631e50f684
commit bfb1f2db25

@ -5562,7 +5562,6 @@ nv.models.scatter = function() {
z .domain(sizeDomain || d3.extent(seriesData.map(function(d) { return d.size }).concat(forceSize)))
.range([16, 256]);
//store old scales if they exist
x0 = x0 || x;
y0 = y0 || y;
z0 = z0 || z;
@ -5577,7 +5576,7 @@ nv.models.scatter = function() {
var wrapEnter = wrap.enter().append('g').attr('class', 'wrap nvd3 scatter chart-' +id);
var defsEnter = wrapEnter.append('defs');
var gEnter = wrapEnter.append('g');
var g = wrap.select('g')
var g = wrap.select('g');
gEnter.append('g').attr('class', 'groups');
gEnter.append('g').attr('class', 'point-paths');
@ -5922,39 +5921,50 @@ nv.models.scatter = function() {
}
nv.models.scatterChart = function() {
var margin = {top: 30, right: 20, bottom: 50, left: 60},
width = null,
height = null,
color = d3.scale.category20().range(),
showDistX = false,
showDistY = false,
showLegend = true,
showControls = true,
fisheye = 0,
pauseFisheye = false,
tooltips = true,
tooltipX = function(key, x, y) { return '<strong>' + x + '</strong>' },
tooltipY = function(key, x, y) { return '<strong>' + y + '</strong>' },
tooltip = function(key, x, y, e, graph) {
//============================================================
// Public Variables with Default Settings
//------------------------------------------------------------
var margin = {top: 30, right: 20, bottom: 50, left: 60}
, width = null
, height = null
, color = d3.scale.category20().range()
//x = scatter.xScale(),
, x = d3.fisheye.scale(d3.scale.linear).distortion(0)
//y = scatter.yScale(),
, y = d3.fisheye.scale(d3.scale.linear).distortion(0)
, showDistX = false
, showDistY = false
, showLegend = true
, showControls = true
, fisheye = 0
, pauseFisheye = false
, tooltips = true
, tooltipX = function(key, x, y) { return '<strong>' + x + '</strong>' }
, tooltipY = function(key, x, y) { return '<strong>' + y + '</strong>' }
, tooltip = function(key, x, y, e, graph) {
return '<h3>' + key + '</h3>' +
'<p>' + y + ' at ' + x + '</p>'
};
}
, scatter = nv.models.scatter().xScale(x).yScale(y)
, xAxis = nv.models.axis().orient('bottom').tickPadding(10)
, yAxis = nv.models.axis().orient('left').tickPadding(10)
, legend = nv.models.legend().height(30)
, controls = nv.models.legend().height(30)
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide')
;
//============================================================
var x = d3.fisheye.scale(d3.scale.linear).distortion(0),
y = d3.fisheye.scale(d3.scale.linear).distortion(0);
var scatter = nv.models.scatter().xScale(x).yScale(y),
//x = scatter.xScale(),
//y = scatter.yScale(),
xAxis = nv.models.axis().orient('bottom').scale(x).tickPadding(10),
yAxis = nv.models.axis().orient('left').scale(y).tickPadding(10),
legend = nv.models.legend().height(30),
controls = nv.models.legend().height(30),
distX = nv.models.distribution().axis('x').scale(x),
distY = nv.models.distribution().axis('y').scale(y),
dispatch = d3.dispatch('tooltipShow', 'tooltipHide'),
x0, y0; //TODO: abstract distribution component and have old scales stored there
//============================================================
// Private Variables
//------------------------------------------------------------
var distX = nv.models.distribution().axis('x').scale(x)
, distY = nv.models.distribution().axis('y').scale(y)
, x0, y0; //TODO: abstract distribution component and have old scales stored there
var showTooltip = function(e, offsetElement) {
//TODO: make tooltip style an option between single or dual on axes (maybe on all charts with axes?)
@ -5980,35 +5990,46 @@ nv.models.scatterChart = function() {
{ key: 'Magnify', disabled: true }
];
//============================================================
function chart(selection) {
selection.each(function(data) {
var container = d3.select(this),
that = this;
var availableWidth = (width || parseInt(container.style('width')) || 960)
- margin.left - margin.right,
availableHeight = (height || parseInt(container.style('height')) || 400)
- margin.top - margin.bottom;
//------------------------------------------------------------
// Setup Scales
x = scatter.xScale();
y = scatter.yScale();
x0 = x0 || x;
y0 = y0 || y;
x0 = x0 || scatter.xScale();
y0 = y0 || scatter.yScale();
//------------------------------------------------------------
//------------------------------------------------------------
// Setup containers and skeleton of chart
var wrap = container.selectAll('g.wrap.scatterChart').data([data]);
var gEnter = wrap.enter().append('g').attr('class', 'wrap nvd3 scatterChart chart-' + scatter.id()).append('g');
var wrapEnter = wrap.enter().append('g').attr('class', 'wrap nvd3 scatterChart chart-' + scatter.id());
var gEnter = wrapEnter.append('g');
var g = wrap.select('g')
// background for pointer events
gEnter.append('rect')
.attr('class', 'nvd3 background')
.attr('width', availableWidth)
.attr('height', availableHeight);
gEnter.append('g').attr('class', 'x axis');
gEnter.append('g').attr('class', 'y axis');
gEnter.append('g').attr('class', 'scatterWrap');
@ -6016,7 +6037,10 @@ nv.models.scatterChart = function() {
gEnter.append('g').attr('class', 'legendWrap');
gEnter.append('g').attr('class', 'controlsWrap');
var g = wrap.select('g')
wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
//------------------------------------------------------------
if (showLegend) {
legend.width( availableWidth / 2 );
@ -6035,6 +6059,7 @@ nv.models.scatterChart = function() {
.attr('transform', 'translate(' + (availableWidth / 2) + ',' + (-margin.top) +')');
}
if (showControls) {
controls.width(180).color(['#444']);
g.select('.controlsWrap')
@ -6045,14 +6070,11 @@ nv.models.scatterChart = function() {
scatter
.width(availableWidth)
.height(availableHeight)
.color(data.map(function(d,i) {
return d.color || color[i % color.length];
}).filter(function(d,i) { return !data[i].disabled }))
g.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
.width(availableWidth)
.height(availableHeight)
.color(data.map(function(d,i) {
return d.color || color[i % color.length];
}).filter(function(d,i) { return !data[i].disabled }))
var scatterWrap = wrap.select('.scatterWrap')
@ -6061,28 +6083,29 @@ nv.models.scatterChart = function() {
xAxis
.ticks( availableWidth / 100 )
.tickSize( -availableHeight , 0);
.scale(x)
.ticks( availableWidth / 100 )
.tickSize( -availableHeight , 0);
g.select('.x.axis')
.attr('transform', 'translate(0,' + y.range()[0] + ')');
d3.transition(g.select('.x.axis'))
.attr('transform', 'translate(0,' + y.range()[0] + ')')
.call(xAxis);
yAxis
.ticks( availableHeight / 36 )
.tickSize( -availableWidth, 0);
.scale(y)
.ticks( availableHeight / 36 )
.tickSize( -availableWidth, 0);
d3.transition(g.select('.y.axis'))
g.select('.y.axis')
.call(yAxis);
distX
.width(availableWidth)
.color(data.map(function(d,i) {
return d.color || color[i % color.length];
}).filter(function(d,i) { return !data[i].disabled }));
.width(availableWidth)
.color(data.map(function(d,i) {
return d.color || color[i % color.length];
}).filter(function(d,i) { return !data[i].disabled }));
gEnter.select('.distWrap').append('g')
.attr('class', 'distributionX')
.attr('transform', 'translate(0,' + y.range()[0] + ')');
@ -6092,10 +6115,10 @@ nv.models.scatterChart = function() {
distY
.width(availableHeight)
.color(data.map(function(d,i) {
return d.color || color[i % color.length];
}).filter(function(d,i) { return !data[i].disabled }));
.width(availableHeight)
.color(data.map(function(d,i) {
return d.color || color[i % color.length];
}).filter(function(d,i) { return !data[i].disabled }));
gEnter.select('.distWrap').append('g')
.attr('class', 'distributionY')
.attr('transform', 'translate(-' + distY.size() + ',0)');
@ -6106,17 +6129,16 @@ nv.models.scatterChart = function() {
g.select('.background').on('mousemove', updateFisheye);
g.select('.background').on('click', function() { pauseFisheye = !pauseFisheye; });
g.select('.point-paths').on('click', function() { pauseFisheye = !pauseFisheye; });
//g.select('.point-paths').on('mousemove', updateFisheye);
function updateFisheye() {
if (pauseFisheye) {
//g.select('.background') .style('pointer-events', 'none');
g.select('.point-paths').style('pointer-events', 'all');
return false;
}
g.select('.background') .style('pointer-events', 'all');
g.select('.point-paths').style('pointer-events', 'none' );
var mouse = d3.mouse(this);
@ -6127,26 +6149,26 @@ nv.models.scatterChart = function() {
g.select('.x.axis').call(xAxis);
g.select('.y.axis').call(yAxis);
g.select('.distributionX')
.datum(data.filter(function(d) { return !d.disabled }))
.datum(data.filter(function(d) { return !d.disabled }))
.call(distX);
g.select('.distributionY')
.datum(data.filter(function(d) { return !d.disabled }))
.datum(data.filter(function(d) { return !d.disabled }))
.call(distY);
}
//============================================================
// Event Handling/Dispatching (in chart's scope)
//------------------------------------------------------------
controls.dispatch.on('legendClick', function(d,i) {
controls.dispatch.on('legendClick', function(d,i) {
d.disabled = !d.disabled;
fisheye = d.disabled ? 0 : 2.5;
g.select('.background') .style('pointer-events', d.disabled ? 'none' : 'all');
g.select('.point-paths').style('pointer-events', d.disabled ? 'all' : 'none' );
//scatter.interactive(d.disabled);
//tooltips = d.disabled;
if (d.disabled) {
x.distortion(fisheye).focus(0);
y.distortion(fisheye).focus(0);
@ -6158,10 +6180,9 @@ nv.models.scatterChart = function() {
pauseFisheye = false;
}
selection.transition().call(chart);
chart(selection);
});
legend.dispatch.on('legendClick', function(d,i, that) {
d.disabled = !d.disabled;
@ -6173,22 +6194,21 @@ nv.models.scatterChart = function() {
});
}
selection.transition().call(chart)
chart(selection);
});
/*
legend.dispatch.on('legendMouseover', function(d, i) {
d.hover = true;
selection.transition().call(chart)
chart(selection);
});
legend.dispatch.on('legendMouseout', function(d, i) {
d.hover = false;
selection.transition().call(chart)
chart(selection);
});
*/
scatter.dispatch.on('elementMouseover.tooltip', function(e) {
d3.select('.chart-' + scatter.id() + ' .series-' + e.seriesIndex + ' .distx-' + e.pointIndex)
.attr('y1', e.pos[1] - availableHeight);
@ -6198,17 +6218,10 @@ nv.models.scatterChart = function() {
e.pos = [e.pos[0] + margin.left, e.pos[1] + margin.top];
dispatch.tooltipShow(e);
});
if (tooltips) dispatch.on('tooltipShow', function(e) { showTooltip(e, that.parentNode) } ); // TODO: maybe merge with above?
scatter.dispatch.on('elementMouseout.tooltip', function(e) {
dispatch.tooltipHide(e);
d3.select('.chart-' + scatter.id() + ' .series-' + e.seriesIndex + ' .distx-' + e.pointIndex)
.attr('y1', 0);
d3.select('.chart-' + scatter.id() + ' .series-' + e.seriesIndex + ' .disty-' + e.pointIndex)
.attr('x2', distY.size());
dispatch.on('tooltipShow', function(e) {
if (tooltips) showTooltip(e, that.parentNode);
});
if (tooltips) dispatch.on('tooltipHide', nv.tooltip.cleanup);
//store old scales for use in transitions on update, to animate from old to new positions, and sizes
@ -6216,24 +6229,43 @@ nv.models.scatterChart = function() {
y0 = y.copy();
//TODO: decide if this makes sense to add into all the models for ease of updating (updating without needing the selection)
chart.update = function() { selection.transition().call(chart) };
chart.update = function() { chart(selection) };
chart.container = this; // I need a reference to the container in order to have outside code check if the chart is visible or not
});
return chart;
}
//============================================================
// Event Handling/Dispatching (out of chart's scope)
//------------------------------------------------------------
scatter.dispatch.on('elementMouseout.tooltip', function(e) {
dispatch.tooltipHide(e);
d3.select('.chart-' + scatter.id() + ' .series-' + e.seriesIndex + ' .distx-' + e.pointIndex)
.attr('y1', 0);
d3.select('.chart-' + scatter.id() + ' .series-' + e.seriesIndex + ' .disty-' + e.pointIndex)
.attr('x2', distY.size());
});
dispatch.on('tooltipHide', function() {
if (tooltips) nv.tooltip.cleanup();
});
//============================================================
// Expose Public Variables
//------------------------------------------------------------
chart.dispatch = dispatch;
chart.legend = legend;
chart.controls = legend;
chart.xAxis = xAxis;
chart.yAxis = yAxis;
d3.rebind(chart, scatter, 'interactive', 'shape', 'size', 'xScale', 'yScale', 'zScale', 'xDomain', 'yDomain', 'sizeDomain', 'forceX', 'forceY', 'forceSize', 'clipVoronoi', 'clipRadius', 'fisheye', 'fisheyeRadius');
d3.rebind(chart, scatter, 'interactive', 'pointActive', 'shape', 'size', 'xScale', 'yScale', 'zScale', 'xDomain', 'yDomain', 'sizeDomain', 'forceX', 'forceY', 'forceSize', 'clipVoronoi', 'clipRadius');
chart.margin = function(_) {
if (!arguments.length) return margin;
@ -6304,6 +6336,8 @@ nv.models.scatterChart = function() {
return chart;
};
//============================================================
return chart;
}

4
nv.d3.min.js vendored

File diff suppressed because one or more lines are too long

@ -12,7 +12,9 @@
.nvd3.background {
fill: none;
/*
pointer-events: none;
*/
}
@ -346,6 +348,10 @@ svg .title {
* Scatter
*/
.nvd3 .groups .point {
pointer-events: none;
}
.nvd3 .groups .point.hover {
stroke-width: 20px;
stroke-opacity: .5;

@ -84,7 +84,6 @@ nv.models.scatter = function() {
z .domain(sizeDomain || d3.extent(seriesData.map(function(d) { return d.size }).concat(forceSize)))
.range([16, 256]);
//store old scales if they exist
x0 = x0 || x;
y0 = y0 || y;
z0 = z0 || z;
@ -99,7 +98,7 @@ nv.models.scatter = function() {
var wrapEnter = wrap.enter().append('g').attr('class', 'wrap nvd3 scatter chart-' +id);
var defsEnter = wrapEnter.append('defs');
var gEnter = wrapEnter.append('g');
var g = wrap.select('g')
var g = wrap.select('g');
gEnter.append('g').attr('class', 'groups');
gEnter.append('g').attr('class', 'point-paths');

@ -1,38 +1,49 @@
nv.models.scatterChart = function() {
var margin = {top: 30, right: 20, bottom: 50, left: 60},
width = null,
height = null,
color = d3.scale.category20().range(),
showDistX = false,
showDistY = false,
showLegend = true,
showControls = true,
fisheye = 0,
pauseFisheye = false,
tooltips = true,
tooltipX = function(key, x, y) { return '<strong>' + x + '</strong>' },
tooltipY = function(key, x, y) { return '<strong>' + y + '</strong>' },
tooltip = function(key, x, y, e, graph) {
//============================================================
// Public Variables with Default Settings
//------------------------------------------------------------
var margin = {top: 30, right: 20, bottom: 50, left: 60}
, width = null
, height = null
, color = d3.scale.category20().range()
//x = scatter.xScale(),
, x = d3.fisheye.scale(d3.scale.linear).distortion(0)
//y = scatter.yScale(),
, y = d3.fisheye.scale(d3.scale.linear).distortion(0)
, showDistX = false
, showDistY = false
, showLegend = true
, showControls = true
, fisheye = 0
, pauseFisheye = false
, tooltips = true
, tooltipX = function(key, x, y) { return '<strong>' + x + '</strong>' }
, tooltipY = function(key, x, y) { return '<strong>' + y + '</strong>' }
, tooltip = function(key, x, y, e, graph) {
return '<h3>' + key + '</h3>' +
'<p>' + y + ' at ' + x + '</p>'
};
}
, scatter = nv.models.scatter().xScale(x).yScale(y)
, xAxis = nv.models.axis().orient('bottom').tickPadding(10)
, yAxis = nv.models.axis().orient('left').tickPadding(10)
, legend = nv.models.legend().height(30)
, controls = nv.models.legend().height(30)
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide')
;
//============================================================
var x = d3.fisheye.scale(d3.scale.linear).distortion(0),
y = d3.fisheye.scale(d3.scale.linear).distortion(0);
//============================================================
// Private Variables
//------------------------------------------------------------
var scatter = nv.models.scatter().xScale(x).yScale(y),
//x = scatter.xScale(),
//y = scatter.yScale(),
xAxis = nv.models.axis().orient('bottom').scale(x).tickPadding(10),
yAxis = nv.models.axis().orient('left').scale(y).tickPadding(10),
legend = nv.models.legend().height(30),
controls = nv.models.legend().height(30),
distX = nv.models.distribution().axis('x').scale(x),
distY = nv.models.distribution().axis('y').scale(y),
dispatch = d3.dispatch('tooltipShow', 'tooltipHide'),
x0, y0; //TODO: abstract distribution component and have old scales stored there
var distX = nv.models.distribution().axis('x').scale(x)
, distY = nv.models.distribution().axis('y').scale(y)
, x0, y0; //TODO: abstract distribution component and have old scales stored there
var showTooltip = function(e, offsetElement) {
//TODO: make tooltip style an option between single or dual on axes (maybe on all charts with axes?)
@ -58,35 +69,46 @@ nv.models.scatterChart = function() {
{ key: 'Magnify', disabled: true }
];
//============================================================
function chart(selection) {
selection.each(function(data) {
var container = d3.select(this),
that = this;
var availableWidth = (width || parseInt(container.style('width')) || 960)
- margin.left - margin.right,
availableHeight = (height || parseInt(container.style('height')) || 400)
- margin.top - margin.bottom;
//------------------------------------------------------------
// Setup Scales
x0 = x0 || scatter.xScale();
y0 = y0 || scatter.yScale();
x = scatter.xScale();
y = scatter.yScale();
x0 = x0 || x;
y0 = y0 || y;
//------------------------------------------------------------
var wrap = container.selectAll('g.wrap.scatterChart').data([data]);
var gEnter = wrap.enter().append('g').attr('class', 'wrap nvd3 scatterChart chart-' + scatter.id()).append('g');
//------------------------------------------------------------
// Setup containers and skeleton of chart
var wrap = container.selectAll('g.wrap.scatterChart').data([data]);
var wrapEnter = wrap.enter().append('g').attr('class', 'wrap nvd3 scatterChart chart-' + scatter.id());
var gEnter = wrapEnter.append('g');
var g = wrap.select('g')
// background for pointer events
gEnter.append('rect')
.attr('class', 'nvd3 background')
.attr('width', availableWidth)
.attr('height', availableHeight);
gEnter.append('g').attr('class', 'x axis');
gEnter.append('g').attr('class', 'y axis');
gEnter.append('g').attr('class', 'scatterWrap');
@ -94,7 +116,10 @@ nv.models.scatterChart = function() {
gEnter.append('g').attr('class', 'legendWrap');
gEnter.append('g').attr('class', 'controlsWrap');
var g = wrap.select('g')
wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
//------------------------------------------------------------
if (showLegend) {
legend.width( availableWidth / 2 );
@ -113,6 +138,7 @@ nv.models.scatterChart = function() {
.attr('transform', 'translate(' + (availableWidth / 2) + ',' + (-margin.top) +')');
}
if (showControls) {
controls.width(180).color(['#444']);
g.select('.controlsWrap')
@ -123,14 +149,11 @@ nv.models.scatterChart = function() {
scatter
.width(availableWidth)
.height(availableHeight)
.color(data.map(function(d,i) {
return d.color || color[i % color.length];
}).filter(function(d,i) { return !data[i].disabled }))
g.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
.width(availableWidth)
.height(availableHeight)
.color(data.map(function(d,i) {
return d.color || color[i % color.length];
}).filter(function(d,i) { return !data[i].disabled }))
var scatterWrap = wrap.select('.scatterWrap')
@ -139,28 +162,29 @@ nv.models.scatterChart = function() {
xAxis
.ticks( availableWidth / 100 )
.tickSize( -availableHeight , 0);
.scale(x)
.ticks( availableWidth / 100 )
.tickSize( -availableHeight , 0);
g.select('.x.axis')
.attr('transform', 'translate(0,' + y.range()[0] + ')');
d3.transition(g.select('.x.axis'))
.attr('transform', 'translate(0,' + y.range()[0] + ')')
.call(xAxis);
yAxis
.ticks( availableHeight / 36 )
.tickSize( -availableWidth, 0);
.scale(y)
.ticks( availableHeight / 36 )
.tickSize( -availableWidth, 0);
d3.transition(g.select('.y.axis'))
g.select('.y.axis')
.call(yAxis);
distX
.width(availableWidth)
.color(data.map(function(d,i) {
return d.color || color[i % color.length];
}).filter(function(d,i) { return !data[i].disabled }));
.width(availableWidth)
.color(data.map(function(d,i) {
return d.color || color[i % color.length];
}).filter(function(d,i) { return !data[i].disabled }));
gEnter.select('.distWrap').append('g')
.attr('class', 'distributionX')
.attr('transform', 'translate(0,' + y.range()[0] + ')');
@ -170,10 +194,10 @@ nv.models.scatterChart = function() {
distY
.width(availableHeight)
.color(data.map(function(d,i) {
return d.color || color[i % color.length];
}).filter(function(d,i) { return !data[i].disabled }));
.width(availableHeight)
.color(data.map(function(d,i) {
return d.color || color[i % color.length];
}).filter(function(d,i) { return !data[i].disabled }));
gEnter.select('.distWrap').append('g')
.attr('class', 'distributionY')
.attr('transform', 'translate(-' + distY.size() + ',0)');
@ -184,17 +208,16 @@ nv.models.scatterChart = function() {
g.select('.background').on('mousemove', updateFisheye);
g.select('.background').on('click', function() { pauseFisheye = !pauseFisheye; });
g.select('.point-paths').on('click', function() { pauseFisheye = !pauseFisheye; });
//g.select('.point-paths').on('mousemove', updateFisheye);
function updateFisheye() {
if (pauseFisheye) {
//g.select('.background') .style('pointer-events', 'none');
g.select('.point-paths').style('pointer-events', 'all');
return false;
}
g.select('.background') .style('pointer-events', 'all');
g.select('.point-paths').style('pointer-events', 'none' );
var mouse = d3.mouse(this);
@ -205,26 +228,26 @@ nv.models.scatterChart = function() {
g.select('.x.axis').call(xAxis);
g.select('.y.axis').call(yAxis);
g.select('.distributionX')
.datum(data.filter(function(d) { return !d.disabled }))
.datum(data.filter(function(d) { return !d.disabled }))
.call(distX);
g.select('.distributionY')
.datum(data.filter(function(d) { return !d.disabled }))
.datum(data.filter(function(d) { return !d.disabled }))
.call(distY);
}
//============================================================
// Event Handling/Dispatching (in chart's scope)
//------------------------------------------------------------
controls.dispatch.on('legendClick', function(d,i) {
controls.dispatch.on('legendClick', function(d,i) {
d.disabled = !d.disabled;
fisheye = d.disabled ? 0 : 2.5;
g.select('.background') .style('pointer-events', d.disabled ? 'none' : 'all');
g.select('.point-paths').style('pointer-events', d.disabled ? 'all' : 'none' );
//scatter.interactive(d.disabled);
//tooltips = d.disabled;
if (d.disabled) {
x.distortion(fisheye).focus(0);
y.distortion(fisheye).focus(0);
@ -236,10 +259,9 @@ nv.models.scatterChart = function() {
pauseFisheye = false;
}
selection.transition().call(chart);
chart(selection);
});
legend.dispatch.on('legendClick', function(d,i, that) {
d.disabled = !d.disabled;
@ -251,22 +273,21 @@ nv.models.scatterChart = function() {
});
}
selection.transition().call(chart)
chart(selection);
});
/*
legend.dispatch.on('legendMouseover', function(d, i) {
d.hover = true;
selection.transition().call(chart)
chart(selection);
});
legend.dispatch.on('legendMouseout', function(d, i) {
d.hover = false;
selection.transition().call(chart)
chart(selection);
});
*/
scatter.dispatch.on('elementMouseover.tooltip', function(e) {
d3.select('.chart-' + scatter.id() + ' .series-' + e.seriesIndex + ' .distx-' + e.pointIndex)
.attr('y1', e.pos[1] - availableHeight);
@ -276,17 +297,10 @@ nv.models.scatterChart = function() {
e.pos = [e.pos[0] + margin.left, e.pos[1] + margin.top];
dispatch.tooltipShow(e);
});
if (tooltips) dispatch.on('tooltipShow', function(e) { showTooltip(e, that.parentNode) } ); // TODO: maybe merge with above?
scatter.dispatch.on('elementMouseout.tooltip', function(e) {
dispatch.tooltipHide(e);
d3.select('.chart-' + scatter.id() + ' .series-' + e.seriesIndex + ' .distx-' + e.pointIndex)
.attr('y1', 0);
d3.select('.chart-' + scatter.id() + ' .series-' + e.seriesIndex + ' .disty-' + e.pointIndex)
.attr('x2', distY.size());
dispatch.on('tooltipShow', function(e) {
if (tooltips) showTooltip(e, that.parentNode);
});
if (tooltips) dispatch.on('tooltipHide', nv.tooltip.cleanup);
//store old scales for use in transitions on update, to animate from old to new positions, and sizes
@ -294,24 +308,43 @@ nv.models.scatterChart = function() {
y0 = y.copy();
//TODO: decide if this makes sense to add into all the models for ease of updating (updating without needing the selection)
chart.update = function() { selection.transition().call(chart) };
chart.update = function() { chart(selection) };
chart.container = this; // I need a reference to the container in order to have outside code check if the chart is visible or not
});
return chart;
}
//============================================================
// Event Handling/Dispatching (out of chart's scope)
//------------------------------------------------------------
scatter.dispatch.on('elementMouseout.tooltip', function(e) {
dispatch.tooltipHide(e);
d3.select('.chart-' + scatter.id() + ' .series-' + e.seriesIndex + ' .distx-' + e.pointIndex)
.attr('y1', 0);
d3.select('.chart-' + scatter.id() + ' .series-' + e.seriesIndex + ' .disty-' + e.pointIndex)
.attr('x2', distY.size());
});
dispatch.on('tooltipHide', function() {
if (tooltips) nv.tooltip.cleanup();
});
//============================================================
// Expose Public Variables
//------------------------------------------------------------
chart.dispatch = dispatch;
chart.legend = legend;
chart.controls = legend;
chart.xAxis = xAxis;
chart.yAxis = yAxis;
d3.rebind(chart, scatter, 'interactive', 'shape', 'size', 'xScale', 'yScale', 'zScale', 'xDomain', 'yDomain', 'sizeDomain', 'forceX', 'forceY', 'forceSize', 'clipVoronoi', 'clipRadius', 'fisheye', 'fisheyeRadius');
d3.rebind(chart, scatter, 'interactive', 'pointActive', 'shape', 'size', 'xScale', 'yScale', 'zScale', 'xDomain', 'yDomain', 'sizeDomain', 'forceX', 'forceY', 'forceSize', 'clipVoronoi', 'clipRadius');
chart.margin = function(_) {
if (!arguments.length) return margin;
@ -382,6 +415,8 @@ nv.models.scatterChart = function() {
return chart;
};
//============================================================
return chart;
}

Loading…
Cancel
Save