Instead of using a dispatch for handling 'highlightPoint' and 'clearHighlights', I am making

those functions a direct method of nv.models.scatter.  So you just say scatter.highlightPoint,
instead of scatter.dispatch.highlightPoint.
master
Robin Hu 11 years ago
parent b07d1f2a87
commit 817340cff5

@ -505,7 +505,7 @@ nv.models.cumulativeLineChart = function() {
*/ */
interactiveLayer.dispatch.on('elementMousemove', function(e) { interactiveLayer.dispatch.on('elementMousemove', function(e) {
lines.dispatch.clearHighlights(); lines.clearHighlights();
var singlePoint, pointIndex, pointXLocation, allData = []; var singlePoint, pointIndex, pointXLocation, allData = [];
data data
.filter(function(series, i) { .filter(function(series, i) {
@ -514,7 +514,7 @@ nv.models.cumulativeLineChart = function() {
}) })
.forEach(function(series,i) { .forEach(function(series,i) {
pointIndex = nv.interactiveBisect(series.values, e.pointXValue, chart.x()); pointIndex = nv.interactiveBisect(series.values, e.pointXValue, chart.x());
lines.dispatch.highlightPoint(i, pointIndex, true); lines.highlightPoint(i, pointIndex, true);
var point = series.values[pointIndex]; var point = series.values[pointIndex];
if (typeof point === 'undefined') return; if (typeof point === 'undefined') return;
if (typeof singlePoint === 'undefined') singlePoint = point; if (typeof singlePoint === 'undefined') singlePoint = point;
@ -547,7 +547,7 @@ nv.models.cumulativeLineChart = function() {
interactiveLayer.dispatch.on("elementMouseout",function(e) { interactiveLayer.dispatch.on("elementMouseout",function(e) {
dispatch.tooltipHide(); dispatch.tooltipHide();
lines.dispatch.clearHighlights(); lines.clearHighlights();
}); });
dispatch.on('tooltipShow', function(e) { dispatch.on('tooltipShow', function(e) {

@ -209,7 +209,8 @@ nv.models.line = function() {
chart.dispatch = scatter.dispatch; chart.dispatch = scatter.dispatch;
chart.scatter = scatter; chart.scatter = scatter;
d3.rebind(chart, scatter, 'id', 'interactive', 'size', 'xScale', 'yScale', 'zScale', 'xDomain', 'yDomain', 'sizeDomain', 'forceX', 'forceY', 'forceSize', 'clipVoronoi', 'useVoronoi', 'clipRadius', 'padData'); d3.rebind(chart, scatter, 'id', 'interactive', 'size', 'xScale', 'yScale', 'zScale', 'xDomain', 'yDomain',
'sizeDomain', 'forceX', 'forceY', 'forceSize', 'clipVoronoi', 'useVoronoi', 'clipRadius', 'padData','highlightPoint','clearHighlights');
chart.margin = function(_) { chart.margin = function(_) {
if (!arguments.length) return margin; if (!arguments.length) return margin;

@ -255,7 +255,7 @@ nv.models.lineChart = function() {
interactiveLayer.dispatch.on('elementMousemove', function(e) { interactiveLayer.dispatch.on('elementMousemove', function(e) {
lines.dispatch.clearHighlights(); lines.clearHighlights();
var singlePoint, pointIndex, pointXLocation, allData = []; var singlePoint, pointIndex, pointXLocation, allData = [];
data data
.filter(function(series, i) { .filter(function(series, i) {
@ -264,7 +264,7 @@ nv.models.lineChart = function() {
}) })
.forEach(function(series,i) { .forEach(function(series,i) {
pointIndex = nv.interactiveBisect(series.values, e.pointXValue, chart.x()); pointIndex = nv.interactiveBisect(series.values, e.pointXValue, chart.x());
lines.dispatch.highlightPoint(i, pointIndex, true); lines.highlightPoint(i, pointIndex, true);
var point = series.values[pointIndex]; var point = series.values[pointIndex];
if (typeof point === 'undefined') return; if (typeof point === 'undefined') return;
if (typeof singlePoint === 'undefined') singlePoint = point; if (typeof singlePoint === 'undefined') singlePoint = point;
@ -297,7 +297,7 @@ nv.models.lineChart = function() {
interactiveLayer.dispatch.on("elementMouseout",function(e) { interactiveLayer.dispatch.on("elementMouseout",function(e) {
dispatch.tooltipHide(); dispatch.tooltipHide();
lines.dispatch.clearHighlights(); lines.clearHighlights();
}); });
dispatch.on('tooltipShow', function(e) { dispatch.on('tooltipShow', function(e) {

@ -34,7 +34,7 @@ nv.models.scatter = function() {
, sizeDomain = null // Override point size domain , sizeDomain = null // Override point size domain
, sizeRange = null , sizeRange = null
, singlePoint = false , singlePoint = false
, dispatch = d3.dispatch('elementClick', 'elementMouseover', 'elementMouseout', 'highlightPoint', 'clearHighlights') , dispatch = d3.dispatch('elementClick', 'elementMouseover', 'elementMouseout')
, useVoronoi = true , useVoronoi = true
; ;
@ -432,20 +432,23 @@ nv.models.scatter = function() {
//============================================================ //============================================================
// Event Handling/Dispatching (out of chart's scope) // Event Handling/Dispatching (out of chart's scope)
//------------------------------------------------------------ //------------------------------------------------------------
dispatch.on('clearHighlights', function() { chart.clearHighlights = function() {
//Remove the 'hover' class from all highlighted points.
d3.selectAll(".nv-chart-" + id + " .nv-point.hover").classed("hover",false); d3.selectAll(".nv-chart-" + id + " .nv-point.hover").classed("hover",false);
}); };
dispatch.on('highlightPoint', function(seriesIndex, pointIndex, isHoverOver) { chart.highlightPoint = function(seriesIndex,pointIndex,isHoverOver) {
d3.select(".nv-chart-" + id + " .nv-series-" + seriesIndex + " .nv-point-" + pointIndex) d3.select(".nv-chart-" + id + " .nv-series-" + seriesIndex + " .nv-point-" + pointIndex)
.classed("hover",isHoverOver); .classed("hover",isHoverOver);
}); };
dispatch.on('elementMouseover.point', function(d) { dispatch.on('elementMouseover.point', function(d) {
if (interactive) dispatch.highlightPoint(d.seriesIndex,d.pointIndex,true); if (interactive) chart.highlightPoint(d.seriesIndex,d.pointIndex,true);
}); });
dispatch.on('elementMouseout.point', function(d) { dispatch.on('elementMouseout.point', function(d) {
if (interactive) dispatch.highlightPoint(d.seriesIndex,d.pointIndex,false); if (interactive) chart.highlightPoint(d.seriesIndex,d.pointIndex,false);
}); });
//============================================================ //============================================================

@ -250,7 +250,8 @@ nv.models.stackedArea = function() {
chart.dispatch = dispatch; chart.dispatch = dispatch;
chart.scatter = scatter; chart.scatter = scatter;
d3.rebind(chart, scatter, 'interactive', 'size', 'xScale', 'yScale', 'zScale', 'xDomain', 'yDomain', 'sizeDomain', 'forceX', 'forceY', 'forceSize', 'clipVoronoi', 'useVoronoi','clipRadius'); d3.rebind(chart, scatter, 'interactive', 'size', 'xScale', 'yScale', 'zScale', 'xDomain', 'yDomain',
'sizeDomain', 'forceX', 'forceY', 'forceSize', 'clipVoronoi', 'useVoronoi','clipRadius','highlightPoint','clearHighlights');
chart.x = function(_) { chart.x = function(_) {
if (!arguments.length) return getX; if (!arguments.length) return getX;

@ -341,7 +341,7 @@ nv.models.stackedAreaChart = function() {
interactiveLayer.dispatch.on('elementMousemove', function(e) { interactiveLayer.dispatch.on('elementMousemove', function(e) {
stacked.scatter.dispatch.clearHighlights(); stacked.clearHighlights();
var singlePoint, pointIndex, pointXLocation, allData = []; var singlePoint, pointIndex, pointXLocation, allData = [];
data data
.filter(function(series, i) { .filter(function(series, i) {
@ -350,7 +350,7 @@ nv.models.stackedAreaChart = function() {
}) })
.forEach(function(series,i) { .forEach(function(series,i) {
pointIndex = nv.interactiveBisect(series.values, e.pointXValue, chart.x()); pointIndex = nv.interactiveBisect(series.values, e.pointXValue, chart.x());
stacked.scatter.dispatch.highlightPoint(i, pointIndex, true); stacked.highlightPoint(i, pointIndex, true);
var point = series.values[pointIndex]; var point = series.values[pointIndex];
if (typeof point === 'undefined') return; if (typeof point === 'undefined') return;
if (typeof singlePoint === 'undefined') singlePoint = point; if (typeof singlePoint === 'undefined') singlePoint = point;
@ -383,7 +383,7 @@ nv.models.stackedAreaChart = function() {
interactiveLayer.dispatch.on("elementMouseout",function(e) { interactiveLayer.dispatch.on("elementMouseout",function(e) {
dispatch.tooltipHide(); dispatch.tooltipHide();
stacked.scatter.dispatch.clearHighlights(); stacked.clearHighlights();
}); });

Loading…
Cancel
Save