script.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. 'use strict';
  2. // import("nmie.js");
  3. // const nmie = new Module.nmie();
  4. const range = (start, stop, step = 1) =>
  5. Array(Math.ceil((stop - start) / step)).fill(start).map((x, y) => x + y * step);
  6. const example = {
  7. data() {
  8. return {
  9. window: {
  10. width: 0,
  11. height: 0
  12. },
  13. // on change of initial value for __ units __
  14. // remember to update this.chart.layout.xaxis.title
  15. units: 'nm',
  16. simulationRuntime: {
  17. mode_n : [],
  18. mode_types: range(0,2),
  19. mode_names: ['E','H'],
  20. WLs: [],
  21. Qsca: [],
  22. Qabs: [],
  23. Qsca_n: [[],[]],
  24. Qabs_n: [[],[]],
  25. layout: {},
  26. trace1: {},
  27. trace2: {}
  28. },
  29. simulationSetup: {
  30. stepWL: 0.5,
  31. fromWL: 300.0,
  32. toWL: 1000.0,
  33. R: 100.0,
  34. reN: 4.0,
  35. imN: 0.01,
  36. total_mode_n:4
  37. },
  38. changes: 0,
  39. isShowInfo: false,
  40. chart: {
  41. uuid: "123",
  42. traces: [
  43. {
  44. y: [],
  45. line: {
  46. color: "#5e9e7e",
  47. width: 4,
  48. shape: "line"
  49. }
  50. }
  51. ],
  52. layout: {
  53. title:'reactive charts',
  54. xaxis: {
  55. // initial value should be same as in units
  56. title: 'Wavelength, nm'
  57. },
  58. yaxis: {
  59. title: 'yaxis title'
  60. }
  61. }
  62. }
  63. };
  64. },
  65. created() {
  66. window.addEventListener('resize', this.handleResize)
  67. this.handleResize();
  68. },
  69. destroyed() {
  70. window.removeEventListener('resize', this.handleResize)
  71. },
  72. mounted(){ this.runMie();},
  73. watch: {
  74. simulationSetup: {
  75. handler: function () {
  76. this.runMie();
  77. },
  78. deep: true
  79. },
  80. units:{
  81. handler: function () {
  82. this.chart.layout.xaxis.title = "Wavelength, "+this.units;
  83. }
  84. }
  85. },
  86. methods: {
  87. handleResize() {
  88. this.window.width = window.innerWidth;
  89. this.window.height = window.innerHeight;
  90. },
  91. runMie(){
  92. let t0 = performance.now();
  93. let fromWL = parseFloat(this.simulationSetup.fromWL);
  94. let toWL = parseFloat(this.simulationSetup.toWL);
  95. let stepWL = parseFloat(this.simulationSetup.stepWL);
  96. let R = parseFloat(this.simulationSetup.R);
  97. let reN = parseFloat(this.simulationSetup.reN);
  98. let imN = parseFloat(this.simulationSetup.imN);
  99. this.changes++;
  100. }
  101. },
  102. };
  103. const app = new Vue(example);
  104. app.$mount('#app');