Skip to content

Commit 1c3e434

Browse files
PieChart: trigger onPointHoverChanged event on legend hover (T1299624) (DevExpress#30460)
1 parent f2291b6 commit 1c3e434

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
@@ -298,12 +298,17 @@ const baseTrackerPrototype = {
298298
}
299299
},
300300

301+
_processArgumentHoveredPoint: function(argument, argumentIndex) {
302+
this._releaseHoveredPoint();
303+
},
304+
301305
_hoverArgument: function(argument, argumentIndex) {
302306
const that = this;
303307
const hoverMode = that._getArgumentHoverMode();
304308

305309
if(isDefined(argument)) {
306-
that._releaseHoveredPoint();
310+
this._processArgumentHoveredPoint(argument, argumentIndex);
311+
307312
that._hoveredArgument = argument;
308313
that._argumentIndex = argumentIndex;
309314
that._notifySeries({
@@ -685,6 +690,17 @@ extend(PieTracker.prototype, baseTrackerPrototype, {
685690
_getArgumentHoverMode: function() {
686691
return correctHoverMode(this._legend);
687692
},
693+
694+
_processArgumentHoveredPoint: function(argument, argumentIndex) {
695+
const points = this._storedSeries.flatMap((series) => series.getPointsByKeys(argument, argumentIndex));
696+
697+
if(points.length === 1) {
698+
this._setHoveredPoint(points[0]);
699+
} else {
700+
this._releaseHoveredPoint();
701+
}
702+
},
703+
688704
_hoverArgumentAxis: _noop,
689705
_setStuckSeries: _noop,
690706
_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
@@ -1209,8 +1209,12 @@ QUnit.test('mouseover on legend item', function(assert) {
12091209
$(this.renderer.root.element).trigger(getEvent('dxpointermove', { pageX: 100, pageY: 50 }));
12101210

12111211
// assert
1212-
assert.ok(this.series.stub('hover').calledOnce);
1213-
assert.deepEqual(this.series.hover.lastCall.args, ['includepoints']);
1212+
assert.strictEqual(this.series.stub('hover').calledOnce, true, 'series hover called');
1213+
assert.deepEqual(this.series.hover.lastCall.args, ['includepoints'], 'hover mode is includepoints');
1214+
1215+
$(this.renderer.root.element).trigger(getEvent('dxpointermove', { pageX: 100, pageY: 50 }));
1216+
1217+
assert.strictEqual(this.series.stub('clearHover').calledOnce, true, 'series clear hover called');
12141218
});
12151219

12161220
QUnit.test('mouseover on legend item. ExcludePoints mode', function(assert) {
@@ -2164,6 +2168,11 @@ QUnit.module('Root events. Pie chart', {
21642168
return createTracker('dxPieChart', options);
21652169
};
21662170

2171+
that.updateTracker = function(series) {
2172+
that.tracker.updateSeries(series);
2173+
that.tracker.update(this.options);
2174+
};
2175+
21672176
that.tracker = that.createTracker(that.options);
21682177
that.options.tooltip.stub('hide').reset();
21692178
},
@@ -2342,6 +2351,41 @@ QUnit.test('mouseover on legend item', function(assert) {
23422351
assert.strictEqual(this.series.notify.lastCall.args[0].target.getOptions().hoverMode, 'allargumentpoints');
23432352
});
23442353

2354+
QUnit.test('hover on legend should trigger point hover if PieChart has single series (T1299624)', function(assert) {
2355+
this.legend.coordsIn.withArgs(97, 45).returns(true);
2356+
this.legend.getItemByCoord.withArgs(97, 45).returns({ id: 0, argument: 'argument1', argumentIndex: 11 });
2357+
this.series.stub('getPointsByKeys').withArgs('argument1', 11).returns([this.point]);
2358+
2359+
$(this.renderer.root.element).trigger(getEvent('dxpointermove', { pageX: 100, pageY: 50 }));
2360+
2361+
assert.strictEqual(this.point.stub('hover').callCount, 1, 'point hover called on legend mouseover');
2362+
2363+
$(this.renderer.root.element).trigger(getEvent('dxpointermove', { pageX: 80, pageY: 50 }));
2364+
2365+
assert.strictEqual(this.point.stub('clearHover').callCount, 1, 'point clear hover called on legend mouseout');
2366+
});
2367+
2368+
QUnit.test('hover on legend should not be triggered point hover if PieChart has multiple series (T1299624)', function(assert) {
2369+
const series2 = createSeries();
2370+
const point2 = createPoint(series2);
2371+
this.updateTracker([this.series, series2]);
2372+
2373+
this.legend.coordsIn.withArgs(97, 45).returns(true);
2374+
this.legend.getItemByCoord.withArgs(97, 45).returns({ id: 0, argument: 'argument1', argumentIndex: 11 });
2375+
this.series.stub('getPointsByKeys').withArgs('argument1', 11).returns([this.point]);
2376+
series2.stub('getPointsByKeys').withArgs('argument1', 11).returns([point2]);
2377+
2378+
$(this.renderer.root.element).trigger(getEvent('dxpointermove', { pageX: 100, pageY: 50 }));
2379+
2380+
assert.strictEqual(this.point.stub('hover').callCount, 0, 'first series point not hovered on legend mouseover');
2381+
assert.strictEqual(point2.stub('hover').callCount, 0, 'second series point not hovered on legend mouseover');
2382+
2383+
$(this.renderer.root.element).trigger(getEvent('dxpointermove', { pageX: 80, pageY: 50 }));
2384+
2385+
assert.strictEqual(this.point.stub('clearHover').callCount, 0, 'first series point hover not cleared on legend mouseout');
2386+
assert.strictEqual(point2.stub('clearHover').callCount, 0, 'second series point hover not cleared on legend mouseout');
2387+
});
2388+
23452389
QUnit.test('mouseout from legend item', function(assert) {
23462390
this.legend.coordsIn.withArgs(97, 45).returns(true);
23472391
this.legend.getItemByCoord.withArgs(97, 45).returns({ id: 0, argument: 'argument1', argumentIndex: 11 });

0 commit comments

Comments
 (0)