This commit is contained in:
Fine 2022-11-03 16:57:51 +08:00
parent 5bfac6fdc9
commit ddf46fe8c1
5 changed files with 26 additions and 5 deletions

View File

@ -14,3 +14,17 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { LegendOptions } from "@/types/dashboard";
export default function useLegendProcess() {
function showEchartsLegend(keys: string[], legend?: LegendOptions) {
if (keys.length === 1) {
return false;
}
if (legend && legend.asTable) {
return false;
}
return true;
}
return { showEchartsLegend };
}

View File

@ -14,14 +14,16 @@ See the License for the specific language governing permissions and
limitations under the License. --> limitations under the License. -->
<template> <template>
<div> <div>
<span class="label">{{ t("legendOptions") }}</span> <span class="label mr-5">{{ t("asTable") }}</span>
<span class="title mr-5">{{ t("asTable") }}</span>
<el-switch <el-switch
v-model="legend.asTable" v-model="legend.asTable"
active-text="Yes" active-text="Yes"
inactive-text="No" inactive-text="No"
@change="updateLegendConfig({ asTable: legend.asTable })" @change="updateLegendConfig({ asTable: legend.asTable })"
/> />
</div>
<div>
<span class="label">{{ t("legendOptions") }}</span>
<span class="title ml-20 mr-5">{{ t("toTheRight") }}</span> <span class="title ml-20 mr-5">{{ t("toTheRight") }}</span>
<el-switch <el-switch
v-model="legend.toTheRight" v-model="legend.toTheRight"

View File

@ -44,7 +44,8 @@ defineProps({
AreaConfig & { AreaConfig & {
filters: Filters; filters: Filters;
relatedTrace: RelatedTrace; relatedTrace: RelatedTrace;
} & { id: string } id: string;
}
>, >,
default: () => ({}), default: () => ({}),
}, },

View File

@ -27,6 +27,7 @@ import {
RelatedTrace, RelatedTrace,
Filters, Filters,
} from "@/types/dashboard"; } from "@/types/dashboard";
import useLegendProcess from "@/hooks/useLegendProcessor";
/*global defineProps, defineEmits */ /*global defineProps, defineEmits */
const emits = defineEmits(["click"]); const emits = defineEmits(["click"]);
@ -48,6 +49,7 @@ const props = defineProps({
default: () => ({}), default: () => ({}),
}, },
}); });
const { showEchartsLegend } = useLegendProcess();
const option = computed(() => getOption()); const option = computed(() => getOption());
function getOption() { function getOption() {
@ -118,7 +120,7 @@ function getOption() {
}, },
legend: { legend: {
type: "scroll", type: "scroll",
show: keys.length === 1 ? false : true, show: showEchartsLegend(keys, props.config.legend),
icon: "circle", icon: "circle",
top: 0, top: 0,
left: 0, left: 0,

View File

@ -33,6 +33,7 @@ import {
Filters, Filters,
} from "@/types/dashboard"; } from "@/types/dashboard";
import Legend from "./components/Legend.vue"; import Legend from "./components/Legend.vue";
import useLegendProcess from "@/hooks/useLegendProcessor";
/*global defineProps, defineEmits */ /*global defineProps, defineEmits */
const emits = defineEmits(["click"]); const emits = defineEmits(["click"]);
@ -63,6 +64,7 @@ const props = defineProps({
}), }),
}, },
}); });
const { showEchartsLegend } = useLegendProcess();
const option = computed(() => getOption()); const option = computed(() => getOption());
function getOption() { function getOption() {
const keys = Object.keys(props.data || {}).filter( const keys = Object.keys(props.data || {}).filter(
@ -156,7 +158,7 @@ function getOption() {
tooltip: props.config.smallTips ? tips : tooltip, tooltip: props.config.smallTips ? tips : tooltip,
legend: { legend: {
type: "scroll", type: "scroll",
show: keys.length === 1 ? false : true, show: showEchartsLegend(keys, props.config.legend),
icon: "circle", icon: "circle",
top: 0, top: 0,
left: 0, left: 0,