mirror of
https://github.com/apache/skywalking-booster-ui.git
synced 2025-05-07 10:42:56 +00:00
feat: add custom config for Bar, Line, Area
This commit is contained in:
parent
ad1e500c54
commit
16085bb56f
@ -41,14 +41,20 @@ export interface StandardConfig {
|
||||
min?: string;
|
||||
}
|
||||
|
||||
export type GraphConfig = BarConfig | LineConfig;
|
||||
interface BarConfig {
|
||||
type GraphConfig = BarConfig | LineConfig;
|
||||
export interface BarConfig {
|
||||
type?: string;
|
||||
showBackground?: boolean;
|
||||
barWidth?: number;
|
||||
}
|
||||
interface LineConfig {
|
||||
export interface LineConfig extends AreaConfig {
|
||||
type?: string;
|
||||
showBackground?: boolean;
|
||||
barWidth?: number;
|
||||
smooth?: boolean;
|
||||
showSymbol?: boolean;
|
||||
step?: boolean;
|
||||
}
|
||||
|
||||
export interface AreaConfig {
|
||||
type?: string;
|
||||
opacity?: number;
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ limitations under the License. -->
|
||||
:is="states.chartType"
|
||||
:intervalTime="appStoreWithOut.intervalTime"
|
||||
:data="states.source"
|
||||
:config="states.graph"
|
||||
/>
|
||||
<div v-show="!states.chartType" class="no-data">{{ t("noData") }}</div>
|
||||
</div>
|
||||
@ -66,7 +67,11 @@ limitations under the License. -->
|
||||
</div>
|
||||
</el-collapse-item>
|
||||
<el-collapse-item :title="t('graphStyles')" name="3">
|
||||
<component :is="`${states.chartType}Config`" :config="states.graph" />
|
||||
<component
|
||||
:is="`${states.chartType}Config`"
|
||||
:config="states.graph"
|
||||
@update="updateGraphOptions"
|
||||
/>
|
||||
</el-collapse-item>
|
||||
<el-collapse-item :title="t('widgetOptions')" name="4">
|
||||
<WidgetOptions
|
||||
@ -212,6 +217,14 @@ export default defineComponent({
|
||||
states.widget[param.label] = param.value;
|
||||
}
|
||||
|
||||
function updateGraphOptions(param: { label: string; value: unknown }) {
|
||||
console.log(param);
|
||||
states.graph = {
|
||||
...states.graph,
|
||||
...param,
|
||||
};
|
||||
}
|
||||
|
||||
async function queryMetrics() {
|
||||
const json = await dashboardStore.fetchMetricValue(
|
||||
dashboardStore.selectedGrid
|
||||
@ -224,7 +237,7 @@ export default defineComponent({
|
||||
return;
|
||||
}
|
||||
const metricVal = json.data.readMetricsValues.values.values.map(
|
||||
(d: { value: number }) => d.value
|
||||
(d: { value: number }) => d.value + 1
|
||||
);
|
||||
const m = states.metrics[0];
|
||||
if (!m) {
|
||||
@ -270,7 +283,7 @@ export default defineComponent({
|
||||
metricOpts,
|
||||
updateWidgetOptions,
|
||||
configHeight,
|
||||
dashboardStore,
|
||||
updateGraphOptions,
|
||||
applyConfig,
|
||||
loading,
|
||||
};
|
||||
|
@ -14,32 +14,36 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License. -->
|
||||
<template>
|
||||
<div>
|
||||
<span class="label">Bar Width</span>
|
||||
<span class="label">Area Opacity</span>
|
||||
<el-slider
|
||||
class="bar-width"
|
||||
v-model="barWidth"
|
||||
v-model="opacity"
|
||||
show-input
|
||||
input-size="small"
|
||||
:min="0.1"
|
||||
:max="1"
|
||||
:step="0.1"
|
||||
@change="updateConfig({ opacity })"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<span class="label">Show Background</span>
|
||||
<el-switch v-model="showBackground" active-text="Yes" inactive-text="No" />
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { defineProps, ref } from "vue";
|
||||
import { defineProps, ref, defineEmits } from "vue";
|
||||
import type { PropType } from "vue";
|
||||
import { BarConfig } from "./types";
|
||||
import { AreaConfig } from "@/types/dashboard";
|
||||
|
||||
const props = defineProps({
|
||||
config: {
|
||||
type: Object as PropType<BarConfig>,
|
||||
default: () => ({ showBackground: true, barWidth: 30 }),
|
||||
type: Object as PropType<AreaConfig>,
|
||||
default: () => ({ opacity: 0.4 }),
|
||||
},
|
||||
});
|
||||
const barWidth = ref(props.config.barWidth);
|
||||
const showBackground = ref(props.config.showBackground);
|
||||
const emits = defineEmits(["update"]);
|
||||
const opacity = ref(props.config.opacity);
|
||||
|
||||
function updateConfig(param: { [key: string]: unknown }) {
|
||||
emits("update", param);
|
||||
}
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.bar-width {
|
||||
|
@ -20,17 +20,23 @@ limitations under the License. -->
|
||||
v-model="barWidth"
|
||||
show-input
|
||||
input-size="small"
|
||||
@change="changeConfig({ barWidth })"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<span class="label">Show Background</span>
|
||||
<el-switch v-model="showBackground" active-text="Yes" inactive-text="No" />
|
||||
<el-switch
|
||||
v-model="showBackground"
|
||||
active-text="Yes"
|
||||
inactive-text="No"
|
||||
@change="changeConfig({ showBackground })"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { defineProps, ref } from "vue";
|
||||
import { defineProps, ref, defineEmits } from "vue";
|
||||
import type { PropType } from "vue";
|
||||
import { BarConfig } from "./types";
|
||||
import { BarConfig } from "@/types/dashboard";
|
||||
|
||||
const props = defineProps({
|
||||
config: {
|
||||
@ -38,8 +44,13 @@ const props = defineProps({
|
||||
default: () => ({ showBackground: true, barWidth: 30 }),
|
||||
},
|
||||
});
|
||||
const barWidth = ref(props.config.barWidth);
|
||||
const showBackground = ref(props.config.showBackground);
|
||||
const emits = defineEmits(["update"]);
|
||||
const barWidth = ref(props.config.barWidth || 30);
|
||||
const showBackground = ref(props.config.showBackground || false);
|
||||
|
||||
function changeConfig(param: { [key: string]: unknown }) {
|
||||
emits("update", param);
|
||||
}
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.bar-width {
|
||||
|
@ -14,32 +14,52 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License. -->
|
||||
<template>
|
||||
<div>
|
||||
<span class="label">Bar Width</span>
|
||||
<el-slider
|
||||
class="bar-width"
|
||||
v-model="barWidth"
|
||||
show-input
|
||||
input-size="small"
|
||||
<span class="label">Smooth</span>
|
||||
<el-switch
|
||||
v-model="smooth"
|
||||
active-text="Yes"
|
||||
inactive-text="No"
|
||||
@change="updateConfig({ smooth })"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<span class="label">Show Background</span>
|
||||
<el-switch v-model="showBackground" active-text="Yes" inactive-text="No" />
|
||||
<span class="label">Show Symbol</span>
|
||||
<el-switch
|
||||
v-model="showSymbol"
|
||||
active-text="Yes"
|
||||
inactive-text="No"
|
||||
@change="updateConfig({ showSymbol })"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<span class="label">Step</span>
|
||||
<el-switch
|
||||
v-model="step"
|
||||
active-text="Yes"
|
||||
inactive-text="No"
|
||||
@change="updateConfig({ step })"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { defineProps, ref } from "vue";
|
||||
import { defineProps, ref, defineEmits } from "vue";
|
||||
import type { PropType } from "vue";
|
||||
import { BarConfig } from "./types";
|
||||
import { LineConfig } from "@/types/dashboard";
|
||||
|
||||
const props = defineProps({
|
||||
config: {
|
||||
type: Object as PropType<BarConfig>,
|
||||
type: Object as PropType<LineConfig>,
|
||||
default: () => ({ showBackground: true, barWidth: 30 }),
|
||||
},
|
||||
});
|
||||
const barWidth = ref(props.config.barWidth);
|
||||
const showBackground = ref(props.config.showBackground);
|
||||
const emits = defineEmits(["update"]);
|
||||
const smooth = ref(props.config.smooth);
|
||||
const showSymbol = ref(props.config.showSymbol);
|
||||
const step = ref(props.config.step);
|
||||
|
||||
function updateConfig(param: { [key: string]: unknown }) {
|
||||
emits("update", param);
|
||||
}
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.bar-width {
|
||||
|
@ -1,20 +0,0 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
export interface BarConfig {
|
||||
showBackground: boolean;
|
||||
barWidth: number;
|
||||
}
|
@ -35,13 +35,13 @@ export const DefaultGraphConfig: { [key: string]: any } = {
|
||||
},
|
||||
Line: {
|
||||
type: "Line",
|
||||
showBackground: true,
|
||||
barWidth: 30,
|
||||
step: false,
|
||||
smooth: false,
|
||||
showSymbol: false,
|
||||
},
|
||||
Area: {
|
||||
type: "Area",
|
||||
showBackground: true,
|
||||
barWidth: 30,
|
||||
opacity: 0.4,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -14,12 +14,13 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License. -->
|
||||
|
||||
<template>
|
||||
<Line :data="data" :intervalTime="intervalTime" :type="'areaChart'" />
|
||||
<Line :data="data" :intervalTime="intervalTime" :config="config" />
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { defineProps } from "vue";
|
||||
import type { PropType } from "vue";
|
||||
import Line from "./Line.vue";
|
||||
import { AreaConfig } from "@/types/dashboard";
|
||||
|
||||
defineProps({
|
||||
data: {
|
||||
@ -27,5 +28,9 @@ defineProps({
|
||||
default: () => ({}),
|
||||
},
|
||||
intervalTime: { type: Array as PropType<string[]>, default: () => [] },
|
||||
config: {
|
||||
type: Object as PropType<AreaConfig>,
|
||||
default: () => ({}),
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
@ -19,6 +19,7 @@ limitations under the License. -->
|
||||
import { defineProps, computed } from "vue";
|
||||
import type { PropType } from "vue";
|
||||
import { Event } from "@/types/events";
|
||||
import { BarConfig } from "@/types/dashboard";
|
||||
|
||||
const props = defineProps({
|
||||
data: {
|
||||
@ -29,12 +30,8 @@ const props = defineProps({
|
||||
theme: { type: String, default: "light" },
|
||||
itemEvents: { type: Array as PropType<Event[]>, default: () => [] },
|
||||
config: {
|
||||
type: Object as PropType<{
|
||||
theme: string;
|
||||
showBackground: boolean;
|
||||
barWidth: number;
|
||||
}>,
|
||||
default: () => ({ theme: "light", showBackground: true, barWidth: 20 }),
|
||||
type: Object as PropType<BarConfig>,
|
||||
default: () => ({}),
|
||||
},
|
||||
});
|
||||
const option = computed(() => getOption());
|
||||
@ -156,7 +153,7 @@ function getOption() {
|
||||
left: 0,
|
||||
itemWidth: 12,
|
||||
textStyle: {
|
||||
color: props.config.theme === "dark" ? "#fff" : "#333",
|
||||
color: "#333",
|
||||
},
|
||||
},
|
||||
grid: {
|
||||
|
@ -19,16 +19,25 @@ limitations under the License. -->
|
||||
import { defineProps, computed } from "vue";
|
||||
import type { PropType } from "vue";
|
||||
import { Event } from "@/types/events";
|
||||
import { LineConfig } from "@/types/dashboard";
|
||||
|
||||
const props = defineProps({
|
||||
data: {
|
||||
type: Object as PropType<{ [key: string]: number[] }>,
|
||||
default: () => ({}),
|
||||
},
|
||||
type: { type: String, default: "" },
|
||||
intervalTime: { type: Array as PropType<string[]>, default: () => [] },
|
||||
theme: { type: String, default: "light" },
|
||||
itemEvents: { type: Array as PropType<Event[]>, default: () => [] },
|
||||
config: {
|
||||
type: Object as PropType<LineConfig>,
|
||||
default: () => ({
|
||||
step: false,
|
||||
smooth: false,
|
||||
showSymbol: false,
|
||||
opacity: 0.4,
|
||||
}),
|
||||
},
|
||||
});
|
||||
const option = computed(() => getOption());
|
||||
function getOption() {
|
||||
@ -68,6 +77,9 @@ function getOption() {
|
||||
type: "line",
|
||||
symbol: "none",
|
||||
barMaxWidth: 10,
|
||||
step: props.config.step,
|
||||
smooth: props.config.smooth,
|
||||
showSymbol: true,
|
||||
lineStyle: {
|
||||
width: 1.5,
|
||||
type: "solid",
|
||||
@ -90,9 +102,9 @@ function getOption() {
|
||||
}
|
||||
: undefined,
|
||||
};
|
||||
if (props.type === "areaChart") {
|
||||
if (props.config.type === "Area") {
|
||||
serie.areaStyle = {
|
||||
opacity: 0.4,
|
||||
opacity: props.config.opacity || 0.4,
|
||||
};
|
||||
}
|
||||
return serie;
|
||||
|
Loading…
Reference in New Issue
Block a user