Browse Source

initial plotting Q total works

Konstantin Ladutenko 3 years ago
parent
commit
6c080ade9d

+ 72 - 0
guiapp/src/components/GetModesToPlot.vue

@@ -0,0 +1,72 @@
+<template>
+  <div class="row items-baseline">
+    <div class="col-xs-12 col-sm-auto text-weight-bold text-center q-px-md q-py-sm">
+      <div :style="flexRowTitleStyle">
+        Modes to plot
+      </div>
+    </div>
+    <div class="col-xs-grow col-sm q-px-xs">
+      <div class="row justify-xs-center justify-sm-start items-center">
+
+        <div class="col-auto">
+              <q-input
+                  v-model.number="numberOfModesToPlot"
+                  outlined
+                  type="number"
+                  min=1
+                  :max='maxModes'
+                  step=1
+                  dense
+                  :style="'width: '+basicSelectorWidthStyle"
+              />
+        </div>
+      </div>
+    </div>
+  </div>
+</template>
+
+<script lang="ts">
+import {
+  defineComponent,
+  computed,
+  watch,
+  } from 'vue'
+
+import { useStore } from 'src/store'
+import { flexRowTitleStyle,
+  maxNumberOfModesToPlot as maxModes,
+  basicSelectorWidthStyle,
+    basicWidthStyle
+} from 'components/config'
+
+export default defineComponent({
+  name: 'GetModesToPlot',
+
+  setup() {
+    const $store = useStore()
+    const numberOfModesToPlot = computed({
+      get: () => $store.state.simulationSetup.gui.numberOfModesToPlot,
+      set: val => {
+        let intVal = parseInt(val.toString())
+        if (isNaN(intVal)) return
+        if (intVal<1) intVal = 1
+        if (intVal>maxModes) intVal = maxModes
+        $store.commit('simulationSetup/setNumberOfModesToPlot', intVal)
+        $store.commit('plotRuntime/resizeSelectorIsPlotMode',intVal)
+      }
+    })
+
+    watch(numberOfModesToPlot, ()=>{
+      const intVal = parseInt(numberOfModesToPlot.value.toString())
+      if (isNaN(intVal)) return
+      if (intVal<1) numberOfModesToPlot.value = 1
+      if (intVal>maxModes) numberOfModesToPlot.value = maxModes
+    })
+
+    return { flexRowTitleStyle, basicSelectorWidthStyle, basicWidthStyle,
+      numberOfModesToPlot, maxModes,
+
+    }
+  },
+})
+</script>

+ 0 - 46
guiapp/src/components/GetPlotSettings.vue

@@ -1,30 +1,5 @@
 <template>
   <div class="row items-baseline">
-    <div class="col-xs-12 col-sm-auto text-weight-bold text-center q-px-md q-py-sm">
-      <div :style="flexRowTitleStyle">
-        Modes to plot
-      </div>
-    </div>
-    <div class="col-xs-grow col-sm q-px-xs">
-      <div class="row justify-xs-center justify-sm-start items-center">
-
-        <div class="col-auto">
-              <q-input
-                  v-model.number="numberOfModesToPlot"
-                  outlined
-                  type="number"
-                  min=1
-                  :max='maxModes'
-                  step=1
-                  dense
-                  :style="'width: '+basicSelectorWidthStyle"
-              />
-        </div>
-      </div>
-    </div>
-  </div>
-  <div class="q-ma-xs"/>
-  <div class="row items-baseline">
     <div class="col-xs-12 col-sm-auto text-center q-px-md q-py-sm">
       <div :style="flexRowTitleStyle">
         <span class="text-weight-bold">Plot label</span> (optional)
@@ -58,14 +33,12 @@
 import {
   defineComponent,
   computed,
-  watch,
   } from 'vue'
 import { event } from 'quasar'
 const { stopAndPrevent } = event
 
 import { useStore } from 'src/store'
 import { flexRowTitleStyle,
-  maxNumberOfModesToPlot as maxModes,
   basicSelectorWidthStyle,
     basicWidthStyle
 } from 'components/config'
