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

login
register
mail settings
Submitter Alexander Plavin
Date Sept. 22, 2013, 10:30 a.m.
Message ID <d1f9b450414949269ff9.1379845801@debian-alexander.dolgopa>
Download mbox | patch
Permalink /patch/2595/
State Accepted
Commit 8123f50555ffc1fb5d1afa4381763a30ceaafa8a
Headers show

Comments

Alexander Plavin - Sept. 22, 2013, 10:30 a.m.
# HG changeset patch
# User Alexander Plavin <alexander@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.

Patch

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 = {