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

feat(style): allow fill and stroke overrides #258

Merged
merged 10 commits into from
Jul 15, 2019

Conversation

markov00
Copy link
Member

@markov00 markov00 commented Jul 3, 2019

Summary

This PR allows the computed series color to be overridden by the theme or the series specific style.

BREAKING CHANGE: LineStyle, AreaStyle and BarSeriesStyle types differs on the optional values.
stroke and fill on the theme or specific series style now override the computed series color.

The a style overrides with the following flows:

  • if a style is declared at the Spec level (on a Bar/Area/Line component) it will take precedence over all the other style (any stroke or fill prop will override the computed series color for that specific style element). If not go to next
  • if a stroke or fill is present on the chart theme prop for a Bar/Area/Line than it will use that color for the point (stroke or fill) line (stroke) bar(stroke, fill, borderStroke)
  • if no stroke or fill is configured on theme or series specific style than we will use the one computed or assigned with customSeriesColors prop

Screenshot 2019-07-03 at 15 24 09

Screenshot 2019-07-03 at 15 24 17

Screenshot 2019-07-03 at 15 24 23

notes

  • I've refactored the build...props used to compute the props for rendering lines/areas/bars/points, cleaning a but the function semantics.
  • The payload of each individual bar rendered geometry is currently increased, but I will find a better way to specify that for bars in the future.
  • I've cleaned the defaults of the two themes
  • I've cleaned the stories for custom styles to align it with that new feature

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

  • Any consumer-facing exports were added to src/index.ts (and stories only import from ../src except for test data & storybook)
  • This was checked for cross-browser compatibility, including a check against IE11
  • Proper documentation or storybook story was added for features that require explanation or tutorials
  • Unit tests were updated or added to match the most common scenarios
  • Each commit follows the convention

This allows the computed series color to be overridden by the theme or the series specific style.

BREAKING CHANGE: `LineStyle`, `AreaStyle` and `BarSeriesStyle` types differs on the optional values.
`stroke` and `fill` on the theme or specific series style now override the computed series color.
@markov00 markov00 added :styling Styling related issue enhancement New feature or request labels Jul 3, 2019
@codecov-io
Copy link

codecov-io commented Jul 3, 2019

Codecov Report

Merging #258 into master will increase coverage by 0.14%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #258      +/-   ##
==========================================
+ Coverage   97.84%   97.99%   +0.14%     
==========================================
  Files          36       36              
  Lines        2693     2840     +147     
  Branches      607      660      +53     
==========================================
+ Hits         2635     2783     +148     
  Misses         51       51              
+ Partials        7        6       -1
Impacted Files Coverage Δ
src/lib/themes/dark_theme.ts 100% <ø> (ø) ⬆️
src/lib/themes/theme.ts 100% <ø> (ø) ⬆️
src/lib/series/specs.ts 100% <ø> (ø) ⬆️
src/lib/themes/light_theme.ts 100% <ø> (ø) ⬆️
src/state/utils.ts 97.5% <100%> (+1.06%) ⬆️
...onents/react_canvas/utils/rendering_props_utils.ts 100% <100%> (ø) ⬆️
src/lib/series/rendering.ts 99.27% <100%> (+1.35%) ⬆️
src/lib/series/series.ts 100% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e727605...acb5a91. Read the comment docs.

@markov00 markov00 requested a review from nickofthyme July 4, 2019 17:03
Copy link
Contributor

@emmacunningham emmacunningham left a comment

Choose a reason for hiding this comment

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

tested locally on firefox and code LGTM just a small couple of questions

rect: RectStyle;
rectBorder: RectBorderStyle;
displayValue: DisplayValueStyle;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

For some of the properties above, we have defined interfaces for them already. Should we use them where possible? For example, we have an Opacity interface that could be referenced instead of duplicating it manually within RectStyle. (The same for FillStyle, StrokeStyle, Visible and StrokeDashArray.) If we aren't going to reuse those interfaces, should we delete them? Looks like Radius was already deleted in favor of defining it inside the interface.

Copy link
Member Author

Choose a reason for hiding this comment

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

@emmacunningham here my difficulty was the following: the StrokeStyle is specified as

export interface StrokeStyle {
  /** The stroke color in hex, rgba, hsl */
  stroke: string;
  /** The stroke width in pixel */
  strokeWidth: number;
}

but I want to to have the stroke optional and the strokeWidth required. Is there a way to achieve that? I can change the StrokeStyle type but we maybe need a different configuration in the future. Splitting the StrokeStyle into two types is useless and we can just go removing all the Stroke/Opacity interfaces.
What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe you can do something like this to extend StrokeStyle such that stroke becomes optional and strokeWidth remains required.

