-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tooltip): custom marker tooltip (#6384)
* feat(tooltip): custom marker tooltip * test: update snapshots
- Loading branch information
Showing
17 changed files
with
170 additions
and
10 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions
9
__tests__/integration/snapshots/tooltip/temperature-line-marker/step0.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div | ||
xmlns="http://www.w3.org/1999/xhtml" | ||
class="g2-tooltip" | ||
style="pointer-events: none; position: absolute; visibility: visible; z-index: 8; transition: visibility 0.2s cubic-bezier(0.23, 1, 0.32, 1), left 0.4s cubic-bezier(0.23, 1, 0.32, 1), top 0.4s cubic-bezier(0.23, 1, 0.32, 1); background-color: rgba(255, 255, 255, 0.96); box-shadow: 0 6px 12px 0 rgba(0, 0, 0, 0.12); border-radius: 4px; color: rgba(0, 0, 0, 0.65); font-size: 12px; line-height: 20px; padding: 12px; min-width: 120px; max-width: 360px; font-family: sans-serif; left: 210px; top: 310px;" | ||
> | ||
Tokyo: 9.5 | ||
<br /> | ||
London: 5.7 | ||
</div> |
7 changes: 7 additions & 0 deletions
7
__tests__/integration/snapshots/tooltip/temperature-line-marker/step1.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<div | ||
xmlns="http://www.w3.org/1999/xhtml" | ||
class="g2-tooltip" | ||
style="pointer-events: none; position: absolute; visibility: visible; z-index: 8; transition: visibility 0.2s cubic-bezier(0.23, 1, 0.32, 1), left 0.4s cubic-bezier(0.23, 1, 0.32, 1), top 0.4s cubic-bezier(0.23, 1, 0.32, 1); background-color: rgba(255, 255, 255, 0.96); box-shadow: 0 6px 12px 0 rgba(0, 0, 0, 0.12); border-radius: 4px; color: rgba(0, 0, 0, 0.65); font-size: 12px; line-height: 20px; padding: 12px; min-width: 120px; max-width: 360px; font-family: sans-serif; left: 199.470002395169px; top: 322.01769911504425px;" | ||
> | ||
Tokyo: 9.5 | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { CustomEvent } from '@antv/g'; | ||
import { G2Spec, PLOT_CLASS_NAME } from '../../../src'; | ||
import { temperatures } from '../../data/temperatures'; | ||
|
||
export function temperatureLineMarker(): G2Spec { | ||
return { | ||
type: 'line', | ||
data: temperatures, | ||
encode: { | ||
x: 'month', | ||
y: 'temperature', | ||
color: 'city', | ||
}, | ||
interaction: { | ||
tooltip: { | ||
render: (event, { items }) => { | ||
const target = event.target; | ||
const format = (item) => `${item.name}: ${item.value}`; | ||
if (target.className === 'g2-tooltip-marker') { | ||
const color = target.style.fill; | ||
const item = items.find((i) => i.color === color); | ||
return format(item); | ||
} | ||
return items.map(format).join('<br>'); | ||
}, | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
temperatureLineMarker.steps = ({ canvas }) => { | ||
const { document } = canvas; | ||
const plot = document.getElementsByClassName(PLOT_CLASS_NAME)[0]; | ||
return [ | ||
{ | ||
changeState: async () => { | ||
plot.dispatchEvent( | ||
new CustomEvent('pointermove', { | ||
offsetX: 200, | ||
offsetY: 300, | ||
}), | ||
); | ||
}, | ||
}, | ||
{ | ||
changeState: async () => { | ||
const marker = plot.getElementsByClassName('g2-tooltip-marker')[0]; | ||
const bbox = marker.getBBox(); | ||
const x = bbox.x + bbox.width / 2; | ||
const y = bbox.y + bbox.height / 2; | ||
marker.dispatchEvent( | ||
new CustomEvent('pointermove', { | ||
offsetX: x, | ||
offsetY: y, | ||
}), | ||
); | ||
}, | ||
}, | ||
]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
site/examples/component/tooltip/demo/tooltip-click-line.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.