Skip to content

Commit ae72d6f

Browse files
committed
Got rid of the key in the axis case class and made it so that axes use identity for ==.
1 parent abcd6f3 commit ae72d6f

File tree

6 files changed

+115
-89
lines changed

6 files changed

+115
-89
lines changed

.scalafmt.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version = "2.6.4"

core/src/main/scala/playground/PlotTesting.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,16 @@ object PlotTesting {
173173
*/
174174
def longForm(): Plot = {
175175
val font = new Renderer.FontData("Ariel", Renderer.FontStyle.Plain)
176-
val xAxis1 = new NumericAxis("x1", None, None, None, Axis.TickStyle.Both, Some(Axis.LabelSettings(90, font, numberFormat)),
176+
val xAxis1 = new NumericAxis(None, None, None, Axis.TickStyle.Both, Some(Axis.LabelSettings(90, font, numberFormat)),
177177
Some(Axis.NameSettings("X1", font)))
178-
val xAxis2 = new NumericAxis("x2", None, None, None, Axis.TickStyle.Both, Some(Axis.LabelSettings(90, font, numberFormat)),
178+
val xAxis2 = new NumericAxis(None, None, None, Axis.TickStyle.Both, Some(Axis.LabelSettings(90, font, numberFormat)),
179179
Some(Axis.NameSettings("X2", font)))
180-
val xAxisCat = new CategoryAxis("xcat", Axis.TickStyle.Both, 0, font, Some(Axis.NameSettings("Categories", font)), Axis.DisplaySide.Max)
181-
val yAxis1 = new NumericAxis("y1", None, None, None, Axis.TickStyle.Both, Some(Axis.LabelSettings(0, font, numberFormat)),
180+
val xAxisCat = new CategoryAxis(Axis.TickStyle.Both, 0, font, Some(Axis.NameSettings("Categories", font)), Axis.DisplaySide.Max)
181+
val yAxis1 = new NumericAxis(None, None, None, Axis.TickStyle.Both, Some(Axis.LabelSettings(0, font, numberFormat)),
182182
Some(Axis.NameSettings("Y1", font)))
183-
val yAxis2 = new NumericAxis("y2", None, None, None, Axis.TickStyle.Both, Some(Axis.LabelSettings(0, font, "%1.0f")),
183+
val yAxis2 = new NumericAxis(None, None, None, Axis.TickStyle.Both, Some(Axis.LabelSettings(0, font, "%1.0f")),
184184
Some(Axis.NameSettings("Y2", font)))
185-
val yAxis3 = new NumericAxis("y3", None, None, None, Axis.TickStyle.Both, Some(Axis.LabelSettings(0, font, "%1.0f")),
185+
val yAxis3 = new NumericAxis(None, None, None, Axis.TickStyle.Both, Some(Axis.LabelSettings(0, font, "%1.0f")),
186186
Some(Axis.NameSettings("Y3", font)), Axis.DisplaySide.Max)
187187

188188
// Main Scatter plot
@@ -376,11 +376,11 @@ object PlotTesting {
376376
)
377377
}
378378
val font = Renderer.FontData("Ariel", Renderer.FontStyle.Plain)
379-
val photonCountAxis = NumericAxis("Count", None, None, None, Axis.TickStyle.Both,
379+
val photonCountAxis = NumericAxis(None, None, None, Axis.TickStyle.Both,
380380
Some(Axis.LabelSettings(0.0, font, "%1.1f")), Some(Axis.NameSettings("Photon Count", font)), Axis.DisplaySide.Max)
381-
val yAxes = plotStyles.zipWithIndex.map { case (_, i) => NumericAxis("Y"+i, None, None, None, Axis.TickStyle.Both,
381+
val yAxes = plotStyles.zipWithIndex.map { case (_, i) => NumericAxis(None, None, None, Axis.TickStyle.Both,
382382
Some(Axis.LabelSettings(0.0, font, "%1.1f")), Some(Axis.NameSettings("Azimuthal Position", font)), Axis.DisplaySide.Min) }
383-
val xAxis = NumericAxis("X", None, None, None, Axis.TickStyle.Both,
383+
val xAxis = NumericAxis(None, None, None, Axis.TickStyle.Both,
384384
Some(Axis.LabelSettings(90.0, font, "%1.1f")), Some(Axis.NameSettings("Radial Position", font)), Axis.DisplaySide.Min)
385385
val grid = PlotGrid(plotStyles.zipWithIndex.map { case ((cart, scans), i) =>
386386
Seq(Seq(Plot2D(cart, "X", "Y"+i)), scans.map(scan => Plot2D(scan, "X", "Count"))) },
@@ -399,8 +399,8 @@ object PlotTesting {
399399
val font = new Renderer.FontData("Ariel", Renderer.FontStyle.Plain)
400400
val style = ScatterStyle(x, y)
401401
val p2d = Plot2D(style, "x", "y")
402-
val xAxis = NumericAxis("x", tickLabelInfo = Some(Axis.LabelSettings(90, font, numberFormat)), name = Some(Axis.NameSettings("X", font)))
403-
val yAxis = NumericAxis("y", tickLabelInfo = Some(Axis.LabelSettings(0, font, numberFormat)), name = Some(Axis.NameSettings("Y", font)))
402+
val xAxis = NumericAxis(tickLabelInfo = Some(Axis.LabelSettings(90, font, numberFormat)), name = Some(Axis.NameSettings("X", font)))
403+
val yAxis = NumericAxis(tickLabelInfo = Some(Axis.LabelSettings(0, font, numberFormat)), name = Some(Axis.NameSettings("Y", font)))
404404
val grid = PlotGrid(Seq(Seq(Seq(p2d))), Map("x" -> xAxis, "y" -> yAxis), Seq(1.0), Seq(1.0))
405405
Plot(grids = Map("main" -> Plot.GridData(grid, Bounds(0.0, 0.05, 0.95, 0.95))))
406406
}
@@ -424,7 +424,7 @@ object PlotTesting {
424424
val ys = xs.map(x => math.sqrt(x))
425425
val counts = (0 to 9).map(i => 1.0 - i*i/100.0)
426426
Plot.simple(ScatterStyle(xs, xs))
427-
.withAxis("y2", NumericAxis.defaultVerticalAxis("y2", "Y2").min(0.0).maxSide)
427+
.withAxis("y2", NumericAxis.defaultVerticalAxis("Y2").min(0.0).maxSide)
428428
.updatedAxis[NumericAxis]("x", _.updatedName("X"))
429429
.updatedAxis[NumericAxis]("x", _.updatedName("Y"))
430430
.updatedPlotGrid(_.withRow().withColumn().withRow(0).withColumn(0)

core/src/main/scala/swiftvis2/plotting/Axes.scala

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ sealed trait Axis {
1818
* the tickSpacing will be ignored, even if it is provided.
1919
*/
2020
case class NumericAxis(
21-
key: String,
2221
min: Option[Double] = None,
2322
max: Option[Double] = None,
2423
tickSpacing: Option[Double] = None,
@@ -251,6 +250,17 @@ case class NumericAxis(
251250
* @return The modified axis.
252251
*/
253252
def ticks(tstyle: Axis.TickStyle.Value): NumericAxis = updatedTickStyle(tstyle)
253+
254+
/**
255+
* Override equality because I need this to check for identify in the sets and maps.
256+
*
257+
* @param that
258+
* @return
259+
*/
260+
override def equals(that: Any): Boolean = that match {
261+
case ar: AnyRef => this eq ar
262+
case _ => false
263+
}
254264

255265
// Private methods
256266

@@ -314,7 +324,7 @@ case class NumericAxis(
314324
}
315325
}
316326

317-
def calcTickLocations(amin: Double, amax: Double): Seq[Double] = {
327+
private def calcTickLocations(amin: Double, amax: Double): Seq[Double] = {
318328
if (tickSpacing.nonEmpty || tickLabelInfo.nonEmpty) {
319329
style match {
320330
case Axis.ScaleStyle.Linear =>
@@ -355,15 +365,15 @@ case class NumericAxis(
355365
}
356366

357367
object NumericAxis {
358-
def defaultHorizontalAxis(text: String, key: String = "x", numFormat: String = "%1.1f", xType: Axis.ScaleStyle.Value = Axis.ScaleStyle.Linear) = {
368+
def defaultHorizontalAxis(text: String, numFormat: String = "%1.1f", xType: Axis.ScaleStyle.Value = Axis.ScaleStyle.Linear) = {
359369
val font = Renderer.FontData("Ariel", Renderer.FontStyle.Plain)
360-
NumericAxis(key, None, None, None, Axis.TickStyle.Both,
370+
NumericAxis(None, None, None, Axis.TickStyle.Both,
361371
Some(Axis.LabelSettings(90.0, font, numFormat)), Some(Axis.NameSettings(text, font)), Axis.DisplaySide.Min, xType)
362372
}
363373

364-
def defaultVerticalAxis(text: String, key: String = "y", numFormat: String = "%1.1f", yType: Axis.ScaleStyle.Value = Axis.ScaleStyle.Linear) = {
374+
def defaultVerticalAxis(text: String, numFormat: String = "%1.1f", yType: Axis.ScaleStyle.Value = Axis.ScaleStyle.Linear) = {
365375
val font = Renderer.FontData("Ariel", Renderer.FontStyle.Plain)
366-
NumericAxis(key, None, None, None, Axis.TickStyle.Both,
376+
NumericAxis(None, None, None, Axis.TickStyle.Both,
367377
Some(Axis.LabelSettings(0.0, font, numFormat)), Some(Axis.NameSettings(text, font)), Axis.DisplaySide.Min, yType)
368378
}
369379
}
@@ -372,7 +382,6 @@ object NumericAxis {
372382
* Axis with text categories for labels instead of numeric values.
373383
*/
374384
case class CategoryAxis(
375-
key: String,
376385
tickStyle: Axis.TickStyle.Value,
377386
labelOrientation: Double, // angle in degrees
378387
labelFont: Renderer.FontData,
@@ -453,6 +462,18 @@ case class CategoryAxis(
453462
}
454463

455464
}
465+
466+
/**
467+
* Override equality because I need this to check for identify in the sets and maps.
468+
*
469+
* @param that
470+
* @return
471+
*/
472+
override def equals(that: Any): Boolean = that match {
473+
case ar: AnyRef => this eq ar
474+
case _ => false
475+
}
476+
456477
}
457478

458479
/**

0 commit comments

Comments
 (0)