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: add color option to use series color #630

Merged
merged 12 commits into from
Apr 21, 2020

Conversation

nickofthyme
Copy link
Collaborator

@nickofthyme nickofthyme commented Apr 14, 2020

Summary

Add ColorVariant type with Series and None

/**
 * Color varients that are unique to `@elastic/charts`. These go beyond the standard
 * static color allocations.
 */
export const ColorVariant = Object.freeze({
  /**
   * Uses series color. Rather than setting a static color, this will use the
   * default series color for a given series.
   */
  Series: '__use__series__color__' as '__use__series__color__',
  /**
   * Uses empty color, similar to transparent.
   */
  None: '__use__empty__color__' as '__use__empty__color__',
});
export type ColorVariant = $Values<typeof ColorVariant>;
  • Series option can be used for any series-related color in the theme object
  • None option can be used to set a default color value to transparent
  • Refactor stringToRGB method to use opacity and OpacityFn
  • Add helper method to process ColorVariant
  • Update theme color string with Color type
  • Refactor renderer styles to allow for new ColorVariant and OpacityFn

The following Theme properties that used to be Color are now Color | ColorVariant

  • PointStyle.stroke
  • PointStyle.fill
  • LineStyle.stroke
  • AreaStyle.fill
  • RectStyle.fill
  • RectBorderStyle.stroke

Example Stories

Area

const customTheme: PartialTheme = {
  areaSeriesStyle: {
    point: {
      visible: true,
      radius: 10,
      fill: ColorVariant.Series,
      stroke: ColorVariant.None,
      opacity: 0.5,
    },
    area: {
      opacity: 0.2,
    },
    line: {
      visible: false,
    },
  },
};

Image 2020-04-14 at 12 01 59 PM

Line

const customTheme: PartialTheme = {
  lineSeriesStyle: {
    point: {
      radius: 10,
      fill: ColorVariant.Series,
      stroke: ColorVariant.None,
    },
  },
};

Image 2020-04-14 at 12 01 44 PM

Bar

const customTheme: PartialTheme = {
  barSeriesStyle: {
    rect: {
      fill: ColorVariant.None,
    },
    rectBorder: {
      visible: true,
      strokeWidth: 10,
      stroke: ColorVariant.Series,
    },
  },
};

Image 2020-04-14 at 12 01 33 PM

Update tests

image
image
image

Checklist

  • Any consumer-facing exports were added to src/index.ts (and stories only import from ../src except for test data & storybook)
  • 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

- Add ColorVariant type with Series and None
- Series option can be used for any series-related color in the theme object
- None option can be used to set a default color value to transparent
- Refactor stringToRGB method to use opacity and opacityFn
- Add helper method to process ColorVariant
- Update theme color string with Color type
- Refactor renderer styles to allow for new ColorVariant and OpacityFn
@nickofthyme nickofthyme requested review from markov00, monfera and rshen91 and removed request for markov00 April 14, 2020 17:19
@nickofthyme nickofthyme added the :styling Styling related issue label Apr 14, 2020
@codecov-io
Copy link

codecov-io commented Apr 14, 2020

Codecov Report

Merging #630 into master will increase coverage by 8.39%.
The diff coverage is 88.07%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #630      +/-   ##
==========================================
+ Coverage   66.44%   74.84%   +8.39%     
==========================================
  Files         240      253      +13     
  Lines        7012     7242     +230     
  Branches     1340     1371      +31     
