Closed lJoublanc closed 6 years ago
Ok I've found that this will make plot.show()
work:
implicit val displayer : String => Unit = { s =>
import org.refptr.iscala.display._
implicit val rawHtml : HTMLDisplay[String] = HTMLDisplay( (t : String) => t)
display_html(s)
}
I was somewhat confused by the fact that there are two ways of triggering the html display:
plot,.show()
, a side-effecting function call of type String => Unit
, which as seen above, calls display_html
.plot
the return value is of type vegas.DSL.ExtendedUnitSpecBuilder
. In this case IScala looks for an implicit HTMLDisplay[ExtendedUnitSpecBuilder]
, which is used to display the plot. Without this implicit conversion, a default is used, and you get back the same as what the REPL would print. e.g.:
ExtendedUnitSpecBuilder(ExtendedUnitSpec(None,None,Bar,Some(Encoding(None,None,Some(PositionChannelDef(None,None,None,Some(country),Some(Nominal),None,None,None,None,None)),Some(PositionChannelDef(None,None,None,Some(population),Some(Quantitative),None,None,None,None,None)),None,None,None,None,None,None,None,None,None,None,None)),None,Some(Country Pop),Some(Data(None,None,Some(List(Values(Map(country -> USA, population -> 314)), Values(Map(country -> UK, population -> 64)), Values(Map(country -> DK, population -> 80)))))),None,None))
This is what I was doing in the OP. By adding a second implicit, IScala will display the graph instead:
implicit val displayer2 : HTMLDisplay[vegas.DSL.ExtendedUnitSpecBuilder] =
HTMLDisplay { plot : vegas.DSL.ExtendedUnitSpecBuilder => plot.show.toString }
Trying to use vega 0.3.6 to render some plots with the IScala kernel (not the jupyter-scala kernel).
I use the following for a display function:
implicit val displayer = display.HTMLDisplay( (plot : vegas.DSL.ExtendedUnitSpecBuilder) => plot.pageHTML())
But, using the example plot from your
README.md
, I get the following:The output of
plot.pageHTML()
is as follows, and the culprit appears to be the call tovg.embed
. Is this normal?It would also be nice if somebody could add these instructions to the readme.
Thanks!
EDIT:
And here's the javascript console: