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

Optimize charts plugin #78922

Merged
merged 4 commits into from
Sep 30, 2020
Merged

Optimize charts plugin #78922

merged 4 commits into from
Sep 30, 2020

Conversation

timroes
Copy link
Contributor

@timroes timroes commented Sep 30, 2020

Summary

This PR replaces the usage of d3 in the charts plugin by usage of the color npm module instead. The goal is to reduce the page load bundle size of the charts plugin significantly, since d3 has a significant larger size than the color module. We are also using that plugin across other parts of the code already.

This PR should not change any functionallity.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@@ -49,7 +49,7 @@ const fraction = function (goal: number) {
* If the number is greater than the length of seed colors available,
* new colors are generated up to the value of the input number.
*/
export function createColorPalette(num?: any): string[] {
export function createColorPalette(num: number): string[] {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ℹ️ I also improved the TypeScript code in that place here and got rid of the any.

@timroes timroes added chore Feature:Visualizations Generic visualization features (in case no more specific feature label is available) release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.10.0 v8.0.0 labels Sep 30, 2020

import { CoreSetup } from 'kibana/public';

import { COLOR_MAPPING_SETTING } from '../../../common';
import { createColorPalette } from './color_palette';

const standardizeColor = (color: string) => d3.rgb(color).toString();
const standardizeColor = (color: string) => new Color(color).hex().toLowerCase();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ℹ️ The old code used d3.toString() which created a lower-case hex value, to make sure I don't need to touch the tests and we can thus better guarantee that this doesn't change any functionality, I kept here the same logic, even though technically we could use .hex() as well and just adjust the tests.

@@ -61,7 +61,7 @@ describe('Mapped Colors', () => {
mappedColors.mapKeys(arr);

const colorValues = _(mappedColors.mapping).values();
expect(colorValues.includes(seedColors[0])).toBe(false);
expect(colorValues).not.toContain(seedColors[0]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ℹ️ A left over from debugging the tests, since this produces way better output, but I'd just leave it with this clearer API.

@timroes timroes marked this pull request as ready for review September 30, 2020 12:55
@timroes timroes requested a review from a team September 30, 2020 12:55
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

@kbn/optimizer bundle module count

id value diff baseline
charts 38 +7 31

page load bundle size

id value diff baseline
charts 137.4KB -206.8KB 344.2KB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

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

LGTM!

@timroes timroes merged commit f993d2d into elastic:master Sep 30, 2020
@timroes timroes deleted the optimize/charts branch September 30, 2020 14:47
timroes pushed a commit to timroes/kibana that referenced this pull request Sep 30, 2020
* Optimize charts plugin

* Fix issues to keep same behavior

* Remove dead import

* Revert name change
gmmorris added a commit to gmmorris/kibana that referenced this pull request Sep 30, 2020
* master: (97 commits)
  [Actions] Adds a "Test Connector" button on the Connectors List to make discovery of the Test tab easier (elastic#78746)
  [Discover] Fix functional time picker test permissions (elastic#78564)
  [ML] Fixing module datafeed overrides (elastic#78925)
  Adds some missing licenses to the CSV export (elastic#78719)
  [dev/cli] ensure plugins/ and all watch source dirs exist (elastic#78973)
  [Lens] Stop using scripted metric to collect telemetry (elastic#78687)
  [Lens] fix wrong message in fields accordion (elastic#78924)
  [Enterprise Search][App Search] Credentials Logic updates (elastic#78644)
  [Monitoring] Disk usage alerting (elastic#75419)
  [SECURITY_SOLUTION] Trusted apps list expand/collapse details (elastic#78601)
  Update content on interstitial page (elastic#78881)
  chore(NA): include hjson as a prod dependency (elastic#78941)
  Fix empty meta fields input in Advanced Settings  (elastic#78576)
  [Lens] Maintain order of operations in dimension panel (elastic#78864)
  Fix plugin doc title (elastic#78880)
  load apm-rum agent lazily (elastic#78760)
  [ML] Skip full ML access permission test
  Optimize charts plugin (elastic#78922)
  ui_actions service initial docs (elastic#78902)
  skip failing suite (elastic#78942)
  ...
timroes pushed a commit that referenced this pull request Oct 1, 2020
* Optimize charts plugin

* Fix issues to keep same behavior

* Remove dead import

* Revert name change
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Feature:Visualizations Generic visualization features (in case no more specific feature label is available) release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants