hgweb: add graph mode of ajax response processing
authorAlexander Plavin <alexander@plav.in>
Fri, 20 Sep 2013 00:42:13 +0400
changeset 19782 8123f50555ff
parent 19781 74564c90026b
child 19783 1c2a309bba4f
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.
mercurial/templates/static/mercurial.js
--- 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 = {