diff --git a/frontend/src/app/components/mempool-graph/mempool-graph.component.ts b/frontend/src/app/components/mempool-graph/mempool-graph.component.ts index c02e8d3f7..1dab981ed 100644 --- a/frontend/src/app/components/mempool-graph/mempool-graph.component.ts +++ b/frontend/src/app/components/mempool-graph/mempool-graph.component.ts @@ -68,9 +68,39 @@ export class MempoolGraphComponent implements OnInit, OnChanges { } onChartReady(myChart: any) { - myChart.getZr().on('mousemove', e => { - if (e.target !== undefined) { - this.hoverIndexSerie = e.target.parent.parent.__ecComponentInfo.index; + myChart.getZr().on('mousemove', (e: any) => { + if (e.target !== undefined && + e.target.parent !== undefined && + e.target.parent.parent !== null && + e.target.parent.parent.__ecComponentInfo !== undefined) { + this.hoverIndexSerie = e.target.parent.parent.__ecComponentInfo.index; + } + }); + + myChart.on('legendselectchanged', (params) => { + let control = false; + Object.entries(params.selected).forEach(([key]) => { + if (control) { + myChart.dispatchAction({ + type: 'legendUnSelect', + name: key + }); + } else { + myChart.dispatchAction({ + type: 'legendSelect', + name: key + }); + } + if (params.name === key) { + control = true; + } + }); + for (let i = 0; i < params.length; i++) { + if (i === 0) { + this.feeLevelsOrdered.push('0 - 1'); + } else { + this.feeLevelsOrdered.push(`${params[i - 1]} - ${params[i]}`); + } } }); } @@ -158,6 +188,26 @@ export class MempoolGraphComponent implements OnInit, OnChanges { series: this.inverted ? [...seriesGraph].reverse() : seriesGraph, hover: true, color: this.inverted ? [...this.chartColorsOrdered].reverse() : this.chartColorsOrdered, + legend: { + bottom: 20, + data: this.inverted ? this.feeLevelsOrdered : [...this.feeLevelsOrdered].reverse(), + left: 0, + icon: 'square', + inactiveColor: '#444', + orient: 'vertical', + pageIconSize: 12, + pageIconColor: '#fff', + pageIconInactiveColor: '#444', + pageTextStyle: { + color: '#666', + }, + show: (this.template === 'advanced') ? true : false, + textStyle: { + color: '#888', + }, + top: 20, + type: 'scroll', + }, tooltip: { show: (window.innerWidth >= 768) ? true : false, trigger: 'axis', @@ -175,85 +225,81 @@ export class MempoolGraphComponent implements OnInit, OnChanges { type: 'line', }, formatter: (params: any) => { - const colorSpan = (index: any) => ` - - ${this.feeLevelsOrdered[index]} - `; - const totals = (values: any) => { - let totalValueTemp = 0; - const totalValueArrayTemp = []; - const valuesInverted = this.inverted ? values : [...values].reverse(); - for (const item of valuesInverted) { - totalValueTemp += item.value; - totalValueArrayTemp.push(totalValueTemp); - } - return { - totalValue: totalValueTemp, - totalValueArray: totalValueArrayTemp.reverse(), - valuesOrdered: this.inverted ? [...values].reverse() : values, - }; - }; - const { totalValue, totalValueArray, valuesOrdered } = totals(params); - const title = `