Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tooltip colorbox supports configurable borderWidth, borderRadius, and…
… dash effect (#8874) * Start on extending tooltip style * Correct borderRadius implementation * Tests of updated tooltip styling * Update docs
- Loading branch information
Showing
10 changed files
with
333 additions
and
63 deletions.
There are no files selected for viewing
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
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
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,75 @@ | ||
module.exports = { | ||
config: { | ||
type: 'line', | ||
data: { | ||
datasets: [{ | ||
data: [8, 7, 6, 5], | ||
pointBorderColor: '#ff0000', | ||
pointBackgroundColor: '#00ff00', | ||
showLine: false | ||
}], | ||
labels: ['', '', '', ''] | ||
}, | ||
options: { | ||
scales: { | ||
x: {display: false}, | ||
y: {display: false} | ||
}, | ||
elements: { | ||
line: { | ||
fill: false | ||
} | ||
}, | ||
plugins: { | ||
legend: false, | ||
title: false, | ||
filler: false, | ||
tooltip: { | ||
mode: 'nearest', | ||
intersect: false, | ||
callbacks: { | ||
label: function() { | ||
return '\u200b'; | ||
}, | ||
labelColor: function(tooltipItem) { | ||
const meta = tooltipItem.chart.getDatasetMeta(tooltipItem.datasetIndex); | ||
const options = meta.controller.getStyle(tooltipItem.dataIndex); | ||
return { | ||
borderColor: options.borderColor, | ||
backgroundColor: options.backgroundColor, | ||
borderWidth: 2, | ||
borderDash: [2, 2] | ||
}; | ||
}, | ||
} | ||
}, | ||
}, | ||
|
||
layout: { | ||
padding: 15 | ||
} | ||
}, | ||
plugins: [{ | ||
afterDraw: function(chart) { | ||
const canvas = chart.canvas; | ||
const rect = canvas.getBoundingClientRect(); | ||
const point = chart.getDatasetMeta(0).data[1]; | ||
const event = { | ||
type: 'mousemove', | ||
target: canvas, | ||
clientX: rect.left + point.x, | ||
clientY: rect.top + point.y | ||
}; | ||
chart._handleEvent(event); | ||
chart.tooltip.handleEvent(event); | ||
chart.tooltip.draw(chart.ctx); | ||
} | ||
}] | ||
}, | ||
options: { | ||
canvas: { | ||
height: 256, | ||
width: 512 | ||
} | ||
} | ||
}; |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,78 @@ | ||
module.exports = { | ||
config: { | ||
type: 'line', | ||
data: { | ||
datasets: [{ | ||
data: [8, 7, 6, 5], | ||
pointBorderColor: '#ff0000', | ||
pointBackgroundColor: '#00ff00', | ||
showLine: false | ||
}], | ||
labels: ['', '', '', ''] | ||
}, | ||
options: { | ||
scales: { | ||
x: {display: false}, | ||
y: {display: false} | ||
}, | ||
elements: { | ||
line: { | ||
fill: false | ||
} | ||
}, | ||
plugins: { | ||
legend: false, | ||
title: false, | ||
filler: false, | ||
tooltip: { | ||
mode: 'nearest', | ||
intersect: false, | ||
callbacks: { | ||
label: function() { | ||
return '\u200b'; | ||
}, | ||
labelColor: function(tooltipItem) { | ||
const meta = tooltipItem.chart.getDatasetMeta(tooltipItem.datasetIndex); | ||
const options = meta.controller.getStyle(tooltipItem.dataIndex); | ||
return { | ||
borderColor: options.borderColor, | ||
backgroundColor: options.backgroundColor, | ||
borderWidth: 2, | ||
borderRadius: { | ||
topRight: 5, | ||
bottomRight: 5, | ||
}, | ||
}; | ||
}, | ||
} | ||
}, | ||
}, | ||
|
||
layout: { | ||
padding: 15 | ||
} | ||
}, | ||
plugins: [{ | ||
afterDraw: function(chart) { | ||
const canvas = chart.canvas; | ||
const rect = canvas.getBoundingClientRect(); | ||
const point = chart.getDatasetMeta(0).data[1]; | ||
const event = { | ||
type: 'mousemove', | ||
target: canvas, | ||
clientX: rect.left + point.x, | ||
clientY: rect.top + point.y | ||
}; | ||
chart._handleEvent(event); | ||
chart.tooltip.handleEvent(event); | ||
chart.tooltip.draw(chart.ctx); | ||
} | ||
}] | ||
}, | ||
options: { | ||
canvas: { | ||
height: 256, | ||
width: 512 | ||
} | ||
} | ||
}; |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.