Skip to content

Commit

Permalink
fix(tooltip): view with inset
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini committed Mar 10, 2023
1 parent 06eb075 commit 2cafce6
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions __tests__/plots/interaction/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ export { pointsPointRegressionQuad } from './points-point-regression-quad';
export { indicesLineChartFacet } from './indices-line-chart-facet';
export { pointsPointRegressionQuadTranspose } from './points-point-regression-quad-transpose';
export { scoreByItemAreaRadar } from './score-by-item-area-radar';
export { pointsPointRegressionQuadInset } from './points-point-regression-quad-inset';
56 changes: 56 additions & 0 deletions __tests__/plots/interaction/points-point-regression-quad-inset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { regressionQuad } from 'd3-regression';
import { G2Spec, PLOT_CLASS_NAME } from '../../../src';
import { points } from '../../data/points';
import { step } from './utils';

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

export function pointsPointRegressionQuadInset(): G2Spec {
return {
type: 'view',
inset: 30,
data: points,
scale: { x: { domain: [-4, 4] }, y: { domain: [-2, 14] } },
axis: { x: { title: false }, y: { title: false } },
interaction: {
tooltip: { body: false, style: { crosshairsStrokeWidth: 30 } },
},
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,
},
},
{ type: 'lineX', data: [0] },
{ type: 'lineY', data: [0] },
],
};
}

pointsPointRegressionQuadInset.tooltip = true;

pointsPointRegressionQuadInset.steps = ({ canvas }) => {
const { document } = canvas;
const [plot] = document.getElementsByClassName(PLOT_CLASS_NAME);
return [
step(plot, 'pointermove', {
offsetX: 450,
offsetY: 350,
}),
];
};
4 changes: 2 additions & 2 deletions src/interaction/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Tooltip as TooltipComponent } from '@antv/gui';
import { Constant, Identity } from '@antv/scale';
import { defined, subObject } from '../utils/helper';
import { isTranspose, isPolar } from '../utils/coordinate';
import { angleWithQuadrant, angle, angleBetween, sub } from '../utils/vector';
import { angle, sub } from '../utils/vector';
import {
selectG2Elements,
createXKey,
Expand Down Expand Up @@ -275,7 +275,7 @@ export function seriesTooltip(
const elements = elementsof(root);
const transposed = isTranspose(coordinate);
const polar = isPolar(coordinate);
const [width, height] = coordinate.getSize();
const { innerWidth: width, innerHeight: height } = coordinate.getOptions();

// Split elements into series elements and item elements.
const seriesElements = [];
Expand Down

0 comments on commit 2cafce6

Please sign in to comment.