First, we need a way to keep one property as required and make the rest optional:

export type RequireOneAndMakeRestOptional<T, K extends keyof T> = { [X in Exclude<keyof T, K>]?: T[X] } & { [P in K]-?: T[P] };

and then RectBorderStyle for example could be:

export type RectBorderStyle = RequireOneAndMakeRestOptional<StrokeStyle, 'strokeWidth'> & Visible;

I'm not sure this is that much better since it requires other contributors to understand what RequireOneAndMakeRestOptional is doing to understand the type annotations where it's being used. I think that the way you have it now is more easy to follow and read.

Having the interfaces for these common styling properties I think is useful because it makes it easier for other contributors to compose new interfaces that are consistent (so we don't accidentally type stroke as a number sometimes, for example). In particulary, I think StrokeDashArray is especially useful because it is not obvious what this should be (in fact, we could probaably make this more explicit as [number, number]) for someone not familiar with the API to create a dashed stroke.

Copy link
Member Author

Choose a reason for hiding this comment

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

I will leave this as it is for the moment, and we can find a clear type later. You are completely right about the fact that a common styling type is required, I will like to open a PR with that in the next future #264

stories/bar_chart.tsx Outdated Show resolved Hide resolved
Copy link
Collaborator

@nickofthyme nickofthyme left a comment

Choose a reason for hiding this comment

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

Tested locally, LGTM. Only a few comments around mergeWithDefaultTheme.

stories/bar_chart.tsx Outdated Show resolved Hide resolved
stories/styling.tsx Outdated Show resolved Hide resolved
stories/styling.tsx Outdated Show resolved Hide resolved
stories/styling.tsx Outdated Show resolved Hide resolved
@markov00 markov00 mentioned this pull request Jul 15, 2019
3 tasks
@markov00 markov00 merged commit 99c5e9f into elastic:master Jul 15, 2019
markov00 pushed a commit that referenced this pull request Jul 15, 2019
# [8.0.0](v7.2.1...v8.0.0) (2019-07-15)

### Code Refactoring

* **legend:** remove visibility button ([#252](#252)) ([90a1ba7](90a1ba7))

### Features

* **style:** allow fill and stroke overrides ([#258](#258)) ([99c5e9f](99c5e9f))

### BREAKING CHANGES

* **style:** `LineStyle`, `AreaStyle` and `BarSeriesStyle` types differs on the optional values.
`stroke` and `fill` on the theme or specific series style now override the computed series color.

* fix: no unused locals error on theme

* fix: avoid key prop override by spread operator

* test: increase test coverage on PR changes

* fix: fontSize is now always a number

* test: increase coverage for rendendering

* refactor(story): simplify theme merging on `with value label` story

* refactor: removed mergeWithDefaultTheme
* **legend:** the `onLegendItemClick` click handler is no longer applied when clicking on the title. Instead a simple visibility change is applied.
@markov00
Copy link
Member Author

🎉 This PR is included in version 8.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@markov00 markov00 added the released Issue released publicly label Jul 15, 2019
@markov00 markov00 deleted the add_fill_point_style branch November 25, 2020 11:43
AMoo-Miki pushed a commit to AMoo-Miki/OpenSearch-Dashboards that referenced this pull request Feb 10, 2022
# [8.0.0](elastic/elastic-charts@v7.2.1...v8.0.0) (2019-07-15)

### Code Refactoring

* **legend:** remove visibility button ([opensearch-project#252](elastic/elastic-charts#252)) ([efb3823](elastic/elastic-charts@efb3823))

### Features

* **style:** allow fill and stroke overrides ([opensearch-project#258](elastic/elastic-charts#258)) ([1648996](elastic/elastic-charts@1648996))

### BREAKING CHANGES

* **style:** `LineStyle`, `AreaStyle` and `BarSeriesStyle` types differs on the optional values.
`stroke` and `fill` on the theme or specific series style now override the computed series color.

* fix: no unused locals error on theme

* fix: avoid key prop override by spread operator

* test: increase test coverage on PR changes

* fix: fontSize is now always a number

* test: increase coverage for rendendering

* refactor(story): simplify theme merging on `with value label` story

* refactor: removed mergeWithDefaultTheme
* **legend:** the `onLegendItemClick` click handler is no longer applied when clicking on the title. Instead a simple visibility change is applied.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released Issue released publicly :styling Styling related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants