| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
(function ($) { |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
var square = function (ctx, x, y, radius, shadow) { |
| 21 |
|
| 22 |
var size = radius * Math.sqrt(Math.PI) / 2; |
| 23 |
ctx.rect(x - size, y - size, size + size, size + size); |
| 24 |
}, |
| 25 |
rectangle = function (ctx, x, y, radius, shadow) { |
| 26 |
|
| 27 |
var size = radius * Math.sqrt(Math.PI) / 2; |
| 28 |
ctx.rect(x - size, y - size, size + size, size + size); |
| 29 |
}, |
| 30 |
diamond = function (ctx, x, y, radius, shadow) { |
| 31 |
|
| 32 |
var size = radius * Math.sqrt(Math.PI / 2); |
| 33 |
ctx.moveTo(x - size, y); |
| 34 |
ctx.lineTo(x, y - size); |
| 35 |
ctx.lineTo(x + size, y); |
| 36 |
ctx.lineTo(x, y + size); |
| 37 |
ctx.lineTo(x - size, y); |
| 38 |
ctx.lineTo(x, y - size); |
| 39 |
}, |
| 40 |
triangle = function (ctx, x, y, radius, shadow) { |
| 41 |
|
| 42 |
var size = radius * Math.sqrt(2 * Math.PI / Math.sin(Math.PI / 3)); |
| 43 |
var height = size * Math.sin(Math.PI / 3); |
| 44 |
ctx.moveTo(x - size / 2, y + height / 2); |
| 45 |
ctx.lineTo(x + size / 2, y + height / 2); |
| 46 |
if (!shadow) { |
| 47 |
ctx.lineTo(x, y - height / 2); |
| 48 |
ctx.lineTo(x - size / 2, y + height / 2); |
| 49 |
ctx.lineTo(x + size / 2, y + height / 2); |
| 50 |
} |
| 51 |
}, |
| 52 |
cross = function (ctx, x, y, radius, shadow) { |
| 53 |
|
| 54 |
var size = radius * Math.sqrt(Math.PI) / 2; |
| 55 |
ctx.moveTo(x - size, y - size); |
| 56 |
ctx.lineTo(x + size, y + size); |
| 57 |
ctx.moveTo(x - size, y + size); |
| 58 |
ctx.lineTo(x + size, y - size); |
| 59 |
}, |
| 60 |
ellipse = function(ctx, x, y, radius, shadow, fill) { |
| 61 |
if (!shadow) { |
| 62 |
ctx.moveTo(x + radius, y); |
| 63 |
ctx.arc(x, y, radius, 0, Math.PI * 2, false); |
| 64 |
} |
| 65 |
}, |
| 66 |
plus = function (ctx, x, y, radius, shadow) { |
| 67 |
var size = radius * Math.sqrt(Math.PI / 2); |
| 68 |
ctx.moveTo(x - size, y); |
| 69 |
ctx.lineTo(x + size, y); |
| 70 |
ctx.moveTo(x, y + size); |
| 71 |
ctx.lineTo(x, y - size); |
| 72 |
}, |
| 73 |
handlers = { |
| 74 |
square: square, |
| 75 |
rectangle: rectangle, |
| 76 |
diamond: diamond, |
| 77 |
triangle: triangle, |
| 78 |
cross: cross, |
| 79 |
ellipse: ellipse, |
| 80 |
plus: plus |
| 81 |
}; |
| 82 |
|
| 83 |
square.fill = true; |
| 84 |
rectangle.fill = true; |
| 85 |
diamond.fill = true; |
| 86 |
triangle.fill = true; |
| 87 |
ellipse.fill = true; |
| 88 |
|
| 89 |
function init(plot) { |
| 90 |
plot.drawSymbol = handlers; |
| 91 |
} |
| 92 |
|
| 93 |
$.plot.plugins.push({ |
| 94 |
init: init, |
| 95 |
name: 'symbols', |
| 96 |
version: '1.0' |
| 97 |
}); |
| 98 |
})(jQuery); |