Home Reference Source

cables_dev/cables_ui/src/ui/glpatch/glgraph.js

  1. import { GlSplineDrawer } from "../gldraw/glsplinedrawer";
  2. export default class GlGraph
  3. {
  4. /**
  5. * @param {GlSplineDrawer} splineRenderer
  6. */
  7. constructor(splineRenderer)
  8. {
  9. this.numValues = 22;
  10. this._splineRenderer = splineRenderer;
  11. this._values = [];
  12. this._points = [];
  13. for (let i = 0; i < this.numValues; i++) this._values[i] = 0;
  14. for (let i = 0; i < this.numValues * 3; i++) this._points[i] = Math.random();
  15. this._scaleX = 6.01;
  16. this._scaleY = 31.01;
  17. this._width = 20;
  18. this._height = 10;
  19. this._idx = this._splineRenderer.getSplineIndex();
  20. this._splineRenderer.setSpline(this._idx, this._points);
  21. this._splineRenderer.setSplineColor(this._idx, [1, 1, 1, 1]);
  22. const z = 0.1;
  23. const zeroLine = this._splineRenderer.getSplineIndex();
  24. this._splineRenderer.setSpline(zeroLine, [0, 0, z, this._width * this._scaleX, 0, z]);
  25. this._splineRenderer.setSplineColor(zeroLine, [0.5, 0.5, 0.5, 1]);
  26. const upperLimitLine = this._splineRenderer.getSplineIndex();
  27. this._splineRenderer.setSpline(upperLimitLine, [0, this._height * this._scaleY, 0, this._width * this._scaleX, this._height * this._scaleY, 0]);
  28. this._splineRenderer.setSplineColor(upperLimitLine, [0.5, 0.5, 0.5, 1]);
  29. const leftLine = this._splineRenderer.getSplineIndex();
  30. this._splineRenderer.setSpline(leftLine, [0, 0, 0, 0, this._height * this._scaleY, 0]);
  31. this._splineRenderer.setSplineColor(leftLine, [0.5, 0.5, 0.5, 1]);
  32. const rightLine = this._splineRenderer.getSplineIndex();
  33. this._splineRenderer.setSpline(rightLine, [this._width * this._scaleX, 0, 0, this._width * this._scaleX, this._height * this._scaleY, 0]);
  34. this._splineRenderer.setSplineColor(rightLine, [0.5, 0.5, 0.5, 1]);
  35. this._splineRenderer.setWidth(0.12);
  36. }
  37. set(value)
  38. {
  39. // const points = [];
  40. // const start = Math.floor(this._anim.getLength() - 10);
  41. // for (let i = Math.floor(this._anim.getLength() * 10) / 10; i > 0; i -= 0.033)
  42. // {
  43. // const x = 10 * this._scaleX + (i) * this._scaleX;
  44. // if (x > 0) points.push(x, this._height * this._scaleY - this._anim.getValue(i) * this._scaleY, 0);
  45. // }
  46. // this._anim.clearBefore(time - 10);
  47. // this._splineRenderer.setSpline(this._idx, points);
  48. // this._anim.setValue(time, value);
  49. for (let i = this._values.length - 1; i > 0; i--)
  50. {
  51. this._values[i] = this._values[i - 1];
  52. }
  53. this._values[0] = value;
  54. // this._values.push(value);
  55. const points = [];
  56. for (let i = 0; i < this._values.length; i++)
  57. {
  58. points.push(i * this._scaleX, this._height * this._scaleY - this._values[i] * this._scaleY, 0);
  59. // points.push((i + 1) * this._scaleX, this._height * this._scaleY - this._values[i] * this._scaleY, 0);
  60. }
  61. this._splineRenderer.setSpline(this._idx, points);
  62. // this._splineRenderer.setSplineColor(this._idx, [0.5, 0.5, 0.5, 1]);
  63. }
  64. /**
  65. * @param {number} resX
  66. * @param {number} resY
  67. * @param {number} scrollX
  68. * @param {number} scrollY
  69. * @param {number} zoom
  70. */
  71. render(resX, resY, scrollX, scrollY, zoom)
  72. {
  73. this._splineRenderer.render(resX, resY, scrollX, scrollY, zoom);
  74. }
  75. }