From f3cf915f1c43f026deeac6cc78a175aad22aafba Mon Sep 17 00:00:00 2001 From: Davis Ford Date: Fri, 17 Oct 2014 22:42:28 -0400 Subject: [PATCH] add new boolean property on line chart to enable/disable mouseover for xy axis refs and data points --- spec/line-chart-spec.js | 14 ++++++++++++++ src/line-chart.js | 17 ++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/spec/line-chart-spec.js b/spec/line-chart-spec.js index d159bbe08..b414ffe91 100644 --- a/spec/line-chart-spec.js +++ b/spec/line-chart-spec.js @@ -122,6 +122,20 @@ describe('dc.lineChart', function() { }); }); + describe('data point highlights and refs off', function () { + beforeEach(function () { + chart.title(function (d) { return d.value; }); + chart.brushOn(false).xyTipsOn(false).render(); + }); + it('should not generate per data points', function () { + expect(chart.selectAll('circle.dot').size())toBe(0); + }); + it('should not generate x and y refs', function () { + expect(chart.selectAll('path.xRef').size()).toBe(0); + expect(chart.selectAll('path.yRef').size()).toBe(0); + }); + }); + describe('data point highlights', function () { beforeEach(function () { chart.title(function (d) { return d.value; }); diff --git a/src/line-chart.js b/src/line-chart.js index 96b36a7bc..568bb72ee 100644 --- a/src/line-chart.js +++ b/src/line-chart.js @@ -52,6 +52,7 @@ dc.lineChart = function (parent, chartGroup) { var _tension = 0.7; var _defined; var _dashStyle; + var _xyTipsOn = true; _chart.transitionDuration(500); _chart._rangeBandPadding(1); @@ -233,7 +234,7 @@ dc.lineChart = function (parent, chartGroup) { } function drawDots(chartBody, layers) { - if (!_chart.brushOn()) { + if (!_chart.brushOn() && _chart.xyTipsOn()) { var tooltipListClass = TOOLTIP_G_CLASS + '-list'; var tooltips = chartBody.select('g.' + tooltipListClass); @@ -338,6 +339,20 @@ dc.lineChart = function (parent, chartGroup) { } } + /** + #### .xyTipsOn([boolean]) + Turn on/off the mouseover behavior of an individual data point which renders a circle and x/y axis + dashed lines back to each respective axis. This is ignored if the chart brush is on (`brushOn`) + Default: true + */ + _chart.xyTipsOn = function (_) { + if (!arguments.length) { + return _xyTipsOn; + } + _xyTipsOn = _; + return _chart; + }; + /** #### .dotRadius([dotRadius]) Get or set the radius (in px) for dots displayed on the data points. Default dot radius is 5.