Skip to content

3d Surface Plots #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/shared/src/main/scala/plotly/Sequence.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ sealed abstract class Sequence extends Product with Serializable

object Sequence {
final case class Doubles(seq: Seq[Double]) extends Sequence
final case class NestedDoubles(seq: Seq[Seq[Double]]) extends Sequence
final case class Strings(seq: Seq[String]) extends Sequence
final case class DateTimes(seq: Seq[LocalDateTime]) extends Sequence

Expand All @@ -17,6 +18,8 @@ object Sequence {
Doubles(s.map(_.toDouble))
implicit def fromLongSeq(s: Seq[Long]): Sequence =
Doubles(s.map(_.toDouble))
implicit def fromNestedDoubleSeq(s: Seq[Seq[Double]]): Sequence =
NestedDoubles(s)
implicit def fromStringSeq(s: Seq[String]): Sequence =
Strings(s)
implicit def fromDateTimes(seq: Seq[LocalDateTime]): Sequence =
Expand Down
25 changes: 25 additions & 0 deletions core/shared/src/main/scala/plotly/Trace.scala
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,28 @@ object Histogram {
Option(histfunc)
)
}

@data class Surface(
x: Option[Sequence],
y: Option[Sequence],
Comment on lines +240 to +241
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out that in order to get something like below you need the x and y axes as well. I though you could provide these via the axes in the scene (part of the layout) but you cannot.

surface

z: Option[Sequence],
showscale: Option[Boolean],
opacity: Option[Double]
) extends Trace

object Surface {
def apply(
x: Sequence = null,
y: Sequence = null,
z: Sequence = null,
showscale: JBoolean = null,
opacity: JDouble = null
): Surface =
Surface(
Option(x),
Option(y),
Option(z),
Option(showscale) .map(b => b: Boolean),
Option(opacity) .map(d => d: Double)
)
}
10 changes: 7 additions & 3 deletions core/shared/src/main/scala/plotly/layout/Layout.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ import dataclass.data
bargap: Option[Double],
bargroupgap: Option[Double],
hovermode: Option[HoverMode],
boxmode: Option[BoxMode]
boxmode: Option[BoxMode],
scene: Option[Scene]

)

object Layout {
Expand Down Expand Up @@ -62,7 +64,8 @@ object Layout {
bargap: JDouble = null,
bargroupgap: JDouble = null,
hovermode: HoverMode = null,
boxmode: BoxMode = null
boxmode: BoxMode = null,
scene: Scene = null
): Layout =
new Layout(
Option(title),
Expand Down Expand Up @@ -90,6 +93,7 @@ object Layout {
Option(bargap).map(x => x),
Option(bargroupgap).map(x => x),
Option(hovermode),
Option(boxmode)
Option(boxmode),
Option(scene)
)
}
25 changes: 25 additions & 0 deletions core/shared/src/main/scala/plotly/layout/Scene.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package plotly
package layout

import java.lang.{ Integer => JInt, Double => JDouble, Boolean => JBoolean }

import dataclass.data
import plotly.element._

@data class Scene(
xaxis: Option[Axis],
yaxis: Option[Axis],
zaxis: Option[Axis]
)

object Scene {
def apply(
xaxis: Axis = null,
yaxis: Axis = null,
zaxis: Axis = null
): Scene = new Scene(
Option(xaxis),
Option(yaxis),
Option(zaxis)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ object ArgonautCodecsInternals extends ArgonautCodecsExtra {
implicit val boxMeanBoolIsWrapper: IsWrapper[BoxMean.Bool] = null
implicit val boxPointsBoolIsWrapper: IsWrapper[BoxPoints.Bool] = null
implicit val sequenceDoublesIsWrapper: IsWrapper[Sequence.Doubles] = null
implicit val sequenceNestedDoublesIsWrapper: IsWrapper[Sequence.NestedDoubles] = null
implicit val sequenceStringsIsWrapper: IsWrapper[Sequence.Strings] = null
implicit val sequenceDatetimesIsWrapper: IsWrapper[Sequence.DateTimes] = null
implicit val doubleElementIsWrapper: IsWrapper[Element.DoubleElement] = null
Expand Down
4 changes: 2 additions & 2 deletions tests/src/test/scala/plotly/doc/DocumentationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,10 @@ class DocumentationTests extends FlatSpec with Matchers {
// TODO Heatmaps
// TODO Heatmap and contour colorscales
// TODO Polar charts
"scientific/log"
"scientific/log",
// TODO Financial charts
// TODO Maps
// TODO 3D charts
"3d/3d-surface"
)

val subDirs = subDirNames.map(new File(dir, _))
Expand Down