График

This commit is contained in:
iriska-gri committed 2024-02-28 12:21:00 +03:00
1 parent 3875cc2a5a
commit 2ad0211d5f
4 files changed
+355 -81

No files matched your search

@@ -0,0 +1,179 @@
<template>
<v-card class="h-100 ">
<line-graph :data="data" :options="options"/>
</v-card>
</template>
<script>
import lineGraph from '@/components/graph/line-graph.vue'
import {computed } from 'vue'
import {formatComa, splitname} from '@/utils/universal_functions'
export default {
components: {
lineGraph,
},
props: {
dataLineChart: {
type: Object,
default: () => {}
},
},
setup(props, {emit}) {
const arrlines = {}
const data = computed({
get() {
arrlines.value = {
labels: [],
datasets: [
{
label: 'Открыто страниц',
backgroundColor: '#C62828',
borderColor: '#C62828',
borderWidth: 3,
cubicInterpolationMode: 'monotone',
data: [],
tooltips: false
},
{
label: 'Активные пользователи',
backgroundColor: 'teal',
borderColor: 'teal',
borderWidth: 3,
cubicInterpolationMode: 'monotone',
data: [],
hidden: true,
customlabel: [],
tooltips: true
}
,
{
label: 'CRR',
backgroundColor: '#673AB7',
borderColor: '#673AB7',
borderWidth: 3,
cubicInterpolationMode: 'monotone',
data: [],
hidden: true,
customlabel: [],
tooltips: true
}
,
{
label: 'BR',
backgroundColor: '#283593',
borderColor: '#283593',
borderWidth: 3,
cubicInterpolationMode: 'monotone',
data: [],
hidden: true,
customlabel: [],
tooltips: true
}
,
{
label: 'PPV',
backgroundColor: '#EF9A9A',
borderColor: '#EF9A9A',
borderWidth: 3,
cubicInterpolationMode: 'monotone',
data: [],
hidden: true,
customlabel: [],
tooltips: true
}
]
}
arrforline()
return arrlines.value
}
})
const options = {
plugins: {
datalabels: {
color: 'grey',
align: 'top',
display: 'auto'
},
legend: {
labels: {
color: 'grey',
}
},
tooltip: {
displayColors: false,
callbacks: {
label: function(context) {
let label = context.dataset.label || '';
if (context.datasetIndex==1) {
if (context.parsed.y !== null) {
label =arrlines.value.datasets[1].customlabel[context.dataIndex];
}
return label
}
}
}
}
},
scales: {
x: {
grid: {
color: 'white',
}
},
y: {
ticks: {
stepSize: 10
},
offset: true,
grid: {
color: 'white',
}
}
},
responsive: true,
maintainAspectRatio: false
}
const arrforline=() => {
Object.entries(props.dataLineChart).forEach(e => {
const [key, value] = e
arrlines.value.datasets[0].data.push(value.count)
arrlines.value.datasets[1].data.push(value.unic.length)
arrlines.value.datasets[2].data.push(value.crr)
arrlines.value.datasets[3].data.push(value.br)
arrlines.value.datasets[4].data.push(value.ppv)
arrlines.value.labels.push(formatComa(key))
arrlines.value.datasets[1].customlabel.push(props.dataLineChart[key].unic)
})
console.log(props.dataLineChart,'dataYear2 -------------');
}
return {
data,
options,
}
}
}
</script>
<style>
canvas {
flex: 1!important
}
</style>
@@ -1,13 +1,15 @@
<template>
<v-card class="h-100 ">
<line-graph :data="data" :options="options"/>
<line-graph v-if="data!==null" :data="data" :options="options"/>
</v-card>
</template>
<script>
import lineGraph from '@/components/graph/line-graph.vue'
import {computed } from 'vue'
import {computed, onMounted, ref, watch } from 'vue'
import {formatComa, splitname} from '@/utils/universal_functions'
export default {
@@ -24,13 +26,9 @@ export default {
},
setup(props, {emit}) {
const arrlines = {}
const data = computed({
get() {
arrlines.value = {
labels: [],
const arrlines = {
// labels: [''],
datasets: [
{
label: 'Открыто страниц',
@@ -38,10 +36,11 @@ export default {
borderColor: '#C62828',
borderWidth: 3,
cubicInterpolationMode: 'monotone',
data: [],
tooltips: false
data: [],
func: (val)=>{return val.count},
datakey: "count",
tooltips: false ,
yAxisID: 'y'
},
{
label: 'Активные пользователи',
@@ -50,35 +49,43 @@ export default {
borderWidth: 3,
cubicInterpolationMode: 'monotone',
data: [],
func: (val)=>{return val.unic.length},
datakey: "unic",
hidden: true,
customlabel: [],
tooltips: true
}
,
{
label: 'CRR',
backgroundColor: '#673AB7',
borderColor: '#673AB7',
borderWidth: 3,
cubicInterpolationMode: 'monotone',
data: [],
hidden: true,
customlabel: [],
tooltips: true
}
,
{
label: 'BR',
backgroundColor: '#283593',
borderColor: '#283593',
borderWidth: 3,
cubicInterpolationMode: 'monotone',
data: [],
hidden: true,
customlabel: [],
tooltips: true
tooltips: true,
yAxisID: 'y'
}
,
// {
// label: 'CRR',
// backgroundColor: '#673AB7',
// borderColor: '#673AB7',
// borderWidth: 3,
// cubicInterpolationMode: 'monotone',
// data: [],
// func: (val)=>{return val},
// hidden: true,
// datakey: "crr",
// customlabel: [],
// tooltips: true,
// }
// ,
// {
// label: 'BR',
// backgroundColor: '#283593',
// borderColor: '#283593',
// borderWidth: 3,
// cubicInterpolationMode: 'monotone',
// data: [],
// func: (val)=>{return val},
// datakey: "br",
// hidden: true,
// customlabel: [],
// tooltips: true
// }
// ,
{
label: 'PPV',
backgroundColor: '#EF9A9A',
@@ -86,16 +93,45 @@ export default {
borderWidth: 3,
cubicInterpolationMode: 'monotone',
data: [],
func: (val)=>{return parseFloat((val.pages/val.unic.length).toFixed(2))},
datakey: "ppv",
hidden: true,
customlabel: [],
tooltips: true
tooltips: true,
yAxisID: 'y'
}
]
}
arrforline()
return arrlines.value
const datachanged=()=> {
let res = null
if (Object.keys(props.dataLineChart).length>0){
res = arrlines
res.labels=[]
console.log(props.dataLineChart, 'uuuuuuuuuuuuuuuuuuuuuu');
for(let [key,val] of Object.entries(props.dataLineChart))
{
res.datasets.forEach((e) => {
e.data.push(e.func(val))
// e.data = [10,20,30]
});
res.labels.push(formatComa(key))
}
console.log(res, "kdjshskjhd");
}
})
// res.datasets[1].data=[]
// console.log(res,"reeeeeeee");
return res
}
watch(()=>props.dataLineChart,()=>{
console.log('changed');
data.value = datachanged()
},{deep:true})
const data = ref(datachanged())
const options = {
plugins: {
@@ -109,20 +145,20 @@ export default {
color: 'grey',
}
},
tooltip: {
displayColors: false,
callbacks: {
label: function(context) {
let label = context.dataset.label || '';
if (context.datasetIndex==1) {
if (context.parsed.y !== null) {
label =arrlines.value.datasets[1].customlabel[context.dataIndex];
}
return label
}
}
}
}
// tooltip: {
// displayColors: false,
// callbacks: {
// label: function(context) {
// let label = context.dataset.label || '';
// if (context.datasetIndex==1) {
// if (context.parsed.y !== null) {
// label =arrlines.value.datasets[1].customlabel[context.dataIndex];
// }
// return label
// }
// }
// }
// }
},
scales: {
@@ -139,7 +175,15 @@ export default {
grid: {
color: 'white',
}
}
},
y1: {
ticks: {
stepSize: 10
},
type: 'linear',
display: true,
position: 'right',
},
},
responsive: true,
@@ -147,21 +191,22 @@ export default {
}
const arrforline=() => {
Object.entries(props.dataLineChart).forEach(e => {
const [key, value] = e
arrlines.value.datasets[0].data.push(value.count)
arrlines.value.datasets[1].data.push(value.unic.length)
arrlines.value.datasets[2].data.push(value.crr)
arrlines.value.datasets[3].data.push(value.br)
arrlines.value.datasets[4].data.push(value.ppv)
arrlines.value.labels.push(formatComa(key))
arrlines.value.datasets[1].customlabel.push(props.dataLineChart[key].unic)
})
// const arrforline=() => {
// console.log(props.dataLineChart);
// for (let [key, val] of Object.entries) {}
// // Object.entries(props.dataLineChart).forEach(e => {
// // const [key, value] = e
// // arrlines.value.datasets[0].data.push(value.count)
// // arrlines.value.datasets[1].data.push(value.unic.length)
// // arrlines.value.datasets[2].data.push(value.crr)
// // arrlines.value.datasets[3].data.push(value.br)
// // arrlines.value.datasets[4].data.push(value.ppv)
// // arrlines.value.labels.push(formatComa(key))
// // arrlines.value.datasets[1].customlabel.push(props.dataLineChart[key].unic)
// // })
console.log(props.dataLineChart,'dataYear2 -------------');
}
// // console.log(props.dataLineChart,'dataYear2 -------------');
// }
return {
data,
+58 -9
View File
@@ -19,7 +19,7 @@
</v-col>
<v-col lg=9>
<!-- <line-chart :dataLineChart="dataLineChart" :dataChart="dataChart"/> -->
<line-chart :dataLineChart="dataLineChart" />
</v-col>
<v-col >
<v-btn block class="text-caption" @click="filter='year'">Год</v-btn>
@@ -100,6 +100,7 @@ export default {
setup(){
const dataLineChart = ref({})
const cardtotal = ref(
{
"crr": {
@@ -159,18 +160,65 @@ setup(){
let periodusers = new Set([])
let brdata = {}
alldata.value.period.forEach((e) => {
let filtr = alldata.value.period
if (formatDash(filterStore.date_period.enddate) !=formatDash(new Date())) {
filtr = filtr.filter(e => e.visitdate != formatDash(new Date()))
}
filtr.forEach((e) => {
periodusers.add(e.user.id)
if (!brdata[e.user.id]) {
brdata[e.user.id] = []
if (!brdata[e.visitdate]) {
brdata[e.visitdate] = {}
}
brdata[e.user.id].push(e.fullPath)
let user = splitname(e.user)
if (!brdata[e.visitdate][user]) {
brdata[e.visitdate][user] = []
}
brdata[e.visitdate][user].push({page:e.fullPath, total:e.count})
})
console.log(brdata, 'brdata')
let traffic ={}
// console.log(brdata, 'brdatabrdatabrdata')
for (let [key, val] of Object.entries(brdata)) {
traffic[key] ={unic: Object.keys(val), count: 0, br:0, pages: 0}
let arr = Object.values(val)
traffic[key].br = arr.filter(e=>e.length==1).length
arr.forEach(e=> traffic[key].pages += e.length)
// traffic[key].pages += arr
arr.flat().reduce((acc, item) => {
traffic[key].count +=item.total
return acc
},traffic[key].count)
}
let bothuser = new Set([...periodusers].filter(element => beforperiodusers.has(element)))
cardtotal.value.crr.data = bothuser.size*100/beforperiodusers.size
sumtraffic(traffic)
dataLineChart.value = traffic
}
const sumtraffic= (data) => {
console.log(data, 'traffic');
let ob = {brtot:0, ppvtot: 0, unictot: 0, pagetot: 0}
Object.values(data).flat().forEach((e) => {
ob.brtot += e.br
ob.ppvtot += e.count
ob.unictot += e.unic.length
ob.pagetot += e.pages
}
)
console.log(ob.ppvtot, ob.unictot, 'xxxxxxxxxxxx');
cardtotal.value.br.data = ob.brtot/ob.unictot*100
cardtotal.value.ppv.data = ob.pagetot/ob.unictot
}
watch(()=>filterStore.date_period,()=>{
@@ -184,7 +232,7 @@ setup(){
// const feedback = ref([])
// const for_formulas = ref({})
// const dataLineChart = ref({})
// const dataActivusers = ref([])
// const dataAttendance = ref({})
// const dataIndicators = ref({})
@@ -435,7 +483,8 @@ setup(){
return {
alldata,
cardtotal
cardtotal,
dataLineChart
// visiting,
// pages_count,
// visitionreduce,
+2 -1
View File
@@ -24,7 +24,8 @@
<v-btn block class="text-caption" @click="filter='year'">Год</v-btn>
<v-btn block class="text-caption" @click="filter='month'">Месяц</v-btn>
<v-btn block class="text-caption" @click="filter='day'">День</v-btn>
<my-helper :pretext="dataAttendance"/>
<!-- ------------------------------------------------------------------------- -->
<my-helper :pretext="dataLineChart"/>
{{filter}}
</v-col>
</v-row>