[PATCH 3 of 4 graph-inf-scroll] hgweb: add graph mode of ajax response processing

Alexander Plavin alexander at plav.in
Sun Sep 22 05:30:01 CDT 2013


# HG changeset patch
# User Alexander Plavin <alexander at plav.in>
# Date 1379623333 -14400
#      Fri Sep 20 00:42:13 2013 +0400
# Node ID d1f9b450414949269ff98ad2597ad44848f119df
# Parent  30520f2ae5319121bb313b668ee5cc97002c2fde
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.

diff -r 30520f2ae531 -r d1f9b4504149 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 = {


More information about the Mercurial-devel mailing list