Skip to content

Commit

Permalink
new event - events.markerClick - fixes #452
Browse files Browse the repository at this point in the history
  • Loading branch information
junedchhipa committed Mar 29, 2019
1 parent 94e059d commit 665cf61
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/modules/settings/Options.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ export default class Options {
updated: undefined,
click: undefined,
legendClick: undefined,
markerClick: undefined,
selection: undefined,
dataPointSelection: undefined,
dataPointMouseEnter: undefined,
Expand Down
4 changes: 4 additions & 0 deletions src/modules/tooltip/Intersect.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ class Intersect {
shared: ttCtx.intersect ? false : w.config.tooltip.shared
})

if (e.type === 'mouseup') {
ttCtx.markerClick(e, i, j)
}

ttCtx.marker.enlargeCurrentPoint(j, opt.paths)

x = cx
Expand Down
52 changes: 38 additions & 14 deletions src/modules/tooltip/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export default class Tooltip {

this.w.globals.tooltipOpts = extendedOpts

let events = ['mousemove', 'touchmove', 'mouseout', 'touchend']
let events = ['mousemove', 'mouseup', 'touchmove', 'mouseout', 'touchend']

events.map((ev) => {
return paths[p].addEventListener(
Expand Down Expand Up @@ -502,7 +502,11 @@ export default class Tooltip {
isStickyTooltip = false
}

if (e.type === 'mousemove' || e.type === 'touchmove') {
if (
e.type === 'mousemove' ||
e.type === 'touchmove' ||
e.type === 'mouseup'
) {
if (xcrosshairs !== null) {
xcrosshairs.classList.add('active')
}
Expand Down Expand Up @@ -542,20 +546,20 @@ export default class Tooltip {
this.tooltipUtil.isXoverlap(j) &&
this.tooltipUtil.isinitialSeriesSameLen()
) {
this.create(self, capturedSeries, j, opt.ttItems)
this.create(e, self, capturedSeries, j, opt.ttItems)
} else {
this.create(self, capturedSeries, j, opt.ttItems, false)
this.create(e, self, capturedSeries, j, opt.ttItems, false)
}
} else {
if (this.tooltipUtil.isXoverlap(j)) {
self.create(self, 0, j, opt.ttItems)
self.create(e, self, 0, j, opt.ttItems)
}
}
} else {
// couldn't capture any series. check if shared X is same,
// if yes, draw a grouped tooltip
if (this.tooltipUtil.isXoverlap(j)) {
self.create(self, 0, j, opt.ttItems)
self.create(e, self, 0, j, opt.ttItems)
}
}
} else {
Expand Down Expand Up @@ -723,9 +727,29 @@ export default class Tooltip {
return bars.length > 0
}

create(context, capturedSeries, j, ttItems, shared = null) {
markerClick(e, seriesIndex, dataPointIndex) {
const w = this.w
if (typeof w.config.chart.events.markerClick === 'function') {
w.config.chart.events.markerClick(e, this.ctx, {
seriesIndex,
dataPointIndex,
w
})
}
this.ctx.fireEvent('markerClick', [
e,
this.ctx,
{ seriesIndex, dataPointIndex, w }
])
}

create(e, context, capturedSeries, j, ttItems, shared = null) {
let w = this.w
let self = context
let ttCtx = context

if (e.type === 'mouseup') {
this.markerClick(e, capturedSeries, j)
}

if (shared === null) shared = w.config.tooltip.shared

Expand All @@ -734,7 +758,7 @@ export default class Tooltip {
const bars = this.getElBars()

if (shared) {
self.tooltipLabels.drawSeriesTexts({
ttCtx.tooltipLabels.drawSeriesTexts({
ttItems,
i: capturedSeries,
j,
Expand All @@ -743,9 +767,9 @@ export default class Tooltip {

if (hasMarkers) {
if (w.globals.markers.largestSize > 0) {
self.marker.enlargePoints(j)
ttCtx.marker.enlargePoints(j)
} else {
self.tooltipPosition.moveDynamicPointsOnHover(j)
ttCtx.tooltipPosition.moveDynamicPointsOnHover(j)
}
}

Expand All @@ -769,19 +793,19 @@ export default class Tooltip {
}
}
} else {
self.tooltipLabels.drawSeriesTexts({
ttCtx.tooltipLabels.drawSeriesTexts({
shared: false,
ttItems,
i: capturedSeries,
j
})

if (this.hasBars()) {
self.tooltipPosition.moveStickyTooltipOverBars(j)
ttCtx.tooltipPosition.moveStickyTooltipOverBars(j)
}

if (hasMarkers) {
self.tooltipPosition.moveMarkers(capturedSeries, j)
ttCtx.tooltipPosition.moveMarkers(capturedSeries, j)
}
}
}
Expand Down

0 comments on commit 665cf61

Please sign in to comment.