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

311 lines
7.3 KiB
Vue
Raw Normal View History

2021-08-04 16:25:56 +00:00
<template>
2021-08-12 19:05:50 +00:00
<div id="v-pm-charts" ref="v-pm-charts" class="v-pm-charts vp-inline-block">
<div class="p-1 v-flex">
2021-09-24 14:09:20 +00:00
<h6 class="v-search-title">{{ $t("ID_DRILL_DOWN_NUMBER_TASKS") }}</h6>
2021-09-24 20:17:56 +00:00
<BreadCrumb :options="dataBreadcrumbs" :settings="settingsBreadcrumbs" />
2021-08-12 19:05:50 +00:00
<apexchart
v-show="typeView === 'donut'"
ref="apexchart1"
:options="optionsDonut"
:series="seriesDonut"
></apexchart>
<apexchart
v-show="typeView === 'bar'"
ref="apexchart2"
:options="optionsBar"
:series="seriesBar"
></apexchart>
<div class="row">
<div class="col-sm vp-align-right">
<button
@click="changeView('donut')"
type="button"
class="btn btn-primary"
>
<i class="fas fa-chart-pie"></i
><span class="vp-padding-l10">{{ $t("ID_VIEW") }}</span>
</button>
</div>
<div class="col-sm">
<button
@click="changeView('bar')"
type="button"
class="btn btn-primary"
>
<i class="fas fa-chart-bar"></i
><span class="vp-padding-l10">{{ $t("ID_VIEW") }}</span>
</button>
</div>
</div>
</div>
</div>
2021-08-04 16:25:56 +00:00
</template>
<script>
import _ from "lodash";
import Api from "../../api/index";
2021-08-16 18:54:43 +00:00
import BreadCrumb from "./../../components/utils/BreadCrumb.vue";
2021-08-04 16:25:56 +00:00
export default {
2021-08-12 19:05:50 +00:00
name: "VueChartLvZero",
mixins: [],
2021-08-16 18:54:43 +00:00
components: { BreadCrumb },
2021-09-24 20:17:56 +00:00
props: [],
2021-08-12 19:05:50 +00:00
data() {
let that = this;
return {
typeView: "donut",
width: 0,
data: [],
currentSelection: null,
seriesDonut: [],
2021-08-26 20:33:59 +00:00
settingsBreadcrumbs: [
{
class: "fas fa-info-circle",
tooltip: this.$t("ID_TASK_RISK_LEVEL0_INFO"),
onClick() {},
},
],
2021-09-24 20:17:56 +00:00
dataBreadcrumbs: [
{
label: that.$i18n.t("ID_INBOX"),
onClick() {
that.$emit("updateDataLevel", {
id: that.$i18n.t("ID_INBOX"),
name: that.$i18n.t("ID_INBOX"),
level: 1,
color: "#179a6e",
});
},
color: "#179a6e",
},
{
label: this.$i18n.t("ID_DRAFT"),
onClick() {
that.$emit("updateDataLevel", {
id: that.$i18n.t("ID_DRAFT"),
name: that.$i18n.t("ID_DRAFT"),
level: 1,
color: "#feb019",
});
},
color: "#feb019",
},
{
label: this.$i18n.t("ID_PAUSED"),
onClick() {
that.$emit("updateDataLevel", {
id: that.$i18n.t("ID_PAUSED"),
name: that.$i18n.t("ID_PAUSED"),
level: 1,
color: "#008ffb",
});
},
color: "#008ffb",
},
{
label: this.$i18n.t("ID_UNASSIGNED"),
onClick() {
that.$emit("updateDataLevel", {
id: that.$i18n.t("ID_UNASSIGNED"),
name: that.$i18n.t("ID_UNASSIGNED"),
level: 1,
color: "#8f99a0",
});
},
color: "#8f99a0",
},
],
2021-08-12 19:05:50 +00:00
optionsDonut: {
labels: [
this.$i18n.t("ID_INBOX"),
this.$i18n.t("ID_DRAFT"),
this.$i18n.t("ID_PAUSED"),
this.$i18n.t("ID_UNASSIGNED"),
],
chart: {
id: "apexchart1",
type: "donut",
2021-09-24 20:17:56 +00:00
events: {},
2021-08-12 19:05:50 +00:00
},
legend: {
2021-09-24 20:17:56 +00:00
show: false,
2021-08-12 19:05:50 +00:00
position: "top",
offsetY: 0,
},
},
seriesBar: [
{
data: [400, 430, 448, 470],
},
],
optionsBar: {
chart: {
type: "bar",
id: "apexchart2",
toolbar: {
show: false,
},
events: {
legendClick: function (chartContext, seriesIndex, config) {
that.currentSelection = that.data[seriesIndex];
that.$emit("updateDataLevel", {
id: that.currentSelection["List Name"],
name: that.currentSelection["List Name"],
level: 0,
data: that.currentSelection,
});
},
},
},
plotOptions: {
bar: {
barHeight: "100%",
distributed: true,
},
},
legend: {
2021-09-24 20:17:56 +00:00
show: false,
2021-08-12 19:05:50 +00:00
position: "top",
offsetY: 0,
},
colors: ["#33b2df", "#546E7A", "#d4526e", "#13d8aa"],
dataLabels: {
enabled: false,
},
xaxis: {
categories: [
this.$i18n.t("ID_INBOX"),
this.$i18n.t("ID_DRAFT"),
this.$i18n.t("ID_PAUSED"),
this.$i18n.t("ID_UNASSIGNED"),
],
},
tooltip: {
x: {
show: false,
},
y: {
title: {
formatter: function () {
return "";
},
},
},
},
},
};
},
created() {},
mounted() {
this.getBodyHeight();
this.getData();
},
watch: {},
computed: {},
updated() {},
beforeCreate() {},
methods: {
/**
* Return the height for Vue Card View body
*/
getBodyHeight() {
2021-08-16 18:54:43 +00:00
this.width = window.innerHeight * 0.8;
2021-08-12 19:05:50 +00:00
},
/**
* Change view - donut/bar
*/
changeView(view) {
this.typeView = view;
this.getData();
},
2021-08-04 16:25:56 +00:00
/**
* Get data from rest API
*/
2021-08-12 19:05:50 +00:00
getData() {
let that = this;
Api.cases
.listTotalCases()
.then((response) => {
that.formatData(response.data);
})
.catch((response) => {});
},
/**
* Format the data for chart
*/
formatData(data) {
let l = [],
c = [],
s = [];
_.each(data, (el) => {
l.push(el["List Name"]);
s.push(el["Total"]);
if (el["Color"] == "green") {
c.push("#179a6e");
}
if (el["Color"] == "yellow") {
c.push("#feb019");
}
if (el["Color"] == "blue") {
c.push("#008ffb");
}
if (el["Color"] == "gray") {
c.push("#8f99a0");
}
});
this.data = data;
this.seriesDonut = s;
this.seriesBar = [
{
data: s,
},
];
this.$refs["apexchart1"].updateOptions({ labels: l, colors: c });
this.$refs["apexchart2"].updateOptions({ labels: l, colors: c });
this.$apexcharts.exec("apexchart1", "updateSeries", s);
this.$apexcharts.exec("apexchart2", "updateSeries", [
{
data: s,
},
]);
},
2021-09-24 14:11:49 +00:00
/**
* Format color for show in breadcrumb
* @param {string} color
* @returns {string}
*/
2021-09-24 14:09:20 +00:00
formatColor(color) {
let code = "#ffffff";
switch (color) {
case "green":
code = "#179a6e";
break;
case "yellow":
code = "#feb019";
break;
case "blue":
code = "#008ffb";
break;
case "gray":
code = "#8f99a0";
break;
}
return code;
},
2021-08-12 19:05:50 +00:00
},
2021-08-04 16:25:56 +00:00
};
</script>
<style>
.vp-center {
2021-08-12 19:05:50 +00:00
text-align: center;
}
.vp-align-right {
text-align: right;
2021-08-04 16:25:56 +00:00
}
.vp-padding-l10 {
2021-08-12 19:05:50 +00:00
padding-left: 10px;
2021-08-04 16:25:56 +00:00
}
</style>