Skip to content

Commit 388c915

Browse files
PieChart: trigger onPointHoverChanged event on legend hover (T1299624) (#30461)
1 parent ad28556 commit 388c915

File tree

2 files changed

+63
-3
lines changed

2 files changed

+63
-3
lines changed

packages/devextreme/js/viz/chart_components/tracker.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,17 @@ const baseTrackerPrototype = {
306306
}
307307
},
308308

309+
_processArgumentHoveredPoint: function(argument, argumentIndex) {
310+
this._releaseHoveredPoint();
311+
},
312+
309313
_hoverArgument: function(argument, argumentIndex) {
310314
const that = this;
311315
const hoverMode = that._getArgumentHoverMode();
312316

313317
if(isDefined(argument)) {
314-
that._releaseHoveredPoint();
318+
this._processArgumentHoveredPoint(argument, argumentIndex);
319+
315320
that._hoveredArgument = argument;
316321
that._argumentIndex = argumentIndex;
317322
that._notifySeries({
@@ -693,6 +698,17 @@ extend(PieTracker.prototype, baseTrackerPrototype, {
693698
_getArgumentHoverMode: function() {
694699
return correctHoverMode(this._legend);
695700
},
701+
702+
_processArgumentHoveredPoint: function(argument, argumentIndex) {
703+
const points = this._storedSeries.flatMap((series) => series.getPointsByKeys(argument, argumentIndex));
704+
705+
if(points.length === 1) {
706+
this._setHoveredPoint(points[0]);
707+
} else {
708+
this._releaseHoveredPoint();
709+
}
710+
},
711+
696712
_hoverArgumentAxis: _noop,
697713
_setStuckSeries: _noop,
698714
_getCanvas: _noop,

packages/devextreme/testing/tests/DevExpress.viz.charts/tracker.tests.js

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,8 +1233,12 @@ QUnit.test('mouseover on legend item', function(assert) {
12331233
$(this.renderer.root.element).trigger(getEvent('dxpointermove', { pageX: 100, pageY: 50 }));
12341234

12351235
// assert
1236-
assert.ok(this.series.stub('hover').calledOnce);
1237-
assert.deepEqual(this.series.hover.lastCall.args, ['includepoints']);
1236+
assert.strictEqual(this.series.stub('hover').calledOnce, true, 'series hover called');
1237+
assert.deepEqual(this.series.hover.lastCall.args, ['includepoints'], 'hover mode is includepoints');
1238+
1239+
$(this.renderer.root.element).trigger(getEvent('dxpointermove', { pageX: 100, pageY: 50 }));
1240+
1241+
assert.strictEqual(this.series.stub('clearHover').calledOnce, true, 'series clear hover called');
12381242
});
12391243

12401244
QUnit.test('mouseover on legend item. ExcludePoints mode', function(assert) {
@@ -2218,6 +2222,11 @@ QUnit.module('Root events. Pie chart', {
22182222
return createTracker('dxPieChart', options);
22192223
};
22202224

2225+
that.updateTracker = function(series) {
2226+
that.tracker.updateSeries(series);
2227+
that.tracker.update(this.options);
2228+
};
2229+
22212230
that.tracker = that.createTracker(that.options);
22222231
that.options.tooltip.stub('hide').reset();
22232232
},
@@ -2396,6 +2405,41 @@ QUnit.test('mouseover on legend item', function(assert) {
23962405
assert.strictEqual(this.series.notify.lastCall.args[0].target.getOptions().hoverMode, 'allargumentpoints');
23972406
});
23982407

2408+
QUnit.test('hover on legend should trigger point hover if PieChart has single series (T1299624)', function(assert) {
2409+
this.legend.coordsIn.withArgs(97, 45).returns(true);
2410+
this.legend.getItemByCoord.withArgs(97, 45).returns({ id: 0, argument: 'argument1', argumentIndex: 11 });
2411+
this.series.stub('getPointsByKeys').withArgs('argument1', 11).returns([this.point]);
2412+
2413+
$(this.renderer.root.element).trigger(getEvent('dxpointermove', { pageX: 100, pageY: 50 }));
2414+
2415+
assert.strictEqual(this.point.stub('hover').callCount, 1, 'point hover called on legend mouseover');
2416+
2417+
$(this.renderer.root.element).trigger(getEvent('dxpointermove', { pageX: 80, pageY: 50 }));
2418+
2419+
assert.strictEqual(this.point.stub('clearHover').callCount, 1, 'point clear hover called on legend mouseout');
2420+
});
2421+
2422+
QUnit.test('hover on legend should not be triggered point hover if PieChart has multiple series (T1299624)', function(assert) {
2423+
const series2 = createSeries();
2424+
const point2 = createPoint(series2);
2425+
this.updateTracker([this.series, series2]);
2426+
2427+
this.legend.coordsIn.withArgs(97, 45).returns(true);
2428+
this.legend.getItemByCoord.withArgs(97, 45).returns({ id: 0, argument: 'argument1', argumentIndex: 11 });
2429+
this.series.stub('getPointsByKeys').withArgs('argument1', 11).returns([this.point]);
2430+
series2.stub('getPointsByKeys').withArgs('argument1', 11).returns([point2]);
2431+
2432+
$(this.renderer.root.element).trigger(getEvent('dxpointermove', { pageX: 100, pageY: 50 }));
2433+
2434+
assert.strictEqual(this.point.stub('hover').callCount, 0, 'first series point not hovered on legend mouseover');
2435+
assert.strictEqual(point2.stub('hover').callCount, 0, 'second series point not hovered on legend mouseover');
2436+
2437+
$(this.renderer.root.element).trigger(getEvent('dxpointermove', { pageX: 80, pageY: 50 }));
2438+
2439+
assert.strictEqual(this.point.stub('clearHover').callCount, 0, 'first series point hover not cleared on legend mouseout');
2440+
assert.strictEqual(point2.stub('clearHover').callCount, 0, 'second series point hover not cleared on legend mouseout');
2441+
});
2442+
23992443
QUnit.test('mouseout from legend item', function(assert) {
24002444
this.legend.coordsIn.withArgs(97, 45).returns(true);
24012445
this.legend.getItemByCoord.withArgs(97, 45).returns({ id: 0, argument: 'argument1', argumentIndex: 11 });

0 commit comments

Comments
 (0)