From 4fc7d16810c29fe1331657894e7b432227461b29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Brunk?= Date: Wed, 28 Nov 2018 12:58:57 +0100 Subject: [PATCH 1/3] Add a few axis options. Fixes #41, fixes #42 --- .../main/scala/plotly/element/TickMode.scala | 11 ++++++++++ .../src/main/scala/plotly/layout/Axis.scala | 22 ++++++++++++++++--- .../src/main/scala/plotly/layout/Margin.scala | 9 +++++--- .../scala/plotly/doc/DocumentationTests.scala | 1 + 4 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 core/shared/src/main/scala/plotly/element/TickMode.scala diff --git a/core/shared/src/main/scala/plotly/element/TickMode.scala b/core/shared/src/main/scala/plotly/element/TickMode.scala new file mode 100644 index 0000000..9c5bd9c --- /dev/null +++ b/core/shared/src/main/scala/plotly/element/TickMode.scala @@ -0,0 +1,11 @@ +package plotly.element + +sealed abstract class TickMode(val mode: String) extends Product with Serializable + +object TickMode { + case object Auto extends TickMode("auto") + case object Linear extends TickMode("linear") + case object Array extends TickMode("array") +} + + diff --git a/core/shared/src/main/scala/plotly/layout/Axis.scala b/core/shared/src/main/scala/plotly/layout/Axis.scala index a96dc5a..fd74361 100644 --- a/core/shared/src/main/scala/plotly/layout/Axis.scala +++ b/core/shared/src/main/scala/plotly/layout/Axis.scala @@ -33,7 +33,12 @@ final case class Axis( anchor: Option[AxisAnchor], `type`: Option[AxisType], overlaying: Option[AxisAnchor], - position: Option[Double] + position: Option[Double], + tickmode: Option[TickMode], + tickvals: Option[Sequence], + ticktext: Option[Sequence], + nticks: Option[Int], + automargin: Option[Boolean] ) object Axis { @@ -65,7 +70,13 @@ object Axis { anchor: AxisAnchor = null, `type`: AxisType = null, overlaying: AxisAnchor = null, - position: JDouble = null + position: JDouble = null, + tickmode: TickMode = null, + tickvals: Sequence = null, + ticktext: Sequence = null, + nticks: JInt = null, + automargin: JBoolean = null, + ): Axis = Axis( Option(title), @@ -95,6 +106,11 @@ object Axis { Option(anchor), Option(`type`), Option(overlaying), - Option(position) .map(x => x: Double) + Option(position) .map(x => x: Double), + Option(tickmode), + Option(tickvals), + Option(ticktext), + Option(nticks) .map(x => x: Int), + Option(automargin) .map(x => x: Boolean) ) } diff --git a/core/shared/src/main/scala/plotly/layout/Margin.scala b/core/shared/src/main/scala/plotly/layout/Margin.scala index 76730d5..04c7588 100644 --- a/core/shared/src/main/scala/plotly/layout/Margin.scala +++ b/core/shared/src/main/scala/plotly/layout/Margin.scala @@ -8,7 +8,8 @@ final case class Margin( l: Option[Int], r: Option[Int], t: Option[Int], - b: Option[Int] + b: Option[Int], + pad: Option[Int], ) object Margin { @@ -17,13 +18,15 @@ object Margin { l: JInt = null, r: JInt = null, t: JInt = null, - b: JInt = null + b: JInt = null, + pad: JInt = null ): Margin = Margin( Option(autoexpand).map(b => b: Boolean), Option(l).map(n => n: Int), Option(r).map(n => n: Int), Option(t).map(n => n: Int), - Option(b).map(n => n: Int) + Option(b).map(n => n: Int), + Option(pad).map(n => n: Int) ) } diff --git a/tests/src/test/scala/plotly/doc/DocumentationTests.scala b/tests/src/test/scala/plotly/doc/DocumentationTests.scala index 45e4477..2975b9e 100644 --- a/tests/src/test/scala/plotly/doc/DocumentationTests.scala +++ b/tests/src/test/scala/plotly/doc/DocumentationTests.scala @@ -233,6 +233,7 @@ class DocumentationTests extends FlatSpec with Matchers { "financial/time-series", "basic/bubble", "basic/area", + "layout/sizing", // TODO? Gauge charts // TODO Multiple chart types (needs contour) // TODO Shapes (need mock of d3) From 0a36312473d535e835b068c389169fe1f88e9cef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Brunk?= Date: Wed, 28 Nov 2018 14:01:36 +0100 Subject: [PATCH 2/3] Use Plotly.plotlyVersion in online mode too --- almond/src/main/scala/plotly/Almond.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/almond/src/main/scala/plotly/Almond.scala b/almond/src/main/scala/plotly/Almond.scala index 9666461..06c4e06 100644 --- a/almond/src/main/scala/plotly/Almond.scala +++ b/almond/src/main/scala/plotly/Almond.scala @@ -25,10 +25,10 @@ object Almond { |}); """.stripMargin else - """require.config({ + s"""require.config({ | paths: { | d3: 'https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.min', - | plotly: 'https://cdn.plot.ly/plotly-1.12.0.min', + | plotly: 'https://cdn.plot.ly/plotly-${Plotly.plotlyVersion}.min', | jquery: 'https://code.jquery.com/jquery-3.3.1.min' | }, | From f8b9567ed83caaa08694b75b632a58ec45222869 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Brunk?= Date: Wed, 28 Nov 2018 15:12:09 +0100 Subject: [PATCH 3/3] Remove trailing commas to make it work on 2.11 again --- core/shared/src/main/scala/plotly/layout/Axis.scala | 3 +-- core/shared/src/main/scala/plotly/layout/Margin.scala | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/core/shared/src/main/scala/plotly/layout/Axis.scala b/core/shared/src/main/scala/plotly/layout/Axis.scala index fd74361..a676af9 100644 --- a/core/shared/src/main/scala/plotly/layout/Axis.scala +++ b/core/shared/src/main/scala/plotly/layout/Axis.scala @@ -75,8 +75,7 @@ object Axis { tickvals: Sequence = null, ticktext: Sequence = null, nticks: JInt = null, - automargin: JBoolean = null, - + automargin: JBoolean = null ): Axis = Axis( Option(title), diff --git a/core/shared/src/main/scala/plotly/layout/Margin.scala b/core/shared/src/main/scala/plotly/layout/Margin.scala index 04c7588..984fd04 100644 --- a/core/shared/src/main/scala/plotly/layout/Margin.scala +++ b/core/shared/src/main/scala/plotly/layout/Margin.scala @@ -9,7 +9,7 @@ final case class Margin( r: Option[Int], t: Option[Int], b: Option[Int], - pad: Option[Int], + pad: Option[Int] ) object Margin {