Mercurial > hg
comparison mercurial/hgweb/webcommands.py @ 35407: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 |
comparison
equal
deleted
inserted
replaced
35406:76dcdc4e707b | 35407:27ab3150cd50 |
---|---|
1229 dag = graphmod.dagwalker(web.repo, smartset.baseset(revs)) | 1229 dag = graphmod.dagwalker(web.repo, smartset.baseset(revs)) |
1230 # As we said one line above... not lazy. | 1230 # As we said one line above... not lazy. |
1231 tree = list(item for item in graphmod.colored(dag, web.repo) | 1231 tree = list(item for item in graphmod.colored(dag, web.repo) |
1232 if item[1] == graphmod.CHANGESET) | 1232 if item[1] == graphmod.CHANGESET) |
1233 | 1233 |
1234 def getcolumns(tree): | |
1235 cols = 0 | |
1236 for (id, type, ctx, vtx, edges) in tree: | |
1237 cols = max(cols, max([edge[0] for edge in edges] or [0]), | |
1238 max([edge[1] for edge in edges] or [0])) | |
1239 return cols | |
1240 | |
1241 def graphdata(usetuples): | 1234 def graphdata(usetuples): |
1242 data = [] | 1235 data = [] |
1243 | 1236 |
1244 row = 0 | 1237 row = 0 |
1245 for (id, type, ctx, vtx, edges) in tree: | 1238 for (id, type, ctx, vtx, edges) in tree: |
1264 | 1257 |
1265 row += 1 | 1258 row += 1 |
1266 | 1259 |
1267 return data | 1260 return data |
1268 | 1261 |
1269 cols = getcolumns(tree) | |
1270 rows = len(tree) | 1262 rows = len(tree) |
1271 canvasheight = (rows + 1) * bg_height - 27 | |
1272 | 1263 |
1273 return tmpl('graph', rev=rev, symrev=symrev, revcount=revcount, | 1264 return tmpl('graph', rev=rev, symrev=symrev, revcount=revcount, |
1274 uprev=uprev, | 1265 uprev=uprev, |
1275 lessvars=lessvars, morevars=morevars, downrev=downrev, | 1266 lessvars=lessvars, morevars=morevars, downrev=downrev, |
1276 cols=cols, rows=rows, changesets=count, | 1267 rows=rows, |
1277 canvaswidth=(cols + 1) * bg_height, | 1268 bg_height=bg_height, |
1278 truecanvasheight=rows * bg_height, | 1269 changesets=count, |
1279 canvasheight=canvasheight, bg_height=bg_height, | |
1280 jsdata=lambda **x: graphdata(True), | 1270 jsdata=lambda **x: graphdata(True), |
1281 nodes=lambda **x: graphdata(False), | 1271 nodes=lambda **x: graphdata(False), |
1282 node=ctx.hex(), changenav=changenav) | 1272 node=ctx.hex(), changenav=changenav) |
1283 | 1273 |
1284 def _getdoc(e): | 1274 def _getdoc(e): |