From 8d0acfa1e04c23cea374571afa84ae047be07e26 Mon Sep 17 00:00:00 2001 From: Qiuxia Fan Date: Wed, 12 Jan 2022 23:04:31 +0800 Subject: [PATCH] feat: add custom config for graphs --- src/types/dashboard.ts | 20 ++++- .../dashboard/configuration/WidgetOptions.vue | 4 +- .../configuration/graph-styles/Card.vue | 60 +++++++++++++ .../configuration/graph-styles/Line.vue | 5 -- .../configuration/graph-styles/Table.vue | 84 +++++++++++++++++++ .../configuration/graph-styles/TopList.vue | 59 +++++++++++++ src/views/dashboard/controls/Widget.vue | 1 + src/views/dashboard/data.ts | 15 ++++ src/views/dashboard/graphs/Card.vue | 51 ++++++----- src/views/dashboard/graphs/EndpointList.vue | 6 +- src/views/dashboard/graphs/HeatMap.vue | 18 ++-- src/views/dashboard/graphs/InstanceList.vue | 6 +- src/views/dashboard/graphs/Pie.vue | 7 +- src/views/dashboard/graphs/Table.vue | 34 +++----- src/views/dashboard/graphs/TopList.vue | 6 +- src/views/dashboard/graphs/index.ts | 4 +- 16 files changed, 303 insertions(+), 77 deletions(-) create mode 100644 src/views/dashboard/configuration/graph-styles/Card.vue create mode 100644 src/views/dashboard/configuration/graph-styles/Table.vue create mode 100644 src/views/dashboard/configuration/graph-styles/TopList.vue diff --git a/src/types/dashboard.ts b/src/types/dashboard.ts index e2a3b046..1680dc34 100644 --- a/src/types/dashboard.ts +++ b/src/types/dashboard.ts @@ -47,7 +47,7 @@ export interface StandardConfig { seconds?: string; } -export type GraphConfig = BarConfig | LineConfig; +export type GraphConfig = BarConfig | LineConfig | CardConfig | TableConfig; export interface BarConfig { type?: string; showBackground?: boolean; @@ -63,3 +63,21 @@ export interface AreaConfig { type?: string; opacity?: number; } + +export interface CardConfig { + type?: string; + fontSize?: number; + showUint: boolean; +} + +export interface TableConfig { + type?: string; + showTableValues: boolean; + tableHeaderCol1: string; + tableHeaderCol2: string; +} + +export interface TopListConfig { + type?: string; + topN: number; +} diff --git a/src/views/dashboard/configuration/WidgetOptions.vue b/src/views/dashboard/configuration/WidgetOptions.vue index 0e2c6da0..8918d204 100644 --- a/src/views/dashboard/configuration/WidgetOptions.vue +++ b/src/views/dashboard/configuration/WidgetOptions.vue @@ -48,8 +48,8 @@ const props = defineProps({ }); const emits = defineEmits(["update"]); const { t } = useI18n(); -const title = ref(props.config.title); -const tips = ref(props.config.tips); +const title = ref(props.config.title || ""); +const tips = ref(props.config.tips || ""); function updateWidgetConfig(param: { [key: string]: unknown }) { emits("update", param); diff --git a/src/views/dashboard/configuration/graph-styles/Card.vue b/src/views/dashboard/configuration/graph-styles/Card.vue new file mode 100644 index 00000000..8a92ddcb --- /dev/null +++ b/src/views/dashboard/configuration/graph-styles/Card.vue @@ -0,0 +1,60 @@ + + + + diff --git a/src/views/dashboard/configuration/graph-styles/Line.vue b/src/views/dashboard/configuration/graph-styles/Line.vue index 71f712ef..357f1926 100644 --- a/src/views/dashboard/configuration/graph-styles/Line.vue +++ b/src/views/dashboard/configuration/graph-styles/Line.vue @@ -62,11 +62,6 @@ function updateConfig(param: { [key: string]: unknown }) { } diff --git a/src/views/dashboard/configuration/graph-styles/TopList.vue b/src/views/dashboard/configuration/graph-styles/TopList.vue new file mode 100644 index 00000000..c75f2006 --- /dev/null +++ b/src/views/dashboard/configuration/graph-styles/TopList.vue @@ -0,0 +1,59 @@ + + + + diff --git a/src/views/dashboard/controls/Widget.vue b/src/views/dashboard/controls/Widget.vue index 2f796d8b..c68111eb 100644 --- a/src/views/dashboard/controls/Widget.vue +++ b/src/views/dashboard/controls/Widget.vue @@ -48,6 +48,7 @@ limitations under the License. --> :intervalTime="appStoreWithOut.intervalTime" :data="state.source" :config="data.graph" + :standard="data.standard" />
{{ t("noData") }}
diff --git a/src/views/dashboard/data.ts b/src/views/dashboard/data.ts index 370c2b21..c93f74c5 100644 --- a/src/views/dashboard/data.ts +++ b/src/views/dashboard/data.ts @@ -41,6 +41,21 @@ export const DefaultGraphConfig: { [key: string]: any } = { type: "Area", opacity: 0.4, }, + Card: { + type: "Card", + fontSize: 14, + showUint: true, + }, + Table: { + type: "Card", + showTableValues: true, + tableHeaderCol1: "", + tableHeaderCol2: "", + }, + TopList: { + type: "TopList", + topN: 10, + }, }; export enum MetricQueryTypes { diff --git a/src/views/dashboard/graphs/Card.vue b/src/views/dashboard/graphs/Card.vue index 288c7197..360f6301 100644 --- a/src/views/dashboard/graphs/Card.vue +++ b/src/views/dashboard/graphs/Card.vue @@ -14,44 +14,41 @@ See the License for the specific language governing permissions and limitations under the License. --> diff --git a/src/views/dashboard/graphs/EndpointList.vue b/src/views/dashboard/graphs/EndpointList.vue index 058d6869..3f14aa94 100644 --- a/src/views/dashboard/graphs/EndpointList.vue +++ b/src/views/dashboard/graphs/EndpointList.vue @@ -18,7 +18,6 @@ limitations under the License. --> diff --git a/src/views/dashboard/graphs/HeatMap.vue b/src/views/dashboard/graphs/HeatMap.vue index 0c968e20..a07f22ce 100644 --- a/src/views/dashboard/graphs/HeatMap.vue +++ b/src/views/dashboard/graphs/HeatMap.vue @@ -16,9 +16,9 @@ limitations under the License. --> diff --git a/src/views/dashboard/graphs/Pie.vue b/src/views/dashboard/graphs/Pie.vue index 25874d42..1f0149ce 100644 --- a/src/views/dashboard/graphs/Pie.vue +++ b/src/views/dashboard/graphs/Pie.vue @@ -24,7 +24,10 @@ const props = defineProps({ type: Array as PropType<{ name: string; value: number }[]>, default: () => [], }, - theme: { type: String, default: "dark" }, + config: { + type: Object as PropType<{ sortOrder: string }>, + default: () => ({}), + }, }); const option = computed(() => getOption()); function getOption() { @@ -40,7 +43,7 @@ function getOption() { left: 0, itemWidth: 12, textStyle: { - color: props.theme === "dark" ? "#fff" : "#333", + color: "#333", }, }, series: [ diff --git a/src/views/dashboard/graphs/Table.vue b/src/views/dashboard/graphs/Table.vue index 1bfd50bd..4e69adbb 100644 --- a/src/views/dashboard/graphs/Table.vue +++ b/src/views/dashboard/graphs/Table.vue @@ -19,28 +19,26 @@ limitations under the License. -->
- {{ item.tableHeaderCol1 || $t("name") }} + {{ config.tableHeaderCol1 || $t("name") }}
-
- {{ item.tableHeaderCol2 || $t("value") }} +
+ {{ config.tableHeaderCol2 || $t("value") }}
{{ key }}
-
- {{ data[key][dataLength(data[key])] }} +
+ {{ data[key][data[key].length - 1 || 0] }}
@@ -54,9 +52,12 @@ const props = defineProps({ type: Object as PropType<{ [key: string]: number[][] }>, default: () => ({}), }, - theme: { type: String, default: "dark" }, - itemConfig: { - type: Object as PropType<{ showTableValues: string | boolean }>, + config: { + type: Object as PropType<{ + showTableValues: boolean; + tableHeaderCol2: string; + tableHeaderCol1: string; + }>, default: () => ({}), }, }); @@ -69,10 +70,10 @@ onMounted(() => { if (!chartTable.value) { return; } - const width = showTableValues.value + const width = props.config.showTableValues ? chartTable.value.offsetWidth / 2 : chartTable.value.offsetWidth; - initWidth.value = showTableValues.value + initWidth.value = props.config.showTableValues ? chartTable.value.offsetWidth / 2 : 0; nameWidth.value = width - 5; @@ -98,15 +99,6 @@ const dataKeys = computed(() => { ); return keys; }); -const showTableValues = computed(() => { - return props.itemConfig.showTableValues === "true" || - props.itemConfig.showTableValues === true - ? true - : false; -}); -const dataLength = computed((param: number[]) => { - return param.length - 1 || 0; -});