New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tooltip textLabelColor callback #4199
Changes from 4 commits
8141200
5623320
6c0acdd
4b04466
d91c759
4d242ac
61410da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,9 @@ module.exports = function(Chart) { | |
backgroundColor: view.backgroundColor | ||
}; | ||
}, | ||
textLabelColor: function(tooltipItem, chart) { | ||
return chart.tooltip._options.bodyFontColor; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it might be an idea here to pass the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @etimberg can you please elaborate on this one. I'm not sure i understood that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i have updated the code using |
||
}, | ||
afterLabel: helpers.noop, | ||
|
||
// Args are: (tooltipItems, data) | ||
|
@@ -487,6 +490,7 @@ module.exports = function(Chart) { | |
model.opacity = 1; | ||
|
||
var labelColors = []; | ||
var textLabelColors = []; | ||
tooltipPosition = Chart.Tooltip.positioners[opts.position](active, me._eventPosition); | ||
|
||
var tooltipItems = []; | ||
|
@@ -511,8 +515,10 @@ module.exports = function(Chart) { | |
// Determine colors for boxes | ||
helpers.each(tooltipItems, function(tooltipItem) { | ||
labelColors.push(opts.callbacks.labelColor.call(me, tooltipItem, me._chart)); | ||
textLabelColors.push(opts.callbacks.textLabelColor.call(me, tooltipItem, me._chart)); | ||
}); | ||
|
||
|
||
// Build the Text Lines | ||
model.title = me.getTitle(tooltipItems, data); | ||
model.beforeBody = me.getBeforeBody(tooltipItems, data); | ||
|
@@ -525,6 +531,7 @@ module.exports = function(Chart) { | |
model.y = Math.round(tooltipPosition.y); | ||
model.caretPadding = opts.caretPadding; | ||
model.labelColors = labelColors; | ||
model.textLabelColors = textLabelColors; | ||
|
||
// data points | ||
model.dataPoints = tooltipItems; | ||
|
@@ -657,9 +664,6 @@ module.exports = function(Chart) { | |
|
||
ctx.textAlign = vm._bodyAlign; | ||
ctx.textBaseline = 'top'; | ||
|
||
var textColor = mergeOpacity(vm.bodyFontColor, opacity); | ||
ctx.fillStyle = textColor; | ||
ctx.font = helpers.fontString(bodyFontSize, vm._bodyFontStyle, vm._bodyFontFamily); | ||
|
||
// Before Body | ||
|
@@ -693,7 +697,7 @@ module.exports = function(Chart) { | |
// Inner square | ||
ctx.fillStyle = mergeOpacity(vm.labelColors[i].backgroundColor, opacity); | ||
ctx.fillRect(pt.x + 1, pt.y + 1, bodyFontSize - 2, bodyFontSize - 2); | ||
|
||
var textColor = mergeOpacity(vm.textLabelColors[i], opacity); | ||
ctx.fillStyle = textColor; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about
labelTextColor
instead?