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 6 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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/charts/api/charts.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,7 @@ export type LegendPositionConfig = {

// @public
export interface LegendSpec {
alignLegendPointStyles?: boolean;
flatLegend?: boolean;
legendAction?: LegendAction;
// (undocumented)
Expand Down
29 changes: 16 additions & 13 deletions packages/charts/src/chart_types/xy_chart/renderer/shapes_paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Side Public License, v 1.
*/

import { getRadians } from '../../../utils/common';
import { PointShape, TextureShape } from '../../../utils/themes/theme';

/** @internal */
Expand All @@ -14,30 +15,32 @@ export type SVGPath = string;
/** @internal */
export type SVGPathFn = (radius: number) => SVGPath;

/** @internal */
export const cross: SVGPathFn = (r: number) => {
const cross: SVGPathFn = (r: number) => {
return `M ${-r} 0 L ${r} 0 M 0 ${r} L 0 ${-r}`;
};

/** @internal */
export const triangle: SVGPathFn = (r: number) => {
const triangle: SVGPathFn = (r: number) => {
const h = (r * Math.sqrt(3)) / 2;
const hr = r / 2;
return `M ${-h} ${hr} L ${h} ${hr} L 0 ${-r} Z`;
};

/** @internal */
export const square: SVGPathFn = (r: number) => {
return `M ${-r} ${-r} L ${-r} ${r} L ${r} ${r} L ${r} ${-r} Z`;
/**
* Returns shape function based on rotation of square in degrees
*/
const square = (rotation = 0): SVGPathFn => (r: number) => {
const d = getRadians(rotation);
const s = Math.abs(Math.cos(d) + Math.sin(d));
// scaled r to account for rotation;
const sr = s > 0 ? r / s : r;
return `M ${-sr} ${-sr} L ${-sr} ${sr} L ${sr} ${sr} L ${sr} ${-sr} Z`;
};

/** @internal */
export const circle: SVGPathFn = (r: number) => {
const circle: SVGPathFn = (r: number) => {
return `M ${-r} 0 a ${r},${r} 0 1,0 ${r * 2},0 a ${r},${r} 0 1,0 ${-r * 2},0`;
};

/** @internal */
export const line: SVGPathFn = (r: number) => {
const line: SVGPathFn = (r: number) => {
return `M 0 ${-r} l 0 ${r * 2}`;
};

Expand All @@ -46,8 +49,8 @@ export const ShapeRendererFn: Record<PointShape, [SVGPathFn, number]> = {
[PointShape.Circle]: [circle, 0],
[PointShape.X]: [cross, 45],
[PointShape.Plus]: [cross, 0],
[PointShape.Diamond]: [square, 45],
[PointShape.Square]: [square, 0],
[PointShape.Diamond]: [square(45), 45],
[PointShape.Square]: [square(0), 0],
[PointShape.Triangle]: [triangle, 0],
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ exports[`Chart should render the legend name test 1`] = `
</Resizer>
</Connect(Resizer)>
<Connect(LegendComponent)>
<LegendComponent debug={true} chartDimensions={{...}} containerDimensions={{...}} chartTheme={{...}} size={{...}} items={{...}} extraValues={{...}} config={{...}} onToggleDeselectSeriesAction={[Function (anonymous)]} onItemOutAction={[Function (anonymous)]} onItemOverAction={[Function (anonymous)]} clearTemporaryColors={[Function (anonymous)]} setTemporaryColor={[Function (anonymous)]} setPersistedColor={[Function (anonymous)]}>
<LegendComponent debug={true} alignLegendPointStyles={[undefined]} chartDimensions={{...}} containerDimensions={{...}} chartTheme={{...}} size={{...}} items={{...}} extraValues={{...}} config={{...}} onToggleDeselectSeriesAction={[Function (anonymous)]} onItemOutAction={[Function (anonymous)]} onItemOverAction={[Function (anonymous)]} clearTemporaryColors={[Function (anonymous)]} setTemporaryColor={[Function (anonymous)]} setPersistedColor={[Function (anonymous)]}>
<div className=\\"echLegend echLegend--debug echLegend--vertical echLegend--right echLegend--top\\" style={{...}}>
<div style={{...}} className=\\"echLegendListContainer\\">
<ul style={{...}} className=\\"echLegendList\\">
<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]}>
<LegendItem item={{...}} positionConfig={{...}} alignLegendPointStyles={[undefined]} 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]} pointStyle={[undefined]}>
<div className=\\"echLegendItem__color\\" title=\\"series color\\">
<LegendIcon pointStyle={[undefined]} color=\\"#1EA593\\">
<svg width={16} height={16} aria-label=\\"series color: #1EA593\\">
<g transform=\\"\\\\n translate(8, 8)\\\\n rotate(0)\\">
<path d=\\"M -3.5 0 a 3.5,3.5 0 1,0 7,0 a 3.5,3.5 0 1,0 -7,0\\" stroke=\\"#1EA593\\" strokeWidth={1} fill=\\"#1EA593\\" opacity={1} />
<g transform=\\"\\\\n translate(8, 8)\\\\n rotate(0)\\\\n \\">
<path d=\\"M -4 0 a 4,4 0 1,0 8,0 a 4,4 0 1,0 -8,0\\" stroke={[undefined]} strokeWidth={[undefined]} fill=\\"#1EA593\\" opacity={[undefined]} />
</g>
</svg>
</LegendIcon>
Expand Down
Loading