Advertisement
nwaughachukwuma

Untitled

Jan 20th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <template>
  2.   <div class="container-fluid is-fullhd" id="app">
  3.   <div class="col-lg-12 col-md-12 col-sm-10 col-xs-10">
  4.     <!-- <div class="text-xs-center row">
  5.         <v-pagination :length="6" v-model="page" circle></v-pagination>
  6.     </div> -->
  7.     <fullscreen ref="fullscreen" :fullscreen.sync="fullscreen">
  8.     <!-- <div class="text-xs-center" style="height: 50%; margin-top: -12px; margin-bottom: -29px;"> -->
  9.         <v-container @click="updateSlide()" class="text-xs-center" height="10px" style="margin-top: -12px; margin-bottom: -29px;">
  10.             <v-layout justify-center height="10px">
  11.                 <v-flex md8 sm10 xs12>
  12.                     <v-card dark md8 sm10 xs12>
  13.                         <v-card-text>
  14.                             <v-pagination :length="4" v-model="page" circle :color="color"></v-pagination>
  15.                         </v-card-text>
  16.                     </v-card>
  17.                 </v-flex>
  18.             </v-layout>
  19.         </v-container>
  20.     <!-- </div> -->
  21.  
  22.     <carousel-3d :autoplay="true" ref="mycarousel" @before-slide-change="updatePaginate" :autoplay-timeout="15000" :width="1330" :height="700" :perspective="3" :space="370" :display="3" :border="2" :controls-visible="false" :controls-prev-html="'&#10092;'" :controls-next-html="'&#10093;'"
  23.                :controls-width="30" :controls-height="60">
  24.  
  25.         <slide :index="0">
  26.             <multiple-state :appData="lsData" style="height: 100%;"></multiple-state>
  27.         </slide>
  28.         <slide :index="1" >
  29.             <multiple-month :appData="lsData" style="height: 100%;"></multiple-month>
  30.         </slide>
  31.         <slide :index="2">
  32.             <multiple-supply :appData="lsData" style="height: 100%;"></multiple-supply>
  33.         </slide>
  34.         <slide :index="3">
  35.             <across-states :appData="lsData" style="height: 100%;"></across-states>
  36.         </slide>
  37.  
  38.     </carousel-3d>
  39.     </fullscreen>
  40.     <div class="text-xs-center pull-right" @click="toggle()">
  41.         <v-btn dark color="primary">Fullscreen <v-icon right x-large dark>fullscreen</v-icon></v-btn>
  42.     </div>
  43.   </div>
  44.   </div>
  45. </template>
  46.  
  47. <script>
  48.  
  49. import Plotly from 'plotly.js/dist/plotly'
  50. import Fullscreen from "vue-fullscreen/src/component.vue"
  51. import MultiSelect from 'vue-multiselect'
  52. import vueSlider from 'vue-slider-component';
  53. import { Carousel3d, Slide } from 'vue-carousel-3d';
  54. import MultipleState from './MultipleState';
  55. import MultipleMonth from './MultipleMonth';
  56. import MultipleSupply from './MultipleSupply';
  57. import AcrossStates from './AcrossStates';
  58.  
  59. export default {
  60.   components: {Fullscreen, Carousel3d, Slide, MultiSelect, MultipleState, MultipleMonth, MultipleSupply, AcrossStates},
  61.   data() {
  62.       return {
  63.         page: 1,
  64.         color:"#c0ff00",
  65.         date: new Date(),
  66.         fullscreen: false,
  67.         apiUrl: "https://somefirebaseAPI.json",
  68.         lsData: JSON.parse(this.$ls.get('nphcdadrr')),
  69.         value: [1, 1],
  70.         options: {
  71.           width: "90%",
  72.           style: {
  73.               "marginLeft": "3%"
  74.           },
  75.           bgStyle: {
  76.             "backgroundColor": "#fff",
  77.             "boxShadow": "inset 0.5px 0.5px 3px 1px rgba(0,0,0,.36)"
  78.           },
  79.           piecewiseStyle: {
  80.               "backgroundColor": "#ccc",
  81.               "visibility": "visible",
  82.               "width": "10px",
  83.               "height": "10px"
  84.           },
  85.           piecewiseActiveStyle: {
  86.               "backgroundColor": "#3498db"
  87.           },
  88.             labelStyle: {
  89.               "height": "5px",
  90.               "color": "#3498db"
  91.           },
  92.           labelActiveStyle: {
  93.               "color": "#3498db"
  94.           },
  95.           height: 9,
  96.           dotSize: 20,
  97.           min: 1,
  98.           max: 1,
  99.           interval: 1,
  100.           disabled: false,
  101.           show: true,
  102.           tooltip: "always",
  103.           piecewise: true,
  104.         },
  105.       }
  106.   },
  107.     methods: {
  108.         // toggle full screen
  109.         toggle () {
  110.             this.$refs['fullscreen'].background = "green";
  111.             this.$refs['fullscreen'].toggle()
  112.         },
  113.         enter(){
  114.             return true
  115.         },
  116.         // to update the paginate page value
  117.         updatePaginate(e){
  118.             this.page = e+1;
  119.         },
  120.         // to move to slide when paginate is clicked
  121.         updateSlide(){
  122.             this.$refs.mycarousel.goSlide(this.page-1); // move to clicked paginate value.
  123.         }
  124.     },
  125.    
  126.     async created(){
  127.         await this.axios.get(this.apiUrl).then(response => {
  128.             this.lsData = response.data;
  129.             this.$ls.set('nphcdadrr', JSON.stringify(this.lsData));      
  130.        }).catch(error =>{
  131.            if(!this.lsData){
  132.                this.lsData = JSON.parse(this.$ls.get('nphcdadrr'));
  133.                if (!this.lsData){
  134.                     alert("No internet connection and no data loaded.\nUse internet the first time before using offline")
  135.                }else{
  136.                    console.log('error in fetching data due to no network connection... using local storage');
  137.                }
  138.            }else{
  139.                 console.log('error in fetching data due to no network connection... using local storage');
  140.            }          
  141.        })
  142.        
  143.     },
  144.     mounted(){
  145.        
  146.     },
  147.     beforeUpdate(){
  148.  
  149.     },
  150.     updated(){
  151.  
  152.    
  153.     },
  154.     computed: {
  155.  
  156.     },
  157.     watch: {
  158.  
  159.  
  160.     }
  161. }
  162. </script>
  163.  
  164. <style scoped>
  165.   /* Some CSS */
  166. </style>
  167.  
  168. |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  169. |||||||||||||||||||||Next Component File Acrossstate.js||||||||||||||||||||||||||||||||
  170. |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  171. //@js-check
  172. import Fullscreen from "vue-fullscreen/src/component.vue"
  173. import MultiSelect from 'vue-multiselect'
  174. import Plotly from 'plotly.js/dist/plotly'
  175. import vueSlider from 'vue-slider-component';
  176. const medSupply = require('../../../assets/js-on/pentaMedSupply');
  177.  
  178. export default {
  179.     name: 'multiplemonth',
  180.     template: `
  181.     <div class="row chart-container">
  182.         <div class="text-xs-center" style="margin-top: 13em;" v-show="!isDataLoadedFirstTime">
  183.             <v-progress-circular indeterminate v-bind:size="70" v-bind:width="7" color="purple"></v-progress-circular>
  184.         </div>  
  185.         <div v-show="isDataLoadedFirstTime" class="is-fullhd" style="padding: 3px;">
  186.             <fullscreen ref="fullscreen" :fullscreen.sync="fullscreen">
  187.             <div class="col-md-12">
  188.                 <div class="chart-wrapper">
  189.                     <div class="chart-title col-md-12">
  190.                         <div class="row">
  191.                             <div class="col-md-4">
  192.                                 <multi-select v-model="selectedMonth" :options="optionsMonth" :hide-selected="true" :searchable="true" :allow-empty="true" placeholder="Select Month" @change="" @select=""></multi-select>
  193.                             </div>
  194.                             <div class="col-md-8">
  195.                                 <multi-select :multiple="true"  v-model="selectedMedSupply" :options="medicalSupply" :hide-selected="true" :searchable="true" :allow-empty="false" placeholder="Select Medical Supplies" @change="" @select=""></multi-select>
  196.                             </div>
  197.                         </div>
  198.                         <!-- <div class="row">
  199.                             <vue-slider ref="slider" v-model="value" v-bind="options"></vue-slider>  
  200.                         </div> -->
  201.                     </div>
  202.                     <div class="chart-stage col-md-12">
  203.                         <b><small>Vaccine wastage rate across the country <em>(comparison for selected medical supplies)</em></small></b>
  204.                         <div ref="line" style="width:100%;"></div>
  205.                     </div>
  206.                     <div class="chart-notes">
  207.                         <h4>
  208.                             <b>
  209.                                 <small style="font-size: 1px;"><v-icon title="Across country for selected medical supplies" left x-large>menu</v-icon></small>
  210.                                     <label class="pull-right bg-info" title="Fullscreen">
  211.                                         <v-icon color="blue darken-2" @click="toggle()" x-large right dark>fullscreen</v-icon>
  212.                                     </label>
  213.                                 <small class="pull-right"><v-icon title="Across country for selected medical supplies" right x-large>menu</v-icon></small>
  214.                             </b>
  215.                         </h4>
  216.                     </div>                    
  217.                 </div>
  218.             </div> <!-- col -->
  219.             </fullscreen>
  220.         </div><!-- row -->  
  221.   </div>
  222.   `,
  223.   components: {Fullscreen, MultiSelect},
  224.   props: ['appData'],
  225.   data() {
  226.       return {
  227.           fullscreen: true,
  228.           data: [],
  229.           layout: {
  230.               title: 'Vaccine Wastage Rate By States',
  231.               showlegend: true,
  232.               legend: {"orientation": "h", x:.01, y:1.6},
  233.               showgrid: false,    
  234.               gridwidth: 0,
  235.               rangemode: "tozero",          
  236.               autosize: true,
  237.               yaxis: {"title": "Frequency", "showgrid": false, "range": [0, 50000], "ticks": "inside",  "mirror": "allticks", "type": "linear", "autorange": false},
  238.               "breakpoints": [],
  239.               xaxis: {"title": "States","type": "category", "autorange": true, "showgrid": false}
  240.           },
  241.           selectedState: null,
  242.           selectedMonth: null,
  243.           optionsMonth: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  244.           selectedMedSupply: [],
  245.           medicalSupply: medSupply, // array of medSupplies; imported
  246.           lsData: JSON.parse(this.$ls.get('nphcdadrr')),
  247.           isDataLoadedFirstTime: false,
  248.           y: {},
  249.       }
  250.   },
  251.     methods: {
  252.    
  253.         toggle () {
  254.             this.$refs['fullscreen'].background = "green";
  255.             this.$refs['fullscreen'].toggle();
  256.             // this.fullscreen = !this.fullscreen
  257.         },
  258.         enter(){
  259.             return true
  260.         },
  261.       loadData() {
  262.           this.computeChartData();
  263.           this.populateChart()
  264.       },
  265.       computeChartData() {
  266.           // compute chart components
  267.           this.y = {};
  268.           this.data = [];
  269.  
  270.           // get current month
  271.           var curMonthIndex = new Date().getMonth();
  272.           var curMonth = this.optionsMonth[curMonthIndex];
  273.  
  274.           var selectedMonth = this.selectedMonth ? this.selectedMonth : curMonth;
  275.           var selectedMedSupply = this.selectedMedSupply.length > 0 ? this.selectedMedSupply.slice(0) : ["025. Penta Vaccine - Maximum Stock"];
  276.           // this.selectedMonth = this.selectedMonth.length > 0 ? this.selectedMonth : "";
  277.  
  278.           // the name of all medical supply as is from localStorage ...
  279.           var medSupply = this.lsData[0].slice(0);
  280.                    
  281.           // initialize this.y
  282.           // the list of all the medical supplies; screened, edited and trimed
  283.           this.medicalSupply.forEach( (elem, index) => {
  284.               this.y[elem] = [];
  285.           })
  286.                    
  287.           selectedMedSupply.map( (elem, index) => {  
  288.               var msi = medSupply.indexOf(elem);  //medSupply Index
  289.               this.lsData.map( (el, ind) => {
  290.                   if (ind > 76 ){  
  291.                    
  292.                     // convert the date format and get MonthIndex
  293.                     var el0 = new Date(el[0]).getMonth();
  294.                     el0 = this.optionsMonth[el0]; // get month String from month Index.
  295.  
  296.                       if (el0 === selectedMonth ){
  297.                           this.y[elem].push(el[msi]); // push the med supply reference data to y axis
  298.                       }                                              
  299.                   }
  300.               });      
  301.           })
  302.           // console.log(this.y);
  303.       },
  304.       populateChart (name) {
  305.           // populate chart subsequently
  306.  
  307.           // get current month
  308.           var curMonthIndex = new Date().getMonth();
  309.           var curMonth = this.optionsMonth[curMonthIndex];
  310.  
  311.           var selectedMedSupply = this.selectedMedSupply.length > 0 ? this.selectedMedSupply.slice(0) : ["025. Penta Vaccine - Maximum Stock"];
  312.           var selectedMonth = this.selectedMonth ? this.selectedMonth : curMonth;
  313.  
  314.           var x = [ 'Enugu', 'Taraba', 'Bayelsa', 'Kano', 'Niger', 'Jigawa', 'Kaduna', 'Benue', 'Osun', 'Federal Government', 'Ekiti', 'Delta', 'Federal Capital Territory', 'Rivers', 'Borno', 'Kebbi', 'Lagos', 'Ondo', 'Katsina', 'Bauchi', 'Abia', 'Ogun', 'Plateau', 'Nasarawa', 'Kogi', 'Yobe', 'Ebonyi', 'Edo', 'Kwara', 'Anambra',
  315.           'Akwa-Ibom', 'Gombe', 'Adamawa', 'Cross River', 'Imo', 'Oyo', 'Sokoto', 'Zamfara' ];          
  316.  
  317.           /* to sort a numeric array, use the function below.
  318.             Array.sort(function(a, b){return b-a});
  319.           */
  320.           selectedMedSupply.map( (elem, index) => {
  321.  
  322.             if (index === 0){
  323.                 var stateNameToValue = {};
  324.                 for (var ix in x){
  325.                     // console.log(x[ix])
  326.                     stateNameToValue[x[ix]] = this.y[elem][ix];
  327.                 }
  328.                 //this.y[elem]
  329.                 stateNameToValue = this.sortObjects(stateNameToValue);
  330.                 x = []; this.y[elem] = []
  331.                 for (let stateName in stateNameToValue){
  332.                     if (stateNameToValue.hasOwnProperty(stateName)){
  333.                         x.push(stateName);
  334.                         this.y[elem].push(stateNameToValue[stateName]);
  335.                     }
  336.                 }
  337.             }
  338.        
  339.             var newObj = {
  340.                 x : x,
  341.                 y : this.y[elem],
  342.                 name: elem,
  343.                 type: "bar"
  344.             }
  345.             this.data.push(newObj)
  346.           });      
  347.           // get the max value for the different medSupplies and configure their chart with it.
  348.           var curMax = 0;
  349.           // iterate over state data object
  350.           for (let elem in this.y){
  351.  
  352.               if (this.y.hasOwnProperty(elem)) {
  353.                  
  354.                   if (selectedMedSupply.indexOf(elem) > -1){
  355.  
  356.                       var arrayMax = Math.max.apply(null, this.y[elem]);
  357.                       curMax = Math.max(curMax, arrayMax);
  358.                   }
  359.               }
  360.           }
  361.           // set the max range to current maximum value based on the medSupply.
  362.           this.layout.yaxis.range = [0, curMax];
  363.       },
  364.       renderChart(){
  365.           Plotly.newPlot(this.$refs.line, this.data, this.layout, {
  366.               scrollZoom: false
  367.           });
  368.       },
  369.       relay() {
  370.           if(this.$refs){
  371.               Plotly.relayout(this.$refs.line, {
  372.                   'xaxis.autorange': true,
  373.                   'yaxis.autorange': false
  374.               });
  375.           }
  376.       },
  377.         // function to ssort an object by its value property
  378.         sortData(dataObj){
  379.             var sortable = [];
  380.             for (var value in dataObj) {
  381.                 sortable.push([value, dataObj[value]]);
  382.             }
  383.             sortable.sort(function(a, b) {
  384.                 return b[1] - a[1];
  385.             });
  386.             return sortable;  
  387.         },
  388.         // returns a sorted object
  389.         sortObjects(objToSort) {
  390.             var newObject = {};
  391.             var sortedArray = this.sortData(objToSort);
  392.             for (var i = 0; i < sortedArray.length; i++) {
  393.                 var key = sortedArray[i][0];
  394.                 var value = sortedArray[i][1];
  395.                 newObject[key] = value;
  396.             }
  397.             return newObject;
  398.         }
  399.   },
  400.   mounted() {      
  401.       if (this.lsData){
  402.           this.loadData();
  403.           this.isDataLoadedFirstTime = true;
  404.       }
  405.   },
  406.   updated(){
  407.       if(this.$refs.line){
  408.           Plotly.relayout(this.$refs.line, {
  409.               'xaxis.autorange': true,
  410.               'yaxis.autorange': false
  411.           });
  412.       }
  413.  },
  414.   watch: {
  415.       data(newData) {
  416.           Plotly.newPlot(this.$refs.line, this.data, this.layout);
  417.       },
  418.       selectedMonth(month){            
  419.           // this.selectedMonth = month;
  420.           if (this.lsData){
  421.             this.loadData();
  422.           }
  423.       },
  424.       selectedMedSupply(medSupply){
  425.           // this.medSupply = medSupply;
  426.           if (this.lsData){
  427.             this.loadData();
  428.           }
  429.       },
  430.       appData (val){
  431.         this.isDataLoadedFirstTime = true;
  432.         this.lsData = val;
  433.         this.loadData();
  434.       }
  435.   }
  436. }
  437.  
  438. |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  439. |||||||||||||||||||||Another Component File MultipleMonth.js|||||||||||||||||||||||||||
  440. |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  441.  
  442. // code goes here
  443.  
  444. |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  445. |||||||||||||||||||||Another Component File MultipleState.js|||||||||||||||||||||||||||
  446. |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  447.  
  448. // code goes here
  449.  
  450. |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  451. |||||||||||||||||||||Another Component File MultipleSupply.js|||||||||||||||||||||||||||
  452. |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  453.  
  454. // code goes here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement