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

fix(css): remove dependency on EUI components and use only EUI styles #208

Merged
merged 16 commits into from
Jun 10, 2019

Conversation

markov00
Copy link
Member

@markov00 markov00 commented May 20, 2019

Summary

This PR update the EUI dependency and clean its use inside the library. The following thing are changed:

  • each css style is prefixed with ech instead of the long elasticCharts
  • the new css is fully compatible with IE11, Chrome and Firefox
  • the legend toggle is currently commented out ( we can decide to reintroduce it or leave that to the external container)
  • the color picker and the contextual menu on the legend are temporarily disabled. They are actually part of EUI, so we can have add them as external prop components in a later version (only vislib is currently use this function)
  • the style for the eye open and closed on the legend is different from the EUI one: there is no animation on that button, but only a static change.

Before
Screenshot 2019-05-20 at 23 04 00

After
Screenshot 2019-05-20 at 23 04 10

  • text are a bit more condensed and the width of the legend is changed from 160px to 200px.

Before
Screenshot 2019-05-20 at 23 11 06

After
Screenshot 2019-05-20 at 23 10 55

  • fixed the alignment of latest element on bottom/top legend

Before
Screenshot 2019-05-20 at 23 01 32

After
Screenshot 2019-05-20 at 23 01 44

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

@codecov-io
Copy link

codecov-io commented May 20, 2019

Codecov Report

Merging #208 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #208      +/-   ##
==========================================
+ Coverage   97.82%   97.82%   +<.01%     
==========================================
  Files          35       36       +1     
  Lines        2569     2571       +2     
  Branches      565      578      +13     
==========================================
+ Hits         2513     2515       +2     
  Misses         49       49              
  Partials        7        7
Impacted Files Coverage Δ
src/state/utils.ts 95.58% <ø> (-0.28%) ⬇️
src/state/crosshair_utils.ts 85.29% <100%> (ø) ⬆️
src/lib/series/legend.ts 100% <100%> (ø) ⬆️
src/lib/series/series.ts 99.22% <100%> (+0.03%) ⬆️
src/lib/themes/colors.ts 100% <100%> (ø)
src/lib/themes/light_theme.ts 100% <100%> (ø) ⬆️
src/state/chart_state.ts 97.04% <100%> (-0.04%) ⬇️
src/lib/series/rendering.ts 97.94% <100%> (+0.11%) ⬆️
src/lib/themes/dark_theme.ts 100% <100%> (ø) ⬆️

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 dd02b52...d1b25d8. Read the comment docs.

@markov00 markov00 requested a review from cchaos May 20, 2019 21:53
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.

just a few small comments but otherwise lgtm. tested locally and looking good!

src/components/icon.tsx Outdated Show resolved Hide resolved
stories/bar_chart.tsx Outdated Show resolved Hide resolved
src/components/icons/assets/alert.tsx Outdated Show resolved Hide resolved
@cchaos
Copy link
Contributor

cchaos commented May 21, 2019

I am struggling to test this in Kibana. I have built it with yarn build then linked it over in Kibana. I see both the theme_light.css and theme_dark.css in node_modules. But when I add those theme files to https://github.com/elastic/kibana/blob/cc7a6ec2c11b51bbbc64a319b29750232a5dc175/src/legacy/ui/ui_render/ui_render_mixin.js#L119-L125

like so:

darkMode ?
              [
                `${basePath}/node_modules/@elastic/eui/dist/eui_theme_dark.css`,
                `${basePath}/node_modules/@kbn/ui-framework/dist/kui_dark.css`,
                `${basePath}/node_modules/@elastic/charts/dist/theme_dark.css`,
              ] : [
                `${basePath}/node_modules/@elastic/eui/dist/eui_theme_light.css`,
                `${basePath}/node_modules/@kbn/ui-framework/dist/kui_light.css`,
                `${basePath}/node_modules/@elastic/charts/dist/theme_light.css`,
              ]

I get 404 errors and it completely borks Kibana, getting the "Kibana didn't load properly" error.

I can import the theme_light.scss file into https://github.com/elastic/kibana/blob/master/src/legacy/ui/public/styles/_styling_constants.scss via:

@import '@elastic/charts/src/theme_light';

But of course, that duplicates these styles numerous times and I'm pretty sure it doesn't swap light for dark.

Any thoughts on how to appropriately handle the themes and importing?

@markov00
Copy link
Member Author

markov00 commented May 21, 2019

