소스 검색

Draw line in scatter plt

tentone 4 년 전
부모
커밋
43c563b70d
1개의 변경된 파일25개의 추가작업 그리고 0개의 파일을 삭제
  1. 25 0
      source/objects/chart/ScatterGraph.js

+ 25 - 0
source/objects/chart/ScatterGraph.js

@@ -15,6 +15,11 @@ function ScatterGraph()
 	 * Radius of each point represented in the scatter plot.
 	 * Radius of each point represented in the scatter plot.
 	 */
 	 */
 	this.radius = 5.0;
 	this.radius = 5.0;
+
+	/**
+	 * Draw lines betwen the points of the scatter graph.
+	 */
+	this.drawLine = false;
 }
 }
 
 
 ScatterGraph.prototype = Object.create(Graph.prototype);
 ScatterGraph.prototype = Object.create(Graph.prototype);
@@ -36,6 +41,26 @@ ScatterGraph.prototype.draw = function(context, viewport, canvas)
 	var gamma = this.max - this.min;
 	var gamma = this.max - this.min;
 
 
 	context.lineWidth = this.lineWidth;
 	context.lineWidth = this.lineWidth;
+	
+	// Draw line
+	if(this.drawLine)
+	{
+		context.beginPath();
+		context.moveTo(this.box.min.x, this.box.max.y - ((this.data[0] - this.min) / gamma) * height);
+		
+		for(var i = 1, s = step; i < this.data.length; s += step, i++)
+		{
+			context.lineTo(this.box.min.x + s, this.box.max.y - ((this.data[i] - this.min) / gamma) * height);
+		}
+	
+		if(this.strokeStyle !== null)
+		{
+			context.strokeStyle = this.strokeStyle.get(context);
+			context.stroke();
+		}
+	}
+
+	// Draw circles
 	context.beginPath();
 	context.beginPath();
 
 
 	for(var i = 0, s = 0; i < this.data.length; s += step, i++)
 	for(var i = 0, s = 0; i < this.data.length; s += step, i++)