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 legend label style option #5622

Closed
wants to merge 1 commit into from
Closed

Conversation

nagix
Copy link
Contributor

@nagix nagix commented Jul 7, 2018

This feature was proposed several times in the past (#4163, #4496, #4811 and #4890) in order to use a line or a custom-sized box as a legend for a line in line charts, but no PR has been merged yet. I would like to try a bit different approach.

  • Deprecate the usePointStyle legend label option
  • Instead, introduce the style legend label option, which can have 'box', 'line' and 'point' value
    • 'box': The same appearance as the current implementation
    • 'line': The line style is used. Border width, border color, line cap style, line join style and line dashes are inherited from the corresponding dataset
    • 'point': The same appearance as the current usePointStyle option.
    • If not set, the 'line' style is used for line elements, and the 'box' style for other elements.
  • As it detects the dataset type and choose a suitable legend label style, mixed charts are also supported.

See https://jsfiddle.net/nagix/d86rvwn5/

screen shot 2018-07-07 at 9 24 20 pm

Note that the chart with style: 'point' shows a dashed circle, but this should not be a dashed line. I'm trying to fix this with #5621.

The existing tests are fixed more tests are added. Also, document is updated.

Fixes #4727

- Add style option to legend labels config suppoting box, line and point style
- Deprecate usePointStyle option
- BoxWidth is now calculated for each legend item as it can have different width
- Fix the existing tests and add more tests
- Update document
@simonbrunel
Copy link
Member

I'm not sure we should deprecate usePointStyle. IMO, this is 2 different features: labels.usePointStyle allows to pick the dataset point options (instead of the dataset line options) while labels.style allows to control the shape of the label.

I think the following use cases should be valid for a line or radar chart:

  • style: 'point' and usePointStyle: false: draw points with the line color/border/...
  • style: 'point' and usePointStyle: true: draw points with the point color/border/...
  • style: 'box' and usePointStyle: true: draw boxes with the point color/border/...
  • style: 'line' and usePointStyle: true: draw lines with the point color/border/...
  • ...

@nagix
Copy link
Contributor Author

nagix commented Jul 7, 2018

@simonbrunel usePointStyle: true doesn't mean using the point color/border/..., but using pointStyle shapes such as 'circle' and 'triangle'. So, style: 'box' and usePointStyle: true are exclusive, and style: 'point' is intended to what usePointStyle: true does. style: 'line' and usePointStyle: true can be used together and useful, though.

@simonbrunel
Copy link
Member

I thought usePointStyle was also using the point color/border/... instead of the line ones.

Note that the chart with style: 'point' shows a dashed circle, but this should not be a dashed line. I'm trying to fix this with #5621.

I think it should be a dashed line in this case and I would not do special cases based on the chart type. If we want the labels to use the point color/border/ ... instead of the line options, then we should introduce a new option (if usePointStyle is not this one).

@nagix
Copy link
Contributor Author

nagix commented Jul 7, 2018

In the current implementation, usePointStyle: true doesn't use point color/border/... but use line color/border/..., and that causes inconsistency in appearance between legend and chart elements when they have different styles. But, this is for the other PR.

In this PR, I'm just focusing on "shapes". usePointStyle only switches between a box and point shape, but this proposal is trying to give more options including a line and possibly "lineWithPoint".

@Hedva
Copy link

Hedva commented Jul 9, 2018

Really appreciate this.

Only I would expect:

 datasets: [{
      type: 'line',

to be:

 datasets: [{
      labelType: 'line', //box, line, circle

And that the labelType property in the dataset, overrides whatever is set as default at options.legend.labels.style.

Edit: Never mind i was confused about type. I didn't realize it was for the combined line/bar chart.
But I still do think this is something you want to be able to adjust per dataset, with something like labelType.

@etimberg etimberg requested a review from simonbrunel July 9, 2018 23:38

return {
text: label,
fillStyle: fill,
strokeStyle: stroke,
lineWidth: bw,
hidden: isNaN(ds.data[i]) || meta.data[i].hidden,
// `usePointStyle` is deprecated. To be removed at version 3
style: !style && labelOpts.usePointStyle ? 'point' : style,
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for adding support for the older option

@@ -6,6 +6,32 @@ describe('Deprecations', function() {
expect(Chart.layoutService).toBe(Chart.layouts);
});
});

describe('Legend Labels: usePointStyle option', function() {
Copy link
Member

Choose a reason for hiding this comment

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

@simonbrunel should we put this inside a describe('Version 2.8.0', ...) block?

Copy link
Member

Choose a reason for hiding this comment

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

It's already inside 2.8.0 deprecations

@simonbrunel
Copy link
Member

@nagix I totally get that this PR is not about color/border/etc. but #5621 uses usePointStyle to switch between the dataset (line) and element (point) colors/border/etc. I don't think style: 'point' should also change the color/border/etc.: the shape and the color/border/etc. should be independent IMO.

I don't really like the term style because it's too confusing. We don't know if we are talking about the shape, the colors, the opacity, ... or everything. We may prefer to call this new option: labels.shape or labels.symbol instead of labels.style.

So I would rather keep usePointStyle to make the legend label match the point style (shape/color/border/etc.). labels.shape (if defined) would override the point 'symbol' if usePointStyle: true while using the point color/border/etc.

Finally, labels.shape: 'point' would mean: use the current point shape (not the other styling options). Ideally, we should support all other shapes, especially circle since it's a wanted feature for any type of charts.

So, style: 'box' and usePointStyle: true are exclusive

It's not exclusive, it allows to use the point color/border/etc. while displaying a box, which I'm sure is a valid use case. The other way is also valid: shape: 'point', usePointStyle: false, meaning I want to use the line color/border/etc. while displaying the current point shape.

What do you guys think? (sorry for the long comment)

@nagix
Copy link
Contributor Author

nagix commented Jul 10, 2018

I agree that we keep usePointStyle to make the legend label symbol match the point style while we introduce symbol to control the type of the symbol. As the value 'point' doesn't represent the shape, I'd prefer the term symbol rather than shape. As @simonbrunel said, style is definitely confusing.

labels.shape (if defined) would override the point 'symbol' if usePointStyle: true while using the point color/border/etc.

Basically, this is fine. But, I would like to enable 'the point symbol on the line' when symbol: 'line' and usePointStyle: true as this style is quite common. So, I propose this:

screen shot 2018-07-11 at 3 13 05 am

Any comments?

@simonbrunel
Copy link
Member

As the value 'point' doesn't represent the shape, I'd prefer the term symbol rather than shape

I would call the point shape (triangle, circle, etc.) a symbol (per #4811)

I don't see the necessity of the box or line symbol in the point style

I still think it's a valid use case, why enforcing such restriction?

--

Actually, #4811 is closer to what I'm thinking about customizing the legend labels: allow the user to pick any available symbol as legend labels (whatever the usePointStyle value). I'm not fan of complex / rigid option logic and prefer to keep things simple and flexible. At some point, someone will ask for circle or triangle in a bar chart.

So I think I prefer the new option to select / override the label symbol (any of this list) while usePointStyle switches between dataset/element style (I would maybe not support point since it doesn't make sense in all charts).

@nagix
Copy link
Contributor Author

nagix commented Jul 13, 2018

Ok, in that case, I can wait for #4811.

@benmccann
Copy link
Contributor

@nagix I'm not completely understanding the conclusion that you and Simon came to. Is this PR a duplicate of #4811 and should be closed? Or only partially a duplicate and still adds some new functionality in which case it should be updated to add only the new functionality?

I'm hoping we can either update or close the PR. I'd like to make sure all the open PRs are in a reviewable state. Otherwise it gets really hard to keep track of which we need to review and which we shouldn't

@benmccann
Copy link
Contributor

@nagix should this PR be updated or closed?

Copy link
Contributor

@benmccann benmccann left a comment

Choose a reason for hiding this comment

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

Drop in favor of #4811 or update to include only functionality not addressed there

@benmccann
Copy link
Contributor

@nagix I'm going to close this PR as inactive since there hasn't been any response and it's not clear to me from the comments that it's still needed. Please feel free to reopen if I'm wrong about that

@benmccann benmccann closed this Aug 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Line label option for line chart legends
5 participants