Skip to content

Commit ecc2cc8

Browse files
authored
Merge pull request #600 from SantiagoG14/capstone/new-design
Capstone/venn spec builder & react component v2
2 parents 507359a + cc26840 commit ecc2cc8

38 files changed

+2637
-179
lines changed

.eslintrc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module.exports = {
4444
message: 'Please use relative path import for types instead (ex. ../types/locales).',
4545
},
4646
],
47+
'no-duplicate-imports': 'error',
4748
'header/header': [
4849
2,
4950
'block',

packages/constants/constants.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ export const DONUT_SUMMARY_FONT_SIZE_RATIO = 0.35;
106106
/** Min inner radius to display the summary metric. If the inner radius is less than this, the summary metric is hidden. */
107107
export const DONUT_SUMMARY_MIN_RADIUS = 45;
108108

109+
// venn constant
110+
export const DEFAULT_VENN_COLOR = 'sets';
111+
/** default key in data for the metric in the venn diagram */
112+
export const DEFAULT_VENN_METRIC = 'size';
113+
/** default key in data for the label inside the venn*/
114+
export const DEFAULT_VENN_LABEL = 'label';
115+
109116
// ratio that each opacity is divded by when hovering or highlighting from legend
110117
export const HIGHLIGHT_CONTRAST_RATIO = 5;
111118

packages/react-spectrum-charts/src/Chart.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
MARK_ID,
2727
} from '@spectrum-charts/constants';
2828
import { getColorValue } from '@spectrum-charts/themes';
29-
import { ChartHandle, LineType, LineWidth } from '@spectrum-charts/vega-spec-builder';
29+
import { ChartData, ChartHandle, LineType, LineWidth } from '@spectrum-charts/vega-spec-builder';
3030

3131
import './Chart.css';
3232
import { RscChart } from './RscChart';
@@ -38,7 +38,7 @@ import useChartImperativeHandle from './hooks/useChartImperativeHandle';
3838
import useChartWidth from './hooks/useChartWidth';
3939
import { useResizeObserver } from './hooks/useResizeObserver';
4040
import { BigNumberInternal } from './rc/components/BigNumber/BigNumber';
41-
import { ChartData, ChartProps, RscChartProps } from './types';
41+
import { ChartProps, RscChartProps } from './types';
4242
import { getBigNumberElementsFromChildren, toArray } from './utils';
4343

