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

[radar] Handling of Point Label Color as Array #5153

Closed
wants to merge 6 commits into from

Conversation

JulianTrei
Copy link

Allows the input of Point Label Colors as array. This change makes it possible to color the axis labels accordingly to the dataset labels.

image

Copy link
Member

@etimberg etimberg left a comment

Choose a reason for hiding this comment

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

One more general idea, we've used array parameters in other parts of the scales to set different options for each grid line.

What do you think about using a 2d array, for the font colour? That way the first level indexes into each point label and the 2nd level for each line. @simonbrunel thoughts on this idea? I fear it might be too confusing and hard to manage

} else {
pointLabelFontColor = valueOrDefault(pointLabelOpts.fontColor[x], globalDefaults.defaultFontColor);
}
var pointLabelPositionNew = JSON.parse(JSON.stringify(pointLabelPosition));
Copy link
Member

Choose a reason for hiding this comment

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

[nit] if this needs to be cloned you could use helpers.clone() https://github.com/chartjs/Chart.js/blob/master/src/helpers/helpers.core.js#L156

if (pointLabelOpts.fontColor) {
// handle scale.pointLabels[i] as string or array combined with pointLabelFontColor as string or array or none given.
if (typeof scale.pointLabels[i] === 'string') {
if (typeof pointLabelOpts.fontColor === 'string') {
Copy link
Member

Choose a reason for hiding this comment

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

I would consider inverting this if and using helpers.isArray that way a fontColor that is not a string would still pass through (CanvasGradient, or CanvasPattern for example)

adjustPointPositionForLabelHeight(angle, scale._pointLabelSizes[i], pointLabelPositionNew);
ctx.fillStyle = pointLabelFontColor;
fillText(ctx, scale.pointLabels[i][x] || '', pointLabelPositionNew, plFont.size);
yOffset += plFont.size + 5;
Copy link
Member

Choose a reason for hiding this comment

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

where does 5 come from?

@simonbrunel
Copy link
Member

You right @etimberg, the first array level should be used for indexable options and that's actually a reasonable use case (a different color for each label). It's not implemented yet, but it needs to be consistent with the rest of the options API, especially when we will introduce scriptable options for the radar chart.

A second array level seems complicated because it will always imply indexable options, meaning that you will have to duplicate your colors for each index:

// first label 'blue', second 'red'
fontColor: ['blue', 'red']   

// only the first label (first line 'blue', second 'red')
fontColor: [                 
  ['blue', 'red']
]

// first 4 labels
fontColor: [                
  ['blue', 'red'],
  ['blue', 'red'],
  ['blue', 'red'],
  ['blue', 'red']
] 

At some point (for consistency), if we accept this feature, we will need to also support the same logic for the font size, weight, style, etc. but also in all places that accept multi-lines text. That will make the code really complicated (this PR already duplicates too much code for a very specific use case).

@benmccann benmccann changed the title Handling of Point Label Color as Array [radar] Handling of Point Label Color as Array Jan 27, 2018
@benmccann
Copy link
Contributor

I think a 2-d array is too complicated. I think a better way to do that would be to support per-dataset options as is proposed in #5191

@simonbrunel
Copy link
Member

@benmccann I don't understand the "per-dataset options" relation? I think this PR is more comparable to supporting rich text, limited to a single use case: each line of the same text can have a different color.

But I agree, the 2-d array is not a great approach and we may receive more and more requests to be able to draw a single text with different formatting: bold, italic, font size, etc., everywhere.

Dealing with arrays is also too restrictive: how to handle the following case: "the first word of my one line text to be in bold or in a different color" (eg. "Foo: bar"). IMO, we should think about a more flexible approach, maybe some king of limited rich text language, and if it's too much code, expose a new hook and implement rich text in an external plugin.

@benmccann
Copy link
Contributor

One index of the 2d array corresponds to the dataset. It would be possible to use only a 1d array and achieve the same results if the options were set on each dataset instead.

@benmccann
Copy link
Contributor

Maybe it would make sense to implement this as is being done in https://github.com/chartjs/Chart.js/pull/5075/files#diff-76b3a981209f1918ec2431f4276b9703L270? That PR should be split up into two though instead of making two different changes in one PR

@simonbrunel
Copy link
Member

I would rather not rely on arrays for that feature, per my previous comment.

@benmccann
Copy link
Contributor

@JulianTrei I'm going to close this PR for now given that we've decided another approach would be best. Please feel free to reopen with the changes suggested. Maybe first it would be best to join the Slack channel and talk through any solution so that we're all on the same page regarding the approach and we don't waste any of your time.

Thanks again for contributing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants