Skip to content

Commit 7942c59

Browse files
committed
dashboard: move the average scatterplot widget to the new graph widget
Change-Id: I564252c2d3e70b24d48c8018f62678358dd2004f
1 parent 6e795f5 commit 7942c59

3 files changed

Lines changed: 58 additions & 9 deletions

File tree

packages/cmk-frontend-vue/src/dashboard/components/DashboardContent/DashboardContent.vue

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,15 @@ function contentTypeToComponent(contentType: string): Component {
5757
return DashboardContentUserMessages
5858
case contentType === 'sidebar_element':
5959
return DashboardContentSidebarElement
60-
// Performance, single-timeseries and combined graphs render client-side on the new graphing
61-
// engine; the remaining GRAPH_TYPES still go through the legacy server-rendered graph
62-
// component.
63-
case ['performance_graph', 'single_timeseries', 'combined_graph'].includes(contentType) &&
64-
cmkToken === undefined:
60+
// These graph widgets render client-side on the new graphing engine; on token-authenticated
61+
// (public) dashboards they fall through to their legacy components below, like the remaining
62+
// GRAPH_TYPES.
63+
case [
64+
'performance_graph',
65+
'single_timeseries',
66+
'combined_graph',
67+
'average_scatterplot'
68+
].includes(contentType) && cmkToken === undefined:
6569
return DashboardContentTimeSeriesGraph
6670
case CONTENT_FIGURE_TYPES.includes(contentType):
6771
return DashboardContentFigure

packages/cmk-frontend-vue/src/dashboard/components/DashboardContent/DashboardContentTimeSeriesGraph.vue

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import CmkHtml from '@/components/CmkHtml.vue'
1515
import CmkIcon from '@/components/CmkIcon'
1616
1717
import type {
18+
AverageScatterplotContent,
1819
CombinedGraphContent,
1920
PerformanceGraphContent,
2021
SingleTimeseriesContent
@@ -29,7 +30,12 @@ type DiscoveredGraph = components['schemas']['ApiDiscoveredGraph']
2930
const { _t } = usei18n()
3031
const props =
3132
defineProps<
32-
ContentProps<PerformanceGraphContent | SingleTimeseriesContent | CombinedGraphContent>
33+
ContentProps<
34+
| PerformanceGraphContent
35+
| SingleTimeseriesContent
36+
| CombinedGraphContent
37+
| AverageScatterplotContent
38+
>
3339
>()
3440
3541
const shell = ref<DiscoveredGraph | null>(null)
@@ -59,6 +65,12 @@ const resolveTimeseriesColor = (color: SingleTimeseriesContent['color']): string
5965
return color === 'default_theme' ? DEFAULT_THEME_COLOR : color
6066
}
6167
68+
const resolveScatterplotColor = (
69+
color: AverageScatterplotContent['metric_color']
70+
): string | null => {
71+
return color === 'default' ? null : color
72+
}
73+
6274
type GraphDiscovery =
6375
| { graphs: DiscoveredGraph[]; no_data_message?: string | null }
6476
| { error: string }
@@ -115,6 +127,22 @@ const discoverGraphs = async (): Promise<GraphDiscovery> => {
115127
}
116128
})
117129
)
130+
case 'average_scatterplot':
131+
return unwrap(
132+
await client.POST(
133+
'/domain-types/graph/actions/discover_average_scatterplot_graphs/invoke',
134+
{
135+
params: { header: { 'Content-Type': 'application/json' } },
136+
body: {
137+
context: props.effective_filter_context.filters,
138+
metric: content.metric,
139+
metric_color: resolveScatterplotColor(content.metric_color),
140+
average_color: resolveScatterplotColor(content.average_color),
141+
median_color: resolveScatterplotColor(content.median_color)
142+
}
143+
}
144+
)
145+
)
118146
default:
119147
staticAssertNever(content)
120148
return { graphs: [] }
@@ -167,6 +195,12 @@ const discoveryKey = computed(() => {
167195
graph_template: content.graph_template,
168196
context: props.effective_filter_context.filters
169197
}
198+
case 'average_scatterplot':
199+
return {
200+
metric: content.metric,
201+
colors: [content.metric_color, content.average_color, content.median_color],
202+
context: props.effective_filter_context.filters
203+
}
170204
default:
171205
staticAssertNever(content)
172206
return {}
@@ -178,8 +212,18 @@ watch(
178212
() => void loadGraph()
179213
)
180214
181-
const showLegend = computed(() => props.content.graph_render_options?.show_legend ?? false)
182-
const showTimestamp = computed(() => props.content.graph_render_options?.show_graph_time ?? false)
215+
// The figure-based average scatterplot has neither graph render options nor the graph
216+
// contents' timerange field (its range lives in time_range).
217+
const graphRenderOptions = computed(() => {
218+
const content = props.content
219+
return 'graph_render_options' in content ? content.graph_render_options : undefined
220+
})
221+
const timerange = computed(() => {
222+
const content = props.content
223+
return content.type === 'average_scatterplot' ? content.time_range : content.timerange
224+
})
225+
const showLegend = computed(() => graphRenderOptions.value?.show_legend ?? false)
226+
const showTimestamp = computed(() => graphRenderOptions.value?.show_graph_time ?? false)
183227
const combinationMode = computed(() => {
184228
const content = props.content
185229
return content.type === 'combined_graph' ? content.presentation : null
@@ -217,7 +261,7 @@ onMounted(() => {
217261
v-else-if="shell"
218262
:graph-type="shell.graph_type"
219263
:internal="shell.internal"
220-
:timerange="content.timerange"
264+
:timerange="timerange"
221265
:combination-mode="combinationMode"
222266
:show-legend="showLegend"
223267
:show-timestamp="showTimestamp"

packages/cmk-frontend-vue/src/dashboard/types/widget.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export type SidebarElementContent = components['schemas']['SidebarElementContent
6666
export type PerformanceGraphContent = components['schemas']['PerformanceGraphContent']
6767
export type SingleTimeseriesContent = components['schemas']['SingleTimeseriesContent']
6868
export type CombinedGraphContent = components['schemas']['CombinedGraphContent']
69+
export type AverageScatterplotContent = components['schemas']['AverageScatterplotContent']
6970
// Only picks graph_render_options, used to check legend visibility in the scrollable preview
7071
// as this is used by multiple widget types we extract it only once here
7172
export type GraphWidgetContent = Pick<

0 commit comments

Comments
 (0)