4444
interface PlaceholderContentProps {

packages/react-spectrum-charts/src/RscChart.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ export const RscChart = forwardRef<ChartHandle, RscChartProps>((props, forwarded
6969
backgroundColor,
7070
children: sanitizedChildren,
7171
colors,
72+
chartWidth,
73+
chartHeight,
7274
data,
7375
description,
7476
idKey,

packages/react-spectrum-charts/src/VegaChart.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import { Options as TooltipOptions } from 'vega-tooltip';
1717

1818
import { TABLE } from '@spectrum-charts/constants';
1919
import { getLocale } from '@spectrum-charts/locales';
20-
import { getVegaEmbedOptions } from '@spectrum-charts/vega-spec-builder';
20+
import { ChartData, getVegaEmbedOptions } from '@spectrum-charts/vega-spec-builder';
2121

2222
import { useDebugSpec } from './hooks/useDebugSpec';
2323
import { extractValues, isVegaData } from './hooks/useSpec';
24-
import { ChartData, ChartProps } from './types';
24+
import { ChartProps } from './types';
2525

2626
export interface VegaChartProps {
2727
config: Config;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2025 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
/* eslint-disable @typescript-eslint/no-unused-vars */
14+
import { FC } from 'react';
15+
16+
import { DEFAULT_VENN_COLOR, DEFAULT_VENN_LABEL, DEFAULT_VENN_METRIC } from '@spectrum-charts/constants';
17+
18+
import { VennProps } from '../../../types';
19+
20+
const Venn: FC<VennProps> = ({
21+
orientation = '0deg',
22+
metric = DEFAULT_VENN_METRIC,
23+
label = DEFAULT_VENN_LABEL,
24+
color = DEFAULT_VENN_COLOR,
25+
}) => {
26+
return null;
27+
};
28+
29+
Venn.displayName = 'Venn';
30+
31+
export { Venn };
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright 2025 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
export * from './Venn';

packages/react-spectrum-charts/src/alpha/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212

1313
export * from './Bullet';
1414
export * from './Combo';
15+
export * from './Venn';

packages/react-spectrum-charts/src/hooks/useSpec.tsx

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,22 @@
99
* OF ANY KIND, either express or implied. See the License for the specific language
1010
* governing permissions and limitations under the License.
1111
*/
12-
import { useMemo } from 'react';
12+
import { useEffect, useMemo, useRef } from 'react';
1313

1414
import { Data, Spec, ValuesData } from 'vega';
1515

1616
import { getColorValue } from '@spectrum-charts/themes';
17-
import { ChartSpecOptions, baseData, buildSpec } from '@spectrum-charts/vega-spec-builder';
17+
import { ChartData, ChartSpecOptions, baseData, buildSpec } from '@spectrum-charts/vega-spec-builder';
1818

19+
import { Venn } from '../alpha';
1920
import { rscPropsToSpecBuilderOptions } from '../rscToSbAdapter';
20-
import { ChartData, SanitizedSpecProps } from '../types';
21+
import { SanitizedSpecProps } from '../types';
22+
import { chartHasChild } from '../utils';
2123

2224
export default function useSpec({
2325
backgroundColor,
26+
chartHeight,
27+
chartWidth,
2428
children,
2529
colors,
2630
colorScheme,
@@ -38,7 +42,38 @@ export default function useSpec({
3842
title,
3943
UNSAFE_vegaSpec,
4044
}: SanitizedSpecProps): Spec {
45+
const prevSpec = useRef<Spec | null>(null);
46+
const hasVenn = useMemo(() => chartHasChild({ children, displayName: Venn.displayName as string }), [children]);
47+
48+
// invalidate cache if changes to props other than width, height change
49+
useEffect(() => {
50+
prevSpec.current = null;
51+
}, [
52+
UNSAFE_vegaSpec,
53+
backgroundColor,
54+
children,
55+
colors,
56+
colorScheme,
57+
description,
58+
hiddenSeries,
59+
highlightedItem,
60+
highlightedSeries,
61+
idKey,
62+
lineTypes,
63+
lineWidths,
64+
opacities,
65+
symbolShapes,
66+
symbolSizes,
67+
title,
68+
data,
69+
]);
70+
4171
return useMemo(() => {
72+
// returned cached spec if there is a cached spec and if venn is not a child element
73+
if (!hasVenn && prevSpec.current !== null) {
74+
return prevSpec.current;
75+
}
76+
4277
// They already supplied a spec, fill it in with defaults
4378
if (UNSAFE_vegaSpec) {
4479
const vegaSpecWithDefaults = initializeSpec(UNSAFE_vegaSpec, {
@@ -50,15 +85,20 @@ export default function useSpec({
5085
});
5186

5287
// copy the spec so we don't mutate the original
53-
return JSON.parse(JSON.stringify(vegaSpecWithDefaults));
88+
const spec = JSON.parse(JSON.stringify(vegaSpecWithDefaults));
89+
prevSpec.current = spec;
90+
return spec;
5491
}
5592

5693
// or we need to build their spec
5794
const chartOptions = rscPropsToSpecBuilderOptions({
5895
backgroundColor,
96+
chartHeight,
97+
chartWidth,
5998
children,
6099
colors,
61100
colorScheme,
101+
data,
62102
description,
63103
hiddenSeries,
64104
highlightedItem,
@@ -73,7 +113,10 @@ export default function useSpec({
73113
});
74114

75115
// stringify-parse so that all immer stuff gets cleared out
76-
return buildSpec(chartOptions);
116+
const spec = buildSpec(chartOptions);
117+
prevSpec.current = spec;
118+
119+
return spec;
77120
}, [
78121
UNSAFE_vegaSpec,
79122
backgroundColor,
@@ -92,6 +135,9 @@ export default function useSpec({
92135
symbolSizes,
93136
title,
94137
data,
138+
chartHeight,
139+
chartWidth,
140+
hasVenn,
95141
]);
96142
}
97143

packages/react-spectrum-charts/src/rc/components/BigNumber/BigNumber.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import { CSSProperties, FC, cloneElement } from 'react';
1313

1414
import { Flex, FlexProps, IconProps } from '@adobe/react-spectrum';
1515
import { getLocale } from '@spectrum-charts/locales';
16-
import { BigNumberMethod, Orientation } from '@spectrum-charts/vega-spec-builder';
16+
import { BigNumberMethod, ChartData, Orientation } from '@spectrum-charts/vega-spec-builder';
1717

1818
import { RscChart } from '../../../RscChart';
1919
import { Line } from '../../../components';
20-
import { BigNumberProps, ChartData, LineProps, RscChartProps } from '../../../types';
20+
import { BigNumberProps, LineProps, RscChartProps } from '../../../types';
2121
import { sanitizeBigNumberChildren } from '../../../utils';
2222
import './BigNumber.css';
2323
import { formatBigNumber } from './bigNumberFormatUtils';

0 commit comments

Comments
 (0)