diff --git a/core/shared/src/main/scala/viz/vega/plots/Examples.scala b/core/shared/src/main/scala/viz/vega/plots/Examples.scala index a6efb16..876f26e 100644 --- a/core/shared/src/main/scala/viz/vega/plots/Examples.scala +++ b/core/shared/src/main/scala/viz/vega/plots/Examples.scala @@ -523,32 +523,37 @@ case class Aninteractivescatterplotofglobalhealthstatisticsbycountryandyear_Lite using PlotTarget ) extends FromUrl(SpecUrl.Aninteractivescatterplotofglobalhealthstatisticsbycountryandyear_Lite) -object BarChart - extends viz.companions.AxisUtils: +object BarChart extends viz.companions.AxisUtils: + import upickle.default.* + import ujson.Obj + import ujson.Value - trait BarData + trait BarData {} trait BarPlottable(val category: String, val amount: Double) extends BarData trait MarkColour(val colour: String) extends BarData - val takeColourFromData : (ujson.Value => Unit) = spec => spec("marks")(0)("encode")("update")("fill") = ujson.Obj("field" -> "colour") + val takeColourFromData: (ujson.Value => Unit) = spec => + spec("marks")(0)("encode")("update")("fill") = Obj("field" -> "colour") + + //def replaceBarData[T <: BarData](d: Seq[BarData]) = writeJs(d) given enc[JsValue, T <: BarData](using upickleDefault: ReadWriter[T]): ReadWriter[T & BarData] = readwriter[ujson.Value].bimap[T & BarData]( in => - var toMerge: scala.collection.mutable.ArraySeq[ujson.Obj] = scala.collection.mutable.ArraySeq() - val vanilla = upickle.default.writeJs(in)(upickleDefault).obj + var toMerge: scala.collection.mutable.ArraySeq[Obj] = scala.collection.mutable.ArraySeq() + val vanilla = writeJs(in)(upickleDefault).obj in match - case colorful: MarkColor => - toMerge :+= ujson.Obj("colour" -> colorful.color) + case colorful: MarkColour => + toMerge :+= Obj("colour" -> colorful.colour) case _ => () in match - case xyData: XYPlottable => - toMerge :+= ujson.Obj("category" -> xyData.x, "amount" -> xyData.y) + case barData: BarPlottable => + toMerge :+= Obj("category" -> barData.category, "amount" -> barData.amount) case _ => () - toMerge.fold[ujson.Obj](vanilla) { case (start, next) => start.value ++ next.value }, + toMerge.fold[Obj](vanilla) { case (start, next) => start.value ++ next.value }, in => ??? //upickle.default.read[T & BarData](in) )