Skip to content

Commit 5e6d3c2

Browse files
committed
Serialise axis type
1 parent ae02964 commit 5e6d3c2

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/main/scala/co/theasi/plotly/writer/AxisOptionsWriter.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package co.theasi.plotly.writer
33
import org.json4s._
44
import org.json4s.JsonDSL._
55

6-
import co.theasi.plotly.AxisOptions
6+
import co.theasi.plotly.{AxisOptions, AxisType}
77

88
object AxisOptionsWriter {
99
def toJson(options: AxisOptions): JObject = (
@@ -18,7 +18,16 @@ object AxisOptionsWriter {
1818
("tickfont" -> FontWriter.toJson(options.tickFont)) ~
1919
("autotick" -> options.autoTick) ~
2020
("dtick" -> options.tickSpacing) ~
21+
("type" -> axisTypeToJson(options.axisType)) ~
22+
2123
("tickcolor" -> options.tickColor.map(ColorWriter.toJson _)) ~
2224
("showticklabels" -> options.tickLabels)
2325
)
26+
27+
private def axisTypeToJson(axisTypeMaybe: Option[AxisType.Value]): JValue = {
28+
axisTypeMaybe match {
29+
case Some(axisType) => JString(axisType.toString)
30+
case None => JNothing
31+
}
32+
}
2433
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package co.theasi.plotly.writer
2+
3+
import org.scalatest.{FlatSpec, Matchers}
4+
5+
import org.json4s.JString
6+
7+
import co.theasi.plotly.{AxisOptions, AxisType}
8+
9+
class AxisOptionsWriterSpec extends FlatSpec with Matchers {
10+
"toJson" should "serialize the plot type" in {
11+
val options = AxisOptions().axisType(AxisType.Log)
12+
val jobj = AxisOptionsWriter.toJson(options)
13+
jobj \ "type" shouldEqual JString("log")
14+
}
15+
}

0 commit comments

Comments
 (0)