22import {
33 h , render ,
44} from ' vue'
5- import {
6- type ElementEvent , use ,
7- } from ' echarts/core'
5+ import { use } from ' echarts/core'
86import { CanvasRenderer } from ' echarts/renderers'
97import { BarChart } from ' echarts/charts'
108import {
@@ -16,27 +14,26 @@ import {
1614 TransformComponent ,
1715} from ' echarts/components'
1816import VChart from ' vue-echarts'
19-
2017import type {
2118 BarSeriesOption ,
2219 EChartsOption ,
2320 EChartsType ,
2421} from ' echarts'
22+ import type { RewardsChartFilter } from ' ../chart/DashboardChartRewardsFilter.vue'
23+
2524import {
2625 getChartTextColor ,
2726 getChartTooltipBackgroundColor ,
2827 getRewardChartColors ,
2928 getRewardsChartLineColor ,
3029} from ' ~/utils/colors'
3130import type { GetValidatorDashboardRewardsChartResponse } from ' ~/types/api/validator_dashboard'
32- import type {
33- ChartData , ChartSeries ,
34- } from ' ~/types/api/common'
31+ import type { ChartSeries } from ' ~/types/api/common'
3532import { DashboardChartRewardsTooltip } from ' #components'
3633
37- const {
38- getTimestampFromEpoch ,
39- } = useNetworkStore ()
34+ const { filter } = defineProps <{
35+ filter : RewardsChartFilter ,
36+ }> ()
4037
4138use ([
4239 GridComponent ,
@@ -55,26 +52,33 @@ const {
5552 dashboardKey,
5653} = useDashboardKey ()
5754
58- const data = ref <ChartData <number , string > | undefined >()
59-
60- const { status } = useAsyncData (
55+ const {
56+ data,
57+ status,
58+ } = useAsyncData (
6159 ' validator_dashboard_rewards_chart' ,
6260 async () => {
6361 if (dashboardKey .value === undefined ) {
64- data .value = undefined
6562 return
6663 }
67- const res = await fetch <GetValidatorDashboardRewardsChartResponse >(
64+ return await fetch <GetValidatorDashboardRewardsChartResponse >(
6865 ' DASHBOARD_VALIDATOR_REWARDS_CHART' ,
69- undefined ,
66+ {
67+ query: {
68+ ... filter ,
69+ group_ids: filter .group_ids .join (' ,' ),
70+ },
71+ },
7072 { dashboardKey: dashboardKey .value },
7173 )
72- data .value = res .data
7374 },
7475 {
7576 immediate: true ,
7677 server: false ,
77- watch: [ dashboardKey ],
78+ watch: [
79+ dashboardKey ,
80+ filter ,
81+ ],
7882 },
7983)
8084
@@ -106,7 +110,7 @@ const {
106110 selectedCurrencyMain,
107111} = useCurrency ()
108112
109- const categoryCount = computed (() => data .value ?.categories ?.length ?? 0 )
113+ const categoryCount = computed (() => data .value ?.data . categories ?.length ?? 0 )
110114
111115const isGwei = ref (false )
112116
@@ -153,7 +157,7 @@ const autoFormatAmount = (values: string[], {
153157 return result
154158}
155159
156- const clSeries = computed (() => data .value ?.series ?.filter (series => series .property === ' cl' ) ?? [])
160+ const clSeries = computed (() => data .value ?.data . series ?.filter (series => series .property === ' cl' ) ?? [])
157161const clSeriesGroupTotal = computed (() => {
158162 let total = Array (categoryCount .value ).fill (' 0' )
159163 clSeries .value .forEach ((group ) => {
@@ -170,7 +174,7 @@ const clSeriesGroupTotal = computed(() => {
170174})
171175const clSeriesGroupTotalFormatted = computed (() => autoFormatAmount (clSeriesGroupTotal .value ))
172176
173- const elSeries = computed (() => data .value ?.series ?.filter (series => series .property === ' el' ) ?? [])
177+ const elSeries = computed (() => data .value ?.data . series ?.filter (series => series .property === ' el' ) ?? [])
174178const elSeriesGroupTotal = computed (() => {
175179 let total = Array (categoryCount .value ).fill (' 0' )
176180 elSeries .value .forEach ((group ) => {
@@ -230,7 +234,7 @@ type DataZoomEvent = {
230234 start: number ,
231235 type: ' datazoom' ,
232236}
233- const dataZoomStart = ref (60 )
237+ const dataZoomStart = ref (0 )
234238const dataZoomEnd = ref (100 )
235239// position of tooltip get's lost due to rerendering of `options` (> computed > currency recalculations > latest-state)
236240const onDatazoom = ({
@@ -246,10 +250,7 @@ const tooltipPosition = ref({
246250 x: 0 ,
247251 y: 0 ,
248252})
249- const setTooltipPosition = (event : ElementEvent ) => {
250- tooltipPosition .value .x = event .offsetX
251- tooltipPosition .value .y = event .offsetY
252- }
253+
253254const restoreTooltip = () => {
254255 nextTick (() => {
255256 if (! chart .value ) return
@@ -318,8 +319,7 @@ const option = computed<EChartsOption>(() => {
318319 },
319320 end: dataZoomEnd .value ,
320321 labelFormatter : (_value : number , valueStr : string ) => {
321- const unixTimestamp = getTimestampFromEpoch (Number (valueStr ))
322- return getDateTime (unixTimestamp , { hasTime: false })
322+ return getDateTime (Number (valueStr ), { hasTime: false })
323323 },
324324 start: dataZoomStart .value ,
325325 type: ' slider' ,
@@ -353,17 +353,18 @@ const option = computed<EChartsOption>(() => {
353353 borderColor: colors .value .background ,
354354 confine: true ,
355355 enterable: true ,
356+ extraCssText: ' z-index: 100;' ,
357+
356358 formatter(params ) {
357359 if (! Array .isArray (params )) return ' '
358360 if (params .length === 0 ) return ' '
359361
360362 const paramsConsensusLayer = params .find (param => param .seriesId === seriesId .cl )
361363 const paramsExecutionLayer = params .find (param => param .seriesId === seriesId .el )
362364 const currentIndex = params [0 ].dataIndex
363- const currentTimestamp = getTimestampFromEpoch (Number (params [0 ].name ))
364365 const currentEpoch = {
365366 index: params [0 ].name ,
366- timestamp: currentTimestamp ,
367+ timestamp: Number ( params [ 0 ]. name ) ,
367368 }
368369 const currentGroupTotalCl = clSeriesGroupTotal .value [currentIndex ]
369370 const currentGroupTotalEl = elSeriesGroupTotal .value [currentIndex ]
@@ -412,20 +413,19 @@ const option = computed<EChartsOption>(() => {
412413 order: ' seriesAsc' ,
413414 padding: 0 ,
414415 trigger: ' axis' ,
415- triggerOn: ' click' ,
416+ triggerOn: isTriggeringOnMouseMove . value ? ' mousemove|click ' : ' click' ,
416417 },
417418 xAxis: {
418419 axisLabel: {
419420 fontSize: textSize ,
420421 fontWeight: fontWeightMedium ,
421- formatter : (epoch : number ) => {
422- const unixTimestamp = getTimestampFromEpoch (epoch )
423- const date = getDateTime (unixTimestamp , { hasTime: false })
424- return ` ${date }\n ${$t (' common.epoch' )} ${epoch } `
422+ formatter : (timestamp : number ) => {
423+ const date = getDateTime (timestamp , { hasTime: false })
424+ return date
425425 },
426426 lineHeight: 20 ,
427427 },
428- data: data .value ?.categories ,
428+ data: data .value ?.data . categories ,
429429 type: ' category' ,
430430 },
431431 yAxis: {
@@ -446,6 +446,12 @@ const option = computed<EChartsOption>(() => {
446446 },
447447 }
448448})
449+
450+ const isTriggeringOnMouseMove = ref (true )
451+
452+ const toggleTriggeringOnMouseMove = () => {
453+ isTriggeringOnMouseMove .value = ! isTriggeringOnMouseMove .value
454+ }
449455 </script >
450456
451457<template >
@@ -459,7 +465,7 @@ const option = computed<EChartsOption>(() => {
459465 :option
460466 autoresize
461467 @datazoom =" onDatazoom"
462- @zr:click = " setTooltipPosition "
468+ @zr:mousedown = " toggleTriggeringOnMouseMove "
463469 />
464470 </ClientOnly >
465471 <BcLoadingSpinner
@@ -473,14 +479,14 @@ const option = computed<EChartsOption>(() => {
473479 class =" no-data"
474480 alignment =" center"
475481 >
476- {{ $t("dashboard.validator.summary .chart.error") }}
482+ {{ $t("dashboard.validator.rewards .chart.error") }}
477483 </div >
478484 <div
479485 v-if =" status === 'success' && !clSeries.length"
480486 class =" no-data"
481487 alignment =" center"
482488 >
483- {{ $t("dashboard.validator.summary .chart.no_data") }}
489+ {{ $t("dashboard.validator.rewards .chart.no_data") }}
484490 </div >
485491 </div >
486492</template >
0 commit comments