Skip to content

Commit

Permalink
[ML] Migrate ColorRangeLegend from SCSS to emotion. (elastic#199156)
Browse files Browse the repository at this point in the history
## Summary

Part of elastic#140695

Migrates SCSS to emotion for ColorRangeLegend.

<img
src="https://github.com/user-attachments/assets/3444fa49-2ef2-4706-b15e-c3e8415c6293"
/>

<img
src="https://github.com/user-attachments/assets/a79648a5-1230-41b6-b8f5-c1ff2dc9f996"
width="75%" />

### Checklist

- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [x] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)
  • Loading branch information
walterra authored Nov 7, 2024
1 parent 4c61876 commit 12dc8c1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
1 change: 0 additions & 1 deletion x-pack/plugins/ml/public/application/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// Components
@import 'components/annotations/annotation_description_list/index'; // SASSTODO: This file overwrites EUI directly
@import 'components/anomalies_table/index'; // SASSTODO: This file overwrites EUI directly
@import 'components/color_range_legend/index';
@import 'components/entity_cell/index';
@import 'components/influencers_list/index';
@import 'components/job_selector/index';
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,36 @@

import type { FC } from 'react';
import React, { useEffect, useRef } from 'react';
import { css } from '@emotion/react';
import d3 from 'd3';

import { EuiFlexGroup, EuiFlexItem, EuiText } from '@elastic/eui';

import { euiThemeVars } from '@kbn/ui-theme';

const COLOR_RANGE_RESOLUTION = 10;

// Overrides for d3/svg default styles
const cssOverride = css({
// Override default font size and color for axis
text: {
fontSize: `calc(${euiThemeVars.euiFontSizeXS} - 2px)`,
fill: euiThemeVars.euiColorDarkShade,
},
// Override default styles for axis lines
'.axis': {
path: {
fill: 'none',
stroke: 'none',
},
line: {
fill: 'none',
stroke: euiThemeVars.euiColorMediumShade,
shapeRendering: 'crispEdges',
},
},
});

interface ColorRangeLegendProps {
colorRange: (d: number) => string;
justifyTicks?: boolean;
Expand Down Expand Up @@ -65,7 +89,6 @@ export const ColorRangeLegend: FC<ColorRangeLegendProps> = ({

const wrapper = d3
.select(d3Container.current)
.classed('mlColorRangeLegend', true)
.attr('width', wrapperWidth)
.attr('height', wrapperHeight)
.append('g')
Expand Down Expand Up @@ -144,7 +167,7 @@ export const ColorRangeLegend: FC<ColorRangeLegendProps> = ({
</EuiText>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<svg ref={d3Container} />
<svg ref={d3Container} css={cssOverride} />
</EuiFlexItem>
</EuiFlexGroup>
);
Expand Down

0 comments on commit 12dc8c1

Please sign in to comment.