From 6ef063270d53b888841da84bc01aa12ff593c3d8 Mon Sep 17 00:00:00 2001 From: Fine Date: Wed, 19 Feb 2025 09:40:36 +0800 Subject: [PATCH] add selector for legend --- src/components/Graph.vue | 19 ++++++ src/components/Selector.vue | 9 ++- src/hooks/useLegendProcessor.ts | 2 +- src/locales/lang/en.ts | 1 + src/locales/lang/es.ts | 1 + src/locales/lang/zh.ts | 1 + src/types/dashboard.d.ts | 1 + .../widget/graph-styles/components/Legend.vue | 10 ++++ src/views/dashboard/graphs/Line.vue | 29 ++++----- .../graphs/components/SelectorLegend.vue | 59 +++++++++++++++++++ 10 files changed, 112 insertions(+), 20 deletions(-) create mode 100644 src/views/dashboard/graphs/components/SelectorLegend.vue diff --git a/src/components/Graph.vue b/src/components/Graph.vue index 280bac4f..3adb42bd 100644 --- a/src/components/Graph.vue +++ b/src/components/Graph.vue @@ -84,6 +84,10 @@ limitations under the License. --> type: Array as PropType<{ widgetId: string }[]>, default: () => [], }, + legend: { + type: Array as PropType, + default: () => [], + }, }); const available = computed( () => @@ -103,6 +107,7 @@ limitations under the License. --> if (!instance) { return; } + instance.on("click", (params: EventParams) => { currentParams.value = params; if (props.option.series.type === "sankey") { @@ -227,6 +232,20 @@ limitations under the License. --> }, ); + watch( + () => props.legend, + () => { + const instance = getInstance(); + console.log(props.legend); + for (const l of props.legend) { + instance.dispatchAction({ + type: "legendSelect", + name: l, + }); + } + }, + ); + onBeforeUnmount(() => { removeResizeListener(unref(chartRef), resize); }); diff --git a/src/components/Selector.vue b/src/components/Selector.vue index 3a26d089..92a19d22 100644 --- a/src/components/Selector.vue +++ b/src/components/Selector.vue @@ -26,6 +26,8 @@ limitations under the License. --> :reserve-keyword="isRemote" :remote-method="remoteMethod" :filterable="filterable" + :collapse-tags="collapseTags" + :collapse-tags-tooltip="collapseTagsTooltip" > import { ref, watch } from "vue"; import type { PropType } from "vue"; - // interface Option { - // label: string | number; - // value: string | number; - // } - /*global defineProps, defineEmits, Indexable*/ const emit = defineEmits(["change", "query"]); const props = defineProps({ @@ -73,6 +70,8 @@ limitations under the License. --> clearable: { type: Boolean, default: false }, isRemote: { type: Boolean, default: false }, filterable: { type: Boolean, default: true }, + collapseTags: { type: Boolean, default: false }, + collapseTagsTooltip: { type: Boolean, default: false }, }); const selected = ref(props.value); diff --git a/src/hooks/useLegendProcessor.ts b/src/hooks/useLegendProcessor.ts index e9439a09..cb7cd7be 100644 --- a/src/hooks/useLegendProcessor.ts +++ b/src/hooks/useLegendProcessor.ts @@ -35,7 +35,7 @@ export default function useLegendProcess(legend?: LegendOptions) { if (keys.length === 1) { return false; } - if (legend && legend.asTable) { + if (legend && (legend.asTable || legend.asSelector)) { return false; } return true; diff --git a/src/locales/lang/en.ts b/src/locales/lang/en.ts index 98764453..b4f2c693 100644 --- a/src/locales/lang/en.ts +++ b/src/locales/lang/en.ts @@ -154,6 +154,7 @@ const msg = { legendOptions: "Legend Options", showLegend: "Show Legend", asTable: "As Table", + asSelector: "As Selector", toTheRight: "To The Right", legendValues: "Legend Values", minDuration: "Minimal Request Duration", diff --git a/src/locales/lang/es.ts b/src/locales/lang/es.ts index bc030873..25a94cc3 100644 --- a/src/locales/lang/es.ts +++ b/src/locales/lang/es.ts @@ -397,5 +397,6 @@ const msg = { instances: "Instances", snapshot: "Snapshot", expression: "Expression", + asSelector: "As Selector", }; export default msg; diff --git a/src/locales/lang/zh.ts b/src/locales/lang/zh.ts index 359ebb97..45f635dc 100644 --- a/src/locales/lang/zh.ts +++ b/src/locales/lang/zh.ts @@ -152,6 +152,7 @@ const msg = { legendOptions: "图例选项", showLegend: "显示图例", asTable: "作为表格", + asSelector: "作为选择器", toTheRight: "在右边", legendValues: "图例值", minDuration: "最小请求持续时间", diff --git a/src/types/dashboard.d.ts b/src/types/dashboard.d.ts index 5ddb9130..e89740a6 100644 --- a/src/types/dashboard.d.ts +++ b/src/types/dashboard.d.ts @@ -197,6 +197,7 @@ export type LegendOptions = { asTable: boolean; toTheRight: boolean; width: number; + asSelector: boolean; }; export type MetricsResults = { metric: { labels: MetricLabel[] }; diff --git a/src/views/dashboard/configuration/widget/graph-styles/components/Legend.vue b/src/views/dashboard/configuration/widget/graph-styles/components/Legend.vue index 4c340eb9..ff9cf241 100644 --- a/src/views/dashboard/configuration/widget/graph-styles/components/Legend.vue +++ b/src/views/dashboard/configuration/widget/graph-styles/components/Legend.vue @@ -22,6 +22,15 @@ limitations under the License. --> @change="updateLegendConfig({ show: legend.show })" /> +
+ {{ t("asSelector") }} + +
{{ t("asTable") }} max: false, mean: false, asTable: false, + asSelector: false, toTheRight: false, width: 130, ...graph.value.legend, diff --git a/src/views/dashboard/graphs/Line.vue b/src/views/dashboard/graphs/Line.vue index 45dc3513..3db40483 100644 --- a/src/views/dashboard/graphs/Line.vue +++ b/src/views/dashboard/graphs/Line.vue @@ -14,12 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. -->