-
Notifications
You must be signed in to change notification settings - Fork 2
/
ScatterMarkerRenderer.js
85 lines (71 loc) · 2.71 KB
/
ScatterMarkerRenderer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
(function($){
// class: $.jqplot.MarkerRenderer
// The default jqPlot marker renderer, rendering the points on the line.
$.jqplot.ScatterMarkerRenderer = function(options){
// Group: Properties
// prop: show
// wether or not to show the marker.
this.show = true;
// prop: style
// One of diamond, circle, square, x, plus, dash, filledDiamond, filledCircle, filledSquare
this.style = 'scatter';
// prop: size
// Size of the marker (diameter or circle, length of edge of square, etc.)
this.defaultSize = 0.3;
this.size = [];
this.allowZero = false;
this.sizeMultiplier = 10;
this.printSize = true;
// prop: color
// color of marker. Will be set to color of series by default on init.
this.color = '#666666';
// prop: shapeRenderer
// Renderer that will draw the marker.
this.shapeRenderer = new $.jqplot.ShapeRenderer();
$.extend(true, this, options);
};
$.jqplot.ScatterMarkerRenderer.prototype.init = function(options) {
$.extend(true, this, options);
var shopt = {fill:false, isarc:false, strokeStyle:this.color, fillStyle:this.color, lineWidth:this.lineWidth, closePath:true};
shopt.fill = true;
shopt.closePath = false;
shopt.isarc = true;
this.shapeRenderer.init(shopt);
};
$.jqplot.ScatterMarkerRenderer.prototype.drawScatter = function(point, x, y, ctx, fill, options) {
if (this.size[point] == 0)
{
var radius = (this.allowZero == true)? 0 : this.defaultSize / 2;
} else if (this.size[point] > 0) {
var radius = this.size[point] / 2;
} else {
var radius = this.defaultSize / 2;
}
radius = radius * this.sizeMultiplier;
var end = 2*Math.PI;
var points = [x, y, radius, 0, end, true];
if (this.shadow) {
this.shadowRenderer.draw(ctx, points);
}
this.shapeRenderer.draw(ctx, points, options);
if (this.printSize == true)
{
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "12px sans-serif";
ctx.fillText(this.size[point],x,y);
}
ctx.restore();
};
$.jqplot.CustomMarkerRenderer.prototype.draw = function(point, x, y, ctx, options) {
options = options || {};
switch (this.style) {
case 'scatter':
this.drawScatter(point,x,y,ctx,true,options);
break;
default:
throw "Only scatter style may be used"
break;
}
};
})(jQuery);