Advertisement
C2Mikko

charts_old.vue

Jul 15th, 2020
1,068
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <template>
  2.   <div class="d-flex flex-column align-items-stretch h-100">
  3.  
  4.     <!-- Goals -->
  5.     <div class="goals container-fluid">
  6.       <div class="py-4 d-flex justify-content-start">
  7.         <div v-for="(col,index) in columns" v-on:click="onColClick(index)" class="goals-box d-flex flex-column justify-content-start col-1 position-relative" :key="index" :class="{ 'goals-selected' : getSelectedColumn().index == index }">
  8.           <progressbar v-bind:data="[1,col.expected/100,col.completed/100]" v-bind:type="col.type" v-bind:opts="col.opts" v-bind:index="index"></progressbar>
  9.           <p class="text-light mb-0"><b>{{col.name}}</b></p>
  10.         </div>
  11.       </div>
  12.     </div>
  13.  
  14.     <div class="d-flex flex-grow-1">
  15.  
  16.         <!-- Left Sidebar -->
  17.         <div class="sidebar col-md-2 text-center d-flex flex-column">
  18.  
  19.           <!-- Achieved -->
  20.           <div class="achieved col px-0 d-flex flex-column align-items-center justify-content-between">
  21.             <div class="achieved-visual">
  22.               <button class="round btn" style="padding:0;border:0;width:15vh;height:4vh;background: #BEA24F;color:white">
  23.                 {{texts.completedString}}
  24.               </button>
  25.               <p style="color:white;font-size:2em; font-family:'impact'">{{avgColValue.toFixed(2)}} %</p>
  26.             </div>
  27.             <a href="admin/bi-report"><img src="/pms-desktop/public/img/logo.png" alt="" class="img-fluid mb-4 p-4 align-self-center"></a>
  28.             <a :href="routes" class="btn btn-primary">
  29.             الإنتقال إلى إدارة المهام
  30.             </a>
  31.           </div>
  32.         </div>
  33.  
  34.         <!-- Main Content -->
  35.         <div class="col-md-10 d-flex flex-column justify-content-stretch">
  36.  
  37.           <!-- Priority -->
  38.           <div v-if="!!columns[selectedColIndex]" class="d-flex overflow-auto mb-3">
  39.             <div v-for="(section,index) in columns[selectedColIndex].sections" :key="index" class="card-container d-flex py-4 mx-3">
  40.               <div class="card priority w-100" :class="{'card-active' : getSelectedSection().index == index }">
  41.                 <div class="card-header">
  42.                   <h5 class="m-0"><b>{{section.name}}</b></h5>
  43.                 </div>
  44.  
  45.                 <div class="card-body d-flex justify-content-between align-items-center">
  46.                   <h2 class="m-0">{{texts.completedString}}</h2>
  47.                   <div class="progress w-100 mb-0 mx-3">
  48.                     <div class="progress__text">{{section.completed}} %</div>
  49.                     <div :style="{width:section.completed+'%', backgroundColor:section.backgroundColor}"> </div>
  50.                   </div>
  51.                 </div>
  52.                 <div class="h-75 d-flex flex-nowrap">
  53.                   <div v-on:click="onTaskClick(index,taskIndex)" v-for="(task,taskIndex) in section.tasks" :key="taskIndex"  class="task task-box w-100 p-4 d-flex flex-column justify-content-between min-w-215" :class="{'task-active' : getSelectedTask().index == taskIndex && getSelectedSection().index == index}">
  54.                     <h5 class="text-center m-0 mb-2">{{task.name}}</h5>
  55.                     <progressbar :text="task.completed+'%'" :text-style="{fontSize : '2rem',fontWeight:'bold'}"  v-bind:data="[task.expected/100,task.completed/100]" v-bind:type="SemiCircle" v-bind:opts="task.opts" v-bind:index="index+'-taskprog-'+taskIndex" style="height:75px;"></progressbar>
  56.                   </div>
  57.                 </div>
  58.               </div>
  59.             </div>
  60.           </div>
  61.  
  62.           <!-- Metric -->
  63.           <div class="metric d-flex flex-column flex-grow-1">
  64.             <div v-if="loaded" class="w-100 d-flex flex-nowrap align-items-stretch matrix-bar">
  65.               <div class="d-flex align-items-center justify-content-center" v-on:click="onTabClick(index)" v-for="(tab,index) in getSelectedTask().task.tabs" :key="index" :class="{'active-matrix' : index == getSelectedTab().index}"><p class="mb-0">{{ departments[tab.name] | underscoreToSpace }}</p></div>
  66.             </div>
  67.             <barChart class="w-100 flex-grow-1" :chart-data="getMetricsData(getSelectedTab().tab)" :options="options" v-if="loaded"></barChart>
  68.           </div>
  69.         </div> <!-- end of col-md-10 -->
  70.     </div> <!-- End of container-fluid -->
  71.   </div>
  72. </template>
  73.  
  74. <script>
  75. export default {
  76.   mounted() {
  77.     this.getData()
  78.   },
  79.   props: ['routes'],
  80.   filters: {
  81.     underscoreToSpace: function (value) {
  82.       if (!value) return ''
  83.       value = value.toString()
  84.       const newStr = value.replace(/_/g, " ")
  85.       return newStr
  86.     }
  87.   },
  88.   data(){
  89.     return {
  90.       departments : {
  91.         "corporate_communication" : "إدارة الاتصال المؤسسي",
  92.         "information_technology" : "إدارة تقنية المعلومات",
  93.         "strategic_planning_performance" : "إدارة التخطيط الاستراتيجي والأداء",
  94.         "excellence_instutional_improvement" : "إدارة التميز والتطوير المؤسسي",
  95.         "happy_dealers" : "إدارة إسعاد المتعاملين",
  96.         "insured_services" : "إدارة خدمات المؤمن عليهم",
  97.         "settlement_administration": "إدارة التسويات",
  98.         "inspection_compliance" : "إدارة التفتيش والامتثال",
  99.         "legal_administration" : "الإدارة القانونية",
  100.         "procurement_unit" : "إدارة المشتريات والخدمات العامة",
  101.         "hr" : "إدارة الموارد البشرية",
  102.         "investment_department" : "قطاع الاستثمار",
  103.         "financial_management": "الإدارة المالية",
  104.         "research_strategic_support": "البحوث والدعم الاستراتيجي",
  105.         "audit_risk" : "إدارة التدقيق والمخاطر",
  106.         "health_safety_unit " : "وحدة الصحة والسلامة",
  107.         "project_management_office" : "مكتب إدارة المشاريع",
  108.       },
  109.       options: {
  110.         layout: {
  111.           padding: {
  112.             top: 25,
  113.             bottom: 25
  114.           }
  115.         },
  116.         responsive: true,
  117.         maintainAspectRatio: false,
  118.         legend: {
  119.           display: false,
  120.         },
  121.         scales: {
  122.           yAxes: [{
  123.             position: 'right',
  124.             ticks: {
  125.               beginAtZero: true,
  126.               max:100
  127.             }
  128.           }]
  129.         }
  130.       },
  131.       texts:{
  132.         completedString:"منجز",
  133.         expectedString:"مستهدف",
  134.         leftColumnTitle:"وسطي مؤشر الأداء"
  135.       },
  136.       loaded : false,
  137.       columns : [],
  138.       col_colors : [],
  139.       selectedColIndex : 0,
  140.       SemiCircle : ProgressBar.SemiCircle,
  141.       Circle : ProgressBar.Circle,
  142.       avgColValue : 0,
  143.     }
  144.   },
  145.   methods : {
  146.     checkValue: function(val,target) {
  147.       let chartColor;
  148.       //console.log(this.expected);
  149.       let threshold_1 = 33*(this.expected/100); //18.15
  150.       let threshold_2 = 66*(this.expected/100); //36.3
  151.       //let threshold_3 = 66*0.423;
  152.       if(val <= threshold_1) {
  153.         return '#CA4256' // red
  154.       } else if(val <= threshold_2) {
  155.           return '#D8973C' // orange
  156.         } else {
  157.           return '#C9CD30' // green
  158.         }
  159.     },
  160.     getData: function(){
  161.       this.$http.get('getPMSData').then((response) =>{
  162.         var cols = response.data;
  163.         for (let i = 0; i < cols.length; i++) {
  164.           const col = cols[i];
  165.           this.avgColValue += (col.value/cols.length);
  166.           col.expected=col.week_of_the_year*100/52,
  167.           this.expected = col.week_of_the_year*100/52,
  168.           col.completed = col.value;
  169.           col.type= ProgressBar.SemiCircle
  170.           col.opts = [
  171.             {color: '#ffffff', strokeWidth: 25},
  172.             {color: '#7f9eb2', strokeWidth: 25},
  173.             {color: this.checkValue(col.value, col.expected), strokeWidth: 20},
  174.           ],
  175.           col.stat="verybad"
  176.           col.run="false"
  177.           col.selectedSectionIndex = 0
  178.  
  179.           for (let j = 0; j < col.sections.length; j++) {
  180.             const section = col.sections[j];
  181.             section.target = col.expected
  182.             section.expected=0
  183.             section.completed=section.value
  184.             section.type=ProgressBar.Circle
  185.             section.backgroundColor=this.checkValue(section.value,section.target)
  186.             section.selectedTaskIndex=0
  187.  
  188.             for (let k = 0; k < section.tasks.length; k++) {
  189.               const task = section.tasks[k];
  190.               task.target = col.expected
  191.               task.expected=0
  192.               task.completed= task.value
  193.               task.opts = [{color: '#9B9B37', strokeWidth: 5}, {color: this.checkValue(task.value,task.target), strokeWidth: 10}]
  194.               task.selectedTabIndex=0
  195.             }
  196.           }
  197.         }
  198.         this.columns = cols;
  199.         this.loaded = true;        
  200.       });
  201.     },
  202.     onColClick : function(colIndex){
  203.       this.selectedColIndex = colIndex;
  204.     },
  205.     onTabClick : function(tabIndex){
  206.       this.getSelectedTask().task.selectedTabIndex = tabIndex;
  207.     },
  208.     onTaskClick: function(sectionIndex,taskIndex){
  209.       this.getSelectedColumn().col.selectedSectionIndex = sectionIndex;
  210.       this.getSelectedSection().section.selectedTaskIndex = taskIndex;
  211.     },
  212.     getSelectedColumn : function(){
  213.       var selectedCol = this.columns[this.selectedColIndex];
  214.       return {
  215.         col : selectedCol,
  216.         index :this.selectedColIndex
  217.       }
  218.     },
  219.     getSelectedSection : function(){
  220.       var selectedCol = this.getSelectedColumn().col;
  221.       var selectedSection = selectedCol.sections[selectedCol.selectedSectionIndex];
  222.       return {
  223.         section:selectedSection,
  224.         index :selectedCol.selectedSectionIndex
  225.       }
  226.     },
  227.     getSelectedTask : function(){
  228.       var selectedSection = this.getSelectedSection().section;
  229.       var selectedTask = selectedSection.tasks[selectedSection.selectedTaskIndex];
  230.       return{
  231.         task: selectedTask,
  232.         index : selectedSection.selectedTaskIndex
  233.       }
  234.     },
  235.     getSelectedTab : function(){
  236.       var selectedTask = this.getSelectedTask().task;
  237.       var selectedTab = selectedTask.tabs[selectedTask.selectedTabIndex];
  238.       return {
  239.         tab: selectedTab,
  240.         index : selectedTask.selectedTabIndex
  241.       }
  242.     },
  243.     getMetricsData : function(tab){
  244.       if(!tab){
  245.         return {
  246.         labels:[],
  247.         datasets : [{
  248.         label:"",
  249.         data:[],
  250.         backgroundColor: []
  251.       }]
  252.       };
  253.       }
  254.       tab.dataCollection = {};
  255.       tab.dataCollection.labels = [];
  256.       tab.dataCollection.datasets = [{
  257.         label:"",
  258.         data:[],
  259.         backgroundColor: []
  260.       }] ;
  261.  
  262.       for (let i = 0; i < tab.operational_metrics.length; i++) {
  263.         const oMetric = tab.operational_metrics[i];
  264.         tab.dataCollection.labels.push(oMetric.name);
  265.         tab.dataCollection.datasets[0].data.push(oMetric.completed);
  266.         tab.dataCollection.datasets[0].backgroundColor.push(this.checkValue(oMetric.completed));
  267.       }
  268.       return tab.dataCollection;
  269.     }
  270.   }
  271. }
  272. </script>
  273. <style>
  274. ::-webkit-scrollbar {
  275.   width: 10px!important;
  276.   height: 10px!important;
  277. }
  278. ::-webkit-scrollbar-track {
  279.   background: #f1f1f1!important;
  280. }
  281. ::-webkit-scrollbar-thumb {
  282.   background: #888!important;
  283. }
  284. ::-webkit-scrollbar-thumb:hover {
  285.   background: #555!important;
  286. }
  287. .goals::-webkit-scrollbar {
  288.   width: 10px!important;
  289.   height: 10px!important;  
  290. }
  291. .goals::-webkit-scrollbar-track {
  292.   background: #5d6870!important;
  293. }
  294. .goals::-webkit-scrollbar-thumb {
  295.   background: #2f383f!important;
  296. }
  297. .goals::-webkit-scrollbar-thumb:hover {
  298.   background: #29333a!important;
  299. }
  300. .goals {
  301.   background-color: #48535b;
  302.   overflow-x: scroll;
  303.   overflow-y: hidden;
  304. }
  305. .goals-box {
  306.   padding: 10px;
  307.   box-sizing: border-box;
  308.   border: 2px solid transparent;
  309.   transition: 0.25s ease-in all;
  310.   min-width: 150px;
  311.   cursor: pointer;
  312. }
  313. .goals-box p {
  314.   font-size: 1.5em;
  315.   line-height: 1.15em;
  316. }
  317. .goals-box .progressBarContainer {
  318.   height: 70px!important;
  319. }
  320. .goals-box svg {
  321.   transition: 0.25s ease-in all;
  322.   transition-delay: 0.5s;
  323.   height: 50px!important;
  324. }
  325. .goals-selected {
  326.   border: 2px solid #8b9aa7;
  327.   background-color: #38688f;
  328. }
  329.  
  330. .sidebar {
  331.   background-color: #cecece;
  332.   padding: 20px 10px;
  333. }
  334.  
  335. .priority {
  336.   background-color: #fff;
  337.   -webkit-box-shadow: 0px 0px 15px -6px rgba(143,143,143,1);
  338.   -moz-box-shadow: 0px 0px 15px -6px rgba(143,143,143,1);
  339.   box-shadow: 0px 0px 15px -6px rgba(143,143,143,1);
  340. }
  341.  
  342. .priority__title {
  343.   border-bottom: 1px solid #333;
  344.   padding: 10px;
  345. }
  346.  
  347. .card-active {
  348.   background-color: #38688f;
  349.   color: #fff;
  350.   transition: 0.25s ease-in all;
  351. }
  352.  
  353. .card-active .progressbar-text {
  354.   color: #fff!important;
  355. }
  356.  
  357. .task-box {
  358.   transition: 0.25s ease-in all;
  359. }
  360.  
  361. .card-active .task-box {
  362.   background-color: #48535b;
  363. }
  364.  
  365. .task:only-child {
  366.   min-width: 350px;
  367. }
  368.  
  369. .task:hover {
  370.   cursor: pointer;
  371.   background-color: #f1f1f1;
  372.   transition: 0.25s ease-in all;
  373. }
  374.  
  375. .card-active .task:hover {
  376.   background-color: #515a61;
  377. }
  378. .task-active {
  379.   background-color: #38688f!important;
  380. }
  381.  
  382. .task-active:hover {
  383.   background-color: #38688f!important;
  384. }
  385.  
  386. .progress {
  387.   position: relative;
  388.   height: 20px;
  389. }
  390.  
  391. .progress__text {
  392.   position: absolute;
  393.   left: 5px;
  394.   padding: 5px;
  395.   font-size: 1.25em;
  396.   font-weight: bold;
  397. }
  398.  
  399. .matrix-bar {
  400.   transition: 0.25s ease-in all;
  401.   background-color: #48535b;
  402.   overflow-x: scroll;
  403. }
  404.  
  405. .matrix-bar > div {
  406.   padding: 8px;
  407.   cursor: pointer;
  408.   color: #fff;
  409.   text-transform: uppercase;
  410.   text-align: center;
  411.   min-width: 100px;
  412. }
  413.  
  414. .matrix-bar > div:hover {
  415.   transition: 0.25s ease-in all;
  416.   background-color: #515a61;
  417. }
  418.  
  419. .active-matrix {
  420.   background-color: #38688f;
  421. }
  422. .active-matrix:hover {
  423.   background-color: #38688f!important;
  424. }
  425.  
  426. .round{
  427.   border-radius: 1vh;
  428. }
  429. .centered{
  430.   display: flex;align-items: center; justify-content: center;
  431. }
  432. @media (min-width: 768px) {
  433.   .section-sm{
  434.     display:inline-flex;
  435.     width:100%;
  436.   }
  437.   .equalrow{
  438.     display: block;
  439.   }
  440.  
  441. }
  442. @media (min-width: 99 2px) {
  443.   .section-md{
  444.     display:inline-flex;
  445.     min-width:33%;
  446.     vertical-align: top;
  447.   }
  448.   .equalrow{
  449.     display: flex;
  450.   }
  451. }
  452. .min-w-460 {
  453.   min-width: 460px;
  454. }
  455. .min-w-215 {
  456.   min-width: 215px;
  457. }
  458. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement