-
Notifications
You must be signed in to change notification settings - Fork 22
Convert old charts to new style #2762
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7bf064d
remove width and height from TimeSeriesChart
david-crespo 2b10d3d
use new chart style on system and silo utilization
david-crespo fe6d11e
fix lint error
david-crespo b423805
Tighten spacing and more consistent with other layouts (#2764)
benjaminleonard 04128b7
very important and helpful comment
david-crespo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,8 @@ import type { TooltipProps } from 'recharts/types/component/Tooltip' | |
| import type { ChartDatum } from '@oxide/api' | ||
| import { Error12Icon } from '@oxide/design-system/icons/react' | ||
|
|
||
| import { classed } from '~/util/classed' | ||
|
|
||
| // Recharts's built-in ticks behavior is useless and probably broken | ||
| /** | ||
| * Split the data into n evenly spaced ticks, with one at the left end and one a | ||
|
|
@@ -110,14 +112,11 @@ type TimeSeriesChartProps = { | |
| className?: string | ||
| data: ChartDatum[] | undefined | ||
| title: string | ||
| width: number | ||
| height: number | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We were passing height and width at every callsite but it had no effect, probably because the |
||
| interpolation?: 'linear' | 'stepAfter' | ||
| startTime: Date | ||
| endTime: Date | ||
| unit?: string | ||
| yAxisTickFormatter?: (val: number) => string | ||
| hasBorder?: boolean | ||
| hasError?: boolean | ||
| } | ||
|
|
||
|
|
@@ -166,17 +165,13 @@ const SkeletonMetric = ({ | |
| ) | ||
|
|
||
| export function TimeSeriesChart({ | ||
| className, | ||
| data: rawData, | ||
| title, | ||
| width, | ||
| height, | ||
| interpolation = 'linear', | ||
| startTime, | ||
| endTime, | ||
| unit, | ||
| yAxisTickFormatter = (val) => val.toLocaleString(), | ||
| hasBorder = true, | ||
| hasError = false, | ||
| }: TimeSeriesChartProps) { | ||
| // We use the largest data point +20% for the graph scale. !rawData doesn't | ||
|
|
@@ -210,34 +205,28 @@ export function TimeSeriesChart({ | |
| // re-render on every render of the parent when the data is undefined | ||
| const data = useMemo(() => rawData || [], [rawData]) | ||
|
|
||
| const wrapperClass = cn(className, hasBorder && 'rounded-lg border border-default') | ||
|
|
||
| if (hasError) { | ||
| return ( | ||
| <SkeletonMetric className={wrapperClass}> | ||
| <SkeletonMetric> | ||
| <MetricsError /> | ||
| </SkeletonMetric> | ||
| ) | ||
| } | ||
|
|
||
| if (!data || data.length === 0) { | ||
| return ( | ||
| <SkeletonMetric shimmer className={wrapperClass}> | ||
| <SkeletonMetric shimmer> | ||
| <MetricsLoadingIndicator /> | ||
| </SkeletonMetric> | ||
| ) | ||
| } | ||
|
|
||
| // ResponsiveContainer has default height and width of 100% | ||
| // https://recharts.org/en-US/api/ResponsiveContainer | ||
| return ( | ||
| <div className="h-[300px] w-full"> | ||
| {/* temporary until we migrate the old metrics to the new style */} | ||
| <ResponsiveContainer className={wrapperClass}> | ||
| <AreaChart | ||
| width={width} | ||
| height={height} | ||
| data={data} | ||
| margin={{ top: 0, right: hasBorder ? 16 : 0, bottom: 0, left: 0 }} | ||
| > | ||
| <div className="px-5 pb-5 pt-8"> | ||
| <ResponsiveContainer height={300}> | ||
| <AreaChart data={data} margin={{ top: 0, right: 0, bottom: 0, left: 0 }}> | ||
| <CartesianGrid stroke={GRID_GRAY} vertical={false} /> | ||
| <XAxis | ||
| axisLine={{ stroke: GRID_GRAY }} | ||
|
|
@@ -277,7 +266,7 @@ export function TimeSeriesChart({ | |
| /> | ||
| <Area | ||
| dataKey="value" | ||
| name={title} | ||
| name={title} // Provides name for value in hover tooltip | ||
| type={interpolation} | ||
| stroke={GREEN_600} | ||
| fill={GREEN_400} | ||
|
|
@@ -320,3 +309,27 @@ const MetricsError = () => ( | |
| /> | ||
| </> | ||
| ) | ||
|
|
||
| export const ChartContainer = classed.div`flex w-full grow flex-col rounded-lg border border-default` | ||
|
|
||
| type ChartHeaderProps = { | ||
| title: string | ||
| label: string | ||
| description?: string | ||
| children?: ReactNode | ||
| } | ||
|
|
||
| export function ChartHeader({ title, label, description, children }: ChartHeaderProps) { | ||
| return ( | ||
| <div className="flex items-center justify-between border-b px-5 pb-4 pt-5 border-secondary"> | ||
| <div> | ||
| <h2 className="flex items-baseline gap-1.5"> | ||
| <div className="text-sans-semi-lg">{title}</div> | ||
| <div className="text-sans-md text-secondary">{label}</div> | ||
| </h2> | ||
| <div className="mt-0.5 text-sans-md text-secondary">{description}</div> | ||
| </div> | ||
| {children} | ||
| </div> | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The loading state is handled inside the chart. The logic needs to be improved, but the loading state does show up for these charts.