Skip to content

Commit

Permalink
[tests] add fType where needed in tests
Browse files Browse the repository at this point in the history
(because we call ~ggcreate~ without calling save / handing a filename)
  • Loading branch information
Vindaar committed Feb 10, 2024
1 parent 32df8a0 commit 32bc4dc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion tests/test_issue2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test "Issue2":
let plt = ggplot(seqsToDf({ "x" : xdata,
"y" : ydata }),
aes("x", "y"),
backend = Backend) +
backend = Backend, fType = fkSvg) +
geom_line()

let plotView = plt.ggcreate()
Expand Down
50 changes: 25 additions & 25 deletions tests/tests.nim
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ suite "GgPlot":

test "Bar plot with string based scale":
let mpg = readCsv("data/mpg.csv")
let plt = ggcreate(ggplot(mpg, aes("class"), backend = Backend) + geom_bar())
let plt = ggcreate(ggplot(mpg, aes("class"), backend = Backend, fType = fkSvg) + geom_bar())
let plotView = plt.view[4]
check plotView.name == "plot"
proc calcPos(classes: seq[string]): seq[float] =
Expand Down Expand Up @@ -209,7 +209,7 @@ suite "GgPlot":

test "Plot with continuous color scale":
let mpg = readCsv("data/mpg.csv")
ggplot(mpg, aes("displ", "hwy", color = "cty"), backend = Backend) +
ggplot(mpg, aes("displ", "hwy", color = "cty"), backend = Backend, fType = fkSvg) +
geom_point() +
ggsave("cont_color.pdf")
# TODO: write an actual test here
Expand Down Expand Up @@ -258,7 +258,7 @@ suite "GgPlot":
let y2 = x.mapIt(pow(it, 4))
let df = toDf({"x" : x, "xSquare" : y1, "x4" : y2})
block:
let plt = ggplot(df, aes("x", "xSquare"), backend = Backend) +
let plt = ggplot(df, aes("x", "xSquare"), backend = Backend, fType = fkSvg) +
geom_line() +
scale_x_log10()
check plt.aes.x.isSome
Expand All @@ -272,7 +272,7 @@ suite "GgPlot":

