add aggregations

This commit is contained in:
Fine 2022-11-08 11:19:14 +08:00
parent 7c6a0bd380
commit 19324ab92d
2 changed files with 36 additions and 5 deletions

View File

@ -33,6 +33,36 @@ export default function useLegendProcess(legend?: LegendOptions) {
}
return true;
}
function aggregations(data: { [key: string]: number[] }) {
const source: any = {};
const keys = Object.keys(data);
return { showEchartsLegend, isRight };
for (const k of keys) {
source[k].linear = data[k];
if (legend) {
if (legend.min) {
source[k].min = Math.min(...data[k]);
}
if (legend.max) {
source[k].max = Math.max(...data[k]);
}
if (legend.mean) {
const total = data[k].reduce((prev: number, next: number) => {
prev += next;
return prev;
}, 0);
source[k].mean = total / data[k].length;
}
if (legend.total) {
source[k].total = data[k].reduce((prev: number, next: number) => {
prev += next;
return prev;
}, 0);
}
}
}
return source;
}
return { showEchartsLegend, isRight, aggregations };
}

View File

@ -18,6 +18,7 @@ limitations under the License. -->
<script lang="ts" setup>
import type { PropType } from "vue";
import { LegendOptions } from "@/types/dashboard";
import useLegendProcess from "@/hooks/useLegendProcessor";
/*global defineProps */
const props = defineProps({
@ -27,10 +28,10 @@ const props = defineProps({
},
config: {
type: Object as PropType<LegendOptions>,
default: () => ({
legend: {},
}),
default: () => ({}),
},
});
console.log(props);
const { aggregations } = useLegendProcess(props.config);
const source = aggregations(props.data);
console.log(source);
</script>