4 <link rel=
"stylesheet" href=
"../dist/dygraph.css">
5 <title>Custom Circles
</title>
6 <script type=
"text/javascript" src=
"../dist/dygraph.js"></script>
7 <script type=
"text/javascript" src=
"../src/extras/shapes.js"></script>
11 <h2>Custom circles and hover circles
</h2>
13 <script type=
"text/javascript">
15 var div = document.createElement('div');
16 document.body.appendChild(div);
18 var data = 'x,A,B
\n' +
24 var g = new Dygraph(div, data, {
27 highlightCircleSize:
8,
30 drawPointCallback : Dygraph.Circles.TRIANGLE,
31 drawHighlightPointCallback : Dygraph.Circles.TRIANGLE
34 drawPointCallback : Dygraph.Circles.HEXAGON,
35 drawHighlightPointCallback : Dygraph.Circles.HEXAGON
42 var smile = function(g, series, ctx, cx, cy, color, radius) {
43 mouthlessFace(g, series, ctx, cx, cy, color, radius);
45 ctx.fillStyle =
"#000000";
47 ctx.arc(cx, cy, radius -
2,
.3, Math.PI -
.3, false);
51 var frown = function(g, series, ctx, cx, cy, color, radius) {
52 mouthlessFace(g, series, ctx, cx, cy, color, radius);
55 ctx.fillStyle =
"#000000";
57 ctx.arc(cx, cy + radius, radius -
2, Math.PI +
.3, -
.3, false);
61 var mouthlessFace = function(g, series, ctx, cx, cy, color, radius) {
63 ctx.strokeStyle =
"#000000";
64 ctx.fillStyle =
"#FFFF00";
66 ctx.arc(cx, cy, radius, Math.PI *
2, false);
71 ctx.fillStyle =
"#000000";
73 ctx.arc(cx - (radius /
3) , cy - (radius /
4),
1, Math.PI *
2, false);
79 ctx.arc(cx + (radius /
3) , cy - (radius /
4),
1, Math.PI *
2, false);
85 var makeGraph = function(title, yFunc, extraOpts) {
92 var addShape = function(name, pointFn, highlightPointFn) {
94 if (!opts['series']) opts['series'] = {};
96 drawPointCallback: pointFn,
97 drawHighlightPointCallback: highlightPointFn
101 for (var shape in Dygraph.Circles) {
102 if (!Dygraph.Circles.hasOwnProperty(shape)) continue;
103 var fn = Dygraph.Circles[shape];
104 if (typeof fn !== 'function') continue;
105 addShape(shape.toLowerCase(), fn, fn);
107 addShape('custom', frown, smile);
109 for (var key in extraOpts) {
110 if (extraOpts.hasOwnProperty(key)) {
111 opts[key] = extraOpts[key];
115 var header = document.createElement('h3');
116 header.appendChild(document.createTextNode(title));
117 document.body.appendChild(header);
119 var div = document.createElement('div');
120 document.body.appendChild(div);
125 var r =
"xval," + shapes.join(',') +
"\n";
126 var n = shapes.length;
127 for (var i=
1; i<=
20; i++) {
129 for (var j =
0; j < n; j++) {
130 r +=
"," + yFunc(i, j, n);
139 "Gallery of predefined shapes, adding a custom shape:",
141 return x /
3 + c *
10;
143 highlightCircleSize :
8
146 "With interactive per-series highlighting:",
148 return Math.sin(x * c / n);
150 strokeBorderWidth:
2,
151 highlightSeriesOpts: {
153 highlightCircleSize:
10,