Mercurial > hg-stable
changeset 19782:8123f50555ff
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.
author | Alexander Plavin <alexander@plav.in> |
---|---|
date | Fri, 20 Sep 2013 00:42:13 +0400 |
parents | 74564c90026b |
children | 1c2a309bba4f |
files | mercurial/templates/static/mercurial.js |
diffstat | 1 files changed, 20 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- 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 = {