Mercurial > public > mercurial-scm > hg-stable
diff mercurial/hgweb/webcommands.py @ 35414:27ab3150cd50
hgweb: calculate <canvas> width and height client-side
hgweb determines and passes to templates some variables related to graph
appearance, like bg_height, canvaswidth and canvasheight. bg_height was and
still is used for graph.scale() call in graph.tmpl, and the two latter
variables were used in <canvas> element as width and height properties, and
they were set before JS code got to run. Setting these properties server-side
doesn't make a lot of sense, because a graph that has been scaled should
calculate things like width and height on its own when being rendered.
Let's move (re)sizing <canvas> to JavaScript (to Graph.render function) and
stop parsing HTML with regular expressions just to know new width and height.
That extra loop that only counts cols is required because <canvas> can't
be resized after or in the process of rendering (or it gets cleared).
Incidentally, SVG doesn't have this problem and I'm hoping to switch graph to
using it in future.
There also was truecanvasheight, but according to hg grep --all it was never
used, see d490edc71146.
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Sun, 10 Dec 2017 15:56:22 +0800 |
parents | 76dcdc4e707b |
children | a48af4993aa0 |
line wrap: on
line diff
--- a/mercurial/hgweb/webcommands.py Fri Dec 08 21:50:11 2017 +0800 +++ b/mercurial/hgweb/webcommands.py Sun Dec 10 15:56:22 2017 +0800 @@ -1231,13 +1231,6 @@ tree = list(item for item in graphmod.colored(dag, web.repo) if item[1] == graphmod.CHANGESET) - def getcolumns(tree): - cols = 0 - for (id, type, ctx, vtx, edges) in tree: - cols = max(cols, max([edge[0] for edge in edges] or [0]), - max([edge[1] for edge in edges] or [0])) - return cols - def graphdata(usetuples): data = [] @@ -1266,17 +1259,14 @@ return data - cols = getcolumns(tree) rows = len(tree) - canvasheight = (rows + 1) * bg_height - 27 return tmpl('graph', rev=rev, symrev=symrev, revcount=revcount, uprev=uprev, lessvars=lessvars, morevars=morevars, downrev=downrev, - cols=cols, rows=rows, changesets=count, - canvaswidth=(cols + 1) * bg_height, - truecanvasheight=rows * bg_height, - canvasheight=canvasheight, bg_height=bg_height, + rows=rows, + bg_height=bg_height, + changesets=count, jsdata=lambda **x: graphdata(True), nodes=lambda **x: graphdata(False), node=ctx.hex(), changenav=changenav)