PluginProbe
Contact Forms by Cimatti / 1.1
Contact Forms by Cimatti v1.1
2.3.6 2.3.5 2.3.0 2.2.32 2.2.4 2.2.0 2.1.2 2.1.1 trunk 1.0 1.1 1.2 1.2.1 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 All 62 releases
contact-forms / flot / jquery.flot.symbol.js

jquery.flot.symbol.js in Contact Forms by Cimatti 1.1, at flot/jquery.flot.symbol.js

71 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /*
2 Flot plugin that adds some extra symbols for plotting points.
3
4 The symbols are accessed as strings through the standard symbol
5 choice:
6
7 series: {
8 points: {
9 symbol: "square" // or "diamond", "triangle", "cross"
10 }
11 }
12
13 */
14
15 (function ($) {
16 function processRawData(plot, series, datapoints) {
17 // we normalize the area of each symbol so it is approximately the
18 // same as a circle of the given radius
19
20 var handlers = {
21 square: function (ctx, x, y, radius, shadow) {
22 // pi * r^2 = (2s)^2 => s = r * sqrt(pi)/2
23 var size = radius * Math.sqrt(Math.PI) / 2;
24 ctx.rect(x - size, y - size, size + size, size + size);
25 },
26 diamond: function (ctx, x, y, radius, shadow) {
27 // pi * r^2 = 2s^2 => s = r * sqrt(pi/2)
28 var size = radius * Math.sqrt(Math.PI / 2);
29 ctx.moveTo(x - size, y);
30 ctx.lineTo(x, y - size);
31 ctx.lineTo(x + size, y);
32 ctx.lineTo(x, y + size);
33 ctx.lineTo(x - size, y);
34 },
35 triangle: function (ctx, x, y, radius, shadow) {
36 // pi * r^2 = 1/2 * s^2 * sin (pi / 3) => s = r * sqrt(2 * pi / sin(pi / 3))
37 var size = radius * Math.sqrt(2 * Math.PI / Math.sin(Math.PI / 3));
38 var height = size * Math.sin(Math.PI / 3);
39 ctx.moveTo(x - size/2, y + height/2);
40 ctx.lineTo(x + size/2, y + height/2);
41 if (!shadow) {
42 ctx.lineTo(x, y - height/2);
43 ctx.lineTo(x - size/2, y + height/2);
44 }
45 },
46 cross: function (ctx, x, y, radius, shadow) {
47 // pi * r^2 = (2s)^2 => s = r * sqrt(pi)/2
48 var size = radius * Math.sqrt(Math.PI) / 2;
49 ctx.moveTo(x - size, y - size);
50 ctx.lineTo(x + size, y + size);
51 ctx.moveTo(x - size, y + size);
52 ctx.lineTo(x + size, y - size);
53 }
54 }
55
56 var s = series.points.symbol;
57 if (handlers[s])
58 series.points.symbol = handlers[s];
59 }
60
61 function init(plot) {
62 plot.hooks.processDatapoints.push(processRawData);
63 }
64
65 $.plot.plugins.push({
66 init: init,
67 name: 'symbols',
68 version: '1.0'
69 });
70 })(jQuery);
71