| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
Also would benefit from renaming some few-character variables, e.g. d -> descent
Sorry, something went wrong.
| # Metrics of the last line that are needed later: | ||
| baseline = (h - d) - thisy | ||
|
|
||
| if i == 0: |
There was a problem hiding this comment.
| if i == 0: | |
| if thisy == 0: # first line |
gets rid of the need for enumerate().
Sorry, something went wrong.
There was a problem hiding this comment.
It's not immediately obvious that thisy cannot be zero for the second line too even if the first line is empty (it's true, but only thanks to the h = max(h, lp_h)/d = max(d, lp_d) lines) so I think leaving it as it is is clearer.
Sorry, something went wrong.
There was a problem hiding this comment.
Just by common sense, the vertical position thisy must increase also for empty lines. So it should only be zero before handling the first line.
But ok, if you want to leave it.
Sorry, something went wrong.
There was a problem hiding this comment.
I don't think common sense applies to this function (or to a lot of matplotlib, sadly). (e.g. if you look at the way center_baseline is defined a bit below, it looks weirdly different between anchor and non-anchor rotations...)
Sorry, something went wrong.
There was a problem hiding this comment.
Funnily that got fixed by #13029 :)
Sorry, something went wrong.
| horizLayout[i] = thisx, thisy, w, h | ||
| thisy -= max(min_dy, (h - d) * self._linespacing) | ||
|
|
||
| xs.append(thisx) # == 0. |
There was a problem hiding this comment.
Alterantively
xs = [0.] * len(ys)
outside of the loop.
Sorry, something went wrong.
There was a problem hiding this comment.
I think the symmetry of handling between xs and ys is nicer.
Sorry, something went wrong.
There was a problem hiding this comment.
IMO xs = [0.] * len(ys) is much clearer about xs than secretly constructing a list of zeros in the loop. The loop should only need to bother about the quantities that actually depend on the lines. But not going to argue about this.
Sorry, something went wrong.
|
The single-character variables are "inside the loop", the longer ones are the one that outlive the loop. |
Sorry, something went wrong.
Which still doesn't make the single-character variables readable. |
Sorry, something went wrong.
There was a problem hiding this comment.
Accepting as an incremental improvement, even though I see room for further improvement.
Sorry, something went wrong.
|
The single-letter variables are defined as w, h, d = renderer.get_text_width_height_descent(...) so their meaning is pretty clear IMO (in the context). |
Sorry, something went wrong.
|
That's fine in a narrow scope like a list comprehension or a few-lines for. Single letter variables should just not live for more than 20 lines. And in particular not multiple different ones at the same time. |
Sorry, something went wrong.
|
Additionally factored out offsets computation, following #13029. |
Sorry, something went wrong.
- Instead of constructing and accessing multidimensional arrays whs and horizLayout by (opaque) index, construct separate lists with more meaningful names. - Define xmin/xmax/ymin/ymax/width/height closer to their place of use. - Make computation of offsetx and offsety more symmetric between rotation_mode == "anchor" and == "default".
| Back | FazBrowse Home | New Git URL |
horizLayout by (opaque) index, construct separate lists with more
meaningful names.
rotation_mode == "anchor" and == "default".
PR Summary
PR Checklist