Skip to content

Commit 1567a27

Browse files
authored
Custom chart line colors (#40)
* Fix stuck panel options When you had a panel still open and wanted to view a different the panel would receive focus but the panel options it would receive would still be the original options. * Use vscode chart/theme colors * Update fiberplane-charts dependency * Improve SingleChart styling And refactor syntax highlighting component out from FunctionChart * Fix additional colors * Move colors to chart/utils * Tweak title * Add called by queries * Improve indenting slightly * Use main branch for fiberplane-charts * Update changelog * Prepare for release 0.3.0
1 parent c30e82f commit 1567a27

File tree

14 files changed

+108
-30
lines changed

14 files changed

+108
-30
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
## [Unreleased]
44

5+
# 0.3.0
56
- [chore] Upgrade several dependencies
67
- Update panel to support showing multiple graphs
8+
- Update styling for single graph charts
9+
- Use more of the vscode theme colors for graphs
710
- [chore] We now use Yarn again instead of NPM. This is necessary to pull in
811
`fiberplane-charts` directly from a workspace repository. The problem with
912
packaging has been solved with a Yarn plugin.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"displayName": "Autometrics",
77
"license": "MIT",
88
"description": "Show enhanced autometrics information from your code",
9-
"version": "0.2.1",
9+
"version": "0.3.0",
1010
"repository": {
1111
"type": "git",
1212
"url": "https://github.com/autometrics-dev/vscode-autometrics"

src/chartPanel.ts

+1-14
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { formatProviderError } from "./providerRuntime/errors";
44
import type { MessageFromWebview, MessageToWebview } from "./charts";
55
import { OPEN_PANEL_COMMAND } from "./constants";
66
import type { Prometheus } from "./prometheus";
7-
import { getNonce } from "./utils";
7+
import { getNonce, getTitle } from "./utils";
88

99
/**
1010
* Options for the kind of chart to display.
@@ -157,16 +157,3 @@ function getHtmlForWebview(
157157
</body>
158158
</html>`;
159159
}
160-
161-
export function getTitle(options: PanelOptions) {
162-
switch (options.type) {
163-
case "called_by":
164-
return `Called by ${options.functionName}`;
165-
case "function":
166-
return options.functionName;
167-
case "metric":
168-
return options.metricName;
169-
case "function_graphs":
170-
return options.functionName;
171-
}
172-
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
2+
import { styles } from "./prismStyles";
3+
4+
export function CodeBlock({ query }: { query: string }) {
5+
return (
6+
<SyntaxHighlighter language="promql" style={styles}>
7+
{query}
8+
</SyntaxHighlighter>
9+
);
10+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./CodeBlock";

src/charts/components/FunctionCharts/FunctionChart.tsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {
88
Timeseries,
99
} from "fiberplane-charts";
1010
import styled from "styled-components";
11-
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
12-
import { styles } from "./prismStyles";
11+
import { CodeBlock } from "../CodeBlock";
12+
import { colors } from "../../utils";
1313

1414
type Props = {
1515
query: string;
@@ -51,11 +51,10 @@ export function FunctionChart(props: Props) {
5151
footerShown={false}
5252
gridBordersShown={false}
5353
gridDashArray="2"
54+
colors={colors}
5455
/>
5556
</div>
56-
<SyntaxHighlighter language="promql" style={styles}>
57-
{query}
58-
</SyntaxHighlighter>
57+
<CodeBlock query={query} />
5958
</>
6059
);
6160
}

src/charts/components/FunctionCharts/FunctionCharts.tsx

+28
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {
55
generateErrorRatioQuery,
66
generateLatencyQuery,
77
generateRequestRateQuery,
8+
getCalledByErrorRatio,
9+
getCalledByRequestRate,
810
} from "../../../queries";
911

1012
type Props = TimeRangeProps & {
@@ -19,6 +21,9 @@ export function FunctionCharts(props: Props) {
1921
const errorRatioQuery = generateErrorRatioQuery(functionName, moduleName);
2022
const latencyQuery = generateLatencyQuery(functionName, moduleName);
2123

24+
const calledByRequestQuery = getCalledByRequestRate(functionName);
25+
const calledByErrorRatioQuery = getCalledByErrorRatio(functionName);
26+
2227
return (
2328
<div>
2429
<Title>
@@ -54,6 +59,29 @@ export function FunctionCharts(props: Props) {
5459
/>
5560
</ChartContainer>
5661
</Container>
62+
<hr />
63+
<h5>"Called by" metrics</h5>
64+
<hr />
65+
<Container>
66+
<ChartContainer>
67+
<FunctionChart
68+
title="Request Rate"
69+
query={calledByRequestQuery}
70+
timeRange={timeRange}
71+
setTimeRange={setTimeRange}
72+
key="request_rate"
73+
/>
74+
</ChartContainer>
75+
<ChartContainer>
76+
<FunctionChart
77+
title="Error Ratio"
78+
query={calledByErrorRatioQuery}
79+
timeRange={timeRange}
80+
setTimeRange={setTimeRange}
81+
key="error_ratio"
82+
/>
83+
</ChartContainer>
84+
</Container>
5785
</div>
5886
);
5987
}

src/charts/components/SingleChart/SingleChart.tsx

+13-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import {
1414
} from "../../../queries";
1515
import { useRequestData } from "../../hooks/useRequestData";
1616
import { TimeRangeProps } from "../types";
17+
import { getTitle } from "../../../utils";
18+
import { CodeBlock } from "../CodeBlock";
19+
import { colors } from "../../utils";
1720

1821
type Props = {
1922
options: SingleChartOptions;
@@ -41,9 +44,11 @@ export function SingleChart(props: Props) {
4144
});
4245
}, [options, timeRange]);
4346

47+
const title = `${options.type} chart for ${getTitle(options)}`;
48+
4449
return (
4550
<>
46-
<h1>{query}</h1>
51+
<h1>{title}</h1>
4752
<MetricsChart
4853
graphType={graphType}
4954
stackingType={stackingType}
@@ -52,7 +57,14 @@ export function SingleChart(props: Props) {
5257
onChangeGraphType={setGraphType}
5358
onChangeStackingType={setStackingType}
5459
onChangeTimeRange={setTimeRange}
60+
chartControlsShown={false}
61+
gridColumnsShown={false}
62+
footerShown={false}
63+
gridBordersShown={false}
64+
gridDashArray="2"
65+
colors={colors}
5566
/>
67+
<CodeBlock query={query || ""} />
5668
</>
5769
);
5870
}

src/charts/utils.ts

+9
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,12 @@ export function getCurrentTimeRange(): TimeRange {
66
oneHourAgo.setHours(oneHourAgo.getHours() - 1);
77
return { from: oneHourAgo.toISOString(), to: now.toISOString() };
88
}
9+
10+
export const colors = [
11+
"var(--vscode-charts-red)",
12+
"var(--vscode-charts-blue)",
13+
"var(--vscode-charts-yellow)",
14+
"var(--vscode-charts-orange)",
15+
"var(--vscode-charts-green)",
16+
"var(--vscode-charts-purple)",
17+
];

src/queries.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,16 @@ export function getSumQuery(
4343
metricName: string,
4444
labels: Record<string, string> = {},
4545
) {
46-
return `sum by (function, module) (rate(${metricName}{${Object.entries(labels)
47-
.map(([key, value]) => `${key}="${value}"`)
48-
.join(",")}}[5m]))`;
46+
return `sum by (function, module) (
47+
rate(
48+
${metricName}{${Object.entries(labels)
49+
.map(
50+
([key, value]) => ` ${key}="${value}"
51+
`,
52+
)
53+
.join(",")}
54+
}[5m])
55+
)`;
4956
}
5057

5158
export function generateRequestRateQuery(

src/utils/getTitle.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { PanelOptions } from "../chartPanel";
2+
3+
export function getTitle(options: PanelOptions) {
4+
switch (options.type) {
5+
case "called_by":
6+
return `Called by ${options.functionName}`;
7+
case "function":
8+
return options.functionName;
9+
case "metric":
10+
return options.metricName;
11+
case "function_graphs":
12+
return options.functionName;
13+
}
14+
}

src/utils/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from "./timeRanges";
22
export * from "./uniq";
33
export * from "./uniqBy";
44
export * from "./getNonce";
5+
export * from "./getTitle";

yarn.lock

+13-6
Original file line numberDiff line numberDiff line change
@@ -1931,7 +1931,7 @@ __metadata:
19311931

19321932
"fiberplane-charts@git+https://[email protected]/fiberplane/fiberplane.git#workspace=fiberplane-charts":
19331933
version: 0.1.0
1934-
resolution: "fiberplane-charts@https://[email protected]/fiberplane/fiberplane.git#workspace=fiberplane-charts&commit=06b1031f60c9067ef76c3f0be44bfdbc027b847d"
1934+
resolution: "fiberplane-charts@https://[email protected]/fiberplane/fiberplane.git#workspace=fiberplane-charts&commit=c84d3ac1fa6509bc8451f0681504fc0b4929f927"
19351935
dependencies:
19361936
"@types/d3-scale": ^4.0.3
19371937
"@visx/axis": ^3.1.0
@@ -1950,7 +1950,7 @@ __metadata:
19501950
react: ^18.0.0
19511951
react-dom: ^18.0.0
19521952
styled-components: ^5.3.0
1953-
checksum: 1fa7d4042ef374ab939b0a4ae7862dc0fe2c7b8f27014f0fc9efc20588ce65ec5c02fbc4afd74a6b298176e04348495d5448d34a57788c6762a076c4440d295b
1953+
checksum: 50b9bcf488a67b1b9b9125a4c1a17b7a2e68ab414e2d84e7cf13be2cf6c0d1fefebf7c2484ee069b3c996df5cd415d56adcedab241ab7be648176dd4e37aae6f
19541954
languageName: node
19551955
linkType: hard
19561956

@@ -2001,8 +2001,8 @@ __metadata:
20012001
linkType: hard
20022002

20032003
"framer-motion@npm:^10.12.4":
2004-
version: 10.12.10
2005-
resolution: "framer-motion@npm:10.12.10"
2004+
version: 10.12.12
2005+
resolution: "framer-motion@npm:10.12.12"
20062006
dependencies:
20072007
"@emotion/is-prop-valid": ^0.8.2
20082008
tslib: ^2.4.0
@@ -2017,7 +2017,7 @@ __metadata:
20172017
optional: true
20182018
react-dom:
20192019
optional: true
2020-
checksum: d4bdca5bc891534d6e4852a5725d1d0e8c29270a79927b50d8136d71e3d3affdca66dcb3a74e8c252fb4508292c4901cce20d93c3a35a4acdfa9a3f6ad9b57bb
2020+
checksum: 28ff7202b79833c0aa2fc412e64055b34f6405dc5b025eceb6fa737725f4005a2b29bec31011dd5c1c4cd44af2430b3d622e4a77a11a032e7b08e1e108456430
20212021
languageName: node
20222022
linkType: hard
20232023

@@ -3884,13 +3884,20 @@ __metadata:
38843884
languageName: node
38853885
linkType: hard
38863886

3887-
"tslib@npm:^2.1.0, tslib@npm:^2.4.0":
3887+
"tslib@npm:^2.1.0":
38883888
version: 2.5.0
38893889
resolution: "tslib@npm:2.5.0"
38903890
checksum: ae3ed5f9ce29932d049908ebfdf21b3a003a85653a9a140d614da6b767a93ef94f460e52c3d787f0e4f383546981713f165037dc2274df212ea9f8a4541004e1
38913891
languageName: node
38923892
linkType: hard
38933893

3894+
"tslib@npm:^2.4.0":
3895+
version: 2.5.2
3896+
resolution: "tslib@npm:2.5.2"
3897+
checksum: 4d3c1e238b94127ed0e88aa0380db3c2ddae581dc0f4bae5a982345e9f50ee5eda90835b8bfba99b02df10a5734470be197158c36f9129ac49fdc14a6a9da222
3898+
languageName: node
3899+
linkType: hard
3900+
38943901
"tunnel-agent@npm:^0.6.0":
38953902
version: 0.6.0
38963903
resolution: "tunnel-agent@npm:0.6.0"

0 commit comments

Comments
 (0)