Skip to content

Commit

Permalink
fix in preparation for nim-lang/Nim#14447
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed May 28, 2020
1 parent 85c35e9 commit 68f96ee
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/ggplotnim.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2106,7 +2106,6 @@ proc getLeftBottom(view: Viewport, annot: Annotation): tuple[left: float, bottom
axis: akY,
scale: view.yScale)).pos


proc drawAnnotations*(view: var Viewport, p: GgPlot) =
## draws all annotations from `p` onto the mutable view `view`.
# this is 0.5 times the string height. Margin between text and
Expand All @@ -2129,8 +2128,9 @@ proc drawAnnotations*(view: var Viewport, p: GgPlot) =
marginH.pos * 2.0,
unit = ukRelative)
# find longest line of annotation to base background on
let font = annot.font # refs https://github.com/nim-lang/Nim/pull/14447
let maxLine = annot.text.strip.splitLines.sortedByIt(
getStrWidth(it, annot.font).val
getStrWidth(it, font).val
)[^1]
let maxWidth = getStrWidth(maxLine, annot.font)
# calculate required width for background rectangle. string width +
Expand Down
5 changes: 4 additions & 1 deletion src/ggplotnim/postprocess_scales.nim
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func mergeScales(s1, s2: ginger.Scale): ginger.Scale =
else:
result = s2

from sugar import capture

proc applyTransformations(df: var DataFrame, scales: seq[Scale]) =
## Given a sequence of scales applies all transformations of the `scales`.
## That is for each `scTransformedData` scale the according transformation
Expand All @@ -77,6 +79,7 @@ proc applyTransformations(df: var DataFrame, scales: seq[Scale]) =
# transformations have been applied!
var fns: seq[FormulaNode]
for s in scales:
# let s = s # this would've also worked but less efficient
if s.scKind == scTransformedData:
when defined(defaultBackend):
let col = evaluate(s.col)
Expand All @@ -85,7 +88,7 @@ proc applyTransformations(df: var DataFrame, scales: seq[Scale]) =
else:
# create a closureScope to capture the value of `s` and `col` instead
# of the reference
closureScope:
capture(s): # refs https://github.com/nim-lang/Nim/pull/14447
let col = evaluate(s.col)
let colStr = getColName(s)
# make a copy of `s` which we hand to the closure
Expand Down

0 comments on commit 68f96ee

Please sign in to comment.