hgweb: add graph mode of ajax response processing
While the default mode appends all the new entries to a container on the page,
the graph mode resizes canvas correctly, and repaints the graph to include
newly received data.
--- a/mercurial/templates/static/mercurial.js Sun Sep 22 14:18:23 2013 +0400
+++ b/mercurial/templates/static/mercurial.js Fri Sep 20 00:42:13 2013 +0400
@@ -358,7 +358,8 @@
nextPageVar,
nextPageVarGet,
containerSelector,
- messageFormat) {
+ messageFormat,
+ mode) {
updateInitiated = false;
container = document.querySelector(containerSelector);
@@ -399,14 +400,25 @@
function onsuccess(htmlText) {
nextPageVar = nextPageVarGet(htmlText, nextPageVar);
- var doc = docFromHTML(htmlText);
- var nodes = doc.querySelector(containerSelector).children;
- while (nodes.length) {
- var node = nodes[0];
- node = document.adoptNode(node);
- container.appendChild(node);
+ if (mode == 'graph') {
+ var addHeight = htmlText.match(/^<canvas id="graph".*height="(\d+)"><\/canvas>$/m)[1];
+ addHeight = parseInt(addHeight);
+ graph.canvas.height = addHeight;
+
+ var dataStr = htmlText.match(/^\s*var data = (.*);$/m)[1];
+ var data = JSON.parse(dataStr)
+ graph.reset();
+ graph.render(data);
+ } else {
+ var doc = docFromHTML(htmlText);
+ var nodes = doc.querySelector(containerSelector).children;
+ while (nodes.length) {
+ var node = nodes[0];
+ node = document.adoptNode(node);
+ container.appendChild(node);
+ }
+ process_dates();
}
- process_dates();
},
function onerror(errorText) {
var message = {