@cchaos I think you have to add the following:

  server.exposeStaticDir('/node_modules/@elastic/charts/dist/{path*}', fromRoot('node_modules/@elastic/charts/dist'));

at line 59 of ui_render_mixin https://github.com/elastic/kibana/blob/cc7a6ec2c11b51bbbc64a319b29750232a5dc175/src/legacy/ui/ui_render/ui_render_mixin.js#L59

I've just tried and it works

src/components/_tooltip.scss Show resolved Hide resolved

// Families

$echFontFamily: 'Inter UI', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial,
Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't be importing 'Inter UI' in this base library. We should probably just stick to system fonts. In fact, I think there's a lot of unnecessary invisibles brought in here from EUI.

Copy link
Member Author

Choose a reason for hiding this comment

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

@cchaos what are the system fonts i can use? -apple-system, BlinkMacSystemFont, Helvetica, Arial, sans-serif ?
I also need the right one to use on the canvas text elements, what I can use there?

Copy link

Choose a reason for hiding this comment

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

Removing the Inter UI bit is all you need. The ones that follow are "system fonts". Apple, then MS, then Linux, then Helvetica.

@markov00
Copy link
Member Author

markov00 commented Jun 4, 2019

Hey @cchaos are you still working on that? Should we start to wrap up and merge this PR?
If you are working on that, please could you list here what are your current task so I can help you on those?

@cchaos
Copy link
Contributor

cchaos commented Jun 4, 2019

@markov00 Yes, I'm actively working on this. I think I'm just about done, but have I'm double-checking it in EUI right now and will need to do so in Kibana as well.

@cchaos
Copy link
Contributor

cchaos commented Jun 4, 2019

@markov00 PR4U: markov00#2

@markov00
Copy link
Member Author

markov00 commented Jun 5, 2019

hey @cchaos I've merged your PR and rebased everything.
What do you think about creating two different css output, one with reset and one without.
So that the user just need to import one or the other css, and not two separate files.
I'm also wondering if we need to apply the reset only under the ech container, and not to the whole html. I don't want to mess with the existing reset, but maybe there is something I'm not considering.

@markov00
Copy link
Member Author

markov00 commented Jun 5, 2019

@cchaos @snide I've also minor concern on the readability of the highlighted value on the tooltip.

This is the current implementation:
Jun-05-2019 15-52-54

This is the Caroline changes:
Jun-05-2019 15-46-51

From my point of view, adding changing the font-weight with a higher value create few disadvantages:

  • the highlighted rows is poorly distinguishable from others (your eyes need to catch a small difference in a font size, than in a background color change) specially if you enter quickly into the chart.
  • changing the font-weight to a higher value increase also the tooltip width creating a strange effect that grow and shrink the tooltip when highlighting a bar.

@markov00 markov00 changed the title fix: remove EUI dependency fix(css): apply EUI styles without interfere with external css Jun 5, 2019
@cchaos
Copy link
Contributor

cchaos commented Jun 5, 2019

@markov00 I actually agree. I wanted to come back and revisit that but had forgotten. I will work on those states.

@@ -91,7 +90,6 @@
"husky": "^1.3.1",
"jest": "^24.1.0",
"jest-environment-jsdom-fourteen": "^0.1.0",
"moment": "^2.24.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

So moment was a dependency of @elastic/[email protected] but not @elastic/eui@^11.2.1?

Copy link
Contributor

Choose a reason for hiding this comment

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

EUI is only being consumed for it's SASS variables so there's no need fo this peer dependency.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@cchaos cool thanks!

@@ -119,7 +117,6 @@
"d3-shape": "^1.3.4",
"fp-ts": "^1.14.2",
"konva": "^2.6.0",
"lodash": "^4.17.11",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice!! 🎉

@cchaos
Copy link
Contributor

cchaos commented Jun 5, 2019

Pushed a fix for the tooltip:

@cchaos
Copy link
Contributor

cchaos commented Jun 5, 2019

I'm also wondering if we need to apply the reset only under the ech container, and not to the whole html. I don't want to mess with the existing reset, but maybe there is something I'm not considering.

The problem with that is that it will override any base styles declared outside of the .echContainer.

Example

Reset file includes:

a { color: blue }

Consumer's theme is:

a { color: red }

But then including the charts styles with the reset would make it:

.echContainer a { color: blue }

completely overriding the consumer's theme.

@cchaos
Copy link
Contributor

cchaos commented Jun 5, 2019

