Update synchronize gallery demo
[dygraphs.git] / tests / custom-circles.html
CommitLineData
773d1312
RK
1<!DOCTYPE html>
2<html>
3 <head>
4 <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7; IE=EmulateIE9">
240c0b11 5 <title>Custom Circles</title>
773d1312
RK
6 <!--[if IE]>
7 <script type="text/javascript" src="../excanvas.js"></script>
8 <![endif]-->
9 <!--
10 For production (minified) code, use:
11 <script type="text/javascript" src="dygraph-combined.js"></script>
12 -->
13 <script type="text/javascript" src="../dygraph-dev.js"></script>
b7a1dc22 14 <script type="text/javascript" src="../extras/shapes.js"></script>
773d1312
RK
15
16 </head>
17 <body>
240c0b11 18 <h2>Custom circles and hover circles</h2>
773d1312
RK
19
20 <script type="text/javascript">
a7803eea
KW
21 // Simple version
22 var div = document.createElement('div');
23 document.body.appendChild(div);
24
25 var data = 'x,A,B\n' +
26 '1,1,2\n' +
27 '2,2,4\n' +
28 '3,3,6\n' +
29 '4,4,8\n' +
30 '5,5,7\n';
31 var g = new Dygraph(div, data, {
32 drawPoints : true,
33 pointSize : 5,
34 highlightCircleSize: 8,
30abcfb6
RK
35 series : {
36 A : {
37 drawPointCallback : Dygraph.Circles.TRIANGLE,
38 drawHighlightPointCallback : Dygraph.Circles.TRIANGLE
39 },
40 B : {
41 drawPointCallback : Dygraph.Circles.HEXAGON,
42 drawHighlightPointCallback : Dygraph.Circles.HEXAGON
43 }
a7803eea
KW
44 }
45 });
46
47
48 // Fancy demos
240c0b11
RK
49 var smile = function(g, series, ctx, cx, cy, color, radius) {
50 mouthlessFace(g, series, ctx, cx, cy, color, radius);
773d1312 51
240c0b11
RK
52 ctx.fillStyle = "#000000";
53 ctx.beginPath();
54 ctx.arc(cx, cy, radius - 2, .3, Math.PI - .3, false);
55 ctx.stroke();
56 };
57
58 var frown = function(g, series, ctx, cx, cy, color, radius) {
59 mouthlessFace(g, series, ctx, cx, cy, color, radius);
60
a8ef67a8 61 ctx.lineWidth = 1;
240c0b11
RK
62 ctx.fillStyle = "#000000";
63 ctx.beginPath();
4ab51f75 64 ctx.arc(cx, cy + radius, radius - 2, Math.PI + .3, -.3, false);
240c0b11
RK
65 ctx.stroke();
66 };
773d1312 67
240c0b11 68 var mouthlessFace = function(g, series, ctx, cx, cy, color, radius) {
a8ef67a8 69 ctx.lineWidth = 1;
240c0b11
RK
70 ctx.strokeStyle = "#000000";
71 ctx.fillStyle = "#FFFF00";
72 ctx.beginPath();
73 ctx.arc(cx, cy, radius, Math.PI * 2, false);
74 ctx.closePath();
75 ctx.stroke();
76 ctx.fill();
773d1312 77
240c0b11
RK
78 ctx.fillStyle = "#000000";
79 ctx.beginPath();
80 ctx.arc(cx - (radius / 3) , cy - (radius / 4), 1, Math.PI * 2, false);
81 ctx.closePath();
82 ctx.stroke();
83 ctx.fill();
773d1312 84
240c0b11
RK
85 ctx.beginPath();
86 ctx.arc(cx + (radius / 3) , cy - (radius / 4), 1, Math.PI * 2, false);
87 ctx.closePath();
88 ctx.stroke();
89 ctx.fill();
90 };
91
a7803eea 92 var makeGraph = function(title, yFunc, extraOpts) {
30b2bf7d
KW
93 var opts = {
94 drawPoints : true,
95 pointSize : 5
96 };
97
98 var shapes = [];
a7803eea 99 var addShape = function(name, pointFn, highlightPointFn) {
30b2bf7d 100 shapes.push(name);
27fd63fc
DV
101 if (!opts['series']) opts['series'] = {};
102 opts.series[name] = {
a7803eea
KW
103 drawPointCallback: pointFn,
104 drawHighlightPointCallback: highlightPointFn
30b2bf7d
KW
105 };
106 };
107
108 for (var shape in Dygraph.Circles) {
109 if (!Dygraph.Circles.hasOwnProperty(shape)) continue;
110 var fn = Dygraph.Circles[shape];
111 if (typeof fn !== 'function') continue;
112 addShape(shape.toLowerCase(), fn, fn);
113 };
114 addShape('custom', frown, smile);
115
116 for (var key in extraOpts) {
117 if (extraOpts.hasOwnProperty(key)) {
118 opts[key] = extraOpts[key];
119 }
120 };
773d1312 121
a7803eea
KW
122 var header = document.createElement('h3');
123 header.appendChild(document.createTextNode(title));
124 document.body.appendChild(header);
125
30b2bf7d
KW
126 var div = document.createElement('div');
127 document.body.appendChild(div);
a7803eea 128
30b2bf7d
KW
129 var g = new Dygraph(
130 div,
131 function() {
132 var r = "xval," + shapes.join(',') + "\n";
133 var n = shapes.length;
240c0b11
RK
134 for (var i=1; i<=20; i++) {
135 r += i;
30b2bf7d
KW
136 for (var j = 0; j < n; j++) {
137 r += "," + yFunc(i, j, n);
240c0b11
RK
138 }
139 r += "\n";
140 }
141 return r;
30b2bf7d
KW
142 }, opts);
143 };
144
145 makeGraph(
a7803eea 146 "Gallery of predefined shapes, adding a custom shape:",
30b2bf7d
KW
147 function(x, c, n) {
148 return x / 3 + c * 10;
149 }, {
150 highlightCircleSize : 8
151 });
152 makeGraph(
a7803eea 153 "With interactive per-series highlighting:",
30b2bf7d
KW
154 function(x, c, n) {
155 return Math.sin(x * c / n);
156 }, {
157 strokeBorderWidth: 2,
158 highlightSeriesOpts: {
159 pointSize: 6,
160 highlightCircleSize: 10,
161 strokeWidth: 2,
162 }});
773d1312
RK
163 </script>
164</body>
3fdc648d 165</html>