Skip to content

Commit

Permalink
Merge pull request #54 from gobitfly/BIDS-2823/ValidatorDashboardSumm…
Browse files Browse the repository at this point in the history
…aryEChart

Bids 2823/validator dashboard summary echart
  • Loading branch information
D13ce authored Mar 4, 2024
2 parents 6434901 + cbcdd4e commit 42b3a04
Show file tree
Hide file tree
Showing 18 changed files with 631 additions and 15 deletions.
8 changes: 8 additions & 0 deletions frontend/assets/css/colors.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// When updating values here, please keep in mind that you might have to updated utils/colors.ts too

:root {
--grey: #a5a5a5;
--grey-1: #e9e9e9;
Expand Down Expand Up @@ -51,6 +53,9 @@
--input-active-text-color: var(--light-black);
--input-placeholder-text-color: var(--grey);

--tooltip-background: var(--light-grey-2);
--tooltip-text-color: var(--light-black);

--link-color: var(--blue);

--negative-color: var(--light-red);
Expand Down Expand Up @@ -87,6 +92,9 @@
--input-active-text-color: var(--light-grey);
--input-placeholder-text-color: var(--grey);

--tooltip-background: var(--light-grey);
--tooltip-text-color: var(--light-black);

--link-color: var(--light-blue);

--negative-color: var(--flashy-red);
Expand Down
25 changes: 25 additions & 0 deletions frontend/assets/css/fonts.scss
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@
--small_text_font_weight: var(--roboto-light);
--small_text_bold_font_weight: var(--roboto-medium);

--tooltip_text_font_family: var(--inter-family);
--tooltip_text_font_size: 10px;
--tooltip_text_font_weight: var(--inter-light);
--tooltip_text_bold_font_weight: var(--inter-medium);

--button_font_family: var(--roboto-family);
--button_font_size: 14px;
--button_font_weight: var(--roboto-medium);
Expand Down Expand Up @@ -182,6 +187,26 @@ h1 {
@include small_text_bold
}

@mixin tooltip_text(){
font-family: var(--tooltip_text_font_family);
font-size: var(--tooltip_text_font_size);
font-weight: var(--tooltip_text_font_weight);
}

.tooltip_text{
@include tooltip_text
}

@mixin tooltip_text_bold(){
font-family: var(--tooltip_text_font_family);
font-size: var(--tooltip_text_font_size);
font-weight: var(--tooltip_text_bold_font_weight);
}

.tooltip_text_bold{
@include tooltip_text_bold
}

@mixin button_text(){
font-family: var(--button_font_family);
font-size: var(--button_font_size);
Expand Down
18 changes: 6 additions & 12 deletions frontend/components/bc/BcTooltip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,6 @@ onUnmounted(() => {
}
.bc-tooltip {
--tt-bg-color: var(--light-grey-2);
--tt-color: var(--light-black);
position: relative;
display: inline-flex;
flex-wrap: wrap;
Expand All @@ -207,16 +203,14 @@ onUnmounted(() => {
padding: 9px 12px;
min-width: 120px;
border-radius: var(--border-radius);
color: var(--tt-color);
background: var(--tt-bg-color);
color: var(--tooltip-text-color);
background: var(--tooltip-background);
font-family: var(--inter-family);
font-weight: var(--inter-light);
font-size: 10px;
pointer-events: none;
&.dark {
--tt-bg-color: var(--light-black);
--tt-color: var(--light-grey);
border: solid 1px var(--container-border-color);
}
Expand All @@ -233,7 +227,7 @@ onUnmounted(() => {
top: -10px;
left: 50%;
border-color: transparent transparent var(--tt-bg-color) transparent;
border-color: transparent transparent var(--tooltip-background) transparent;
}
&.hover,
Expand All @@ -250,7 +244,7 @@ onUnmounted(() => {
&::after {
top: 100%;
left: 50%;
border-color: var(--tt-bg-color) transparent transparent transparent;
border-color: var(--tooltip-background) transparent transparent transparent;
}
}
Expand All @@ -259,15 +253,15 @@ onUnmounted(() => {
&::after {
top: calc(50% - 5px);
left: -10px;
border-color: transparent var(--tt-bg-color) transparent transparent;
border-color: transparent var(--tooltip-background) transparent transparent;
}
}
&.left {
&::after {
top: calc(50% - 5px);
left: 100%;
border-color: transparent transparent transparent var(--tt-bg-color);
border-color: transparent transparent transparent var(--tooltip-background);
}
}
Expand Down
192 changes: 192 additions & 0 deletions frontend/components/dashboard/chart/SummaryChart.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
<script lang="ts" setup>
import { h, render } from 'vue'
import { use } from 'echarts/core'
import { CanvasRenderer } from 'echarts/renderers'
import { LineChart } from 'echarts/charts'
import {
TooltipComponent,
LegendComponent,
GridComponent,
DataZoomComponent
} from 'echarts/components'
import VChart from 'vue-echarts'
import SummaryChartTooltip from './SummaryChartTooltip.vue'
import { formatEpochToDate } from '~/utils/format'
import { useValidatorDashboardOverview } from '~/stores/dashboard/useValidatorDashboardOverviewStore'
import { getSummaryChartGroupColors, getSummaryChartTextColor, getSummaryChartTooltipBackgroundColor } from '~/utils/colors'
import type { DashboardKey } from '~/types/dashboard'
use([
CanvasRenderer,
LineChart,
TooltipComponent,
LegendComponent,
DataZoomComponent,
GridComponent
])
interface Props {
dashboardKey: DashboardKey
}
const props = defineProps<Props>()
const store = useValidatorDashboardSummaryChartStore()
const { getDashboardSummaryChart } = store
const { chartData } = storeToRefs(store)
watch(props, () => {
getDashboardSummaryChart(props.dashboardKey)
}, { immediate: true })
const { overview } = storeToRefs(useValidatorDashboardOverview())
const { t: $t } = useI18n()
const colorMode = useColorMode()
const colors = computed(() => {
return {
groups: getSummaryChartGroupColors(colorMode.value),
label: getSummaryChartTextColor(colorMode.value),
background: getSummaryChartTooltipBackgroundColor(colorMode.value)
}
})
const styles = window.getComputedStyle(document.documentElement)
const fontFamily = styles.getPropertyValue('--roboto-family')
const textSize = parseInt(styles.getPropertyValue('--standard_text_font_size'))
const fontWeightLight = parseInt(styles.getPropertyValue('--roboto-light'))
const fontWeightMedium = parseInt(styles.getPropertyValue('--roboto-medium'))
const option = computed(() => {
interface SeriesObject {
data: number[];
type: string;
name: string;
}
const series: SeriesObject[] = []
if (chartData.value?.series) {
const allGroups = $t('dashboard.validator.summary.chart.all_groups')
chartData.value.series.forEach((element) => {
let name = allGroups
if (element.id !== -1) {
const group = overview.value?.groups.find(group => group.id === element.id)
name = group?.name || element.id.toString()
}
const newObj: SeriesObject = {
data: element.data,
type: 'line',
name
}
series.push(newObj)
})
}
return {
height: 400,
xAxis: {
type: 'category',
data: chartData.value?.categories,
boundaryGap: false,
axisLabel: {
fontSize: textSize,
lineHeight: 20,
formatter: (value: number) => {
const date = formatEpochToDate(value, $t('locales.date'))
if (date === undefined) {
return ''
}
return `${date}\n${$t('common.epoch')} ${value}`
}
}
},
yAxis: {
name: $t('dashboard.validator.summary.chart.efficiency'),
nameLocation: 'center',
nameTextStyle: {
padding: [0, 0, 35, 0]
},
type: 'value',
minInterval: 50,
silent: true,
axisLabel: {
formatter: '{value} %',
fontSize: textSize
},
splitLine: {
lineStyle: {
color: colors.value.label
}
}
},
series,
textStyle: {
fontFamily,
fontSize: textSize,
fontWeight: fontWeightLight,
color: colors.value.label
},
color: colors.value.groups,
legend: {
type: 'scroll',
orient: 'horizontal',
bottom: 65,
textStyle: {
color: colors.value.label,
fontSize: textSize,
fontWeight: fontWeightMedium
}
},
tooltip: {
order: 'seriesAsc',
trigger: 'axis',
padding: 0,
borderColor: colors.value.background,
valueFormatter: (value: number) => {
return `${value}% ${$t('dashboard.validator.summary.chart.efficiency')}`
},
formatter (params : any) : HTMLElement {
const startEpoch = parseInt(params[0].axisValue)
const groupInfos = params.map((param: any) => {
return {
name: param.seriesName,
efficiency: param.value,
color: param.color
}
})
const d = document.createElement('div')
render(h(SummaryChartTooltip, { t: $t, startEpoch, groupInfos }), d)
return d
}
},
dataZoom: {
type: 'slider',
start: 80,
end: 100,
dataBackground: {
lineStyle: {
color: colors.value.label
},
areaStyle: {
color: colors.value.label
}
},
borderColor: colors.value.label
}
}
})
</script>

<template>
<VChart class="chart" :option="option" autoresize />
</template>

<style lang="scss">
.chart-container {
background-color: var(--container-background);
}
</style>
Loading

0 comments on commit 42b3a04

Please sign in to comment.