Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/graphmod.py @ 16138:6e4de55a41a4
hgweb: refactor graph customization javascript
- Avoid flipping lineWidth state around the edge() call, pass it to the
function instead.
- Pass the line width and color appended to the other parameters instead of in
a dictionary. The javascript code is simpler, no need to check for all
containers existence, and the JSON output is smaller.
- Reindent setColor() comments and fix code spacing.
author | Patrick Mezard <patrick@mezard.eu> |
---|---|
date | Sun, 22 Jan 2012 19:35:26 +0700 |
parents | 41fc1e078d68 |
children | 0849d725e2f9 |
comparison
equal
deleted
inserted
replaced
16137:8fd18eb8aab7 | 16138:6e4de55a41a4 |
---|---|
89 for key, val in repo.ui.configitems('graph'): | 89 for key, val in repo.ui.configitems('graph'): |
90 if '.' in key: | 90 if '.' in key: |
91 branch, setting = key.rsplit('.', 1) | 91 branch, setting = key.rsplit('.', 1) |
92 # Validation | 92 # Validation |
93 if setting == "width" and val.isdigit(): | 93 if setting == "width" and val.isdigit(): |
94 config.setdefault(branch, {})[setting] = val | 94 config.setdefault(branch, {})[setting] = int(val) |
95 elif setting == "color" and val.isalnum(): | 95 elif setting == "color" and val.isalnum(): |
96 config.setdefault(branch, {})[setting] = val | 96 config.setdefault(branch, {})[setting] = val |
97 | 97 |
98 if config: | 98 if config: |
99 getconf = util.lrucachefunc(lambda rev: config.get(repo[rev].branch())) | 99 getconf = util.lrucachefunc( |
100 lambda rev: config.get(repo[rev].branch(), {})) | |
100 else: | 101 else: |
101 getconf = lambda rev: None | 102 getconf = lambda rev: {} |
102 | 103 |
103 for (cur, type, data, parents) in dag: | 104 for (cur, type, data, parents) in dag: |
104 | 105 |
105 # Compute seen and next | 106 # Compute seen and next |
106 if cur not in seen: | 107 if cur not in seen: |
126 | 127 |
127 # Add edges to the graph | 128 # Add edges to the graph |
128 edges = [] | 129 edges = [] |
129 for ecol, eid in enumerate(seen): | 130 for ecol, eid in enumerate(seen): |
130 if eid in next: | 131 if eid in next: |
132 bconf = getconf(eid) | |
131 edges.append(( | 133 edges.append(( |
132 ecol, next.index(eid), colors[eid], | 134 ecol, next.index(eid), colors[eid], |
133 getconf(eid))) | 135 bconf.get('width', -1), |
136 bconf.get('color', ''))) | |
134 elif eid == cur: | 137 elif eid == cur: |
135 for p in parents: | 138 for p in parents: |
139 bconf = getconf(p) | |
136 edges.append(( | 140 edges.append(( |
137 ecol, next.index(p), color, | 141 ecol, next.index(p), color, |
138 getconf(p))) | 142 bconf.get('width', -1), |
143 bconf.get('color', ''))) | |
139 | 144 |
140 # Yield and move on | 145 # Yield and move on |
141 yield (cur, type, data, (col, color), edges) | 146 yield (cur, type, data, (col, color), edges) |
142 seen = next | 147 seen = next |
143 | 148 |