script.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. const example = {
  2. data() {
  3. return {
  4. window: {
  5. width: 0,
  6. height: 0
  7. },
  8. textStyle:"underline",
  9. styleObject: {
  10. color: 'red',
  11. fontSize: '13px'
  12. },
  13. units: 'nm',
  14. stepWL: 0.5,
  15. fromWL: 300.0,
  16. toWL:1000.0,
  17. R: 100.0,
  18. reN: 4.0,
  19. imN: 0.01,
  20. isShowInfo: false,
  21. total_mode_n:4,
  22. chart: {
  23. uuid: "123",
  24. traces: [
  25. {
  26. y: [],
  27. line: {
  28. color: "#5e9e7e",
  29. width: 4,
  30. shape: "line"
  31. }
  32. }
  33. ],
  34. layout: {
  35. title:'reactive charts',
  36. xaxis: {
  37. title: 'xaxis title'
  38. },
  39. yaxis: {
  40. title: 'yaxis title'
  41. }
  42. }
  43. }
  44. };
  45. },
  46. created() {
  47. window.addEventListener('resize', this.handleResize)
  48. this.handleResize();
  49. },
  50. destroyed() {
  51. window.removeEventListener('resize', this.handleResize)
  52. },
  53. methods: {
  54. handleResize() {
  55. this.window.width = window.innerWidth;
  56. this.window.height = window.innerHeight;
  57. }
  58. },
  59. watch: {
  60. window: function () {
  61. this.styleObject.color ='blue';
  62. }
  63. }
  64. };
  65. Vue.component("reactive-chart", {
  66. props: ["chart"],
  67. template: '<div :ref="chart.uuid"></div>',
  68. mounted() {
  69. Plotly.newPlot(this.$refs[this.chart.uuid], this.chart.traces, this.chart.layout, {responsive: true});
  70. },
  71. watch: {
  72. chart: {
  73. handler: function() {
  74. Plotly.react(
  75. this.$refs[this.chart.uuid],
  76. this.chart.traces,
  77. this.chart.layout
  78. );
  79. },
  80. deep: true
  81. }
  82. }
  83. });
  84. Vue.component('input-with-units',{
  85. // data: function() {return {value: 303.0}},
  86. watch: {
  87. value: {
  88. handler: function () {
  89. this.$emit('newdata',this.value);
  90. }
  91. },
  92. deep: true
  93. },
  94. props: ['title', 'units', 'value'],
  95. template: `
  96. <div class="field has-addons">
  97. <p class="control">
  98. <a class="button is-static" style="width:4rem">
  99. {{ title }}
  100. </a>
  101. </p>
  102. <p class="control">
  103. <b-input v-model="value" type="number" step="any" style="width:6rem"></b-input>
  104. </p>
  105. <p class="control">
  106. <a class="button is-static" style="width:3rem">
  107. {{ units }}
  108. </a>
  109. </p>
  110. </div>
  111. `
  112. })
  113. const app = new Vue(example);
  114. app.$mount('#app');