108 lines
2.6 KiB
Vue
108 lines
2.6 KiB
Vue
<template>
|
|
<v-card variant="outlined">
|
|
<v-card-item>
|
|
<v-card-title>Past Performance</v-card-title>
|
|
</v-card-item>
|
|
<v-card-text>
|
|
<v-skeleton-loader class="chart-loader" v-if="epsCompData.loading" />
|
|
<ag-charts-vue class="chart" v-else :options="options" />
|
|
</v-card-text>
|
|
</v-card>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { EpsComp, getEpsComp } from '@/api';
|
|
import { defineLoader } from '@/api/loader';
|
|
import { AgAxisLabelFormatterParams } from 'ag-charts-community';
|
|
import { roundTo } from 'round-to';
|
|
import { onMounted, computed } from 'vue';
|
|
import { AgChartsVue } from 'ag-charts-vue3';
|
|
|
|
const renderer = (params: any) => ({
|
|
title: params.title,
|
|
content: params.xValue + ': ' + roundTo(params.yValue, 4) + '%',
|
|
});
|
|
|
|
const props = defineProps<{
|
|
tickers: string[],
|
|
colors: string[]
|
|
}>();
|
|
|
|
const getTickerColor = (ticker: string) => props.colors[props.tickers.indexOf(ticker)];
|
|
|
|
const epsCompData = defineLoader<EpsComp[]>(() => getEpsComp(props.tickers));
|
|
|
|
const options = computed(() => {
|
|
if (epsCompData.loading) return null;
|
|
|
|
return {
|
|
theme: 'ag-material',
|
|
data: epsCompData.data?.map(e => ({ ...e })),
|
|
series: props.tickers.map((t: string) => ({
|
|
xKey: 'quarter',
|
|
type: 'line',
|
|
yKey: t,
|
|
yName: t,
|
|
stroke: getTickerColor(t),
|
|
marker: {
|
|
fill: getTickerColor(t),
|
|
stroke: getTickerColor(t)
|
|
},
|
|
tooltip: { renderer: renderer },
|
|
highlightStyle: {
|
|
item: { fillOpacity: 0 },
|
|
series: { enabled: false }
|
|
},
|
|
})),
|
|
axes: [
|
|
{
|
|
type: 'category',
|
|
position: 'bottom',
|
|
label: {
|
|
rotation: 315,
|
|
},
|
|
gridStyle: [
|
|
{
|
|
lineDash: [Infinity],
|
|
}, {
|
|
lineDash: [Infinity],
|
|
}
|
|
],
|
|
},
|
|
{
|
|
type: 'number',
|
|
position: 'left',
|
|
label: {
|
|
format: '$~s',
|
|
formatter: (params: AgAxisLabelFormatterParams) => {
|
|
params?.formatter?.(params.value)
|
|
return params.value + '%';
|
|
}
|
|
},
|
|
min: Math.min(0, ...epsCompData.data?.flatMap(e => Object.values(e)
|
|
.filter((e: string | number): e is number => typeof e === 'number')) ?? []),
|
|
gridStyle: [{
|
|
lineDash: [Infinity],
|
|
}, {
|
|
lineDash: [Infinity],
|
|
}],
|
|
crossLines: [
|
|
{
|
|
type: 'range',
|
|
value: 0,
|
|
lineDash: [6, 3],
|
|
stroke: 'black',
|
|
}
|
|
]
|
|
},
|
|
],
|
|
legend: {
|
|
position: 'bottom',
|
|
}
|
|
};
|
|
});
|
|
|
|
onMounted(() => {
|
|
epsCompData.load();
|
|
});
|
|
</script> |