Skip to content
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

Thresholds: Add option for dashed line style #55875

Merged
merged 1 commit into from Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/grafana-schema/src/schema/mudball.cue
Expand Up @@ -123,7 +123,7 @@ HideableFieldConfig: {
} @cuetsy(kind="interface")

// TODO docs
GraphTresholdsStyleMode: "off" | "line" | "area" | "line+area" | "series" @cuetsy(kind="enum",memberNames="Off|Line|Area|LineAndArea|Series")
GraphTresholdsStyleMode: "off" | "line" | "dashed" | "area" | "line+area" | "dashed+area" | "series" @cuetsy(kind="enum",memberNames="Off|Line|Dashed|Area|LineAndArea|DashedAndArea|Series")

// TODO docs
GraphThresholdsStyleConfig: {
Expand Down Expand Up @@ -240,9 +240,9 @@ VizLegendOptions: {
showLegend: bool
asTable?: bool
isVisible?: bool
sortBy?: string
sortDesc?: bool
width?: number
sortBy?: string
sortDesc?: bool
width?: number
calcs: [...string]
} @cuetsy(kind="interface")

Expand Down
2 changes: 2 additions & 0 deletions packages/grafana-schema/src/schema/mudball.gen.ts
Expand Up @@ -232,6 +232,8 @@ export interface HideableFieldConfig {
*/
export enum GraphTresholdsStyleMode {
Area = 'area',
Dashed = 'dashed',
DashedAndArea = 'dashed+area',
Line = 'line',
LineAndArea = 'line+area',
Off = 'off',
Expand Down
2 changes: 2 additions & 0 deletions packages/grafana-ui/src/components/uPlot/config.ts
Expand Up @@ -66,7 +66,9 @@ export const graphFieldOptions = {
thresholdsDisplayModes: [
{ label: 'Off', value: GraphTresholdsStyleMode.Off },
{ label: 'As lines', value: GraphTresholdsStyleMode.Line },
{ label: 'As lines (dashed)', value: GraphTresholdsStyleMode.Dashed },
{ label: 'As filled regions', value: GraphTresholdsStyleMode.Area },
{ label: 'As filled regions and lines', value: GraphTresholdsStyleMode.LineAndArea },
{ label: 'As filled regions and lines (dashed)', value: GraphTresholdsStyleMode.DashedAndArea },
] as Array<SelectableValue<GraphTresholdsStyleMode>>,
};
Expand Up @@ -18,6 +18,12 @@ export interface UPlotThresholdOptions {
}

export function getThresholdsDrawHook(options: UPlotThresholdOptions) {
const dashSegments =
options.config.mode === GraphTresholdsStyleMode.Dashed ||
options.config.mode === GraphTresholdsStyleMode.DashedAndArea
? [10, 10]
: null;

function addLines(u: uPlot, steps: Threshold[], theme: GrafanaTheme2, xMin: number, xMax: number, yScaleKey: string) {
let ctx = u.ctx;

Expand All @@ -34,6 +40,10 @@ export function getThresholdsDrawHook(options: UPlotThresholdOptions) {

ctx.lineWidth = 2;

if (dashSegments) {
ctx.setLineDash(dashSegments);
}

// Ignore the base -Infinity threshold by always starting on index 1
for (let idx = 1; idx < steps.length; idx++) {
const step = steps[idx];
Expand Down Expand Up @@ -114,12 +124,14 @@ export function getThresholdsDrawHook(options: UPlotThresholdOptions) {

switch (config.mode) {
case GraphTresholdsStyleMode.Line:
case GraphTresholdsStyleMode.Dashed:
addLines(u, steps, theme, xMin, xMax, scaleKey);
break;
case GraphTresholdsStyleMode.Area:
addAreas(u, steps, theme);
break;
case GraphTresholdsStyleMode.LineAndArea:
case GraphTresholdsStyleMode.DashedAndArea:
addAreas(u, steps, theme);
addLines(u, steps, theme, xMin, xMax, scaleKey);
}
Expand Down