Skip to content

Commit 0868185

Browse files
committed
Add legends
1 parent f7c7488 commit 0868185

File tree

2 files changed

+63
-16
lines changed

2 files changed

+63
-16
lines changed

site/src/modules/workspaces/WorkspaceTiming/Chart/Chart.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ import {
1919
} from "./constants";
2020
import { Bar, type BarColor } from "./Bar";
2121

22-
// Data can be divided into sections. For example, display the provisioning
23-
// timings in one section and the scripting timings in another.
24-
type DataSection = {
25-
name: string;
26-
timings: Timing[];
27-
};
28-
2922
export type Timing = Duration & {
3023
/**
3124
* Label that will be displayed on the Y axis.
@@ -58,6 +51,13 @@ export type Duration = {
5851
endedAt: Date;
5952
};
6053

54+
// Data can be divided into sections. For example, display the provisioning
55+
// timings in one section and the scripting timings in another.
56+
type DataSection = {
57+
name: string;
58+
timings: Timing[];
59+
};
60+
6161
export type ChartProps = {
6262
data: DataSection[];
6363
onBarClick: (label: string, section: string) => void;

site/src/modules/workspaces/WorkspaceTiming/WorkspaceTimings.tsx

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export const WorkspaceTimings: FC<WorkspaceTimingsProps> = ({
4646
provisionerTimings,
4747
}) => {
4848
const [view, setView] = useState<TimingView>({ name: "basic" });
49+
const data = selectChartData(view, provisionerTimings);
4950

5051
return (
5152
<div css={styles.panelBody}>
@@ -80,11 +81,28 @@ export const WorkspaceTimings: FC<WorkspaceTimingsProps> = ({
8081
}));
8182
}}
8283
/>
84+
85+
<ul css={styles.legends}>
86+
{Object.entries(colorsByActions).map(([action, colors]) => (
87+
<li key={action} css={styles.legend}>
88+
<div
89+
css={[
90+
styles.legendSquare,
91+
{
92+
borderColor: colors?.border,
93+
backgroundColor: colors?.fill,
94+
},
95+
]}
96+
/>
97+
{action}
98+
</li>
99+
))}
100+
</ul>
83101
</div>
84102
)}
85103

86104
<Chart
87-
data={selectChartData(view, provisionerTimings)}
105+
data={data}
88106
onBarClick={(stage, section) => {
89107
setView({
90108
name: "advanced",
@@ -98,10 +116,21 @@ export const WorkspaceTimings: FC<WorkspaceTimingsProps> = ({
98116
);
99117
};
100118

119+
const selectActions = (timings: readonly ProvisionerTiming[]) => {
120+
return [...new Set(timings.map((t) => t.action))];
121+
};
122+
101123
export const selectChartData = (
102124
view: TimingView,
103125
timings: readonly ProvisionerTiming[],
104126
) => {
127+
const extractDuration = (t: ProvisionerTiming): Duration => {
128+
return {
129+
startedAt: new Date(t.started_at),
130+
endedAt: new Date(t.ended_at),
131+
};
132+
};
133+
105134
switch (view.name) {
106135
case "basic": {
107136
const groupedTimingsByStage = provisioningStages.map((stage) => {
@@ -159,13 +188,6 @@ export const selectChartData = (
159188
}
160189
};
161190

162-
const extractDuration = (t: ProvisionerTiming): Duration => {
163-
return {
164-
startedAt: new Date(t.started_at),
165-
endedAt: new Date(t.ended_at),
166-
};
167-
};
168-
169191
const styles = {
170192
panelBody: {
171193
display: "flex",
@@ -176,6 +198,7 @@ const styles = {
176198
borderBottom: `1px solid ${theme.palette.divider}`,
177199
fontSize: 12,
178200
display: "flex",
201+
flexAlign: "stretch",
179202
}),
180203
breadcrumbs: (theme) => ({
181204
listStyle: "none",
@@ -211,6 +234,7 @@ const styles = {
211234
}),
212235
breadcrumbButton: (theme) => ({
213236
background: "none",
237+
padding: 0,
214238
border: "none",
215239
fontSize: "inherit",
216240
color: "inherit",
@@ -221,7 +245,7 @@ const styles = {
221245
},
222246
}),
223247
searchField: (theme) => ({
224-
width: "100%",
248+
flex: "1",
225249

226250
"& fieldset": {
227251
border: 0,
@@ -234,4 +258,27 @@ const styles = {
234258
fontSize: 12,
235259
},
236260
}),
261+
legends: {
262+
listStyle: "none",
263+
margin: 0,
264+
padding: 0,
265+
display: "flex",
266+
alignItems: "center",
267+
gap: 24,
268+
paddingRight: YAxisSidePadding,
269+
},
270+
legend: {
271+
fontWeight: 500,
272+
display: "flex",
273+
alignItems: "center",
274+
gap: 8,
275+
lineHeight: 1,
276+
},
277+
legendSquare: (theme) => ({
278+
width: 18,
279+
height: 18,
280+
borderRadius: 4,
281+
border: `1px solid ${theme.palette.divider}`,
282+
backgroundColor: theme.palette.background.default,
283+
}),
237284
} satisfies Record<string, Interpolation<Theme>>;

0 commit comments

Comments
 (0)