mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Thresholds: Add option for dashed line style (#55875)
This commit is contained in:
parent
e31cb93ec0
commit
bd50fd1606
@ -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: {
|
||||
@ -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")
|
||||
|
||||
|
@ -232,6 +232,8 @@ export interface HideableFieldConfig {
|
||||
*/
|
||||
export enum GraphTresholdsStyleMode {
|
||||
Area = 'area',
|
||||
Dashed = 'dashed',
|
||||
DashedAndArea = 'dashed+area',
|
||||
Line = 'line',
|
||||
LineAndArea = 'line+area',
|
||||
Off = 'off',
|
||||
|
@ -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>>,
|
||||
};
|
||||
|
@ -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;
|
||||
|
||||
@ -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];
|
||||
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user