var html = "";
for (var i = 0; i < ann.length; i++) {
var name = nameAnnotation(ann[i]);
- html += "<span id='" + name + "'>"
- html += name + ": " + (ann[i].shortText || '(icon)')
+ html += "<span id='" + name + "'>";
+ html += name + ": " + (ann[i].shortText || '(icon)');
html += " -> " + ann[i].text + "</span><br/>";
}
document.getElementById("list").innerHTML = html;
- }
- }
+ }
+ }
);
-
+
var last_ann = 0;
annotations = [];
for (var x = 10; x < 15; x += 2) {
}
} );
g.setAnnotations(annotations);
-
+
document.getElementById('add').onclick = function() {
var x = last_ann + 2;
var annnotations = g.annotations();
} );
last_ann = x;
g.setAnnotations(annotations);
- }
+ };
var bottom = document.getElementById('bottom');
bottom.onclick = function() {
var to_bottom = bottom.textContent == 'Shove to bottom';
-
+
var anns = g.annotations();
for (var i = 0; i < anns.length; i++) {
anns[i].attachAtBottom = to_bottom;
}
g.setAnnotations(anns);
-
+
if (to_bottom) {
bottom.textContent = 'Lift back up';
} else {
bottom.textContent = 'Shove to bottom';
}
- }
-
+ };
+
var saveBg = '';
var num = 0;
g.updateOptions( {
"2008-05-10,0\n" +
"2008-05-11,3\n" +
"2008-05-12,4\n"
- )
+ );
var g2 = new Dygraph(document.getElementById("graphd2"),
"Date,Temperature\n" +
"2008-05-07,0\n" +
{
stepPlot: true
}
- )
+ );
var g3 = new Dygraph(document.getElementById("graph3"),
"Date,Temperature\n" +
"2008-05-07,0\n" +
{
avoidMinZero: true
}
- )
+ );
var g4 = new Dygraph(document.getElementById("graphd4"),
"Date,Temperature\n" +
"2008-05-07,0\n" +
stepPlot: true,
avoidMinZero: true
}
- )
+ );
}
});
var showLabels = document.getElementById('showLabels');
showLabels.onclick = function() {
g.updateOptions({showLabelsOnHighlight: showLabels.checked});
- }
+ };
var s = document.getElementById("status");
var clearStatus = function() {
s.innerHTML = '';
- }
+ };
document.getElementById('clear').onclick = clearStatus;
var g = null;
['#284785', '#EE1111', '#8AE234'],
['#444444', '#888888', '#DDDDDD'],
null
- ]
+ ];
chart = new Dygraph(document.getElementById("blah"),
"X,a,b,c\n" +
"10,12345,23456,34567\n" +
"2009-08-15,9135.34;9496.28;9580.63,4232.5768877934;4399.8072592826;4438.88821965029\n" +
"2009-09-15,9280.67;9712.28;9829.87,4297.2232125907;4497.07133894216;4551.51896800004\n" +
"2009-10-15,9487.67;9712.73;10092.2,4388.84340147194;4492.9525342659;4668.48924723722\n";
-}
+};
run: function() {
var zoom = document.getElementById('tool_zoom');
- zoom.onclick = function() { change_tool(zoom) };
+ zoom.onclick = function() { change_tool(zoom); };
var pencil = document.getElementById('tool_pencil');
- pencil.onclick = function() { change_tool(pencil) };
+ pencil.onclick = function() { change_tool(pencil); };
var eraser = document.getElementById('tool_eraser');
- eraser.onclick = function() { change_tool(eraser) };
+ eraser.onclick = function() { change_tool(eraser); };
var start_date = new Date("2002/12/29").getTime();
var end_date = new Date().getTime();
var data = [];
for (var d = start_date; d < end_date; d += 604800 * 1000) {
var millis = d + 2 * 3600 * 1000;
- data.push( [ new Date(new Date(millis).strftime("%Y/%m/%d")), 50 ]);
+ data.push( [ new Date(Dygraph.dateString_(millis)), 50 ]);
}
-
+
var isDrawing = false;
var lastDrawRow = null, lastDrawValue = null;
var tool = 'pencil';
var valueRange = [0, 100];
-
+
function setPoint(event, g, context) {
var graphPos = Dygraph.findPos(g.graphDiv);
var canvasx = Dygraph.pageX(event) - graphPos.x;
closest_row = row;
}
}
-
+
if (closest_row != -1) {
if (lastDrawRow === null) {
lastDrawRow = closest_row;
var val = lastDrawValue + coeff * (row - lastDrawRow);
val = Math.max(valueRange[0], Math.min(val, valueRange[1]));
data[row][1] = val;
- if (val == null || isNaN(val)) console.log(val);
+ if (val === null || value === undefined || isNaN(val)) {
+ console.log(val);
+ }
} else if (tool == 'eraser') {
data[row][1] = null;
}
g.setSelection(closest_row); // prevents the dot from being finnicky.
}
}
-
+
function finishDraw() {
isDrawing = false;
lastDrawRow = null;
lastDrawValue = null;
}
-
+
var change_tool = function(tool_div) {
var ids = ['tool_zoom', 'tool_pencil', 'tool_eraser'];
for (var i = 0; i < ids.length; i++) {
}
}
tool = tool_div.id.replace('tool_', '');
-
+
var dg_div = document.getElementById("draw_div");
if (tool == 'pencil') {
dg_div.style.cursor = 'url(images/cursor-pencil.png) 2 30, auto';
} else if (tool == 'zoom') {
dg_div.style.cursor = 'crosshair';
}
- }
+ };
change_tool(document.getElementById("tool_pencil"));
-
+
g = new Dygraph(document.getElementById("draw_div"), data,
{
valueRange: valueRange,
var xOffset = g.toDomCoords(axis[0], null)[0];
var x = event.offsetX - xOffset;
var w = g.toDomCoords(axis[1], null)[0] - xOffset;
- var xPct = w == 0 ? 0 : (x / w);
-
+ var xPct = w === 0 ? 0 : (x / w);
+
var delta = axis[1] - axis[0];
var increment = delta * percentage;
var foo = [increment * xPct, increment * (1 - xPct)];
var dateWindow = [ axis[0] + foo[0], axis[1] - foo[1] ];
-
+
g.updateOptions({
dateWindow: dateWindow
});
avoidMinZero: false,
xRangePad: 3,
yRangePad: 10,
- drawAxesAtZero: true})};
+ drawAxesAtZero: true});
+ };
mode[1].onchange = function() {
updateGraphOpts({
avoidMinZero: true,
xRangePad: 0,
yRangePad: null,
- drawAxesAtZero: false})};
+ drawAxesAtZero: false});
+ };
mode[0].checked = true;
mode[0].onchange();
+/*jshint loopfunc:true */
var Gallery = {};
Gallery.entries = {};
innerDiv.textContent = demo.name;
div.onclick = function(demo, id) { return function() {
- if (Gallery.runningDemo != null) {
+ if (Gallery.runningDemo !== null) {
Gallery.runningDemo.innerDiv.className = "";
- if (Gallery.runningDemo.clean != null) {
+ if (Gallery.runningDemo.clean) {
Gallery.runningDemo.clean(Gallery.workareaChild);
}
}
javascriptLink.textContent = "Javascript";
var css = getCss(id);
+ var cssLink;
if (css) {
Gallery.create("span", codeSpan).textContent = " | ";
- var cssLink = Gallery.create("a", codeSpan);
+ cssLink = Gallery.create("a", codeSpan);
cssLink.textContent = "CSS";
}
var html = Gallery.workareaChild.innerHTML;
// tweak for use in jsfiddle
- javascript = " $(document).ready(" + javascript + "\n);"
+ javascript = " $(document).ready(" + javascript + "\n);";
jQuery('<textarea/>', { name: 'html' })
- .val(html)
- .hide()
- .appendTo(jsfs);
+ .val(html)
+ .hide()
+ .appendTo(jsfs);
jQuery('<textarea/>', { name: 'js' })
- .val(javascript)
- .hide()
- .appendTo(jsfs);
+ .val(javascript)
+ .hide()
+ .appendTo(jsfs);
if (css) {
jQuery('<textarea/>', { name: 'css' })
- .val(css)
- .hide()
- .appendTo(jsfs);
- }
+ .val(css)
+ .hide()
+ .appendTo(jsfs);
+ }
jQuery('<input/>', {
type: 'text',
name: 'title',
value: 'title tbd'
})
- .hide()
- .appendTo(jsfs);
+ .hide()
+ .appendTo(jsfs);
jQuery('<input/>', {
type: 'text',
name: 'description',
value: 'desc tbd'
})
- .hide()
- .appendTo(jsfs);
+ .hide()
+ .appendTo(jsfs);
htmlLink.onclick = function() {
Gallery.textarea.show("HTML", html);
Gallery.hashChange();
- window.onhashchange = Gallery.setHash;("hashchange", Gallery.hashChange, false);
+ window.onhashchange = Gallery.setHash;
};
var getCss = function(id) {
var rule = rules[j];
var cssText = rule.cssText;
var key = "#workarea #" + id + " ";
- if (cssText.indexOf(key) == 0) {
+ if (cssText.indexOf(key) === 0) {
arry.push(cssText.substr(key.length));
}
}
}
}
return "not found";
-}
+};
Gallery.register = function(id, demo) {
if (Gallery.entries[id]) {
Gallery.hashChange = function(event) {
if (location.hash) {
- if (location.hash.indexOf("#g/") == 0) {
+ if (location.hash.indexOf("#g/") === 0) {
var id = location.hash.substring(3) + "-toc";
var elem = document.getElementById(id);
elem.onclick();
return;
}
}
- Gallery.workareaChild.innerHTML = "<h3>Select a demo from the gallery on the left</h3>"
+ Gallery.workareaChild.innerHTML = "<h3>Select a demo from the gallery on the left</h3>";
};
highlightSeriesOpts: {
strokeWidth: 3,
strokeBorderWidth: 1,
- highlightCircleSize: 5,
- },
+ highlightCircleSize: 5
+ }
});
var onclick = function(ev) {
if (g.isSeriesLocked()) {
},
run: function() {
// Some sample data
- var data = "2011-01-01," + Math.random()*100 + "\n"
- + "2011-01-02," + Math.random()*100 + "\n"
- + "2011-01-03," + Math.random()*100 + "\n"
- + "2011-01-04," + Math.random()*100 + "\n"
- + "2011-01-05," + Math.random()*100 + "\n"
- + "2011-01-06," + Math.random()*100 + "\n"
- + "2011-01-07," + Math.random()*100 + "\n"
- + "2011-01-08," + Math.random()*100 + "\n"
- + "2011-01-09," + Math.random()*100 + "\n"
- + "2011-01-10," + Math.random()*100 + "\n"
- + "2011-01-11," + Math.random()*100 + "\n"
- + "2011-01-12," + Math.random()*100 + "\n"
- + "2011-01-13," + Math.random()*100 + "\n"
- + "2011-01-14," + Math.random()*100 + "\n"
- + "2011-01-15," + Math.random()*100 + "\n"
- + "2011-01-16," + Math.random()*100 + "\n"
- + "2011-01-17," + Math.random()*100 + "\n"
- + "2011-01-18," + Math.random()*100 + "\n"
- + "2011-01-19," + Math.random()*100 + "\n"
- + "2011-01-20," + Math.random()*100 + "\n"
- + "2011-01-21," + Math.random()*100 + "\n"
- + "2011-01-22," + Math.random()*100 + "\n"
- + "2011-01-23," + Math.random()*100 + "\n"
- + "2011-01-24," + Math.random()*100 + "\n"
- + "2011-01-25," + Math.random()*100 + "\n"
- + "2011-01-26," + Math.random()*100 + "\n"
- + "2011-01-27," + Math.random()*100 + "\n"
- + "2011-01-28," + Math.random()*100 + "\n"
- + "2011-01-29," + Math.random()*100 + "\n"
- + "2011-01-30," + Math.random()*100 + "\n"
- + "2011-01-31," + Math.random()*100 + "\n"
- ;
+ var data = "2011-01-01," + Math.random()*100 + "\n" +
+ "2011-01-02," + Math.random()*100 + "\n" +
+ "2011-01-03," + Math.random()*100 + "\n" +
+ "2011-01-04," + Math.random()*100 + "\n" +
+ "2011-01-05," + Math.random()*100 + "\n" +
+ "2011-01-06," + Math.random()*100 + "\n" +
+ "2011-01-07," + Math.random()*100 + "\n" +
+ "2011-01-08," + Math.random()*100 + "\n" +
+ "2011-01-09," + Math.random()*100 + "\n" +
+ "2011-01-10," + Math.random()*100 + "\n" +
+ "2011-01-11," + Math.random()*100 + "\n" +
+ "2011-01-12," + Math.random()*100 + "\n" +
+ "2011-01-13," + Math.random()*100 + "\n" +
+ "2011-01-14," + Math.random()*100 + "\n" +
+ "2011-01-15," + Math.random()*100 + "\n" +
+ "2011-01-16," + Math.random()*100 + "\n" +
+ "2011-01-17," + Math.random()*100 + "\n" +
+ "2011-01-18," + Math.random()*100 + "\n" +
+ "2011-01-19," + Math.random()*100 + "\n" +
+ "2011-01-20," + Math.random()*100 + "\n" +
+ "2011-01-21," + Math.random()*100 + "\n" +
+ "2011-01-22," + Math.random()*100 + "\n" +
+ "2011-01-23," + Math.random()*100 + "\n" +
+ "2011-01-24," + Math.random()*100 + "\n" +
+ "2011-01-25," + Math.random()*100 + "\n" +
+ "2011-01-26," + Math.random()*100 + "\n" +
+ "2011-01-27," + Math.random()*100 + "\n" +
+ "2011-01-28," + Math.random()*100 + "\n" +
+ "2011-01-29," + Math.random()*100 + "\n" +
+ "2011-01-30," + Math.random()*100 + "\n" +
+ "2011-01-31," + Math.random()*100 + "\n";
var g = new Dygraph(
document.getElementById("div_g"),
var w = min_data_x;
// starting on Sunday is a special case
- if (dow == 0) {
+ if (dow === 0) {
highlight_period(w,w+12*3600*1000);
}
// find first saturday
dow = d.getUTCDay();
}
// shift back 1/2 day to center highlight around the point for the day
- w -= 12*3600*1000;
+ w -= 12*3600*1000;
while (w < max_data_x) {
var start_x_highlight = w;
var end_x_highlight = w + 2*24*3600*1000;
g2 = new Dygraph(
document.getElementById('graph2'),
-'x,A,B \n' +
-'1,,3 \n' +
-'2,2, \n' +
-'3,,5 \n' +
-'4,4, \n' +
-'5,,7 \n' +
-'6,NaN, \n' +
-'8,8, \n' +
-'10,10, \n'
- , {
+ 'x,A,B \n' +
+ '1,,3 \n' +
+ '2,2, \n' +
+ '3,,5 \n' +
+ '4,4, \n' +
+ '5,,7 \n' +
+ '6,NaN, \n' +
+ '8,8, \n' +
+ '10,10, \n',
+ {
labels: ['x', 'A', 'B' ],
connectSeparatedPoints: true,
drawPoints: true
var h = g.toDomCoords(null, yar0[0])[1] - yOffset;
// Percentage from the left.
- var xPct = w == 0 ? 0 : (x / w);
+ var xPct = w === 0 ? 0 : (x / w);
// Percentage from the top.
- var yPct = h == 0 ? 0 : (y / h);
+ var yPct = h === 0 ? 0 : (y / h);
// The (1-) part below changes it from "% distance down from the top"
// to "% distance up from the bottom".
var yPct = percentages[1];
if (event.ctrlKey) {
- zoom(g, -.25, xPct, yPct);
+ zoom(g, -0.25, xPct, yPct);
} else {
- zoom(g, +.2, xPct, yPct);
+ zoom(g, +0.2, xPct, yPct);
}
}
for (var col = 1; col < 3; col++) {
// TODO(konigsberg): these will throw exceptions as data is removed.
var vals = g.getValue(row, col);
- if (vals == null) { continue; }
+ if (vals === null || vals === undefined) { continue; }
var val = vals[0];
var y = g.toDomCoords(null, val)[1];
var diff2 = Math.abs(canvasy - y);
" to mark them.",
" </p>",
" <div id='div_g4' style='width:600px; height:300px;'></div>",
- "</div>",
+ "</div>"
].join('\n');
},
}});
document.getElementById("restore3").onclick = function() {
restorePositioning(g3);
- }
+ };
var g4 = new Dygraph(document.getElementById("div_g4"),
- NoisyData, { errorBars : true, drawPoints : true, interactionModel : {
- 'mousedown' : downV4,
- 'mousemove' : moveV4,
- 'mouseup' : upV4,
- 'dblclick' : dblClickV4,
- },
- underlayCallback : captureCanvas
- });
+ NoisyData, {
+ errorBars : true,
+ drawPoints : true,
+ interactionModel : {
+ 'mousedown' : downV4,
+ 'mousemove' : moveV4,
+ 'mouseup' : upV4,
+ 'dblclick' : dblClickV4
+ },
+ underlayCallback : captureCanvas
+ });
}
});
"</div>"].join("\n");
},
run: function() {
- document.getElementById("ry1").onclick = function() { regression(1) };
- document.getElementById("ry2").onclick = function() { regression(2) };
- document.getElementById("clear").onclick = function() { clearLines() };
+ document.getElementById("ry1").onclick = function() { regression(1); };
+ document.getElementById("ry2").onclick = function() { regression(2); };
+ document.getElementById("clear").onclick = function() { clearLines(); };
var data = [];
for (var i = 0; i < 120; i++) {
if (x < range[0] || x > range[1]) continue;
var y = g.getValue(i, series);
- if (y == null) continue;
+ if (y === null || y === undefined) continue;
if (y.length == 2) {
// using fractions
y = y[0] / y[1];
var p1 = g.toDomCoords(x1, y1);
var p2 = g.toDomCoords(x2, y2);
- var c = new RGBColorParser(g.getColors()[i - 1]);
+ var c = Dygraph.toRGB_(g.getColors()[i - 1]);
c.r = Math.floor(255 - 0.5 * (255 - c.r));
c.g = Math.floor(255 - 0.5 * (255 - c.g));
c.b = Math.floor(255 - 0.5 * (255 - c.b));
- var color = c.toHex();
+ var color = 'rgb(' + c.r + ',' + c.g + ',' + c.b + ')';
ctx.save();
ctx.strokeStyle = color;
ctx.lineWidth = 1.0;
ctx.restore();
}
}
-
+
g = new Dygraph(
document.getElementById("demodiv"),
data,
var w = g.xAxisRange();
desired_range = [ w[0], w[0] + res * 1000 ];
animate();
- }
+ };
var reset = function() {
desired_range = orig_range;
animate();
- }
+ };
var pan = function(dir) {
var w = g.xAxisRange();
var amount = scale * 0.25 * dir;
desired_range = [ w[0] + amount, w[1] + amount ];
animate();
- }
+ };
document.getElementById('hour').onclick = function() { zoom(3600); };
document.getElementById('day').onclick = function() { zoom(86400); };
var text = document.createTextNode(columns[i]);
th.appendChild(text);
row.appendChild(th);
- };
+ }
return row;
};
var headers = ['Dygraph.floatFormat()', 'toPrecision()',
'Dygraph.floatFormat()', 'toPrecision()'];
var numbers = [];
- var p = parseInt(document.getElementById('p_input').value);
+ var p = parseInt(document.getElementById('p_input').value, 10);
for (var i = -10; i <= 10; i++) {
var n = Math.pow(10, i);
// Check exact values of 0.
numbers.push([Dygraph.floatFormat(0.0, p),
- 0.0.toPrecision(p)]);
+ (0.0).toPrecision(p)]);
var elem = document.getElementById('content');
elem.innerHTML = '';
+/*jshint evil:true */
Gallery.register(
'plotter',
{
document.getElementById("x2").value = presets[id][1];
document.getElementById("eq").value = presets[id][2];
plot();
- }
+ };
var plotButton = document.getElementById("plot");
var plot = function() {
eval("fn = " + eq);
var graph = document.getElementById("graph_div");
- var width = parseInt(graph.style.width);
+ var width = parseInt(graph.style.width, 10);
var x1 = parseFloat(document.getElementById("x1").value);
var x2 = parseFloat(document.getElementById("x2").value);
var xs = 1.0 * (x2 - x1) / width;
}
g = new Dygraph(graph, data);
- }
+ };
plotButton.onclick = plot;
plot();
}
customBars: true,
logscale: true
});
-
+
var linear = document.getElementById("linear");
var log = document.getElementById("log");
- linear.onclick = function() { setLog(false); }
- log.onclick = function() { setLog(true); }
+ linear.onclick = function() { setLog(false); };
+ log.onclick = function() { setLog(true); };
var setLog = function(val) {
g.updateOptions({ logscale: val });
linear.disabled = !val;
log.disabled = val;
- }
+ };
}
- });
\ No newline at end of file
+ });
+/*jshint loopfunc:true */
Gallery.register(
'synchronize',
{
{
name: "Multiple y-axes",
setup: function(parent) {
- parent.innerHTML =
+ parent.innerHTML =
"<p>The same data with both one and two y-axes. Two y-axes:</p>" +
"<div id='demodiv' style='width: 640; height: 350; border: 1px solid black'></div>" +
"<p>A single y-axis:</p>" +
"<input type='checkbox' id='check'><label for='check'> Fill?</label>";
},
run: function() {
- document.getElementById('check') = function(el) {
+ document.getElementById('check').onchange = function(el) {
g.updateOptions( { fillGraph: el.checked } );
g2.updateOptions( { fillGraph: el.checked } );
- }
+ };
var data = [];
for (var i = 1; i <= 100; i++) {
labels: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ],
labelsKMB: true,
ylabel: 'Primary y-axis',
- y2label: 'Secondary y-axis',
+ y2label: 'Secondary y-axis'
}
);
}
jsc_opts='maxerr:10000,devel:true,browser:true,shadow:true'
rhino_opts='maxerr=10000,devel=true,browser=true,shadow=true'
-if [ $# -gt 1 ]; then
- echo "Usage: $0 [file.js]"
- exit 1
-fi
-
RETURN_VALUE=0
if [ $# -eq 0 ]; then
- files=$(ls dygraph*.js plugins/*.js datahandler/*.js | grep -v combined | grep -v dev.js| grep -v externs)
+ files=$(ls dygraph*.js plugins/*.js datahandler/*.js gallery/*.js | grep -v combined | grep -v dev.js| grep -v externs)
else
- files=$1
+ files=$@
fi
if [ -e /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc ]; then