CN-649 feat: Dahsboard - npm - location六个折线图开发

This commit is contained in:
@changcode
2022-07-29 15:15:36 +08:00
parent 415f6c31b5
commit efa3d03f51
6 changed files with 143 additions and 12 deletions

View File

@@ -69,6 +69,7 @@
height: 100%; height: 100%;
border: 1px solid #E2E5EC; border: 1px solid #E2E5EC;
border-radius: 4px; border-radius: 4px;
padding: 1px;
.app-table.el-table { .app-table.el-table {
.el-table__header-wrapper { .el-table__header-wrapper {
tr th { tr th {

View File

@@ -1,6 +1,6 @@
.npm-event { .npm-event {
height: calc(100% - 24px);
width: 100%; width: 100%;
height: 100%;
.npm-event-title { .npm-event-title {
font-family: NotoSansHans-Medium; font-family: NotoSansHans-Medium;
font-size: 14px; font-size: 14px;
@@ -10,7 +10,7 @@
} }
.npm-event-pie { .npm-event-pie {
width: 100%; width: 100%;
height: 100%; height: calc(100% - 30px);
border: 1px solid #E2E5EC; border: 1px solid #E2E5EC;
border-radius: 4px; border-radius: 4px;
display: flex; display: flex;

View File

@@ -1,5 +1,6 @@
.npm-recent { .npm-recent {
height: calc(100% - 24px); height: 100%;
width: 100%;
.npm-recent-title { .npm-recent-title {
font-family: NotoSansHans-Medium; font-family: NotoSansHans-Medium;
font-size: 14px; font-size: 14px;
@@ -8,11 +9,13 @@
margin-bottom: 10px; margin-bottom: 10px;
} }
.npm-recent-table { .npm-recent-table {
height: calc(100% - 30px) !important;
border: 1px solid #E2E5EC; border: 1px solid #E2E5EC;
border-radius: 4px; border-radius: 4px;
padding: 1px;
.el-table__header-wrapper { .el-table__header-wrapper {
tr th { tr th {
padding: 5px 0; padding: 4px 0;
.data-column__span { .data-column__span {
font-family: NotoSansHans-Medium; font-family: NotoSansHans-Medium;
font-size: 12px; font-size: 12px;
@@ -23,7 +26,7 @@
} }
.el-table__body-wrapper.is-scrolling-none { .el-table__body-wrapper.is-scrolling-none {
tr td { tr td {
padding: 7px 0; padding: 7.5px 0;
} }
} }
} }

View File

@@ -216,8 +216,7 @@ export const chartColor2 = ['#86B565', '#A37FA7', '#EFAFC7', '#EFC48F', '#B4B1A8
export const chartColor3 = ['#00A7AB', '#7FA054', '#35ADDA', '#E48F3E', '#9FBC1D', '#98709B'] export const chartColor3 = ['#00A7AB', '#7FA054', '#35ADDA', '#E48F3E', '#9FBC1D', '#98709B']
export const chartColor4 = ['#E5F6F6', '#F2F6EE', '#EBF7FC', '#FCF4EB', '#9FBC1D', '#F5F1F5'] export const chartColor4 = ['#E5F6F6', '#F2F6EE', '#EBF7FC', '#FCF4EB', '#9FBC1D', '#F5F1F5']
export const chartColor5 = ['#749F4D', '#98709B', '#E5A219'] export const chartColor5 = ['#E26154', '#E48E4D', '#E7B34E', '#DAC74B', '#88AF65']
export const chartColor6 = ['#E26154', '#E48E4D', '#E7B34E', '#DAC74B', '#88AF65']
export const iso36112 = { export const iso36112 = {
[storageKey.iso36112Capital]: 'data/countriesWithCapital', [storageKey.iso36112Capital]: 'data/countriesWithCapital',

View File

@@ -1,9 +1,139 @@
<template> <template>
<div style="height: 100%;width: 100%;border: 1px solid #f0f0f0"></div> <div class="npm-line">
<div class="npm-line-header" v-if="chartData.params && chartData.params.showLegend">
<div class="npm-line-header-right" v-for="(item, index) in chartOptionLineData" :key="index" @click="legendSelectChange(item, index)">
<div class="npm-line-header-icon" :class="'icon' + index"></div>
<div class="npm-line-header-value">{{$t(item.legend)}}</div>
</div>
</div>
<div class="chart-drawing" :id="`chart${chartData.name}`"></div>
</div>
</template> </template>
<script> <script>
import * as echarts from 'echarts'
import { npmLineChartOption } from '@/views/charts2/charts/options/echartOption.js'
import { shallowRef } from 'vue'
import _ from 'lodash'
import { stackedLineTooltipFormatter } from '@/views/charts/charts/tools'
export default { export default {
name: 'NpmLine' name: 'NpmLine',
props: {
chart: Object
},
setup () {
return {
myChart: shallowRef()
}
},
data () {
return {
chartData: {},
chartOptionLineData: [
{ legend: 'network.total', index: 0 },
{ legend: 'network.inbound', index: 1 },
{ legend: 'network.outbound', index: 2 }
],
timer: null,
myChartArray: []
}
},
methods: {
init () {
const dom = document.getElementById(`chart${this.chartData.name}`)
this.myChart = echarts.init(dom)
this.chartOption = npmLineChartOption
const seriesTemplate = this.chartOption.series[0]
this.chartOption.title.text = this.chartData.i18n ? this.chartData.i18n : this.chartData.name
this.chartOption.color = this.chartData.params.color
let result = [
{
values: [[1435781430781, '1'], [1435781431781, '2']],
legend: 'network.total',
color: '#749F4D'
},
{
values: [[1435781430781, '1'], [1435781431781, '2']],
legend: 'network.inbound',
color: '#98709B'
},
{
values: [[1435781430781, '1'], [1435781431781, '2']],
legend: 'network.outbound',
color: '#E5A219'
}
]
result = result.filter(item => this.chartData.params.color.indexOf(item.color) > -1)
this.chartOption.series = result.map((t, i) => {
return {
...seriesTemplate,
name: t.legend,
stack: this.chartData.params.isStack ? 'network.total' : '',
lineStyle: {
width: 1
},
areaStyle: {
opacity: 0.1
},
data: t.values.map((v) => [Number(v[0]) * 1000, Number(v[1]), this.chartData.params.unitType])
}
})
this.chartOption.tooltip.formatter = (params) => {
params.forEach(t => {
t.seriesName = this.$t(t.seriesName)
})
const str = stackedLineTooltipFormatter(params)
return str
}
this.myChartArray.push(this.myChart)
this.myChart.setOption(this.chartOption)
},
dispatchLegendSelectAction (name) {
this.myChart.dispatchAction({
type: 'legendSelect',
name: name
})
},
dispatchLegendUnSelectAction (name) {
this.myChart.dispatchAction({
type: 'legendUnSelect',
name: name
})
},
legendSelectChange (item, index) {
if (index === 0) {
this.chartOptionLineData.forEach((t) => {
this.dispatchLegendSelectAction(t.legend)
})
} else {
if (this.chartOptionLineData[index].legend == item.legend) {
this.dispatchLegendSelectAction(item.legend)
this.chartOptionLineData.forEach((t) => {
if (t.legend !== item.legend) {
this.dispatchLegendUnSelectAction(t.legend)
}
})
}
}
},
resize () {
this.myChartArray.forEach(t => {
t.resize()
})
}
},
mounted () {
if (this.chart) {
this.chartData = _.cloneDeep(this.chart)
}
this.timer = setTimeout(() => {
this.init()
}, 100)
window.addEventListener('resize', this.resize)
},
beforeUnmount () {
clearTimeout(this.timer)
}
} }
</script> </script>

View File

@@ -4,7 +4,6 @@ import {
chartColor2, chartColor2,
chartColor3, chartColor3,
chartColor5, chartColor5,
chartColor6,
unitTypes unitTypes
} from '@/utils/constants' } from '@/utils/constants'
import unitConvert from '@/utils/unit-convert' import unitConvert from '@/utils/unit-convert'
@@ -119,7 +118,7 @@ export const pieChartOption2 = {
] ]
} }
export const pieChartOption3 = { export const pieChartOption3 = {
color: chartColor6, color: chartColor5,
series: [ series: [
{ {
name: 'Access From', name: 'Access From',
@@ -241,7 +240,6 @@ export const appListChartOption = {
} }
export const npmLineChartOption = { export const npmLineChartOption = {
color: chartColor5,
title: { title: {
text: '', text: '',
top: 20, top: 20,