# check also applied to another geom added before
block:
let plt = ggplot(df, aes("x", "xSquare"), backend = Backend) +
let plt = ggplot(df, aes("x", "xSquare"), backend = Backend, fType = fkSvg) +
geom_line(aes(y = "x4")) +
geom_point(aes(y = "x4")) +
scale_y_log10()
Expand All @@ -293,7 +293,7 @@ suite "GgPlot":
# the call to `scale_*` (this is in contrast to `ggplot2` where the
# order does not matter
block:
let plt = ggplot(df, aes("x", "xSquare"), backend = Backend) +
let plt = ggplot(df, aes("x", "xSquare"), backend = Backend, fType = fkSvg) +
scale_x_log10() +
geom_line(aes(y = "x4"))
check plt.aes.x.isSome
Expand All @@ -312,7 +312,7 @@ suite "GgPlot":
let x = logspace(-6, 1.0, 100)
let y = x.mapIt(exp(-it))
let df = toDf({"x" : x, "exp" : y})
let pltView = ggcreate(ggplot(df, aes("x", "exp"), backend = Backend) +
let pltView = ggcreate(ggplot(df, aes("x", "exp"), backend = Backend, fType = fkSvg) +
geom_line() +
scale_y_log10())
let plt = pltView.view
Expand Down Expand Up @@ -354,7 +354,7 @@ suite "GgPlot":
let df = toDf({"x" : x, "exp" : y})
const xMargin = 0.5
const yMargin = 1.7
let pltView = ggcreate(ggplot(df, aes("x", "exp"), backend = Backend) +
let pltView = ggcreate(ggplot(df, aes("x", "exp"), backend = Backend, fType = fkSvg) +
geom_line() +
xlab("Custom label", margin = xMargin) +
ylab("More custom!", margin = yMargin) +
Expand Down Expand Up @@ -423,12 +423,12 @@ suite "Theme":
check canvasStyle.fillColor == white

block:
let plt = ggplot(mpg, aes("hwy", "cty"), backend = Backend) +
let plt = ggplot(mpg, aes("hwy", "cty"), backend = Backend, fType = fkSvg) +
geom_point() +
canvasColor(color = white)
checkPlt(plt)
block:
let plt = ggplot(mpg, aes("hwy", "cty"), backend = Backend) +
let plt = ggplot(mpg, aes("hwy", "cty"), backend = Backend, fType = fkSvg) +
geom_point() +
theme_opaque()
checkPlt(plt)
Expand All @@ -437,7 +437,7 @@ suite "Annotations":
test "Annotation using relative coordinates":
let df = readCsv("data/mpg.csv")
let annot = "A simple\nAnnotation\nMulti\nLine"
let plt = ggcreate(ggplot(df, aes("hwy", "cty"), backend = Backend) +
let plt = ggcreate(ggplot(df, aes("hwy", "cty"), backend = Backend, fType = fkSvg) +
geom_line() +
annotate(annot,
left = 0.5,
Expand Down Expand Up @@ -472,7 +472,7 @@ suite "Annotations":
let annot = "A simple\nAnnotation\nMulti\nLine"
let font = font(size = 12.0,
family = "monospace")
let plt = ggcreate(ggplot(df, aes("hwy", "cty"), backend = Backend) +
let plt = ggcreate(ggplot(df, aes("hwy", "cty"), backend = Backend, fType = fkSvg) +
geom_point() +
annotate(annot,
x = 10.0,
Expand Down Expand Up @@ -508,7 +508,7 @@ suite "Annotations":
check dfAt44.len == 2
check dfAt44["cty"].toTensor(float) == toTensor @[33.0, 35.0]
block:
let plt = ggcreate(ggplot(df, aes("hwy", "cty"), backend = Backend) +
let plt = ggcreate(ggplot(df, aes("hwy", "cty"), backend = Backend, fType = fkSvg) +
geom_point() +
ylim(5, 30)) # will cut off two values at hwy = 44, clip them to `30`, since
# default is `outsideRange = "clip"` (`orkClip`)
Expand All @@ -521,7 +521,7 @@ suite "Annotations":
check almostEq(gobj.ptPos.y.pos, 30.0, 1e-8)
else: discard
block:
let plt = ggcreate(ggplot(df, aes("hwy", "cty"), backend = Backend) +
let plt = ggcreate(ggplot(df, aes("hwy", "cty"), backend = Backend, fType = fkSvg) +
geom_point() +
ylim(5, 30, outsideRange = "drop")) # will drop 2 values at `hwy = 44`
let view = plt.view
Expand All @@ -535,7 +535,7 @@ suite "Annotations":
else: discard
check count == 0
block:
let plt = ggcreate(ggplot(df, aes("hwy", "cty"), backend = Backend) +
let plt = ggcreate(ggplot(df, aes("hwy", "cty"), backend = Backend, fType = fkSvg) +
geom_point() +
ylim(5, 30, outsideRange = "none")) # will leave two values at `hwy = 44` somewhere
# outside the plot
Expand All @@ -552,10 +552,10 @@ suite "Annotations":
test "Set custom plot data margins":
let df = readCsv("data/mpg.csv")
const marg = 0.05
let plt = ggcreate(ggplot(df, aes("hwy", "cty"), backend = Backend) +
let plt = ggcreate(ggplot(df, aes("hwy", "cty"), backend = Backend, fType = fkSvg) +
geom_point() +
xMargin(marg))
let pltRef = ggcreate(ggplot(df, aes("hwy", "cty"), backend = Backend) +
let pltRef = ggcreate(ggplot(df, aes("hwy", "cty"), backend = Backend, fType = fkSvg) +
geom_point())
let pltRefXScale = pltRef.view[4].xScale
let view = plt.view[4]
Expand All @@ -568,9 +568,9 @@ suite "Annotations":
test "Margin plus limit using orkClip clips to range + margin":
let df = readCsv("data/mpg.csv")
const marg = 0.1
#let pltRef = ggcreate(ggplot(df, aes("hwy", "cty"), backend = Backend) +
#let pltRef = ggcreate(ggplot(df, aes("hwy", "cty"), backend = Backend, fType = fkSvg) +
# geom_point())
let plt = ggcreate(ggplot(df, aes("hwy", "cty"), backend = Backend) +
let plt = ggcreate(ggplot(df, aes("hwy", "cty"), backend = Backend, fType = fkSvg) +
geom_point() +
xlim(0.0, 30.0) +
xMargin(marg))
Expand Down Expand Up @@ -616,7 +616,7 @@ suite "Annotations":

block:
let plt = ggcreate(
ggplot(df, aes("spikes", "neurons"), backend = Backend) +
ggplot(df, aes("spikes", "neurons"), backend = Backend, fType = fkSvg) +
geom_linerange(aes(ymin = f{-1.0},
ymax = f{1.0})) +
scale_y_continuous() + # make sure y is considered cont.
Expand Down Expand Up @@ -658,7 +658,7 @@ suite "Annotations":

block:
let plt = ggcreate(
ggplot(df, aes("spikes", "neurons"), backend = Backend) +
ggplot(df, aes("spikes", "neurons"), backend = Backend, fType = fkSvg) +
geom_linerange(aes(ymin = f{-1.0},
ymax = f{1.0})) +
scale_y_continuous() + # make sure y is considered cont.
Expand Down Expand Up @@ -704,7 +704,7 @@ suite "Annotations":
## TODO: fix the bug!
expect(ValueError):
discard ggcreate(
ggplot(df, aes("spikes", "neurons"), backend = Backend) +
ggplot(df, aes("spikes", "neurons"), backend = Backend, fType = fkSvg) +
geom_linerange(aes(ymin = f{-1.0})) +
scale_y_continuous() + # make sure y is considered cont.
ylim(-1, 1) + # at the moment ymin, ymax are not considered for the plot range (that's a bug)
Expand All @@ -721,7 +721,7 @@ suite "Annotations":
"Height" : @[1.87, 1.75, 1.78],
"Name" : @["Mike", "Laura", "Sue"] })
let plt = ggcreate(
ggplot(df, aes("Name","Height"), backend = Backend) +
ggplot(df, aes("Name","Height"), backend = Backend, fType = fkSvg) +
geom_bar(stat="identity")
)

Expand All @@ -739,7 +739,7 @@ suite "Annotations":
let df = toDf({ "Trial" : trials,
"Value" : values })
let plt = ggcreate(
ggplot(df, aes(x="Trial", y="Value"), backend = Backend) +
ggplot(df, aes(x="Trial", y="Value"), backend = Backend, fType = fkSvg) +
geom_bar(stat="identity", position="identity")
)

Expand All @@ -756,7 +756,7 @@ suite "Annotations":
# first check that this does indeed result in a classification by
# guessType that's continuous
let plt = ggcreate(
ggplot(df, aes(x, y, color = class), backend = Backend) +
ggplot(df, aes(x, y, color = class), backend = Backend, fType = fkSvg) +
geom_line()
)
check plt.filledScales.color.main.isSome
Expand All @@ -768,7 +768,7 @@ suite "Annotations":
block FactorMakesDiscrete:
# now check factor has desired effect
let plt = ggcreate(
ggplot(df, aes(x, y, color = factor(class)), backend = Backend) +
ggplot(df, aes(x, y, color = factor(class)), backend = Backend, fType = fkSvg) +
geom_line()
)
check plt.filledScales.color.main.isSome
Expand Down

0 comments on commit 32bc4dc

Please sign in to comment.