Skip to content

Commit d11c557

Browse files
authored
Merge pull request #501 from vizzuhq/marker-label-tooltip
Tooltip on marker labels.
2 parents 6ff1a88 + eed3e43 commit d11c557

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- When X axis dimension labels are close to each other, they are rotated to avoid overlapping.
2929
- The event handler registration order changed. Now the handlers are called in the opposite order of the registration.
3030
- Added the padded rectangle, the bounding rectangle and the align parameter to the draw text event object.
31+
- Tooltip works on marker labels too.
3132

3233
## [0.9.3] - 2023-12-20
3334

src/apps/weblib/ts-api/plugins/tooltip.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Snapshot } from '../module/cchart.js'
2-
import { Element, Marker, PointerEvent } from '../events.js'
2+
import { Element, Marker, MarkerLabel, PointerEvent } from '../events.js'
33
import { Plugin, type PluginHooks, type PrepareAnimationContext } from '../plugins.js'
44

55
import Vizzu from '../vizzu.js'
@@ -71,8 +71,8 @@ export class Tooltip implements Plugin {
7171
_mouseon(param: PointerEvent): void {
7272
this._id++
7373
const id = this._id
74-
if (param.target && this._isMarker(param.target)) {
75-
const markerId = param.target.index
74+
const markerId = this._getMarkerId(param.target)
75+
if (markerId !== null) {
7676
setTimeout(() => {
7777
this._in(id, markerId)
7878
}, 0)
@@ -86,6 +86,8 @@ export class Tooltip implements Plugin {
8686
_getMarkerId(target: Element | null): number | null {
8787
if (target && this._isMarker(target)) {
8888
return target.index
89+
} else if (target && this._isMarkerLabel(target)) {
90+
return target.parent.index
8991
} else {
9092
return null
9193
}
@@ -95,6 +97,10 @@ export class Tooltip implements Plugin {
9597
return target.tagName === 'plot-marker'
9698
}
9799

100+
_isMarkerLabel(target: Element): target is MarkerLabel {
101+
return target.tagName === 'plot-marker-label'
102+
}
103+
98104
_in(id: number, markerId: number): void {
99105
if (this._id === id) {
100106
if (!this._animating) {

0 commit comments

Comments
 (0)