4 <title>Custom Circles
</title>
6 For production (minified) code, use:
7 <script type=
"text/javascript" src=
"dygraph-combined.js"></script>
9 <script type=
"text/javascript" src=
"../dygraph-dev.js"></script>
10 <script type=
"text/javascript" src=
"../src/extras/shapes.js"></script>
14 <h2>Custom circles and hover circles
</h2>
16 <script type=
"text/javascript">
18 var div = document.createElement('div');
19 document.body.appendChild(div);
21 var data = 'x,A,B
\n' +
27 var g = new Dygraph(div, data, {
30 highlightCircleSize:
8,
33 drawPointCallback : Dygraph.Circles.TRIANGLE,
34 drawHighlightPointCallback : Dygraph.Circles.TRIANGLE
37 drawPointCallback : Dygraph.Circles.HEXAGON,
38 drawHighlightPointCallback : Dygraph.Circles.HEXAGON
45 var smile = function(g, series, ctx, cx, cy, color, radius) {
46 mouthlessFace(g, series, ctx, cx, cy, color, radius);
48 ctx.fillStyle =
"#000000";
50 ctx.arc(cx, cy, radius -
2,
.3, Math.PI -
.3, false);
54 var frown = function(g, series, ctx, cx, cy, color, radius) {
55 mouthlessFace(g, series, ctx, cx, cy, color, radius);
58 ctx.fillStyle =
"#000000";
60 ctx.arc(cx, cy + radius, radius -
2, Math.PI +
.3, -
.3, false);
64 var mouthlessFace = function(g, series, ctx, cx, cy, color, radius) {
66 ctx.strokeStyle =
"#000000";
67 ctx.fillStyle =
"#FFFF00";
69 ctx.arc(cx, cy, radius, Math.PI *
2, false);
74 ctx.fillStyle =
"#000000";
76 ctx.arc(cx - (radius /
3) , cy - (radius /
4),
1, Math.PI *
2, false);
82 ctx.arc(cx + (radius /
3) , cy - (radius /
4),
1, Math.PI *
2, false);
88 var makeGraph = function(title, yFunc, extraOpts) {
95 var addShape = function(name, pointFn, highlightPointFn) {
97 if (!opts['series']) opts['series'] = {};
99 drawPointCallback: pointFn,
100 drawHighlightPointCallback: highlightPointFn
104 for (var shape in Dygraph.Circles) {
105 if (!Dygraph.Circles.hasOwnProperty(shape)) continue;
106 var fn = Dygraph.Circles[shape];
107 if (typeof fn !== 'function') continue;
108 addShape(shape.toLowerCase(), fn, fn);
110 addShape('custom', frown, smile);
112 for (var key in extraOpts) {
113 if (extraOpts.hasOwnProperty(key)) {
114 opts[key] = extraOpts[key];
118 var header = document.createElement('h3');
119 header.appendChild(document.createTextNode(title));
120 document.body.appendChild(header);
122 var div = document.createElement('div');
123 document.body.appendChild(div);
128 var r =
"xval," + shapes.join(',') +
"\n";
129 var n = shapes.length;
130 for (var i=
1; i<=
20; i++) {
132 for (var j =
0; j < n; j++) {
133 r +=
"," + yFunc(i, j, n);
142 "Gallery of predefined shapes, adding a custom shape:",
144 return x /
3 + c *
10;
146 highlightCircleSize :
8
149 "With interactive per-series highlighting:",
151 return Math.sin(x * c / n);
153 strokeBorderWidth:
2,
154 highlightSeriesOpts: {
156 highlightCircleSize:
10,