Skip to content

Commit

Permalink
feat: highlighting flags chart (#8237)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew authored Sep 25, 2024
1 parent 4fe80ff commit e33f71a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export const NetworkTrafficUsage: VFC = () => {
<Grid item xs={12} md={2}>
<Bar
data={data}
plugins={[customHighlightPlugin]}
plugins={[customHighlightPlugin()]}
options={options}
aria-label='An instance metrics line chart with two lines: requests per second for admin API and requests per second for client API'
/>
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/component/common/Chart/customHighlightPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { Chart } from 'chart.js';

export const customHighlightPlugin = {
export const customHighlightPlugin = (width = 46, bottomOverflow = 34) => ({
id: 'customLine',
beforeDraw: (chart: Chart) => {
const width = 46;
if (chart.tooltip?.opacity && chart.tooltip.x) {
const x = chart.tooltip.caretX;
const yAxis = chart.scales.y;
Expand All @@ -22,11 +21,11 @@ export const customHighlightPlugin = {
x - width / 2,
yAxis.top,
width,
yAxis.bottom - yAxis.top + 34,
yAxis.bottom - yAxis.top + bottomOverflow,
5,
);
ctx.fill();
ctx.restore();
}
},
};
});
9 changes: 7 additions & 2 deletions frontend/src/component/personalDashboard/FlagMetricsChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
createPlaceholderBarChartOptions,
} from './createChartOptions';
import { useFeature } from 'hooks/api/getters/useFeature/useFeature';
import { customHighlightPlugin } from '../common/Chart/customHighlightPlugin';

const defaultYes = [
45_000_000, 28_000_000, 28_000_000, 25_000_000, 50_000_000, 27_000_000,
Expand Down Expand Up @@ -79,7 +80,10 @@ export const PlaceholderFlagMetricsChart = () => {
const useMetricsEnvironments = (project: string, flagName: string) => {
const [environment, setEnvironment] = useState<string | null>(null);
const { feature } = useFeature(project, flagName);
const activeEnvironments = feature.environments;
const activeEnvironments = feature.environments.map((env) => ({
name: env.name,
type: env.type,
}));
const firstProductionEnvironment = activeEnvironments.find(
(env) => env.type === 'production',
);
Expand All @@ -90,7 +94,7 @@ const useMetricsEnvironments = (project: string, flagName: string) => {
} else if (activeEnvironments.length > 0) {
setEnvironment(activeEnvironments[0].name);
}
}, [flagName]);
}, [flagName, JSON.stringify(activeEnvironments)]);

return { environment, setEnvironment, activeEnvironments };
};
Expand Down Expand Up @@ -188,6 +192,7 @@ export const FlagMetricsChart: FC<{

<Bar
data={data}
plugins={[customHighlightPlugin(30, 0)]}
options={options}
aria-label='A bar chart with a single feature flag exposure metrics'
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ export const createBarChartOptions = (
return {
plugins: {
legend: plugins?.legend,
// required to avoid the highlight plugin highlighting empty annotation
annotation: {
clip: false,
annotations: {},
},
tooltip: {
backgroundColor: theme.palette.background.paper,
titleColor: theme.palette.text.primary,
Expand Down

0 comments on commit e33f71a

Please sign in to comment.