Skip to content
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

Merged
merged 7 commits into from May 28, 2017
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/core/core.tooltip.js
Expand Up @@ -95,7 +95,8 @@ module.exports = function(Chart) {
// Args are: (tooltipItems, data)
beforeFooter: helpers.noop,
footer: helpers.noop,
afterFooter: helpers.noop
afterFooter: helpers.noop,
textLabelColor: helpers.noop
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] I would put this after labelColor since it's related to that stuff

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, since this is defaulting to helpers.noop what is the default colour of the text? I feel like we should provide a default function that has the old behaviour

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. i tried that, but the value of view.bodyFontColor at that moment returned to be black. instead of white so i reverted that to line 698. let me try something else.

}
};

Expand Down Expand Up @@ -487,6 +488,7 @@ module.exports = function(Chart) {
model.opacity = 1;

var labelColors = [];
var textLabelColors = [];
tooltipPosition = Chart.Tooltip.positioners[opts.position](active, me._eventPosition);

var tooltipItems = [];
Expand All @@ -511,8 +513,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);
Expand All @@ -525,6 +529,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;
Expand Down Expand Up @@ -657,9 +662,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
Expand Down Expand Up @@ -693,7 +695,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] || vm.bodyFontColor, opacity);
ctx.fillStyle = textColor;
}

Expand Down