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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 14 deletions
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-
}
Lines changed: 10 additions & 0 deletions
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+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./CodeBlock";

src/charts/components/FunctionCharts/FunctionChart.tsx

Lines changed: 4 additions & 5 deletions
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

Lines changed: 28 additions & 0 deletions
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

Lines changed: 13 additions & 1 deletion
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

Lines changed: 9 additions & 0 deletions
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+
];

0 commit comments

Comments
 (0)