==========================================
+ Hits         4659     5420     +761     
+ Misses       2337     1798     -539     
- Partials       16       24       +8     
Impacted Files Coverage Δ
..._types/xy_chart/renderer/canvas/primitives/rect.ts 5.35% <0.00%> (-0.42%) ⬇️
src/mocks/specs/specs.ts 72.58% <61.90%> (ø)
...art_types/partition_chart/layout/utils/d3_utils.ts 96.87% <96.15%> (+42.32%) ⬆️
...ypes/partition_chart/layout/viewmodel/viewmodel.ts 88.70% <100.00%> (+74.77%) ⬆️
...s/partition_chart/state/selectors/picked_shapes.ts 100.00% <100.00%> (+80.76%) ⬆️
...hart_types/xy_chart/renderer/canvas/styles/area.ts 100.00% <100.00%> (+60.00%) ⬆️
...chart_types/xy_chart/renderer/canvas/styles/bar.ts 100.00% <100.00%> (+84.61%) ⬆️
...hart_types/xy_chart/renderer/canvas/styles/line.ts 100.00% <100.00%> (+60.00%) ⬆️
...art_types/xy_chart/renderer/canvas/styles/point.ts 100.00% <100.00%> (+75.00%) ⬆️
src/mocks/index.ts 100.00% <100.00%> (ø)
... and 44 more

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 2c1d224...a20be00. Read the comment docs.

@nickofthyme nickofthyme marked this pull request as ready for review April 18, 2020 15:37
Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

Overall looks good, I've added few comments.
I've some doubts on this weird looking render: I wasn't able to reproduce the same image on chrome from a running storybook. Seems like we are missing the lineCap='square' when rendering the border
Screenshot 2020-04-20 at 12 42 45

@@ -58,9 +58,9 @@ export interface SharedGeometryStateStyle {
unhighlighted: GeometryStateStyle;
}

export interface StrokeStyle {
export interface StrokeStyle<C = Color> {
Copy link
Member

Choose a reason for hiding this comment

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

What is the benefit of having a generic type here? I think we don't want that to have someone using a different generic value other than Color here like StrokeStyle<number>

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I didn't need this but I thought this was shared between more interfaces on the theme.

The intent was to be able to add the ColorVariant as an option for color. But in some places in the theme that doesn't apply.

src/utils/commons.test.ts Outdated Show resolved Hide resolved
stories/stylings/17_bar_series_color_variant.tsx Outdated Show resolved Hide resolved
@nickofthyme
Copy link
Collaborator Author

Thanks for pointing out the linecap issue. I saw that in safari and firefox. Looks to be fixed with this 80da4fc.

Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

Changes LGTM.
Ok to merge after fixing the rendering error on the debug react (caused by the linecap)

@nickofthyme nickofthyme merged commit e5a206d into elastic:master Apr 21, 2020
markov00 pushed a commit that referenced this pull request Apr 22, 2020
# [18.4.0](v18.3.0...v18.4.0) (2020-04-22)

### Bug Fixes

* **partition:** single slice wrong text positioning ([#643](#643)) ([6298d36](6298d36)), closes [#637](#637)
* **treemap:** align onElementClick parameters to sunburst ([#636](#636)) ([2c1d224](2c1d224)), closes [#624](#624)

### Features

* allow colorVariant option for series specific color styles ([#630](#630)) ([e5a206d](e5a206d))
* **series:** BubbleSeries (alpha) and markSizeAccessor ([#559](#559)) ([3aa235e](3aa235e))
@nickofthyme nickofthyme deleted the feat/color-variant branch June 9, 2020 02:20
AMoo-Miki pushed a commit to AMoo-Miki/OpenSearch-Dashboards that referenced this pull request Feb 10, 2022
# [18.4.0](elastic/elastic-charts@v18.3.0...v18.4.0) (2020-04-22)

### Bug Fixes

* **partition:** single slice wrong text positioning ([opensearch-project#643](elastic/elastic-charts#643)) ([f8b5b8a](elastic/elastic-charts@f8b5b8a)), closes [opensearch-project#637](elastic/elastic-charts#637)
* **treemap:** align onElementClick parameters to sunburst ([opensearch-project#636](elastic/elastic-charts#636)) ([8dd87bf](elastic/elastic-charts@8dd87bf)), closes [opensearch-project#624](elastic/elastic-charts#624)

### Features

* allow colorVariant option for series specific color styles ([opensearch-project#630](elastic/elastic-charts#630)) ([e2444ef](elastic/elastic-charts@e2444ef))
* **series:** BubbleSeries (alpha) and markSizeAccessor ([opensearch-project#559](elastic/elastic-charts#559)) ([85d9bda](elastic/elastic-charts@85d9bda))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:styling Styling related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants