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(legend): add point shape styles to legend item #1227

Merged
merged 65 commits into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
414fa37
feat: add shape to legend item
rshen91 Jun 29, 2021
10f447b
Merge remote-tracking branch 'upstream/master' into shape-legend
rshen91 Jun 29, 2021
d779b28
test: update tests
rshen91 Jun 29, 2021
a68797c
feat: add point style type check for area and line series
rshen91 Jul 1, 2021
bf69b05
test: add story
rshen91 Jul 1, 2021
9d26b1a
Merge branch 'master' into shape-legend
rshen91 Jul 1, 2021
95cac10
Merge branch 'master' into shape-legend
rshen91 Jul 7, 2021
7e2d1f5
Merge remote-tracking branch 'upstream/master' into shape-legend
rshen91 Jul 7, 2021
badbef6
Merge remote-tracking branch 'origin/shape-legend' into shape-legend
rshen91 Jul 7, 2021
5b847e4
test: update stories
rshen91 Jul 7, 2021
bfaa207
fix: update shapes per chart theme as fallback
rshen91 Jul 7, 2021
c03bf6c
Merge remote-tracking branch 'upstream/master' into shape-legend
rshen91 Jul 8, 2021
5ebd342
Merge branch 'master' into shape-legend
rshen91 Jul 8, 2021
2040290
Merge remote-tracking branch 'origin/shape-legend' into shape-legend
rshen91 Jul 8, 2021
37cf9c1
fix: remove the fill for the square icon
rshen91 Jul 8, 2021
957d817
feat: refactor to allow all point styles
rshen91 Jul 8, 2021
4c47d58
fix: remove unused icon files
rshen91 Jul 8, 2021
59e649d
fix: add default check of seriesTypes for vrt
rshen91 Jul 9, 2021
f079e8c
test: update test snapshots
rshen91 Jul 9, 2021
fedf375
fix: update chart api
rshen91 Jul 9, 2021
10a2825
fix: fix tests and circle size
rshen91 Jul 9, 2021
b57c8f4
fix: catch filled circles for legend
rshen91 Jul 9, 2021
617a2eb
fix: fix default icons for areas and lines
rshen91 Jul 12, 2021
d727e2f
Merge remote-tracking branch 'upstream/master' into shape-legend
rshen91 Jul 12, 2021
15966e9
fix: fix header for story
rshen91 Jul 12, 2021
dba376a
Merge remote-tracking branch 'upstream/master' into shape-legend
rshen91 Jul 12, 2021
9997f0e
fix: optional seriesType
rshen91 Jul 12, 2021
d15eefd
fix: fix api extractor
rshen91 Jul 12, 2021
ec6987c
refactor: remove circle from theme
rshen91 Jul 12, 2021
3f19f9b
test: update tests
rshen91 Jul 12, 2021
613b336
fix: filled circle
rshen91 Jul 13, 2021
b2df204
test: update vrt dot icons
rshen91 Jul 13, 2021
b18dcf3
Merge remote-tracking branch 'upstream/master' into shape-legend
rshen91 Jul 13, 2021
ac503ed
fix: add stroke to theme
rshen91 Jul 13, 2021
4197004
fix: remove point shape from theme and adjust the mergePartial logic …
rshen91 Jul 13, 2021
2bc10ec
feat: add max and min check for icon radius
rshen91 Jul 14, 2021
038d178
fix: add /3 for diamond shape clipping
rshen91 Jul 14, 2021
dffd8ba
Merge remote-tracking branch 'upstream/master' into shape-legend
rshen91 Jul 14, 2021
2ad550b
Merge remote-tracking branch 'upstream/master' into shape-legend
rshen91 Jul 14, 2021
199e482
fix: fix marker size to match current master defaults
rshen91 Jul 14, 2021
7ccf870
test: update chart test
rshen91 Jul 14, 2021
bec8df6
Merge remote-tracking branch 'upstream/master' into shape-legend
rshen91 Jul 14, 2021
02470d6
test: add test
rshen91 Jul 14, 2021
06c3cca
fix: add mergeOptionalPartialValues
rshen91 Jul 15, 2021
80c4cea
fix: code review changes
rshen91 Jul 15, 2021
656ade1
Merge remote-tracking branch 'upstream/master' into shape-legend
rshen91 Jul 15, 2021
13e576d
refactor: code review changes
rshen91 Jul 16, 2021
139289c
Merge remote-tracking branch 'upstream/master' into shape-legend
rshen91 Jul 16, 2021
3a2fd8b
Merge remote-tracking branch 'upstream/master' into shape-legend
rshen91 Jul 20, 2021
57d1684
refactor: code review changes
rshen91 Jul 20, 2021
150b3d6
fix: code review changes
rshen91 Jul 20, 2021
624ab42
fix: fix ternary for default icons
rshen91 Jul 21, 2021
e01d9a3
fix: vrt radius for custom styling fix
rshen91 Jul 21, 2021
8637423
fix: square/diamond shape size based on rotation
nickofthyme Jul 21, 2021
3527eda
refactor: cleanup defaults add alignLegendPointStyles option
nickofthyme Jul 21, 2021
07fde21
feat: allow partial compare with deepEqual with tests
nickofthyme Jul 21, 2021
c3219d1
test: fix broken tests, update vrts per changes
nickofthyme Jul 21, 2021
db4bbf0
fix: minor math check
nickofthyme Jul 21, 2021
34b3012
fix: legend icon with color picker
nickofthyme Jul 21, 2021
537b375
test: update tests
rshen91 Jul 22, 2021
a9feb73
refactor: remove align prop in favor of always applying styles
nickofthyme Jul 22, 2021
46ab4e4
test: update vrts to take on styling
rshen91 Jul 22, 2021
71c00ed
test: finalize scope and vrts
rshen91 Jul 26, 2021
47702ab
test: update snapshot unit tests
rshen91 Jul 26, 2021
f2d780b
test: update vrt
rshen91 Jul 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import { LegendItem } from '../../../../common/legend';
import { createCustomCachedSelector } from '../../../../state/create_selector';
import { getDeselectedSeriesSelector } from '../../../../state/selectors/get_deselected_data_series';
import { PointShape } from '../../../../utils/themes/theme';
import { getColorScale } from './get_color_scale';
import { getSpecOrNull } from './heatmap_spec';

Expand Down Expand Up @@ -48,6 +49,7 @@ export const computeLegendSelector = createCustomCachedSelector(
isToggleable: true,
path: [{ index: 0, value: seriesIdentifier.key }],
keys: [],
shape: PointShape.Circle,
};
});
},
Expand Down
24 changes: 23 additions & 1 deletion packages/charts/src/chart_types/xy_chart/legend/legend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@

import { LegendItem } from '../../../common/legend';
import { SeriesKey, SeriesIdentifier } from '../../../common/series_id';
import { IconType } from '../../../components/icons/icon';
import { ScaleType } from '../../../scales/constants';
import { SortSeriesByConfig, TickFormatterOptions } from '../../../specs';
import { Color } from '../../../utils/common';
import { BandedAccessorType } from '../../../utils/geometry';
import { getLegendCompareFn, SeriesCompareFn } from '../../../utils/series_sort';
import { PointShape, Theme } from '../../../utils/themes/theme';
import { getXScaleTypeFromSpec } from '../scales/get_api_scales';
import { getAxesSpecForSpecId, getSpecsById } from '../state/utils/spec';
import { LastValues } from '../state/utils/types';
Expand All @@ -39,7 +41,15 @@ import {
isDataSeriesBanded,
getSeriesIdentifierFromDataSeries,
} from '../utils/series';
import { AxisSpec, BasicSeriesSpec, Postfixes, isAreaSeriesSpec, isBarSeriesSpec } from '../utils/specs';
import {
AxisSpec,
BasicSeriesSpec,
Postfixes,
isAreaSeriesSpec,
isBarSeriesSpec,
isBubbleSeriesSpec,
isLineSeriesSpec,
} from '../utils/specs';

/** @internal */
export interface FormattedLastValues {
Expand Down Expand Up @@ -101,6 +111,7 @@ export function computeLegend(
showLegendExtra: boolean,
serialIdentifierDataSeriesMap: Record<string, DataSeries>,
deselectedDataSeries: SeriesIdentifier[] = [],
theme: Theme,
sortSeriesBy?: SeriesCompareFn | SortSeriesByConfig,
): LegendItem[] {
const legendItems: LegendItem[] = [];
Expand Down Expand Up @@ -139,6 +150,15 @@ export function computeLegend(
const lastValue = lastValues.get(key);
const seriesIdentifier = getSeriesIdentifierFromDataSeries(series);
const xScaleType = getXScaleTypeFromSpec(spec.xScaleType);

let shape = PointShape.Circle as IconType;
if (isBubbleSeriesSpec(spec)) {
shape = spec.bubbleSeriesStyle?.point?.shape ?? theme.bubbleSeriesStyle.point.shape;
} else if (isLineSeriesSpec(spec)) {
shape = spec.lineSeriesStyle?.point?.shape ?? theme.lineSeriesStyle.point.shape;
} else if (isAreaSeriesSpec(spec)) {
shape = spec.areaSeriesStyle?.point?.shape ?? theme.areaSeriesStyle.point.shape;
}
nickofthyme marked this conversation as resolved.
Show resolved Hide resolved
legendItems.push({
color,
label: labelY1,
Expand All @@ -150,6 +170,7 @@ export function computeLegend(
defaultExtra: getLegendExtra(showLegendExtra, xScaleType, formatter, 'y1', lastValue),
path: [{ index: 0, value: seriesIdentifier.key }],
keys: [specId, spec.groupId, yAccessor, ...series.splitAccessors.values()],
shape,
});
if (banded) {
const labelY0 = getBandedLegendItemLabel(name, BandedAccessorType.Y0, postFixes);
Expand All @@ -164,6 +185,7 @@ export function computeLegend(
defaultExtra: getLegendExtra(showLegendExtra, xScaleType, formatter, 'y0', lastValue),
path: [{ index: 0, value: seriesIdentifier.key }],
keys: [specId, spec.groupId, yAccessor, ...series.splitAccessors.values()],
shape,
});
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const computeLegendSelector = createCustomCachedSelector(
settings.showLegendExtra,
siDataSeriesMap,
deselectedDataSeries,
chartTheme,
// @ts-ignore
settings.sortSeriesBy,
nickofthyme marked this conversation as resolved.
Show resolved Hide resolved
);
Expand Down
2 changes: 2 additions & 0 deletions packages/charts/src/common/legend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import { PrimitiveValue } from '../chart_types/partition_chart/layout/utils/group_by_rollup';
import { IconType } from '../components/icons/icon';
import { LegendPath } from '../state/actions/legend';
import { Color } from '../utils/common';
import { CategoryKey, CategoryLabel } from './category';
Expand Down Expand Up @@ -47,6 +48,7 @@ export type LegendItem = {
// TODO: Remove when partition layers are toggleable
isToggleable?: boolean;
keys: Array<string | number>;
shape?: IconType;
nickofthyme marked this conversation as resolved.
Show resolved Hide resolved
};

/** @internal */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ exports[`Chart should render the legend name test 1`] = `
<LegendItem item={{...}} positionConfig={{...}} totalItems={1} extraValues={{...}} showExtra={false} onMouseOut={[undefined]} onMouseOver={[undefined]} onClick={[undefined]} clearTemporaryColorsAction={[Function (anonymous)]} setPersistedColorAction={[Function (anonymous)]} setTemporaryColorAction={[Function (anonymous)]} mouseOutAction={[Function (anonymous)]} mouseOverAction={[Function (anonymous)]} toggleDeselectSeriesAction={[Function (anonymous)]} colorPicker={[undefined]} action={[undefined]}>
<li className=\\"echLegendItem echLegendItem--vertical\\" onMouseEnter={[Function (anonymous)]} onMouseLeave={[Function (anonymous)]} style={[undefined]} data-ech-series-name=\\"test\\">
<div className=\\"background\\" />
<ForwardRef color=\\"#1EA593\\" seriesName=\\"test\\" isSeriesHidden={false} hasColorPicker={false} onClick={[undefined]}>
<ForwardRef color=\\"#1EA593\\" seriesName=\\"test\\" isSeriesHidden={false} hasColorPicker={false} onClick={[undefined]} shape=\\"circle\\">
<div className=\\"echLegendItem__color\\" title=\\"series color\\">
<Icon type=\\"dot\\" color=\\"#1EA593\\" aria-label=\\"series color: #1EA593\\">
<Icon type=\\"circle\\" color=\\"#1EA593\\" aria-label=\\"series color: #1EA593\\">
<DotIcon className=\\"echIcon\\" color=\\"#1EA593\\" tabIndex={[undefined]} focusable=\\"false\\" aria-label=\\"series color: #1EA593\\">
<svg width={16} height={16} viewBox=\\"0 0 16 16\\" xmlns=\\"http://www.w3.org/2000/svg\\" className=\\"echIcon\\" color=\\"#1EA593\\" tabIndex={[undefined]} focusable=\\"false\\" aria-label=\\"series color: #1EA593\\">
<circle cx={8} cy={8} r={4} />
Expand Down
31 changes: 31 additions & 0 deletions packages/charts/src/components/icons/assets/diamond.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import React from 'react';

import { IconComponentProps } from '../icon';

/** @internal */
export function DiamondIcon(extraProps: IconComponentProps) {
return (
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" {...extraProps}>
<path d="M 8 13 L 13 7 L 13 7 L 8 1 L 3 7 Z M 8 -1 L 15 7 L 8 15 L 1 7 L 8 -1 Z" />
</svg>
);
}
31 changes: 31 additions & 0 deletions packages/charts/src/components/icons/assets/plus.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import React from 'react';

import { IconComponentProps } from '../icon';

/** @internal */
export function PlusIcon(extraProps: IconComponentProps) {
return (
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" {...extraProps}>
<path d="M8.25,3 C8.52614237,3 8.75,3.22385763 8.75,3.5 L8.75,7.25 L12.5,7.25 C12.7761424,7.25 13,7.47385763 13,7.75 L13,8.25 C13,8.52614237 12.7761424,8.75 12.5,8.75 L8.75,8.75 L8.75,12.5 C8.75,12.7761424 8.52614237,13 8.25,13 L7.75,13 C7.47385763,13 7.25,12.7761424 7.25,12.5 L7.25,8.75 L3.5,8.75 C3.22385763,8.75 3,8.52614237 3,8.25 L3,7.75 C3,7.47385763 3.22385763,7.25 3.5,7.25 L7.25,7.25 L7.25,3.5 C7.25,3.22385763 7.47385763,3 7.75,3 L8.25,3 Z" />
</svg>
);
}
31 changes: 31 additions & 0 deletions packages/charts/src/components/icons/assets/square.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import React from 'react';

import { IconComponentProps } from '../icon';

/** @internal */
export function SquareIcon(extraProps: IconComponentProps) {
return (
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" {...extraProps}>
<rect width="12" height="12" x="2" y="2" rx="2" fillRule="evenodd" />
</svg>
);
}
35 changes: 35 additions & 0 deletions packages/charts/src/components/icons/assets/triangle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import React from 'react';

import { IconComponentProps } from '../icon';

/** @internal */
export function TriangleIcon(extraProps: IconComponentProps) {
// https://codepen.io/knod/pen/YqLgwR
return (
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" {...extraProps}>
<path
fillRule="evenodd"
d="M 2 14 A 1 1 0 0 1 1.122 12.521 L 7.122 1.521 A 1 1 0 0 1 8.878 1.521 L 14.878 12.521 A 1 1 0 0 1 14 14 H 2 Z M 2 13 H 14 L 8 2 L 2 13 Z"
/>
</svg>
);
}
31 changes: 31 additions & 0 deletions packages/charts/src/components/icons/assets/x.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import React from 'react';

import { IconComponentProps } from '../icon';

/** @internal */
export function XIcon(extraProps: IconComponentProps) {
return (
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" {...extraProps}>
<path d="M7.29289322,8 L3.14644661,3.85355339 C2.95118446,3.65829124 2.95118446,3.34170876 3.14644661,3.14644661 C3.34170876,2.95118446 3.65829124,2.95118446 3.85355339,3.14644661 L8,7.29289322 L12.1464466,3.14644661 C12.3417088,2.95118446 12.6582912,2.95118446 12.8535534,3.14644661 C13.0488155,3.34170876 13.0488155,3.65829124 12.8535534,3.85355339 L8.70710678,8 L12.8535534,12.1464466 C13.0488155,12.3417088 13.0488155,12.6582912 12.8535534,12.8535534 C12.6582912,13.0488155 12.3417088,13.0488155 12.1464466,12.8535534 L8,8.70710678 L3.85355339,12.8535534 C3.65829124,13.0488155 3.34170876,13.0488155 3.14644661,12.8535534 C2.95118446,12.6582912 2.95118446,12.3417088 3.14644661,12.1464466 L7.29289322,8 Z" />
</svg>
);
}
14 changes: 12 additions & 2 deletions packages/charts/src/components/icons/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ import React, { SVGAttributes, memo } from 'react';

import { deepEqual } from '../../utils/fast_deep_equal';
import { AlertIcon } from './assets/alert';
import { DiamondIcon } from './assets/diamond';
import { DotIcon } from './assets/dot';
import { EmptyIcon } from './assets/empty';
import { EyeIcon } from './assets/eye';
import { EyeClosedIcon } from './assets/eye_closed';
import { ListIcon } from './assets/list';
import { PlusIcon } from './assets/plus';
import { QuestionInCircle } from './assets/question_in_circle';
import { SquareIcon } from './assets/square';
import { TriangleIcon } from './assets/triangle';
import { XIcon } from './assets/x';

const typeToIconMap = {
alert: AlertIcon,
Expand All @@ -37,13 +42,19 @@ const typeToIconMap = {
eyeClosed: EyeClosedIcon,
list: ListIcon,
questionInCircle: QuestionInCircle,
circle: DotIcon,
x: XIcon,
plus: PlusIcon,
diamond: DiamondIcon,
square: SquareIcon,
triangle: TriangleIcon,
nickofthyme marked this conversation as resolved.
Show resolved Hide resolved
};

/** @internal */
export type IconColor = string;

/** @internal */
export type IconType = keyof typeof typeToIconMap;
export type IconType = keyof typeof typeToIconMap | undefined;
nickofthyme marked this conversation as resolved.
Show resolved Hide resolved

interface IconProps {
className?: string;
Expand All @@ -64,7 +75,6 @@ function IconComponent({ type, color, className, tabIndex, ...rest }: IconCompon
}

const classes = classNames('echIcon', className);

const Svg = (type && typeToIconMap[type]) || EmptyIcon;

/*
Expand Down
Loading