GetWlFromPlot.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <div>
  3. <div class="row items-baseline">
  4. <div
  5. class="col-xs-12 col-sm-auto text-weight-bold text-center q-pr-md q-py-sm"
  6. >
  7. <div :style="flexRowTitleStyle">Source plane wave</div>
  8. </div>
  9. <div class="col-xs-grow col-sm">
  10. <div class="row justify-xs-center justify-sm-start items-baseline">
  11. <div class="col-auto">
  12. <input-with-units
  13. v-model:input-result="currentWavelengthInSourceUnits"
  14. v-model:is-showing-help="isShowingHelpForInputWithUnits"
  15. :initial-expression="currentWavelengthInSourceUnits.toString()"
  16. :units="sourceUnits"
  17. title="at"
  18. />
  19. </div>
  20. <div class="col-auto q-px-sm">
  21. or <span class="text-bold">click on plot</span> below to select a
  22. data point
  23. </div>
  24. </div>
  25. </div>
  26. </div>
  27. <div class="q-ma-xs" />
  28. <ReactiveChart
  29. :chart="chartContent"
  30. :window-height-share="0.4"
  31. @plotCreated="manageID($event)"
  32. />
  33. </div>
  34. </template>
  35. <script lang="ts">
  36. import ReactiveChart from 'components/ReactiveChart.vue';
  37. import { useStore } from 'src/store';
  38. import { defineComponent, computed } from 'vue';
  39. import { fromUnits, toUnits } from 'components/utils';
  40. import InputWithUnits from 'components/InputWithUnits.vue';
  41. import { flexRowTitleStyle } from 'components/config';
  42. import { PlotlyHTMLElement } from 'plotly.js-dist-min';
  43. import { cloneDeep } from 'lodash';
  44. export default defineComponent({
  45. name: 'GetWlFromPlot',
  46. components: {
  47. ReactiveChart,
  48. InputWithUnits,
  49. },
  50. setup() {
  51. const $store = useStore();
  52. const sourceUnits = computed(() => $store.state.guiRuntime.sourceUnits);
  53. const isShowingHelpForInputWithUnits = computed({
  54. get: () => $store.state.guiRuntime.isShowingHelpForInputWithUnits,
  55. set: (val) =>
  56. $store.commit('guiRuntime/setIsShowingHelpForInputWithUnits', val),
  57. });
  58. const currentWavelengthInSourceUnits = computed({
  59. get: () =>
  60. toUnits(
  61. $store.state.simulationSetup.gui.nearFieldSetup.atWL,
  62. sourceUnits.value
  63. ),
  64. set: (val) =>
  65. $store.commit(
  66. 'simulationSetup/setNearFieldWL',
  67. fromUnits(sourceUnits.value, val)
  68. ),
  69. });
  70. const chartContent = computed(() => {
  71. let content = cloneDeep($store.state.plotRuntime.spectrumPlots);
  72. if (content.layout.yaxis) content.layout.yaxis.title = 'Cross-section';
  73. content.layout['shapes'] = [
  74. {
  75. type: 'line',
  76. x0: currentWavelengthInSourceUnits.value,
  77. y0: 0,
  78. x1: currentWavelengthInSourceUnits.value,
  79. yref: 'paper',
  80. y1: 1,
  81. line: {
  82. color: 'red',
  83. width: 1.5,
  84. dash: 'dot',
  85. },
  86. },
  87. ];
  88. return content;
  89. });
  90. function manageID(chartID: string) {
  91. const myPlot = document.getElementById(chartID) as PlotlyHTMLElement;
  92. myPlot.on('plotly_click', function (data) {
  93. for (let i = 0; i < data.points.length; i++) {
  94. let val = data.points[i].x;
  95. if (val)
  96. currentWavelengthInSourceUnits.value = parseFloat(val.toString());
  97. }
  98. });
  99. }
  100. return {
  101. currentWavelengthInSourceUnits,
  102. sourceUnits,
  103. chartContent,
  104. flexRowTitleStyle,
  105. isShowingHelpForInputWithUnits,
  106. manageID,
  107. };
  108. },
  109. });
  110. </script>