@@ -75,17 +48,6 @@ export default defineComponent({
 
   setup() {
     const $store = useStore()
-    const numberOfModesToPlot = computed({
-      get: () => $store.state.simulationSetup.gui.numberOfModesToPlot,
-      set: val => {
-        let intVal = parseInt(val.toString())
-        if (isNaN(intVal)) return
-        if (intVal<1) intVal = 1
-        if (intVal>maxModes) intVal = maxModes
-        $store.commit('simulationSetup/setNumberOfModesToPlot', intVal)
-        $store.commit('plotRuntime/resizeSelectorIsPlotMode',intVal)
-      }
-    })
 
     const plotLabel = computed({
       get: ()=> $store.state.simulationSetup.gui.plotLabel,
@@ -110,15 +72,7 @@ export default defineComponent({
       return particleType+' R='+R+units
     })
 
-    watch(numberOfModesToPlot, ()=>{
-      const intVal = parseInt(numberOfModesToPlot.value.toString())
-      if (isNaN(intVal)) return
-      if (intVal<1) numberOfModesToPlot.value = 1
-      if (intVal>maxModes) numberOfModesToPlot.value = maxModes
-    })
-
     return { flexRowTitleStyle, basicSelectorWidthStyle, basicWidthStyle,
-      numberOfModesToPlot, maxModes,
       plotLabel, isRemovePlots,
       shadowText,
 

+ 18 - 4
guiapp/src/components/PlotSpectra.vue

@@ -22,11 +22,25 @@ export default defineComponent({
   },
   setup () {
     const $store = useStore()
+    const isPlotQsca = computed( ()=>$store.state.plotRuntime.isPlotQsca)
+    watch(isPlotQsca, ()=>$store.commit('plotRuntime/updateSpectraPlot'))
     const isPlotQabs = computed( ()=>$store.state.plotRuntime.isPlotQabs)
-    watch(isPlotQabs, ()=>{
-      console.log('isPlotQabs = ', isPlotQabs.value)
-      $store.commit('plotRuntime/updateSpectraPlot')
-    })
+    watch(isPlotQabs, ()=>$store.commit('plotRuntime/updateSpectraPlot'))
+    const isPlotQext = computed( ()=>$store.state.plotRuntime.isPlotQext)
+    watch(isPlotQext, ()=>$store.commit('plotRuntime/updateSpectraPlot'))
+
+    const isPlotQscaTotal = computed( ()=>$store.state.plotRuntime.isPlotQscaTotal)
+    watch(isPlotQscaTotal, ()=>$store.commit('plotRuntime/updateSpectraPlot'))
+    const isPlotQabsTotal = computed( ()=>$store.state.plotRuntime.isPlotQabsTotal)
+    watch(isPlotQabsTotal, ()=>$store.commit('plotRuntime/updateSpectraPlot'))
+    const isPlotQextTotal = computed( ()=>$store.state.plotRuntime.isPlotQextTotal)
+    watch(isPlotQextTotal, ()=>$store.commit('plotRuntime/updateSpectraPlot'))
+
+    const isPlotModeE = computed( ()=>$store.state.plotRuntime.isPlotModeE)
+    watch(isPlotModeE, ()=>$store.commit('plotRuntime/updateSpectraPlot'), { deep: true })
+    const isPlotModeH = computed( ()=>$store.state.plotRuntime.isPlotModeH)
+    watch(isPlotModeH, ()=>$store.commit('plotRuntime/updateSpectraPlot'), { deep: true })
+
     return {}
   }
 })

+ 3 - 0
guiapp/src/components/RunSimulationSpectrum.vue

@@ -125,6 +125,9 @@ export default defineComponent({
           // console.log('Total simulation time:', nmieTotalRunTime, 's')
           $store.commit('simulationSetup/setNmieTotalRunTime', nmieTotalRunTime)
           $store.commit('plotRuntime/setQ', {WLs, Qsca, Qabs, Qext, Qsca_n, Qabs_n, Qext_n})
+          $store.commit('plotRuntime/updateNumberOfPlotsFromPreviousSimulations')
+          $store.commit('plotRuntime/setCommonLabel', $store.state.simulationSetup.current.plotLabel)
+          $store.commit('simulationSetup/setPlotLabel', '')
           $store.commit('plotRuntime/updateSpectraPlot')
         } catch (e) {
           console.log(e)

+ 5 - 1
guiapp/src/pages/Spectrum.vue

@@ -9,6 +9,8 @@
     <div class="q-ma-xs"/>
     <GetParticleParameters/>
     <div class="q-ma-xs"/>
+    <GetModesToPlot/>
+    <div class="q-ma-xs"/>
     <GetPlotSettings/>
     <div class="q-ma-xs"/>
     <RunSimulationSpectrum/>
@@ -31,8 +33,9 @@ import GetUnits from 'components/GetUnits.vue'
 import GetHostIndex from 'components/GetHostIndex.vue'
 import GetSourceParameters from 'components/GetSourceParameters.vue'
 import GetParticleParameters from 'components/GetParticleParameters.vue'
-import GetPlotSettings from 'components/GetPlotSettings.vue'
+import GetModesToPlot from 'components/GetModesToPlot.vue'
 import RunSimulationSpectrum from 'components/RunSimulationSpectrum.vue'
+import GetPlotSettings from 'components/GetPlotSettings.vue'
 import PlotSelector from 'components/PlotSelector.vue'
 import PlotSpectra from 'components/PlotSpectra.vue'
 // import { useStore } from 'src/store'
@@ -41,6 +44,7 @@ import PlotSpectra from 'components/PlotSpectra.vue'
 export default defineComponent({
   name: 'PageIndex',
   components: {
+    GetModesToPlot,
     RunSimulationSpectrum, GetUnits, GetHostIndex,
     GetSourceParameters, GetParticleParameters,
     GetPlotSettings, PlotSelector,

+ 38 - 7
guiapp/src/store/plot-runtime/mutations.ts

@@ -21,6 +21,7 @@ const mutation: MutationTree<prsi> = {
   setQabsTotalPlotToggle (state: prsi, val: boolean) {state.isPlotQabsTotal = val},
   setQextTotalPlotToggle (state: prsi, val: boolean) {state.isPlotQextTotal = val},
   setIsRemovePlots (state:prsi, val:boolean) {state.isRemovePlots = val},
+  setCommonLabel  (state:prsi, val:string) {state.commonLabel = val},
 
   resizeSelectorIsPlotMode (state:prsi, val:number) {
     while (state.isPlotModeE.length > val) state.isPlotModeE.pop();
@@ -35,15 +36,45 @@ const mutation: MutationTree<prsi> = {
     for (let i = 0; i< val.length; ++i) state.isPlotModeH[i] = val[i]
   },
 
+  updateNumberOfPlotsFromPreviousSimulations(state: prsi) {
+    state.numberOfPlotsFromPreviousSimulations = state.spectraPlot.data.length
+  },
   updateSpectraPlot (state: prsi) {
-    console.log('updating spectra plot...')
-    const traceQsca:Partial<Data> = {
-      x: state.WLs,
-      y: state.Qsca,
-      type: 'scatter',
-      name: 'Qsca'
+    if (state.isRemovePlots) state.numberOfPlotsFromPreviousSimulations = 0
+    state.spectraPlot.data.length = state.numberOfPlotsFromPreviousSimulations
+
+    const label:string = state.commonLabel
+    if (state.isPlotQscaTotal) {
+      const traceQsca: Partial<Data> = {
+        x: state.WLs,
+        y: state.Qsca,
+        type: 'scatter',
+        name: 'Qsca '+label
+      }
+      state.spectraPlot.data.push(traceQsca)
+    }
+
+    if (state.isPlotQabsTotal) {
+      const traceQabs: Partial<Data> = {
+        x: state.WLs,
+        y: state.Qabs,
+        type: 'scatter',
+        name: 'Qabs '+label
+      }
+      state.spectraPlot.data.push(traceQabs)
     }
-    state.spectraPlot.data.push(traceQsca)
+
+    if (state.isPlotQextTotal) {
+      const traceQext: Partial<Data> = {
+        x: state.WLs,
+        y: state.Qext,
+        type: 'scatter',
+        name: 'Qext '+label
+      }
+      state.spectraPlot.data.push(traceQext)
+    }
+
+
 
   },
 

+ 6 - 1
guiapp/src/store/plot-runtime/state.ts

@@ -34,6 +34,8 @@ export interface plotRuntimeStateInterface {
   isPlotModeE: boolean[]
   isPlotModeH: boolean[]
   isRemovePlots: boolean
+  numberOfPlotsFromPreviousSimulations:number
+  commonLabel:string
 }
 
 function state(): plotRuntimeStateInterface {
@@ -50,6 +52,8 @@ function state(): plotRuntimeStateInterface {
   const isPlotQextTotal = false
   const isPlotModeE:boolean[] = [true]
   const isPlotModeH:boolean[] = [true]
+  const numberOfPlotsFromPreviousSimulations = 0
+  const commonLabel=''
 
   const spectraPlot:plotlyChart = {
     data: [],
@@ -88,7 +92,8 @@ function state(): plotRuntimeStateInterface {
     spectraPlot, isPlotQsca, isPlotQabs, isPlotQext,
     isPlotQscaTotal, isPlotQabsTotal, isPlotQextTotal,
     isPlotModeE, isPlotModeH,
-    isRemovePlots
+    isRemovePlots, numberOfPlotsFromPreviousSimulations,
+    commonLabel
   }
 }