Skip to content

Commit 352991d

Browse files
nickrobinson251pbugnion
authored andcommitted
Add name options to bar.
1 parent 4f4d444 commit 352991d

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/main/scala/co/theasi/plotly/Plot.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,12 @@ extends Plot {
136136
/** Add a bar series to this plot. */
137137
def withBar[X: Writable, Y: Writable](
138138
xs: Iterable[X],
139-
ys: Iterable[Y]
139+
ys: Iterable[Y],
140+
options: BarOptions = BarOptions()
140141
): CartesianPlot = {
141142
val xsAsPType = xs.map { implicitly[Writable[X]].toPType }
142143
val ysAsPType = ys.map { implicitly[Writable[Y]].toPType }
143-
copy(series = series :+ Bar(xsAsPType, ysAsPType, BarOptions()))
144+
copy(series = series :+ Bar(xsAsPType, ysAsPType, options))
144145
}
145146

146147
/** Add a box plot to this plot. */

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import org.json4s.JsonDSL._
66
import co.theasi.plotly.{
77
ScatterOptions, ScatterMode, MarkerOptions,
88
TextValue, StringText, IterableText, SrcText, SurfaceOptions,
9-
LineOptions
9+
LineOptions, BarOptions
1010
}
1111

1212
object OptionsWriter {
@@ -26,6 +26,10 @@ object OptionsWriter {
2626
("colorscale" -> options.colorscale.map { ColorscaleWriter.toJson })
2727
)
2828

29+
def barOptionsToJson(options: BarOptions): JObject = {
30+
("name" -> options.name)
31+
}
32+
2933
private def scatterModeToJson(mode: Seq[ScatterMode.Value])
3034
: Option[String] =
3135
if (mode.isEmpty) { None }

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ object SeriesWriter {
3333
("xsrc" -> xsrc) ~
3434
("ysrc" -> ysrc) ~
3535
axisToJson(info.axisIndex) ~
36-
("type" -> "bar")
36+
("type" -> "bar") ~
37+
OptionsWriter.barOptionsToJson(info.options)
3738
}
3839

3940
private def boxToJson(info: BoxWriteInfo)

0 commit comments

Comments
 (0)