@markov00 @snide My latest commit does as @markov00 had asked and compiles one file with reset and theme, and then a theme only file.

@snide
Copy link

snide commented Jun 5, 2019

@cchaos OK. Looks good. Thanks for updating the docs too.

@markov00 markov00 changed the title fix(css): apply EUI styles without interfere with external css fix(css): remove dependency on EUI components and use only EUI styles Jun 6, 2019
@markov00
Copy link
Member Author

markov00 commented Jun 6, 2019

@cchaos I've added the legend toggle button, Do you want to take a look if everything seems fine?

I've also played a bit with the dark mode, and seems that in darkmode the tooltip is fully black. if we have a full black 000 background the tooltip can disappear easily:

This PR:
Screenshot 2019-06-06 at 18 53 46
Screenshot 2019-06-06 at 18 53 56

On a chart with #000 background
Screenshot 2019-06-06 at 18 56 53

Current implementation:
Screenshot 2019-06-06 at 18 56 09

@cchaos
Copy link
Contributor

cchaos commented Jun 6, 2019

I've also played a bit with the dark mode, and seems that in darkmode the tooltip is fully black.

This is how the tooltip works in EUI. Not backgrounds should actually be fully black. Our default "white" background actually goes to a "dark gray" in dark mode:

Screen Shot 2019-06-06 at 13 39 14 PM

I had also changed that fully black background to our default background color here: https://github.com/elastic/elastic-charts/pull/208/files#diff-6cc5987d83a2bd4599131f08c70199cf

Screen Shot 2019-06-06 at 13 44 03 PM

You can see there is a slight variation in color. But that's how we work with them currently in EUI and would like to stick with the same method here.

@cchaos
Copy link
Contributor

cchaos commented Jun 6, 2019

Pushed more fixes to legend toggle.

@markov00
Copy link
Member Author

markov00 commented Jun 7, 2019

@cchaos I'm ok with the changes. If you think we are done, I will fix the squash commit and merge it

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

I'm happy with it. We'll want to setup a PR to update it in Kibana correctly with the new styles imports.

@markov00
Copy link
Member Author

markov00 commented Jun 7, 2019

@cchaos I can do that if you want, let me fix conflict, merge and I will create the PR in Kibana

markov00 and others added 16 commits June 7, 2019 18:17
Introduced new chart scss code to replace the existing EUI sass styles.
All class and mixins are now under .ech prefix
This commit change the current output style to two different styles, one for dark and one for light
theme.

BREAKING CHANGE: EUI is removed from this library. The single chart `style.css` stylesheet is now
replaced by a `theme_light.css` or `theme_dark.css` file that brings in all the required styling for
chart, tooltip and legends.
the time-scale-utils file was to test some assumptions but it's currently not required. The same for
the color functions
@markov00 markov00 merged commit 122fade into elastic:master Jun 10, 2019
markov00 pushed a commit that referenced this pull request Jun 10, 2019
# [5.0.0](v4.2.9...v5.0.0) (2019-06-10)

### Bug Fixes

* **css:** remove dependency on EUI components and use only EUI styles ([#208](#208)) ([122fade](122fade))

### BREAKING CHANGES

* **css:** EUI components are removed from this library. The single chart `style.css` stylesheet is now replaced by a `theme_only_light.css` or `theme_only_dark.css` file that brings in all the required styling for chart, tooltip and legends. `theme_light.css` and `theme_dark.css` styles include also a reset CSS style
@markov00
Copy link
Member Author

🎉 This PR is included in version 5.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@markov00 markov00 added the released Issue released publicly label Jun 10, 2019
@markov00 markov00 deleted the remove_eui branch December 13, 2019 11:52
AMoo-Miki pushed a commit to AMoo-Miki/OpenSearch-Dashboards that referenced this pull request Feb 10, 2022
# [5.0.0](elastic/elastic-charts@v4.2.9...v5.0.0) (2019-06-10)

### Bug Fixes

* **css:** remove dependency on EUI components and use only EUI styles ([opensearch-project#208](elastic/elastic-charts#208)) ([a26d2db](elastic/elastic-charts@a26d2db))

### BREAKING CHANGES

* **css:** EUI components are removed from this library. The single chart `style.css` stylesheet is now replaced by a `theme_only_light.css` or `theme_only_dark.css` file that brings in all the required styling for chart, tooltip and legends. `theme_light.css` and `theme_dark.css` styles include also a reset CSS style
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released Issue released publicly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants