script.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. 'use strict';
  2. const example = {
  3. data() {
  4. return {
  5. window: {
  6. width: 0,
  7. height: 0
  8. },
  9. // on change of initial value for __ units __
  10. // remember to update this.chart.layout.xaxis.title
  11. units: 'nm',
  12. simulationSetup: {
  13. stepWL: 0.5,
  14. fromWL: 300.0,
  15. toWL: 1000.0,
  16. R: 100.0,
  17. reN: 4.0,
  18. imN: 0.01,
  19. total_mode_n:4
  20. },
  21. changes: 0,
  22. isShowInfo: false,
  23. chart: {
  24. uuid: "123",
  25. traces: [
  26. {
  27. y: [],
  28. line: {
  29. color: "#5e9e7e",
  30. width: 4,
  31. shape: "line"
  32. }
  33. }
  34. ],
  35. layout: {
  36. title:'reactive charts',
  37. xaxis: {
  38. // initial value should be same as in units
  39. title: 'Wavelength, nm'
  40. },
  41. yaxis: {
  42. title: 'yaxis title'
  43. }
  44. }
  45. }
  46. };
  47. },
  48. created() {
  49. window.addEventListener('resize', this.handleResize)
  50. this.handleResize();
  51. },
  52. destroyed() {
  53. window.removeEventListener('resize', this.handleResize)
  54. },
  55. mounted(){ this.runMie();},
  56. watch: {
  57. simulationSetup: {
  58. handler: function () {
  59. this.runMie();
  60. },
  61. deep: true
  62. },
  63. units:{
  64. handler: function () {
  65. this.chart.layout.xaxis.title = "Wavelength, "+this.units;
  66. }
  67. }
  68. },
  69. methods: {
  70. handleResize() {
  71. this.window.width = window.innerWidth;
  72. this.window.height = window.innerHeight;
  73. },
  74. runMie(){
  75. this.changes++;
  76. }
  77. },
  78. };
  79. const app = new Vue(example);
  80. app.$mount('#app');