2019-11-26 09:19:57 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div class="chart">
|
2020-03-05 14:23:56 +00:00
|
|
|
<p class="ingress-chart__data-dimension">{{ chartDataDimension }}</p>
|
2019-11-26 09:19:57 +00:00
|
|
|
<VChart
|
|
|
|
id="ingress-chart"
|
|
|
|
:chart-data="chartData"
|
2020-03-05 14:23:56 +00:00
|
|
|
:width="chartWidth"
|
|
|
|
:height="chartHeight"
|
2019-11-26 09:19:57 +00:00
|
|
|
:tooltip-constructor="ingressTooltip"
|
2020-03-05 14:23:56 +00:00
|
|
|
:key="chartKey"
|
2019-11-26 09:19:57 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-03-05 14:23:56 +00:00
|
|
|
import { Component } from 'vue-property-decorator';
|
2019-11-26 09:19:57 +00:00
|
|
|
|
2020-03-05 14:23:56 +00:00
|
|
|
import BaseChart from '@/app/components/BaseChart.vue';
|
2019-11-26 09:19:57 +00:00
|
|
|
|
|
|
|
import { ChartData } from '@/app/types/chartData';
|
2019-12-27 12:16:44 +00:00
|
|
|
import { Tooltip, TooltipParams } from '@/app/types/tooltip';
|
2019-11-26 09:19:57 +00:00
|
|
|
import { ChartUtils } from '@/app/utils/chart';
|
|
|
|
import { formatBytes } from '@/app/utils/converter';
|
|
|
|
import { IngressUsed } from '@/storagenode/satellite';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* stores ingress data for ingress bandwidth chart's tooltip
|
|
|
|
*/
|
|
|
|
class IngressTooltip {
|
|
|
|
public normalIngress: string;
|
|
|
|
public repairIngress: string;
|
|
|
|
public date: string;
|
|
|
|
|
|
|
|
public constructor(bandwidth: IngressUsed) {
|
|
|
|
this.normalIngress = formatBytes(bandwidth.ingress.usage);
|
|
|
|
this.repairIngress = formatBytes(bandwidth.ingress.repair);
|
|
|
|
this.date = bandwidth.intervalStart.toUTCString().slice(0, 16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-05 14:23:56 +00:00
|
|
|
@Component
|
|
|
|
export default class IngressChart extends BaseChart {
|
2020-03-15 11:50:40 +00:00
|
|
|
private get chartBackgroundColor(): string {
|
|
|
|
return this.isDarkMode ? '#E1A128' : '#fff4df';
|
|
|
|
}
|
|
|
|
|
2019-11-26 09:19:57 +00:00
|
|
|
private get allBandwidth(): IngressUsed[] {
|
|
|
|
return ChartUtils.populateEmptyBandwidth(this.$store.state.node.ingressChartData);
|
|
|
|
}
|
|
|
|
|
|
|
|
public get chartDataDimension(): string {
|
|
|
|
if (!this.$store.state.node.ingressChartData.length) {
|
|
|
|
return 'Bytes';
|
|
|
|
}
|
|
|
|
|
|
|
|
return ChartUtils.getChartDataDimension(this.allBandwidth.map((elem) => {
|
|
|
|
return elem.summary();
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
public get chartData(): ChartData {
|
|
|
|
let data: number[] = [0];
|
|
|
|
const daysCount = ChartUtils.daysDisplayedOnChart();
|
2020-03-15 11:50:40 +00:00
|
|
|
const chartBackgroundColor = this.chartBackgroundColor;
|
2019-11-26 09:19:57 +00:00
|
|
|
const chartBorderColor = '#e1a128';
|
2020-03-15 11:50:40 +00:00
|
|
|
const chartBorderWidth = 1;
|
2019-11-26 09:19:57 +00:00
|
|
|
|
|
|
|
if (this.allBandwidth.length) {
|
|
|
|
data = ChartUtils.normalizeChartData(this.allBandwidth.map(elem => elem.summary()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return new ChartData(daysCount, chartBackgroundColor, chartBorderColor, chartBorderWidth, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ingressTooltip(tooltipModel): void {
|
2019-12-27 12:16:44 +00:00
|
|
|
const tooltipParams = new TooltipParams(tooltipModel, 'ingress-chart', 'ingress-tooltip',
|
|
|
|
'ingress-tooltip-arrow', 'ingress-tooltip-point', this.tooltipMarkUp(tooltipModel),
|
|
|
|
205, 94, 35, 24, 6, 4, `#e1a128`);
|
2019-11-26 09:19:57 +00:00
|
|
|
|
2019-12-27 12:16:44 +00:00
|
|
|
Tooltip.custom(tooltipParams);
|
|
|
|
}
|
2019-11-26 09:19:57 +00:00
|
|
|
|
2019-12-27 12:16:44 +00:00
|
|
|
private tooltipMarkUp(tooltipModel: any): string {
|
|
|
|
if (!tooltipModel.dataPoints) {
|
|
|
|
return '';
|
2019-11-26 09:19:57 +00:00
|
|
|
}
|
|
|
|
|
2019-12-27 12:16:44 +00:00
|
|
|
const dataIndex = tooltipModel.dataPoints[0].index;
|
|
|
|
const dataPoint = new IngressTooltip(this.allBandwidth[dataIndex]);
|
|
|
|
|
|
|
|
return `<div class='ingress-tooltip-body'>
|
|
|
|
<div class='ingress-tooltip-body__info'>
|
|
|
|
<p>USAGE</p>
|
|
|
|
<b class="ingress-tooltip-bold-text">${dataPoint.normalIngress}</b>
|
|
|
|
</div>
|
|
|
|
<div class='ingress-tooltip-body__info'>
|
|
|
|
<p>REPAIR</p>
|
|
|
|
<b class="ingress-tooltip-bold-text">${dataPoint.repairIngress}</b>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class='ingress-tooltip-footer'>
|
|
|
|
<p>${dataPoint.date}</p>
|
|
|
|
</div>`;
|
2019-11-26 09:19:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.ingress-chart {
|
2020-03-05 14:23:56 +00:00
|
|
|
z-index: 102;
|
2019-11-26 09:19:57 +00:00
|
|
|
|
|
|
|
&__data-dimension {
|
|
|
|
font-size: 13px;
|
2020-03-15 11:50:40 +00:00
|
|
|
color: var(--regular-text-color);
|
2020-03-05 14:23:56 +00:00
|
|
|
margin: 0 0 5px 31px !important;
|
2019-11-26 09:19:57 +00:00
|
|
|
font-family: 'font_medium', sans-serif;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ingress-tooltip {
|
2020-03-15 11:50:40 +00:00
|
|
|
background-image: var(--tooltip-background-path);
|
2019-11-26 09:19:57 +00:00
|
|
|
background-repeat: no-repeat;
|
|
|
|
background-size: cover;
|
|
|
|
min-width: 190px;
|
|
|
|
min-height: 170px;
|
|
|
|
font-size: 12px;
|
|
|
|
border-radius: 14px;
|
|
|
|
color: #535f77;
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ingress-tooltip-arrow {
|
2020-03-15 11:50:40 +00:00
|
|
|
background-image: var(--tooltip-arrow-path);
|
2019-11-26 09:19:57 +00:00
|
|
|
background-repeat: no-repeat;
|
|
|
|
background-size: 50px 30px;
|
|
|
|
min-width: 50px;
|
|
|
|
min-height: 30px;
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
.ingress-tooltip-body {
|
|
|
|
margin: 8px;
|
|
|
|
|
|
|
|
&__info {
|
|
|
|
display: flex;
|
2020-03-15 11:50:40 +00:00
|
|
|
background-color: var(--ingress-tooltip-info-background-color);
|
2019-11-26 09:19:57 +00:00
|
|
|
border-radius: 12px;
|
|
|
|
padding: 14px;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: space-between;
|
|
|
|
margin-bottom: 14px;
|
|
|
|
position: relative;
|
2020-03-15 11:50:40 +00:00
|
|
|
color: var(--ingress-font-color);
|
2019-11-26 09:19:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.ingress-tooltip-bold-text {
|
|
|
|
font-size: 14px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.ingress-tooltip-footer {
|
|
|
|
position: relative;
|
|
|
|
font-size: 12px;
|
|
|
|
width: auto;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
padding: 10px 0 16px 0;
|
2020-03-15 11:50:40 +00:00
|
|
|
color: var(--regular-text-color);
|
2019-11-26 09:19:57 +00:00
|
|
|
}
|
|
|
|
</style>
|