Skip to content
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

Change FlotSerie to enable additional fields such as yaxis #9

Open
fmpwizard opened this issue Jul 29, 2013 · 0 comments
Open

Change FlotSerie to enable additional fields such as yaxis #9

fmpwizard opened this issue Jul 29, 2013 · 0 comments
Labels

Comments

@fmpwizard
Copy link
Member

FlotSerie does not provide for putting data on second y axis.
Proposed FlotSerie:

trait FlotSerie extends BaseFlotOptions
{
  def data: List[(Double, Double)] = Nil
  def label: Box[String] = Empty
  def lines: Box[FlotLinesOptions] = Empty
  def points: Box[FlotPointsOptions] = Empty
  def bars: Box[FlotBarsOptions] = Empty
  def color: Box[Either[String, Int]] = Empty
  def shadowSize: Box[Int] = Empty

  def buildOptions = {
    List(label.map(v => ("label", Str(v))),
         lines.map(v => ("lines", v.asJsObj)),
         points.map(v => ("points", v.asJsObj)),
         bars.map(v => ("bars", v.asJsObj)),
         color.map {
           case Left(c) => ("color", Str(c))
           case Right(c) => ("color", Num(c))
         },
         shadowSize.map(s => ("shadowSize", Num(s)))
      )
  }
}

Then using it in Flot:

  def renderOneSerie(data: FlotSerie, idPlaceholder: String, idSerie: Int): JsObj = {
    val info: List[Box[(String, JsExp)]] =
      Full(("data", JsVar("data_"+idPlaceholder + "_" + idSerie))) ::
      data.buildOptions
    JsObj(info.flatten(_.toList) :_*)
  }

Enables user code such as:

      series = new FlotSerie () {
        override val label = Full(theDs.split("@")(0))
        override val data = theDataMap(theDs)
        val yaxis = Full (2)
        override def buildOptions = {
          yaxis.map( v => ("yaxis", Num(v))) ::
          super.buildOptions
        }
      } :: series

Migrated from lift/framework#559

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant