mirror of
https://github.com/apache/skywalking-booster-ui.git
synced 2025-05-14 00:37:33 +00:00
add aggregations
This commit is contained in:
parent
7c6a0bd380
commit
19324ab92d
@ -33,6 +33,36 @@ export default function useLegendProcess(legend?: LegendOptions) {
|
|||||||
}
|
}
|
||||||
return true;
|
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 };
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ limitations under the License. -->
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { PropType } from "vue";
|
import type { PropType } from "vue";
|
||||||
import { LegendOptions } from "@/types/dashboard";
|
import { LegendOptions } from "@/types/dashboard";
|
||||||
|
import useLegendProcess from "@/hooks/useLegendProcessor";
|
||||||
|
|
||||||
/*global defineProps */
|
/*global defineProps */
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@ -27,10 +28,10 @@ const props = defineProps({
|
|||||||
},
|
},
|
||||||
config: {
|
config: {
|
||||||
type: Object as PropType<LegendOptions>,
|
type: Object as PropType<LegendOptions>,
|
||||||
default: () => ({
|
default: () => ({}),
|
||||||
legend: {},
|
|
||||||
}),
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
console.log(props);
|
const { aggregations } = useLegendProcess(props.config);
|
||||||
|
const source = aggregations(props.data);
|
||||||
|
console.log(source);
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user