Skip to content
Snippets Groups Projects
App.vue 1.99 KiB
Newer Older
  • Learn to ignore specific revisions
  • <template>   
      <v-app class= "grey lighten-2">
        
        <Navbar/>
        <v-main class="grey lighten-2" align="center">
    
    IsolatedSushi's avatar
    IsolatedSushi committed
          <!-- set to true for normal grpcClient -->
    
    IsolatedSushi's avatar
    IsolatedSushi committed
          <gRPCPointclient v-if="false"  v-on:newPoint="addPoint($event)" />
          <gRPCProjectorClient v-if="true" v-on:newPoint="addPoint($event)" />
    
    IsolatedSushi's avatar
    IsolatedSushi committed
          <ScatterPlot ref = "scatter"/>
    
    IsolatedSushi's avatar
    IsolatedSushi committed
          <Counter ref = "counter"/>
    
    
    import Navbar from './components/Navbar';
    
    IsolatedSushi's avatar
    IsolatedSushi committed
    import gRPCProjectorClient from './components/gRPCProjectorClient'
    import gRPCPointclient from './components/gRPCPointclient'
    
    IsolatedSushi's avatar
    IsolatedSushi committed
    import ScatterPlot from './components/ScatterPlot'
    
    IsolatedSushi's avatar
    IsolatedSushi committed
    import { interval } from 'rxjs';
    import Counter from './components/counter'
    
    export default {
      name: 'App',
    
    IsolatedSushi's avatar
    IsolatedSushi committed
        gRPCProjectorClient,
        gRPCPointclient,
    
    IsolatedSushi's avatar
    IsolatedSushi committed
        ScatterPlot,
        Counter  },
    
    IsolatedSushi's avatar
    IsolatedSushi committed
      created(){    
    
    IsolatedSushi's avatar
    IsolatedSushi committed
        //To handle to insane amount of points being send over
    
    IsolatedSushi's avatar
    IsolatedSushi committed
        const interValsource = interval(1000);
    
    IsolatedSushi's avatar
    IsolatedSushi committed
        interValsource.subscribe(val => this.distributeStreams(val));   
    
    IsolatedSushi's avatar
    IsolatedSushi committed
      },
    
    IsolatedSushi's avatar
    IsolatedSushi committed
    
    
    IsolatedSushi's avatar
    IsolatedSushi committed
      data(){
        return {
    
    IsolatedSushi's avatar
    IsolatedSushi committed
          pointList: [],
          streamStarted: false,
          pointCount: 0
    
    IsolatedSushi's avatar
    IsolatedSushi committed
        }
      },
    
    IsolatedSushi's avatar
    IsolatedSushi committed
      
    
    IsolatedSushi's avatar
    IsolatedSushi committed
      methods: {
        addPoint: function(point){
    
    IsolatedSushi's avatar
    IsolatedSushi committed
          this.streamStarted = true;
          this.pointList.push(point);
    
    IsolatedSushi's avatar
    IsolatedSushi committed
          if(this.pointList.length  == 1){
            console.log("Received point from ID",point.getId())
          }
    
    IsolatedSushi's avatar
    IsolatedSushi committed
        },
    
    IsolatedSushi's avatar
    IsolatedSushi committed
        //Update all the components which rely on the data
        //Is this the best way to do this?
    
    IsolatedSushi's avatar
    IsolatedSushi committed
        distributeStreams: function(val){
          //REMOVE THIS LATER
          if(val == -1){
            return
          }
          if(!this.streamStarted){
            return;
          }
    
          if(this.pointList.length <= this.pointCount){
            return;
          }
    
          //Give the point to all components
    
    
          //var index = Math.floor(Math.random() * Math.floor(this.pointList.length));
          this.$refs.scatter.addPointToPlot(this.pointList[this.pointCount]);
    
    IsolatedSushi's avatar
    IsolatedSushi committed
          this.$refs.counter.setCounter(this.pointList.length)
    
          this.pointCount += 1;
        }
    
    IsolatedSushi's avatar
    IsolatedSushi committed
        }
    
    IsolatedSushi's avatar
    IsolatedSushi committed
      };