-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathjquery.flot.fastline.js
More file actions
83 lines (78 loc) · 2.27 KB
/
jquery.flot.fastline.js
File metadata and controls
83 lines (78 loc) · 2.27 KB
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
(function ($) {
"use strict";
var pluginName = "fastline", pluginVersion = "0.1";
var options = {
series: {
fastline: {
active: false,
show: false,
}
}
};
var defaultOptions = {
};
function init(plot) {
plot.hooks.processOptions.push(processOptions);
function processOptions(plot,options){
if(options.series.fastline.active){
plot.hooks.drawSeries.push(drawSeries);
}
}
function drawSeries(plot, ctx, serie){
if (serie.fastline.show) {
var offset = plot.getPlotOffset();
if (serie.xaxis.min!=undefined) {var x_min = serie.xaxis.min;}
else {var x_min = Math.min.apply(null, serie.data[0]);}
if (serie.xaxis.max!=undefined) {var x_max = serie.xaxis.max;}
else {var x_max = Math.max.apply(null, serie.data[0]);}
if (serie.yaxis.min!=undefined) {var y_min = serie.yaxis.min;}
else {var y_min = Math.min.apply(null, serie.data[1]);}
if (serie.yaxis.max!=undefined) {var y_max = serie.yaxis.max;}
else {var y_max = Math.max.apply(null, serie.data[1]);}
var dx = x_max - x_min;
var dy = y_max - y_min;
var np = serie.data[0].length;
var w = plot.width();
var h = plot.height();
// builds line
ctx.save();
ctx.beginPath();
ctx.lineWidth=1;
ctx.strokeStyle=serie.color;
var ox = offset.left;
var oh = h+offset.top;
var oy = offset.top;
var ow = w+offset.left;
var px = ox, py=oy;
var xscale = w/dx;
var yscale = h/dy;
var first = true;
var pnx = ox, pny = oh;
for (var i = 0; i < np; i++) {
px = ox + parseInt((serie.data[0][i]-x_min)*xscale);
py = oh - parseInt((serie.data[1][i]-y_min)*yscale);
if (pnx!=px || pny!=py) {
if (px>=ox && py>=oy && px<=ow && py<=oh) {
if (first) {
ctx.moveTo(px,py);
first = false;
} else {
ctx.lineTo(px,py);
}
pnx = px;
pny = py;
}
}
}
ctx.stroke();
ctx.restore();
}
}
}
$.plot.plugins.push({
init: init,
options: options,
name: pluginName,
version: pluginVersion
});
})(jQuery);