Skip to content

Add candlestick chart, plus maintainance #226

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 7 commits into from
Oct 19, 2020
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
target/
.bsp/
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ lazy val core = crossProject(JVMPlatform, JSPlatform)
libraryDependencies += Deps.dataClass % Provided
)
.jvmSettings(
compatibilitySettings
compatibilitySettings,
mimaPreviousArtifacts := mimaPreviousArtifacts.value
.filter(!_.revision.startsWith("0.7."))
)

lazy val coreJvm = core.jvm
Expand Down
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)
}
49 changes: 45 additions & 4 deletions core/shared/src/main/scala/plotly/Trace.scala
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ object Bar {
Option(xaxis),
Option(yaxis),
Option(error_y),
Option(showlegend).map(b => b: Boolean),
Option(showlegend) .map(b => b: Boolean),
Option(hoverinfo),
Option(textposition),
Option(opacity).map(d => d: Double),
Option(opacity) .map(d => d: Double),
Option(width),
Option(base)
)
Expand Down Expand Up @@ -316,9 +316,50 @@ object Heatmap {
Option(y),
Option(x),
Option(z),
Option(autocolorscale).map(b => b: Boolean),
Option(autocolorscale) .map(b => b: Boolean),
Option(colorscale),
Option(showscale).map(b => b: Boolean),
Option(showscale) .map(b => b: Boolean),
Option(name)
)
}

@data(optionSetters = true) class Candlestick(
x: Option[Sequence] = None,
close: Option[Sequence] = None,
high: Option[Sequence] = None,
low: Option[Sequence] = None,
open: Option[Sequence] = None,
decreasing: Option[Marker] = None,
increasing: Option[Marker] = None,
line: Option[Marker] = None,
xaxis: Option[AxisReference] = None,
yaxis: Option[AxisReference] = None
) extends Trace

object Candlestick {
@deprecated("Use Candlestick() and chain-call .with* methods on it instead", "0.8.0")
def apply(
x: Sequence = null,
close: Sequence = null,
high: Sequence = null,
low: Sequence = null,
open: Sequence = null,
decreasing: Marker = null,
increasing: Marker = null,
line: Marker = null,
xaxis: AxisReference = null,
yaxis: AxisReference = null
): Candlestick =
Candlestick(
Option(x),
Option(close),
Option(high),
Option(low),
Option(open),
Option(decreasing),
Option(increasing),
Option(line),
Option(xaxis),
Option(yaxis)
)
}
5 changes: 3 additions & 2 deletions core/shared/src/main/scala/plotly/element/Color.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ object Color {
"blue",
"cls", // ???
"pink",
"green"
"green",
"magenta"
)
}

@data class RGB(r: Int, g: Int, b: Int) extends Color

@data class HSL(h: Int, s: Int, l: Int) extends Color
}
}
2 changes: 2 additions & 0 deletions core/shared/src/main/scala/plotly/element/LocalDateTime.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ object LocalDateTime extends PlotlyJavaTimeConversions {
(d.split('-'), t.split(':')) match {
case (Array(IntStr(y), IntStr(m), IntStr(d)), Array(IntStr(h), IntStr(min), IntStr(s))) =>
Some(LocalDateTime(y, m, d, h, min, s))
case (Array(IntStr(y), IntStr(m), IntStr(d)), Array(IntStr(h), IntStr(min))) =>
Some(LocalDateTime(y, m, d, h, min, 0))
case _ => None
}
case _ => None
Expand Down
7 changes: 5 additions & 2 deletions core/shared/src/main/scala/plotly/layout/Annotation.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package plotly
package layout

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

import dataclass.data
import plotly.element._
Expand All @@ -15,7 +15,10 @@ import plotly.element._
yanchor: Option[Anchor] = None,
text: Option[Element] = None,
font: Option[Font] = None,
showarrow: Option[Boolean] = None
showarrow: Option[Boolean] = None,
@since("0.8.0")
ax: Option[Double] = None,
ay: Option[Double] = None
)

object Annotation {
Expand Down
12 changes: 7 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[(Double, Double)] = 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 All @@ -41,7 +41,9 @@ import plotly.element._
tickvals: Option[Sequence] = None,
ticktext: Option[Sequence] = None,
nticks: Option[Int] = None,
automargin: Option[Boolean] = None
automargin: Option[Boolean] = None,
@since("0.8.0")
rangeslider: Option[RangeSlider] = None
)

object Axis {
Expand Down Expand Up @@ -105,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
6 changes: 4 additions & 2 deletions core/shared/src/main/scala/plotly/layout/Layout.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ import plotly.element._
bargroupgap: Option[Double] = None,
hovermode: Option[HoverMode] = None,
boxmode: Option[BoxMode] = None,
scene: Option[Scene] = None

scene: Option[Scene] = None,
@since("0.8.0")
dragmode: Option[String] = None,
shapes: Option[Seq[Shape]] = None
)

object Layout {
Expand Down
8 changes: 8 additions & 0 deletions core/shared/src/main/scala/plotly/layout/RangeSlider.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package plotly.layout

import dataclass.data
import plotly.Range

@data(optionSetters = true) class RangeSlider(
range: Option[Range] = None
)
17 changes: 17 additions & 0 deletions core/shared/src/main/scala/plotly/layout/Shape.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package plotly.layout

import dataclass.data
import plotly.element.{Color, Line}

@data(optionSetters = true) class Shape (
`type`: Option[String] = None,
xref: Option[String] = None,
yref: Option[String] = None,
x0: Option[String] = None,
y0: Option[Double] = None,
x1: Option[String] = None,
y1: Option[Double] = None,
fillcolor: Option[Color] = None,
opacity: Option[Double] = None,
line: Option[Line] = None
)
6 changes: 2 additions & 4 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.3")
addSbtPlugin(("io.github.alexarchambault.sbt" % "sbt-compatibility" % "0.0.8").exclude("com.typesafe", "sbt-mima-plugin"))
addSbtPlugin("io.github.alexarchambault.sbt" % "sbt-compatibility" % "0.0.8")
addSbtPlugin("io.github.alexarchambault.sbt" % "sbt-eviction-rules" % "0.2.0")
addSbtPlugin("com.github.alexarchambault.tmp" % "sbt-mima-plugin" % "0.7.1-SNAPSHOT")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.8.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.3.0")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.0.0")
addSbtPlugin("org.scala-js" % "sbt-jsdependencies" % "1.0.2")
addSbtPlugin("io.get-coursier" % "sbt-shading" % "2.0.0")

resolvers += Resolver.sonatypeRepo("snapshots")
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
2 changes: 2 additions & 0 deletions tests/src/test/scala/plotly/doc/DocumentationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ class DocumentationTests extends AnyFlatSpec with Matchers {
"basic/horizontal-bar",
// TODO? Pie charts
"financial/time-series",
"financial/candlestick-charts",
// "financial/ohlc",
"basic/bubble",
"basic/area",
"layout/sizing",
Expand Down