Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(demo): disable series tooltip for regression #4912

Merged
merged 2 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
null
pearmini marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions __tests__/plots/tooltip/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ export { aaplAreaMissingDataTranspose } from './aapl-area-missing-data-transpose
export { alphabetIntervalBrushTooltip } from './alphabet-interval-brush-tooltip';
export { mockLineFalsy } from './mock-line-falsy';
export { provincesLineGroupName } from './provinces-line-group-name';
export { pointsPointRegressionQuad } from './points-point-regression-quad';
pearmini marked this conversation as resolved.
Show resolved Hide resolved
42 changes: 42 additions & 0 deletions __tests__/plots/tooltip/points-point-regression-quad.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { regressionQuad } from 'd3-regression';
import { G2Spec } from '../../../src';
import { points } from '../../data/points';
import { seriesTooltipSteps } from './utils';

const regression = regressionQuad()
.x((d) => d.x)
// @ts-ignore
.y((d) => d.y)
.domain([-4, 4]);

export function pointsPointRegressionQuad(): G2Spec {
return {
type: 'view',
data: points,
scale: { x: { domain: [-4, 4] }, y: { domain: [-2, 14] } },
axis: { x: { title: false }, y: { title: false } },
children: [
{
type: 'point',
encode: { x: 'x', y: 'y', shape: 'point' },
},
{
type: 'line',
data: { transform: [{ type: 'custom', callback: regression }] },
encode: {
x: (d) => d[0],
y: (d) => d[1],
},
style: {
stroke: '#30BF78',
lineWidth: 2,
},
tooltip: false,
},
{ type: 'lineX', data: [0] },
{ type: 'lineY', data: [0] },
],
};
}

pointsPointRegressionQuad.steps = seriesTooltipSteps([100, 300]);
pearmini marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ chart
style: {
textAlign: 'end',
},
});
})
.tooltip(false);

chart.render();
pearmini marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 0 additions & 2 deletions site/examples/analysis/regression/demo/linear-regression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,4 @@ chart
})
.tooltip(false);

chart.interaction('tooltip', { series: false });

chart.render();
pearmini marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ chart
style: {
textAlign: 'end',
},
});
})
.tooltip(false);

chart.render();
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ chart
textAlign: 'end',
dx: -8,
},
});
})
.tooltip(null);
pearmini marked this conversation as resolved.
Show resolved Hide resolved

chart.render();
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ chart
.encode('x', (d) => d[0])
.encode('y', (d) => d[1])
.style('stroke', '#30BF78')
.style('lineWidth', 2);
.style('lineWidth', 2)
.tooltip(false);

chart.lineX().data([0]);
chart.lineY().data([0]);
Expand Down
10 changes: 8 additions & 2 deletions src/interaction/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,13 @@ function isEmptyTooltipData(data) {
return false;
}

function hasSeries(markState): boolean {
return Array.from(markState.values()).some(
// @ts-ignore
(d) => d.interaction?.seriesTooltip && d.tooltip,
);
}

/**
* Show tooltip for series item.
*/
Expand Down Expand Up @@ -599,15 +606,14 @@ export function Tooltip(options) {
return (target, viewInstances) => {
const { container, view } = target;
const { scale, markState, coordinate } = view;

// Get default value from mark states.
const defaultSeries = interactionKeyof(markState, 'seriesTooltip');
const defaultShowCrosshairs = interactionKeyof(markState, 'crosshairs');
const plotArea = selectPlotArea(container);
const isSeries = maybeValue(series, defaultSeries);

// For non-facet and series tooltip.
if (isSeries && !facet) {
if (isSeries && hasSeries(markState) && !facet) {
return seriesTooltip(plotArea, {
...rest,
elements: selectG2Elements,
Expand Down