GetSourceParameters.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <div class="field is-horizontal source-params">
  3. <div class="field-label is-normal">
  4. <label class="label">
  5. <div v-if="source_units.endsWith('Hz')"> Frequency </div>
  6. <div v-else-if="source_units.endsWith('eV')"> Energy </div>
  7. <div v-else-if="source_units.endsWith('s')"> Period </div>
  8. <div v-else> Wavelength </div>
  9. </label>
  10. </div>
  11. <div class="field-body">
  12. <div class="field is-grouped is-grouped-multiline">
  13. <input-with-units title="from" v-bind:units="source_units"
  14. v-bind:value="fromWLLocal"
  15. @newdata="fromWLLocal=$event"/>
  16. <input-with-units title="to" v-bind:units="source_units"
  17. v-bind:value="toWLLocal"
  18. @newdata="toWLLocal=$event"/>
  19. <div>
  20. <div v-if="isStep">
  21. <input-with-units title="step" v-bind:units="source_units"
  22. v-bind:value="stepWLLocal"
  23. @newdata="stepWLLocal=$event"/>
  24. </div>
  25. <div v-else>
  26. <input-with-units title="points" units=""
  27. v-bind:value="pointsNum"
  28. @newdata="pointsNum=$event"/>
  29. </div>
  30. <b-switch v-model="isStep" class="switch-style"/>
  31. </div>
  32. </div>
  33. </div>
  34. </div>
  35. </template>
  36. <script>
  37. import InputWithUnits from "./InputWithUnits.vue";
  38. export default {
  39. name: "GetSourceParameters",
  40. components: {
  41. InputWithUnits
  42. },
  43. data () {
  44. return {
  45. // TODO: Is it OK to modify Local later?
  46. fromWLLocal: this.fromWL,
  47. toWLLocal: this.toWL,
  48. stepWLLocal: this.stepWL,
  49. pointsNum: 100,
  50. isStep: true
  51. }
  52. },
  53. watch: {
  54. isStep: {
  55. handler: function () {
  56. if (this.isStep) {
  57. this.stepWLLocal = (this.toWLLocal-this.fromWLLocal)/this.pointsNum;
  58. } else {
  59. this.pointsNum = Math.round((this.toWLLocal-this.fromWLLocal)/this.stepWLLocal);
  60. }
  61. }
  62. },
  63. // emit updated values
  64. fromWLLocal: {
  65. handler: function () {
  66. this.$emit('fromWLData',this.fromWLLocal);
  67. }
  68. },
  69. toWLLocal: {
  70. handler: function () {
  71. this.$emit('toWLData',this.toWLLocal);
  72. }
  73. },
  74. stepWLLocal: {
  75. handler: function () {
  76. this.$emit('stepWLData',this.stepWLLocal);
  77. }
  78. },
  79. // update local values
  80. fromWL: {
  81. handler: function () {
  82. this.fromWLLocal = this.fromWL;
  83. }
  84. },
  85. toWL: {
  86. handler: function () {
  87. this.toWLLocal = this.toWL;
  88. }
  89. },
  90. stepWL: {
  91. handler: function () {
  92. this.stepWLLocal = this.stepWL;
  93. }
  94. },
  95. deep: true
  96. },
  97. props: ['fromWL', 'toWL', 'stepWL', 'source_units']
  98. }
  99. </script>
  100. <style scoped>
  101. .source-params {
  102. padding-bottom: 5px;
  103. }
  104. .switch-style {
  105. padding: 5px;
  106. }
  107. </style>