Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
ab5e3f7
chore: add timer value to signals
gideontonkinson Feb 14, 2024
c421d9f
fix: remove debug from chart.story.tsx
gideontonkinson Feb 14, 2024
9e09a53
chore: add tests for timer signal
gideontonkinson Feb 14, 2024
b8f65df
fix: remove debug
gideontonkinson Feb 14, 2024
30a0af4
feat: add timer value to signals (#127)
gideontonkinson Feb 14, 2024
84b075f
feat: add previous data table to data
gideontonkinson Feb 16, 2024
20288a6
fix: fix broken test
gideontonkinson Feb 16, 2024
41d7141
fix: remove debug
gideontonkinson Feb 19, 2024
3b09115
Gtonkinson/animations (#132)
gideontonkinson Feb 19, 2024
c8fc4df
Merge remote to local
Judd2000 Feb 20, 2024
3bcd803
Animations implement from zero and using previous data
Judd2000 Feb 20, 2024
4876f79
Animations Between Data: starting implementation
Judd2000 Feb 21, 2024
b4405e3
Animations finished new-old data animations for line chart
Judd2000 Feb 23, 2024
d36b674
Animations remove todo
Judd2000 Feb 23, 2024
df8c5fb
Animations remove todo
Judd2000 Feb 23, 2024
c1fc3d7
Animations added static line animations and removed lint issues
Judd2000 Feb 23, 2024
a7897f1
Animations stacked bar and areas animations added)
Judd2000 Feb 26, 2024
c349cd5
Animations dodged bar experimentaion
Judd2000 Feb 28, 2024
496e62f
Resolve merge conflicts
gideontonkinson Feb 28, 2024
248d2d2
resolve merge conflicts
gideontonkinson Feb 28, 2024
43a29ff
Animations add dodged bar-specific animations as well as hide labels …
Judd2000 Feb 29, 2024
d96361f
Animations lint fixes
Judd2000 Feb 29, 2024
e736d42
Animations use structuredClone instead of JSON.stringify
Judd2000 Feb 29, 2024
a3c56d9
Merge pull request #153 from adobe/nathaniel-judd/byu-team/animations
Judd2000 Mar 1, 2024
00ec648
Add animation easing
jacob-hart Mar 1, 2024
e7bcc86
Merge pull request #160 from adobe/jacob-hart/byu-team/easing
Judd2000 Mar 1, 2024
af1a1e6
Animations added global mock for structuredClone
Judd2000 Mar 1, 2024
56b39a5
Merge remote to local
Judd2000 Mar 1, 2024
6159cad
Test: Add animations story
gideontonkinson Mar 1, 2024
644ec12
Animations added extra check for animating between datasets that they…
Judd2000 Mar 1, 2024
53c2c06
animation storybook
gideontonkinson Mar 4, 2024
560d4e1
merge in changes
gideontonkinson Mar 4, 2024
7702d7a
Animations fixed previousData causing strange animations
Judd2000 Mar 6, 2024
18bba7a
Merge branch 'animations' of github.com:adobe/react-spectrum-charts i…
gideontonkinson Mar 6, 2024
fb885e6
feat: add animations storybook
gideontonkinson Mar 6, 2024
4b849ed
Add animation spec backwards compatibility with existing tests (#169)
jacob-hart Mar 8, 2024
956e421
Animations fix previousData, add filter
Judd2000 Mar 8, 2024
8174613
Merge branch 'animations' of https://github.com/adobe/react-spectrum-…
Judd2000 Mar 8, 2024
5cc4c2a
merge in main animations
gideontonkinson Mar 8, 2024
9832018
failed to remove merge conflict
gideontonkinson Mar 8, 2024
e56701b
missed an additional merge conflict
gideontonkinson Mar 8, 2024
c7cc0a1
Test: Add testing for the animation stories
gideontonkinson Mar 8, 2024
83bad13
feat: add more tests
gideontonkinson Mar 8, 2024
abe7efd
Animations fix (most) remaining tests
Judd2000 Mar 8, 2024
14285ba
merge in main branch
gideontonkinson Mar 11, 2024
acb855e
Merge "main" into "animations"
Judd2000 Mar 11, 2024
1aa7490
Animation resolve new test data expected lengths
Judd2000 Mar 11, 2024
9329ade
Animations disable animations for the dodged trellis bar
Judd2000 Mar 13, 2024
cbea9a1
Animations re-add semicolon
Judd2000 Mar 13, 2024
2bf86f8
Animations disabled animations on animation-supported chart types
Judd2000 Mar 13, 2024
0fca769
Animations remove unused import
Judd2000 Mar 13, 2024
5c53a88
Merge "main" into "animations"
Judd2000 Mar 14, 2024
8905b7e
Merge "main" into "animations"
Judd2000 Mar 18, 2024
7174ba9
Merge branch 'main' into njudd/byu-team/animations
Judd2000 Mar 18, 2024
628ee82
Animations fix tests from main
Judd2000 Mar 18, 2024
151cbe2
Animations added interface to allow certain tests to override animati…
Judd2000 Mar 18, 2024
b7bcc62
Animations move VegaChart out to useMemo
Judd2000 Mar 19, 2024
a2f9e66
Animations removed console log:
Judd2000 Mar 19, 2024
1c7c546
Animations njudd remove comments
Judd2000 Mar 19, 2024
42ece8e
Animations useState var for spec, when popoverIsOpen set spec to no a…
Judd2000 Mar 20, 2024
e785232
Animations trying to fix rerendering
Judd2000 Mar 21, 2024
6aa151e
Change animation duration (#198)
jacob-hart Mar 24, 2024
b6a0b91
njudd/animations added animateFromZero state variable to RscChart and…
Judd2000 Mar 27, 2024
23345a7
Animations sounarcloud code smells
Judd2000 Mar 27, 2024
aa2e00c
Made animateFromZero optional
Judd2000 Mar 27, 2024
e217127
Merge pull request #207 from adobe/njudd/byu-team/animations
Judd2000 Mar 29, 2024
fc12bef
Animations removed console.logs
Judd2000 Apr 1, 2024
c3ee2b8
Animations made area and line charts have tooltips and highlight mark…
Judd2000 Apr 1, 2024
78d712a
Removed unused vars
Judd2000 Apr 1, 2024
46b5251
Minor build fixes
Judd2000 Apr 1, 2024
44cac56
Animations made area and line charts have tooltips and highlight mark…
Judd2000 Apr 3, 2024
05d1de3
Add animations to window and regression trendlines (#212)
jacob-hart Apr 3, 2024
f15f413
Add Opacity animation functionality to line, bar, scatter, trendline,…
agardn87 Apr 3, 2024
7fdca27
Gtonkinson/animations (#225)
gideontonkinson Apr 4, 2024
2a9de92
Animations-3 fixed issues with stacked bars and stacked areas - added…
Judd2000 Apr 5, 2024
b68afae
Merge "adam/byu-team/animations" into "animations-demo"
Judd2000 Apr 5, 2024
04128b1
Merge "adam/byu-team/animations" into "animations-demo"
Judd2000 Apr 5, 2024
2b75a2b
Animations fix utils
Judd2000 Apr 5, 2024
f001052
Merge pull request #228 from adobe/njudd/byu-team/animations-3
Judd2000 Apr 5, 2024
7fc39fa
fix: add proper switch testing
gideontonkinson Apr 5, 2024
03c4ebe
Merge branch 'animations' of github.com:adobe/react-spectrum-charts i…
gideontonkinson Apr 5, 2024
d34b64c
fix: tests
gideontonkinson Apr 6, 2024
f255a21
Animations code cleanup, logical flipping, removal of magic numbers
Judd2000 Apr 8, 2024
5aa58af
Animation more code cleanup
Judd2000 Apr 8, 2024
ce160d5
Animations made ANIMATION_FUNCTION constant that is assigned to EASE_…
Judd2000 Apr 10, 2024
52e5826
Animations only add timer signal when animations are enabled
Judd2000 Apr 10, 2024
f6a7f1c
Animations fixed timer signal and annotation opacity
Judd2000 Apr 10, 2024
b1ac8ba
Animations pass animations to scatterSpecBuilder, add animations togg…
Judd2000 Apr 10, 2024
6c9cb9a
Animations removed nested ternary inside markUtils
Judd2000 Apr 10, 2024
67a5778
fix: remove todo where tests are already implemented
gideontonkinson Apr 10, 2024
57a120f
Merge branch 'animations' of github.com:adobe/react-spectrum-charts i…
gideontonkinson Apr 10, 2024
97c8c6b
Animations fixed tests to not expect timerValue when animations are offA
Judd2000 Apr 10, 2024
7365302
Merge branch 'animations' of https://github.com/adobe/react-spectrum-…
Judd2000 Apr 10, 2024
7927719
Replace timer value with constant
agardn87 Apr 10, 2024
f87e38c
Animatioins moved usePreviousChartData out to the react hooks directo…
Judd2000 Apr 10, 2024
579dcf9
Merge branch 'animations' of https://github.com/adobe/react-spectrum-…
Judd2000 Apr 10, 2024
dabe3e9
Animations removed console.warn
Judd2000 Apr 10, 2024
2923b15
Animations removed unnecessary const
Judd2000 Apr 10, 2024
31dc879
Add animation toggle to opacity animation stories
agardn87 Apr 10, 2024
51e4b18
Merge branch 'animations' of https://github.com/adobe/react-spectrum-…
agardn87 Apr 10, 2024
1a64554
fix unneccessary logic
gideontonkinson Apr 12, 2024
3bd61d6
remove todo where tests are already completed
gideontonkinson Apr 12, 2024
c2e20e3
Use mark id for animations
jacob-hart Apr 12, 2024
1488446
Merge branch 'animations' of https://github.com/adobe/react-spectrum-…
jacob-hart Apr 12, 2024
a5e9caf
Remove unused imports
jacob-hart Apr 12, 2024
a1bebf4
add more testing
gideontonkinson Apr 12, 2024
ede3c17
removed unneccessary todos
gideontonkinson Apr 12, 2024
0d82e8f
Merge branch 'animations' of github.com:adobe/react-spectrum-charts i…
gideontonkinson Apr 12, 2024
fc9273f
Animations more logical suggestion fixes
Judd2000 Apr 12, 2024
2771e35
Merge branch 'animations' of https://github.com/adobe/react-spectrum-…
Judd2000 Apr 12, 2024
2f7e3a8
Animations removed commented code and uneccessary space
Judd2000 Apr 12, 2024
fc1ce4c
remove added console.logs
gideontonkinson Apr 12, 2024
af6f684
Merge branch 'animations' of github.com:adobe/react-spectrum-charts i…
gideontonkinson Apr 12, 2024
6546d0c
remove warns
gideontonkinson Apr 12, 2024
a1b32db
remove more todos
gideontonkinson Apr 12, 2024
f695e8c
remove documentation todo
gideontonkinson Apr 12, 2024
00b1d03
fixed nested turnerary
gideontonkinson Apr 12, 2024
573305b
Animations removed useMemo wrapping the VegaChart component
Judd2000 Apr 12, 2024
05db649
Animations moved onNewView inline lambda to const
Judd2000 Apr 12, 2024
d9aa043
Animation set SharedChartProps animations to optional, added necessar…
Judd2000 Apr 12, 2024
39b7a41
Animations switched to ?? instead of comparing against undefined
Judd2000 Apr 12, 2024
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ test-report.xml

# exclude vscode config except for our shared snippets
.vscode/*
!.vscode/reactSpectrumCharts.code-snippets
!.vscode/reactSpectrumCharts.code-snippets

.idea/
7 changes: 6 additions & 1 deletion .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
const config: StorybookConfig = {
stories: ['../src/**/*.story.mdx', '../src/**/*.story.@(js|jsx|ts|tsx)'],

addons: ['@storybook/addon-links', '@storybook/addon-essentials', 'storybook-dark-mode'],
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
'storybook-dark-mode',
'@storybook/addon-webpack5-compiler-babel'
],

framework: {
name: '@storybook/react-webpack5',
Expand Down
1 change: 1 addition & 0 deletions global.mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global.structuredClone = (value) => JSON.parse(JSON.stringify(value));
4 changes: 1 addition & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ module.exports = {
transform: {
'^.+\\.(j|t)sx?$': 'babel-jest',
},
globals: {
structuredClone: (value) => JSON.parse(JSON.stringify(value)),
},
setupFiles: ['./global.mock.js'],
moduleDirectories: ['src', 'node_modules'],
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
Expand Down
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"@babel/runtime": "^7.20.6",
"@storybook/addon-actions": "7.6.17",
"@storybook/addon-essentials": "7.6.17",
"@storybook/addon-links": "7.6.17",
"@storybook/addon-actions": "^8.0.4",
"@storybook/addon-essentials": "^8.0.4",
"@storybook/addon-links": "^8.0.4",
"@storybook/addon-webpack5-compiler-babel": "^3.0.3",
"@storybook/preset-scss": "^1.0.3",
"@storybook/react": "7.6.17",
"@storybook/react-webpack5": "7.6.17",
"@storybook/testing-library": "^0.2.2",
"@storybook/theming": "7.6.17",
"@storybook/react": "^8.0.4",
"@storybook/react-webpack5": "^8.0.4",
"@storybook/test": "^8.0.4",
"@storybook/theming": "^8.0.4",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "12.1.5",
"@testing-library/user-event": "^14.4.3",
Expand Down Expand Up @@ -100,9 +101,9 @@
"react-docgen-typescript-loader": "3.7.2",
"react-dom": "17.0.2",
"resize-observer-polyfill": "^1.5.1",
"storybook": "7.6.17",
"storybook": "^8.0.4",
"storybook-addon-react-docgen": "^1.2.44",
"storybook-dark-mode": "^3.0.3",
"storybook-dark-mode": "^4.0.1",
"style-loader": "^3.3.3",
"ts-jest": "^29.0.3",
"ts-loader": "^9.4.2",
Expand Down
13 changes: 12 additions & 1 deletion src/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import { FC, forwardRef, useEffect, useMemo, useRef, useState } from 'react';

import { EmptyState } from '@components/EmptyState';
import { LoadingState } from '@components/LoadingState';
import { DEFAULT_BACKGROUND_COLOR, DEFAULT_COLOR_SCHEME, DEFAULT_LINE_TYPES, DEFAULT_LOCALE } from '@constants';
import {
DEFAULT_BACKGROUND_COLOR,
DEFAULT_COLOR_SCHEME,
DEFAULT_LINE_TYPES,
DEFAULT_LOCALE
} from '@constants';
import useChartImperativeHandle from '@hooks/useChartImperativeHandle';
import useChartWidth from '@hooks/useChartWidth';
import { useResizeObserver } from '@hooks/useResizeObserver';
Expand All @@ -27,6 +32,7 @@ import { Theme } from '@react-types/provider';

import './Chart.css';
import { ChartData, ChartHandle, ChartProps } from './types';
import usePreviousChartData from '@hooks/usePreviousChartData';

interface PlaceholderContentProps {
data: ChartData[];
Expand All @@ -40,6 +46,7 @@ export const Chart = forwardRef<ChartHandle, ChartProps>(
{
backgroundColor = DEFAULT_BACKGROUND_COLOR,
data,
animations = true,
colors = 'categorical12',
colorScheme = DEFAULT_COLOR_SCHEME,
config,
Expand Down Expand Up @@ -77,6 +84,8 @@ export const Chart = forwardRef<ChartHandle, ChartProps>(

useChartImperativeHandle(forwardedRef, { chartView, title });

const previousChartData = usePreviousChartData(data);

const containerRef = useResizeObserver<HTMLDivElement>((_target, entry) => {
if (typeof width === 'number') return;
setContainerWidth(entry.contentRect.width);
Expand Down Expand Up @@ -129,6 +138,8 @@ export const Chart = forwardRef<ChartHandle, ChartProps>(
chartView={chartView}
chartId={chartId}
data={data}
previousData={previousChartData}
animations={animations}
backgroundColor={backgroundColor}
colors={colors}
colorScheme={colorScheme}
Expand Down
129 changes: 75 additions & 54 deletions src/RscChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export const RscChart = forwardRef<ChartHandle, RscChartProps>(
chartView,
backgroundColor = DEFAULT_BACKGROUND_COLOR,
data,
previousData,
animations,
colors = 'categorical12',
colorScheme = DEFAULT_COLOR_SCHEME,
config,
Expand All @@ -93,7 +95,10 @@ export const RscChart = forwardRef<ChartHandle, RscChartProps>(
forwardedRef
) => {
// uuid is used to make a unique id so there aren't duplicate ids if there is more than one Chart component in the document
const selectedData = useRef<Datum | null>(null); // data that is currently selected, get's set on click if a popover exists

// state variable for storing if chart should reanimate from zero / animate across data sets
const [animateFromZero, setAnimateFromZero] = useState(true);
const selectedData = useRef<Datum | null>(null); // data that is currently selected, gets set on click if a popover exists
const selectedDataName = useRef<string>();
const selectedDataBounds = useRef<MarkBounds>();
const popoverAnchorRef = useRef<HTMLDivElement>(null);
Expand All @@ -102,12 +107,20 @@ export const RscChart = forwardRef<ChartHandle, RscChartProps>(

const sanitizedChildren = sanitizeRscChartChildren(props.children);

// THE MAGIC, builds our spec
// when data changes, make sure that we are animating from zero (especially in the case where a popover was just
// opened and closed)
useEffect(() => {
setAnimateFromZero(true);
}, [data]);

const spec = useSpec({
backgroundColor,
children: sanitizedChildren,
colors,
data,
previousData,
animations: animations ?? true,
animateFromZero,
description,
hiddenSeries,
highlightedSeries,
Expand All @@ -130,8 +143,11 @@ export const RscChart = forwardRef<ChartHandle, RscChartProps>(
// Hide tooltips on all charts when a popover is open
tooltipElement.hidden = popoverIsOpen;

// if the popover is closed, reset the selected data
if (!popoverIsOpen) {

if (popoverIsOpen) {
setAnimateFromZero(false);
} else {
// if the popover is closed, reset the selected data
selectedData.current = null;
}
}, [popoverIsOpen]);
Expand Down Expand Up @@ -173,7 +189,6 @@ export const RscChart = forwardRef<ChartHandle, RscChartProps>(
<LegendTooltip
value={value}
descriptions={legendDescriptions}
// TODO: support multiple legends
domain={chartView.current?.scale('legend0Entries').domain()}
/>
);
Expand All @@ -198,6 +213,7 @@ export const RscChart = forwardRef<ChartHandle, RscChartProps>(
const signals: Record<string, unknown> = {
backgroundColor: getColorValue('gray-50', colorScheme),
};

if (legendIsToggleable) {
signals.hiddenSeries = hiddenSeriesState;
}
Expand All @@ -207,6 +223,56 @@ export const RscChart = forwardRef<ChartHandle, RscChartProps>(
return signals;
}, [colorScheme, hiddenSeriesState, legendIsToggleable]);

const newSpec = structuredClone(spec);

const onNewView = (view) => {
chartView.current = view;
// Add a delay before displaying legend tooltips on hover.
let tooltipTimeout: NodeJS.Timeout | undefined;
view.tooltip((_, event, item, value) => {
const tooltipHandler = new Handler(tooltipConfig);
// Cancel delayed tooltips if the mouse moves before the delay is resolved.
if (tooltipTimeout) {
clearTimeout(tooltipTimeout);
tooltipTimeout = undefined;
}
if (event && event.type === 'pointermove' && itemIsLegendItem(item) && 'tooltip' in item) {
tooltipTimeout = setTimeout(() => {
tooltipHandler.call(this, event, item, value);
tooltipTimeout = undefined;
}, LEGEND_TOOLTIP_DELAY);
} else {
tooltipHandler.call(this, event, item, value);
}
});
if (popovers.length || legendIsToggleable || onLegendClick) {
if (legendIsToggleable) {
view.signal('hiddenSeries', hiddenSeriesState);
}
setSelectedSignals({
selectedData: selectedData.current,
view,
});
view.addEventListener(
'click',
getOnMarkClickCallback(
chartView,
hiddenSeriesState,
chartId,
selectedData,
selectedDataBounds,
selectedDataName,
setHiddenSeries,
legendIsToggleable,
onLegendClick
)
);
}
view.addEventListener('mouseover', getOnMouseInputCallback(onLegendMouseOver));
view.addEventListener('mouseout', getOnMouseInputCallback(onLegendMouseOut));
// this will trigger the autosize calculation making sure that everything is correct size
};

return (
<>
<div
Expand All @@ -216,9 +282,10 @@ export const RscChart = forwardRef<ChartHandle, RscChartProps>(
style={targetStyle}
/>
<VegaChart
spec={spec}
spec={newSpec}
config={chartConfig}
data={data}
previousData={previousData ?? []}
debug={debug}
renderer={renderer}
width={chartWidth}
Expand All @@ -227,53 +294,7 @@ export const RscChart = forwardRef<ChartHandle, RscChartProps>(
padding={padding}
signals={signals}
tooltip={tooltipConfig} // legend show/hide relies on this
onNewView={(view) => {
chartView.current = view;
// Add a delay before displaying legend tooltips on hover.
let tooltipTimeout: NodeJS.Timeout | undefined;
view.tooltip((_, event, item, value) => {
const tooltipHandler = new Handler(tooltipConfig);
// Cancel delayed tooltips if the mouse moves before the delay is resolved.
if (tooltipTimeout) {
clearTimeout(tooltipTimeout);
tooltipTimeout = undefined;
}
if (event && event.type === 'pointermove' && itemIsLegendItem(item) && 'tooltip' in item) {
tooltipTimeout = setTimeout(() => {
tooltipHandler.call(this, event, item, value);
tooltipTimeout = undefined;
}, LEGEND_TOOLTIP_DELAY);
} else {
tooltipHandler.call(this, event, item, value);
}
});
if (popovers.length || legendIsToggleable || onLegendClick) {
if (legendIsToggleable) {
view.signal('hiddenSeries', hiddenSeriesState);
}
setSelectedSignals({
selectedData: selectedData.current,
view,
});
view.addEventListener(
'click',
getOnMarkClickCallback(
chartView,
hiddenSeriesState,
chartId,
selectedData,
selectedDataBounds,
selectedDataName,
setHiddenSeries,
legendIsToggleable,
onLegendClick
)
);
}
view.addEventListener('mouseover', getOnMouseInputCallback(onLegendMouseOver));
view.addEventListener('mouseout', getOnMouseInputCallback(onLegendMouseOut));
// this will trigger the autosize calculation making sure that everything is correct size
}}
onNewView={onNewView}
/>
<ChartDialog
datum={selectedData.current}
Expand Down Expand Up @@ -332,4 +353,4 @@ const LegendTooltip: FC<LegendTooltipProps> = ({ value, descriptions, domain })

const itemIsLegendItem = (item: Item<unknown>): boolean => {
return 'name' in item.mark && typeof item.mark.name === 'string' && item.mark.name.includes('legend');
};
};
Loading