add legend in line/bar/area graphs

This commit is contained in:
Fine 2022-11-03 16:14:21 +08:00
parent 42d2545e61
commit 5bfac6fdc9
5 changed files with 50 additions and 21 deletions

View File

@ -95,7 +95,7 @@ export type GraphConfig =
export interface BarConfig { export interface BarConfig {
type?: string; type?: string;
showBackground?: boolean; showBackground?: boolean;
LegendOptions?: LegendOptions; legend?: LegendOptions;
} }
export interface LineConfig extends AreaConfig { export interface LineConfig extends AreaConfig {
type?: string; type?: string;
@ -111,7 +111,7 @@ export interface LineConfig extends AreaConfig {
export interface AreaConfig { export interface AreaConfig {
type?: string; type?: string;
opacity?: number; opacity?: number;
LegendOptions?: LegendOptions; legend?: LegendOptions;
} }
export interface CardConfig { export interface CardConfig {

View File

@ -13,15 +13,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
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. -->
<template> <template>
<div>
<span class="label">{{ t("showLegend") }}</span>
<el-switch
v-model="legend.showLegend"
active-text="Yes"
inactive-text="No"
@change="updateLegendConfig({ showLegend: legend.showLegend })"
/>
</div>
<div> <div>
<span class="label">{{ t("legendOptions") }}</span> <span class="label">{{ t("legendOptions") }}</span>
<span class="title mr-5">{{ t("asTable") }}</span> <span class="title mr-5">{{ t("asTable") }}</span>

View File

@ -13,7 +13,10 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
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. -->
<template> <template>
<div class="graph">
<Graph :option="option" @select="clickEvent" :filters="config.filters" /> <Graph :option="option" @select="clickEvent" :filters="config.filters" />
<Legend :config="config.legend" :data="data" />
</div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { computed } from "vue"; import { computed } from "vue";
@ -39,7 +42,8 @@ const props = defineProps({
BarConfig & { BarConfig & {
filters: Filters; filters: Filters;
relatedTrace: RelatedTrace; relatedTrace: RelatedTrace;
} & { id: string } id: string;
}
>, >,
default: () => ({}), default: () => ({}),
}, },
@ -160,3 +164,9 @@ function clickEvent(params: EventParams) {
emits("click", params); emits("click", params);
} }
</script> </script>
<style lang="scss" scoped>
.graph {
width: 100%;
height: 100%;
}
</style>

View File

@ -13,12 +13,15 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
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. -->
<template> <template>
<div class="graph">
<Graph <Graph
:option="option" :option="option"
@select="clickEvent" @select="clickEvent"
:filters="config.filters" :filters="config.filters"
:relatedTrace="config.relatedTrace" :relatedTrace="config.relatedTrace"
/> />
<Legend :config="config.legend" :data="data" />
</div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { computed } from "vue"; import { computed } from "vue";
@ -29,6 +32,7 @@ import {
RelatedTrace, RelatedTrace,
Filters, Filters,
} from "@/types/dashboard"; } from "@/types/dashboard";
import Legend from "./components/Legend.vue";
/*global defineProps, defineEmits */ /*global defineProps, defineEmits */
const emits = defineEmits(["click"]); const emits = defineEmits(["click"]);
@ -206,3 +210,9 @@ function clickEvent(params: EventParams) {
emits("click", params); emits("click", params);
} }
</script> </script>
<style lang="scss" scoped>
.graph {
width: 100%;
height: 100%;
}
</style>

View File

@ -13,6 +13,24 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
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. -->
<template> <template>
<div>legend</div> <div></div>
</template> </template>
<script lang="ts" setup></script> <script lang="ts" setup>
import type { PropType } from "vue";
import { LegendOptions } from "@/types/dashboard";
/*global defineProps */
const props = defineProps({
data: {
type: Object as PropType<{ [key: string]: number[] }>,
default: () => ({}),
},
config: {
type: Object as PropType<LegendOptions>,
default: () => ({
legend: {},
}),
},
});
// console.log(props);
</script>