2
0

objects_chart_ScatterGraph.js.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JSDoc: Source: objects/chart/ScatterGraph.js</title>
  6. <script src="scripts/prettify/prettify.js"> </script>
  7. <script src="scripts/prettify/lang-css.js"> </script>
  8. <!--[if lt IE 9]>
  9. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  10. <![endif]-->
  11. <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
  12. <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
  13. </head>
  14. <body>
  15. <div id="main">
  16. <h1 class="page-title">Source: objects/chart/ScatterGraph.js</h1>
  17. <section>
  18. <article>
  19. <pre class="prettyprint source linenums"><code>import {Object2D} from "../../Object2D.js";
  20. import {Graph} from "./Graph.js";
  21. /**
  22. * Scatter graph can be used to draw numeric data as points.
  23. *
  24. * @class
  25. * @extends {Object2D}
  26. */
  27. function ScatterGraph()
  28. {
  29. Graph.call(this);
  30. /**
  31. * Radius of each point represented in the scatter plot.
  32. *
  33. * @type {number}
  34. */
  35. this.radius = 5.0;
  36. /**
  37. * Draw lines betwen the points of the scatter graph.
  38. *
  39. * @type {boolean}
  40. */
  41. this.drawLine = false;
  42. }
  43. ScatterGraph.prototype = Object.create(Graph.prototype);
  44. ScatterGraph.prototype.constructor = ScatterGraph;
  45. ScatterGraph.prototype.type = "BarGraph";
  46. Object2D.register(ScatterGraph, "BarGraph");
  47. ScatterGraph.prototype.draw = function(context, viewport, canvas)
  48. {
  49. if(this.data.length === 0)
  50. {
  51. return;
  52. }
  53. var width = this.box.max.x - this.box.min.x;
  54. var height = this.box.max.y - this.box.min.y;
  55. var step = width / (this.data.length - 1);
  56. var gamma = this.max - this.min;
  57. context.lineWidth = this.lineWidth;
  58. // Draw line
  59. if(this.drawLine)
  60. {
  61. context.beginPath();
  62. context.moveTo(this.box.min.x, this.box.max.y - ((this.data[0] - this.min) / gamma) * height);
  63. for(var i = 1, s = step; i &lt; this.data.length; s += step, i++)
  64. {
  65. context.lineTo(this.box.min.x + s, this.box.max.y - ((this.data[i] - this.min) / gamma) * height);
  66. }
  67. if(this.strokeStyle !== null)
  68. {
  69. context.strokeStyle = this.strokeStyle.get(context);
  70. context.stroke();
  71. }
  72. }
  73. // Draw circles
  74. context.beginPath();
  75. for(var i = 0, s = 0; i &lt; this.data.length; s += step, i++)
  76. {
  77. var y = this.box.max.y - ((this.data[i] - this.min) / gamma) * height;
  78. context.moveTo(this.box.min.x + s + this.radius, y);
  79. context.arc(this.box.min.x + s, y, this.radius, 0, Math.PI * 2, true);
  80. }
  81. if(this.strokeStyle !== null)
  82. {
  83. context.strokeStyle = this.strokeStyle.get(context);
  84. context.stroke();
  85. }
  86. if(this.fillStyle !== null)
  87. {
  88. context.fillStyle = this.fillStyle.get(context);
  89. context.fill();
  90. }
  91. };
  92. ScatterGraph.prototype.serialize = function(recursive)
  93. {
  94. var data = Graph.prototype.serialize.call(this, recursive);
  95. data.radius = this.radius;
  96. return data;
  97. };
  98. ScatterGraph.prototype.parse = function(data, root)
  99. {
  100. Graph.prototype.parse.call(this, data, root);
  101. this.radius = data.radius;
  102. };
  103. export {ScatterGraph};
  104. </code></pre>
  105. </article>
  106. </section>
  107. </div>
  108. <nav>
  109. <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="AnimationTimer.html">AnimationTimer</a></li><li><a href="BarGraph.html">BarGraph</a></li><li><a href="BezierCurve.html">BezierCurve</a></li><li><a href="Box.html">Box</a></li><li><a href="Box2.html">Box2</a></li><li><a href="BoxMask.html">BoxMask</a></li><li><a href="Circle.html">Circle</a></li><li><a href="ColorStyle.html">ColorStyle</a></li><li><a href="DOM.html">DOM</a></li><li><a href="EventManager.html">EventManager</a></li><li><a href="FileUtils.html">FileUtils</a></li><li><a href="Gauge.html">Gauge</a></li><li><a href="GradientColorStop.html">GradientColorStop</a></li><li><a href="GradientStyle.html">GradientStyle</a></li><li><a href="Graph.html">Graph</a></li><li><a href="Helpers.html">Helpers</a></li><li><a href="Image.html">Image</a></li><li><a href="Key.html">Key</a></li><li><a href="Line.html">Line</a></li><li><a href="LinearGradientStyle.html">LinearGradientStyle</a></li><li><a href="Mask.html">Mask</a></li><li><a href="Matrix.html">Matrix</a></li><li><a href="MultiLineText.html">MultiLineText</a></li><li><a href="Node.html">Node</a></li><li><a href="NodeConnector.html">NodeConnector</a></li><li><a href="NodeGraph.html">NodeGraph</a></li><li><a href="NodeSocket.html">NodeSocket</a></li><li><a href="Object2D.html">Object2D</a></li><li><a href="Path.html">Path</a></li><li><a href="Pattern.html">Pattern</a></li><li><a href="PatternStyle.html">PatternStyle</a></li><li><a href="PieChart.html">PieChart</a></li><li><a href="Pointer.html">Pointer</a></li><li><a href="QuadraticCurve.html">QuadraticCurve</a></li><li><a href="RadialGradientStyle.html">RadialGradientStyle</a></li><li><a href="Renderer.html">Renderer</a></li><li><a href="RoundedBox.html">RoundedBox</a></li><li><a href="ScatterGraph.html">ScatterGraph</a></li><li><a href="Style.html">Style</a></li><li><a href="Text.html">Text</a></li><li><a href="UUID.html">UUID</a></li><li><a href="Vector2.html">Vector2</a></li><li><a href="Viewport.html">Viewport</a></li><li><a href="ViewportControls.html">ViewportControls</a></li></ul><h3>Global</h3><ul><li><a href="global.html#writeFile">writeFile</a></li></ul>
  110. </nav>
  111. <br class="clear">
  112. <footer>
  113. Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Sat Sep 17 2022 14:24:36 GMT+0100 (Hora de verão da Europa Ocidental)
  114. </footer>
  115. <script> prettyPrint(); </script>
  116. <script src="scripts/linenumber.js"> </script>
  117. </body>
  118. </html>