Files
luos/resources/assets/js/home/TaskMetrics/VueChartLvTwo.vue

227 lines
5.5 KiB
Vue
Raw Normal View History

2021-08-12 19:05:50 +00:00
<template>
<div id="v-pm-charts" ref="v-pm-charts" class="v-pm-charts vp-inline-block">
<div class="p-1 v-flex">
<h6 class="v-search-title">Number of Tasks Status per Process</h6>
<div>
2021-08-16 18:54:43 +00:00
<BreadCrumb
:options="breadCrumbs.data"
:settings="breadCrumbs.settings"
/>
2021-08-12 19:05:50 +00:00
<div class="vp-width-p30 vp-inline-block">
2021-08-16 18:54:43 +00:00
<b-form-datepicker
id="date-from"
:date-format-options="{
year: '2-digit',
month: '2-digit',
day: '2-digit',
}"
size="sm"
:placeholder="$t('ID_DELEGATE_DATE_FROM')"
v-model="dateFrom"
@input="changeOption"
></b-form-datepicker>
2021-08-12 19:05:50 +00:00
</div>
<div class="vp-width-p30 vp-inline-block">
2021-08-16 18:54:43 +00:00
<b-form-datepicker
id="date-to"
size="sm"
:date-format-options="{
year: '2-digit',
month: '2-digit',
day: '2-digit',
}"
:placeholder="$t('ID_DELEGATE_DATE_TO')"
v-model="dateTo"
@input="changeOption"
></b-form-datepicker>
2021-08-12 19:05:50 +00:00
</div>
<div class="vp-inline-block">
2021-08-16 18:54:43 +00:00
<b-form-radio-group
id="btn-radios"
v-model="period"
:options="periodOptions"
button-variant="outline-secondary"
size="sm"
name="radio-btn-outline"
buttons
@change="changeOption"
></b-form-radio-group>
2021-08-12 19:05:50 +00:00
</div>
</div>
<apexchart
2021-08-16 18:54:43 +00:00
ref="LevelTwoChart"
2021-08-12 19:05:50 +00:00
:width="width"
:options="options"
:series="series"
></apexchart>
</div>
</div>
</template>
<script>
import _ from "lodash";
import Api from "../../api/index";
import Multiselect from "vue-multiselect";
import BreadCrumb from "../../components/utils/BreadCrumb.vue";
2021-08-16 18:54:43 +00:00
import moment from "moment";
2021-08-12 19:05:50 +00:00
export default {
2021-08-16 18:54:43 +00:00
name: "VueChartLvTwo",
2021-08-12 19:05:50 +00:00
mixins: [],
components: {
Multiselect,
BreadCrumb,
},
2021-08-16 18:54:43 +00:00
props: ["data", "breadCrumbs"],
2021-08-12 19:05:50 +00:00
data() {
let that = this;
return {
2021-08-16 18:54:43 +00:00
dateFrom: "",
dateTo: "",
period: "",
periodOptions: [
{ text: this.$t("ID_DAY"), value: "day" },
{ text: this.$t("ID_MONTH"), value: "month" },
{ text: this.$t("ID_YEAR"), value: "year" },
],
dataCasesByRange: [],
2021-08-12 19:05:50 +00:00
width: 0,
options: {
chart: {
2021-08-16 18:54:43 +00:00
type: "area",
2021-08-12 19:05:50 +00:00
zoom: {
2021-08-16 18:54:43 +00:00
enabled: false,
2021-08-12 19:05:50 +00:00
},
2021-08-16 18:54:43 +00:00
id: "LevelTwoChart",
2021-08-17 18:46:57 +00:00
events: {
markerClick: function (event, chartContext, config) {
that.currentSelection = that.dataCasesByRange[config.seriesIndex];
that.$emit("updateDataLevel", {
id: that.currentSelection["PRO_ID"],
name: that.currentSelection["PRO_TITLE"],
level: 2,
data: that.currentSelection,
});
},
},
2021-08-12 19:05:50 +00:00
},
dataLabels: {
2021-08-17 18:46:57 +00:00
enabled: false,
2021-08-12 19:05:50 +00:00
},
2021-08-16 18:54:43 +00:00
stroke: {
2021-08-17 18:46:57 +00:00
curve: "smooth",
2021-08-16 18:54:43 +00:00
},
2021-08-12 19:05:50 +00:00
xaxis: {
type: "datetime",
},
2021-08-17 18:46:57 +00:00
tooltip: {
fixed: {
enabled: false,
position: "topRight",
},
2021-08-12 19:05:50 +00:00
},
},
2021-08-17 18:46:57 +00:00
series: [],
2021-08-12 19:05:50 +00:00
};
},
created() {},
mounted() {
this.getBodyHeight();
},
watch: {},
computed: {},
updated() {},
beforeCreate() {},
methods: {
/**
* Return the height for Vue Card View body
*/
getBodyHeight() {
this.width = window.innerHeight;
},
/**
2021-08-16 18:54:43 +00:00
* Change datepickers or radio button
2021-08-12 19:05:50 +00:00
*/
2021-08-16 18:54:43 +00:00
changeOption() {
let that = this,
dt;
if (this.dateFrom && this.dateTo && this.period) {
dt = {
processId: this.data[1].id,
caseList: this.data[0].id.toLowerCase(),
dateFrom: moment(this.dateFrom).format("DD/MM/YYYY"),
dateTo: moment(this.dateTo).format("DD/MM/YYYY"),
groupBy: this.period,
};
Api.process
.totalCasesByRange(dt)
.then((response) => {
that.formatDataRange(response.data);
})
.catch((e) => {
console.error(err);
});
}
2021-08-12 19:05:50 +00:00
},
/**
2021-08-16 18:54:43 +00:00
* Format response fromn API
2021-08-12 19:05:50 +00:00
*/
2021-08-16 18:54:43 +00:00
formatDataRange(data) {
let labels = [],
serie = [];
this.dataCasesByRange = data;
2021-08-12 19:05:50 +00:00
_.each(data, (el) => {
2021-08-16 18:54:43 +00:00
serie.push(el["TOTAL"]);
labels.push(el["dateGroup"]);
2021-08-12 19:05:50 +00:00
});
2021-08-16 18:54:43 +00:00
console.log("DRWAWWW");
this.$refs["LevelTwoChart"].updateOptions({
labels: labels,
title: {
text: this.data[0]["PRO_TITLE"],
align: "left",
2021-08-12 19:05:50 +00:00
},
2021-08-16 18:54:43 +00:00
});
this.$apexcharts.exec("LevelTwoChart", "updateSeries", [
2021-08-12 19:05:50 +00:00
{
2021-08-16 18:54:43 +00:00
name: this.data[0]["PRO_TITLE"],
data: serie,
2021-08-12 19:05:50 +00:00
},
]);
},
generateDayWiseTimeSeries(baseval, count, yrange) {
var i = 0;
var series = [];
while (i < count) {
var y =
Math.floor(Math.random() * (yrange.max - yrange.min + 1)) +
yrange.min;
series.push([baseval, y]);
baseval += 86400000;
i++;
}
console.log(series);
return series;
},
},
};
</script>
<style>
.vp-task-metrics-label {
display: inline-block;
}
.vp-width-p30 {
width: 30%;
}
.vp-inline-block {
display: inline-block;
}
.vp-padding-l20 {
padding-left: 20px;
}
</style>
<style src="vue-multiselect/dist/vue-multiselect.min.css"></style>