mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
VisualizationSuggestions: More suggestions and refinements (#41480)
* VisualizationSuggestions: More suggestions * more refinements * Minor fixes
This commit is contained in:
@@ -77,6 +77,7 @@ const getStyles = (theme: GrafanaTheme2) => {
|
|||||||
background: none;
|
background: none;
|
||||||
border-radius: ${theme.shape.borderRadius(1)};
|
border-radius: ${theme.shape.borderRadius(1)};
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
text-align: left;
|
||||||
border: 1px solid ${theme.colors.border.strong};
|
border: 1px solid ${theme.colors.border.strong};
|
||||||
|
|
||||||
transition: ${theme.transitions.create(['background'], {
|
transition: ${theme.transitions.create(['background'], {
|
||||||
|
|||||||
@@ -92,7 +92,9 @@ scenario('Single frame with time and number field', (ctx) => {
|
|||||||
SuggestionName.LineChart,
|
SuggestionName.LineChart,
|
||||||
SuggestionName.LineChartSmooth,
|
SuggestionName.LineChartSmooth,
|
||||||
SuggestionName.AreaChart,
|
SuggestionName.AreaChart,
|
||||||
|
SuggestionName.LineChartGradientColorScheme,
|
||||||
SuggestionName.BarChart,
|
SuggestionName.BarChart,
|
||||||
|
SuggestionName.BarChartGradientColorScheme,
|
||||||
SuggestionName.Gauge,
|
SuggestionName.Gauge,
|
||||||
SuggestionName.GaugeNoThresholds,
|
SuggestionName.GaugeNoThresholds,
|
||||||
SuggestionName.Stat,
|
SuggestionName.Stat,
|
||||||
@@ -101,6 +103,7 @@ scenario('Single frame with time and number field', (ctx) => {
|
|||||||
SuggestionName.BarGaugeLCD,
|
SuggestionName.BarGaugeLCD,
|
||||||
SuggestionName.Table,
|
SuggestionName.Table,
|
||||||
SuggestionName.StateTimeline,
|
SuggestionName.StateTimeline,
|
||||||
|
SuggestionName.StatusHistory,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -146,6 +149,7 @@ scenario('Single frame with time 2 number fields', (ctx) => {
|
|||||||
SuggestionName.BarGaugeLCD,
|
SuggestionName.BarGaugeLCD,
|
||||||
SuggestionName.Table,
|
SuggestionName.Table,
|
||||||
SuggestionName.StateTimeline,
|
SuggestionName.StateTimeline,
|
||||||
|
SuggestionName.StatusHistory,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ export const panelsToCheckFirst = [
|
|||||||
'bargauge',
|
'bargauge',
|
||||||
'table',
|
'table',
|
||||||
'state-timeline',
|
'state-timeline',
|
||||||
|
'status-history',
|
||||||
'text',
|
'text',
|
||||||
'dashlist',
|
'dashlist',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { StatusHistoryPanel } from './StatusHistoryPanel';
|
|||||||
import { StatusPanelOptions, StatusFieldConfig, defaultStatusFieldConfig } from './types';
|
import { StatusPanelOptions, StatusFieldConfig, defaultStatusFieldConfig } from './types';
|
||||||
import { VisibilityMode } from '@grafana/schema';
|
import { VisibilityMode } from '@grafana/schema';
|
||||||
import { commonOptionsBuilder } from '@grafana/ui';
|
import { commonOptionsBuilder } from '@grafana/ui';
|
||||||
|
import { StatusHistorySuggestionsSupplier } from './suggestions';
|
||||||
|
|
||||||
export const plugin = new PanelPlugin<StatusPanelOptions, StatusFieldConfig>(StatusHistoryPanel)
|
export const plugin = new PanelPlugin<StatusPanelOptions, StatusFieldConfig>(StatusHistoryPanel)
|
||||||
.useFieldConfig({
|
.useFieldConfig({
|
||||||
@@ -77,4 +78,5 @@ export const plugin = new PanelPlugin<StatusPanelOptions, StatusFieldConfig>(Sta
|
|||||||
|
|
||||||
commonOptionsBuilder.addLegendOptions(builder, false);
|
commonOptionsBuilder.addLegendOptions(builder, false);
|
||||||
commonOptionsBuilder.addTooltipOptions(builder, true);
|
commonOptionsBuilder.addTooltipOptions(builder, true);
|
||||||
});
|
})
|
||||||
|
.setSuggestionsSupplier(new StatusHistorySuggestionsSupplier());
|
||||||
|
|||||||
48
public/app/plugins/panel/status-history/suggestions.ts
Normal file
48
public/app/plugins/panel/status-history/suggestions.ts
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import { FieldColorModeId, VisualizationSuggestionsBuilder } from '@grafana/data';
|
||||||
|
import { SuggestionName } from 'app/types/suggestions';
|
||||||
|
import { StatusPanelOptions, StatusFieldConfig } from './types';
|
||||||
|
|
||||||
|
export class StatusHistorySuggestionsSupplier {
|
||||||
|
getSuggestionsForData(builder: VisualizationSuggestionsBuilder) {
|
||||||
|
const { dataSummary } = builder;
|
||||||
|
|
||||||
|
if (!dataSummary.hasData) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This panel needs a time field and a string or number field
|
||||||
|
if (!dataSummary.hasTimeField || (!dataSummary.hasStringField && !dataSummary.hasNumberField)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there are many series then they won't fit on y-axis so this panel is not good fit
|
||||||
|
if (dataSummary.numberFieldCount >= 30) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if there a lot of data points for each series then this is not a good match
|
||||||
|
if (dataSummary.rowCountMax > 100) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const list = builder.getListAppender<StatusPanelOptions, StatusFieldConfig>({
|
||||||
|
name: '',
|
||||||
|
pluginId: 'status-history',
|
||||||
|
options: {},
|
||||||
|
fieldConfig: {
|
||||||
|
defaults: {
|
||||||
|
color: {
|
||||||
|
mode: FieldColorModeId.ContinuousGrYlRd,
|
||||||
|
},
|
||||||
|
custom: {},
|
||||||
|
},
|
||||||
|
overrides: [],
|
||||||
|
},
|
||||||
|
previewModifier: (s) => {
|
||||||
|
s.options!.colWidth = 0.7;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
list.append({ name: SuggestionName.StatusHistory });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { VisualizationSuggestionsBuilder } from '@grafana/data';
|
import { FieldColorModeId, VisualizationSuggestionsBuilder } from '@grafana/data';
|
||||||
import {
|
import {
|
||||||
GraphDrawStyle,
|
GraphDrawStyle,
|
||||||
GraphFieldConfig,
|
GraphFieldConfig,
|
||||||
@@ -34,7 +34,7 @@ export class TimeSeriesSuggestionsSupplier {
|
|||||||
s.options!.legend.displayMode = LegendDisplayMode.Hidden;
|
s.options!.legend.displayMode = LegendDisplayMode.Hidden;
|
||||||
|
|
||||||
if (s.fieldConfig?.defaults.custom?.drawStyle !== GraphDrawStyle.Bars) {
|
if (s.fieldConfig?.defaults.custom?.drawStyle !== GraphDrawStyle.Bars) {
|
||||||
s.fieldConfig!.defaults.custom!.lineWidth = 3;
|
s.fieldConfig!.defaults.custom!.lineWidth = Math.max(s.fieldConfig!.defaults.custom!.lineWidth ?? 1, 2);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -73,6 +73,24 @@ export class TimeSeriesSuggestionsSupplier {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
list.append({
|
||||||
|
name: SuggestionName.LineChartGradientColorScheme,
|
||||||
|
fieldConfig: {
|
||||||
|
defaults: {
|
||||||
|
color: {
|
||||||
|
mode: FieldColorModeId.ContinuousGrYlRd,
|
||||||
|
},
|
||||||
|
custom: {
|
||||||
|
gradientMode: GraphGradientMode.Scheme,
|
||||||
|
lineInterpolation: LineInterpolation.Smooth,
|
||||||
|
lineWidth: 3,
|
||||||
|
fillOpacity: 20,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
overrides: [],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
if (dataSummary.rowCountMax < maxBarsCount) {
|
if (dataSummary.rowCountMax < maxBarsCount) {
|
||||||
list.append({
|
list.append({
|
||||||
name: SuggestionName.BarChart,
|
name: SuggestionName.BarChart,
|
||||||
@@ -88,7 +106,26 @@ export class TimeSeriesSuggestionsSupplier {
|
|||||||
overrides: [],
|
overrides: [],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
list.append({
|
||||||
|
name: SuggestionName.BarChartGradientColorScheme,
|
||||||
|
fieldConfig: {
|
||||||
|
defaults: {
|
||||||
|
color: {
|
||||||
|
mode: FieldColorModeId.ContinuousGrYlRd,
|
||||||
|
},
|
||||||
|
custom: {
|
||||||
|
drawStyle: GraphDrawStyle.Bars,
|
||||||
|
fillOpacity: 90,
|
||||||
|
lineWidth: 1,
|
||||||
|
gradientMode: GraphGradientMode.Scheme,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
overrides: [],
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
export enum SuggestionName {
|
export enum SuggestionName {
|
||||||
LineChart = 'Line chart',
|
LineChart = 'Line chart',
|
||||||
LineChartSmooth = 'Line chart smooth',
|
LineChartSmooth = 'Line chart smooth',
|
||||||
|
LineChartGradientColorScheme = 'Line chart with gradient color scheme',
|
||||||
AreaChart = 'Area chart',
|
AreaChart = 'Area chart',
|
||||||
AreaChartStacked = 'Area chart stacked',
|
AreaChartStacked = 'Area chart stacked',
|
||||||
AreaChartStackedPercent = 'Area chart 100% stacked',
|
AreaChartStackedPercent = 'Area chart 100% stacked',
|
||||||
BarChart = 'Bar chart',
|
BarChart = 'Bar chart',
|
||||||
|
BarChartGradientColorScheme = 'Bar chart with gradient color scheme',
|
||||||
BarChartStacked = 'Bar chart stacked',
|
BarChartStacked = 'Bar chart stacked',
|
||||||
BarChartStackedPercent = 'Bar chart 100% stacked',
|
BarChartStackedPercent = 'Bar chart 100% stacked',
|
||||||
BarChartHorizontal = 'Bar chart horizontal',
|
BarChartHorizontal = 'Bar chart horizontal',
|
||||||
@@ -19,7 +21,8 @@ export enum SuggestionName {
|
|||||||
BarGaugeBasic = 'Bar gauge basic',
|
BarGaugeBasic = 'Bar gauge basic',
|
||||||
BarGaugeLCD = 'Bar gauge LCD',
|
BarGaugeLCD = 'Bar gauge LCD',
|
||||||
Table = 'Table',
|
Table = 'Table',
|
||||||
StateTimeline = 'StateTimeline',
|
StateTimeline = 'State timeline',
|
||||||
|
StatusHistory = 'Status history',
|
||||||
TextPanel = 'Text panel',
|
TextPanel = 'Text panel',
|
||||||
DashboardList = 'Dashboard list',
|
DashboardList = 'Dashboard list',
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user