Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add Range data type
  • Loading branch information
alexarchambault committed Oct 19, 2020
commit bc17090a728ab369c29b3b7b101da574caba5117
17 changes: 17 additions & 0 deletions core/shared/src/main/scala/plotly/Range.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package plotly

import plotly.element.LocalDateTime

import scala.language.implicitConversions

sealed abstract class Range extends Product with Serializable

object Range {
final case class Doubles(range: (Double, Double)) extends Range
final case class DateTimes(range: (LocalDateTime, LocalDateTime)) extends Range

implicit def fromDoubleTuple(t: (Double, Double)): Range =
Doubles(t)
implicit def fromDateTimes(t: (LocalDateTime, LocalDateTime)): Range =
DateTimes(t)
}
10 changes: 5 additions & 5 deletions core/shared/src/main/scala/plotly/layout/Axis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ import plotly.element._
zeroline: Option[Boolean] = None,
zerolinewidth: Option[Double] = None,
zerolinecolor: Option[Color] = None,
range: Option[Sequence] = None,
range: Option[Range] = None,
autorange: Option[Boolean] = None,
ticks: Option[Ticks] = None,
domain: Option[(Double, Double)] = None,
domain: Option[Range] = None,
side: Option[Side] = None,
anchor: Option[AxisAnchor] = None,
`type`: Option[AxisType] = None,
Expand Down Expand Up @@ -70,7 +70,7 @@ object Axis {
zeroline: JBoolean = null,
zerolinewidth: JDouble = null,
zerolinecolor: Color = null,
range: Sequence = null,
range: (Double, Double) = null,
autorange: JBoolean = null,
ticks: Ticks = null,
domain: (Double, Double) = null,
Expand Down Expand Up @@ -107,10 +107,10 @@ object Axis {
Option(zeroline) .map(x => x: Boolean),
Option(zerolinewidth) .map(x => x: Double),
Option(zerolinecolor),
Option(range),
Option(range) .map(x => x: Range),
Option(autorange) .map(x => x: Boolean),
Option(ticks),
Option(domain),
Option(domain) .map(x => x: Range),
Option(side),
Option(anchor),
Option(`type`),
Expand Down
4 changes: 2 additions & 2 deletions core/shared/src/main/scala/plotly/layout/RangeSlider.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package plotly.layout

import dataclass.data
import plotly.Sequence
import plotly.Range

@data(optionSetters = true) class RangeSlider(
range: Option[Sequence] = None
range: Option[Range] = None
)
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ object ArgonautCodecsInternals extends ArgonautCodecsExtra {
implicit val sequenceNestedIntsIsWrapper: IsWrapper[Sequence.NestedInts] = null
implicit val sequenceStringsIsWrapper: IsWrapper[Sequence.Strings] = null
implicit val sequenceDatetimesIsWrapper: IsWrapper[Sequence.DateTimes] = null
implicit val rangeDoublesIsWrapper: IsWrapper[Range.Doubles] = null
implicit val rangeDatetimesIsWrapper: IsWrapper[Range.DateTimes] = null
implicit val doubleElementIsWrapper: IsWrapper[Element.DoubleElement] = null
implicit val stringElementIsWrapper: IsWrapper[Element.StringElement] = null
implicit def oneOrSeqOneIsWrapper[T]: IsWrapper[OneOrSeq.One[T]] = null
Expand Down Expand Up @@ -408,6 +410,9 @@ object ArgonautCodecsInternals extends ArgonautCodecsExtra {
implicit val sequenceJsonCodec: JsonSumCodecFor[Sequence] =
JsonSumCodecFor(jsonSumDirectCodecFor("sequence"))

implicit val rangeJsonCodec: JsonSumCodecFor[Range] =
JsonSumCodecFor(jsonSumDirectCodecFor("range"))

implicit val boxPointsJsonCodec: JsonSumCodecFor[BoxPoints] =
JsonSumCodecFor(jsonSumDirectCodecFor("box points"))

Expand Down