All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.liftmodules.widgets.flot.Flot.scala Maven / Gradle / Ivy

/*
 * Copyright 2007-2011 WorldWide Conferencing, LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.liftmodules
package widgets
package flot

import xml.{NodeSeq, Unparsed}

import net.liftweb._
import common._
import util._
import Helpers._
import http.LiftRules
import http.js._
import jquery._
import JsCmds._
import JE._
import JqJE._


/**
 * renders a flot graph using http://code.google.com/p/flot/ jQuery widget
 * 
* See the sites/flotDemo webapp for examples. */ object Flot { /** * register the resources with lift (typically in boot) */ def init() { import net.liftweb.http.ResourceServer ResourceServer.allow({ case "flot" :: "jquery.flot.css" :: Nil => true case "flot" :: "jquery.flot.js" :: Nil => true case "flot" :: "jquery.flot.navigate.js" :: Nil => true case "flot" :: "excanvas.js" :: Nil => true }) } def script(xml: NodeSeq): JsCmd = (xml \ "script").map(x => JsRaw(x.text).cmd).foldLeft(Noop)(_ & _) /** * render a flot graph *

* a comet actor should use this version */ def render(idPlaceholder: String, datas: List[FlotSerie], options: FlotOptions, script: JsCmd, caps: FlotCapability* ): NodeSeq = { renderHead() ++ Script(_renderJs(idPlaceholder, datas, options, script, caps :_*)) } def renderHead(): NodeSeq = { val ieExcanvasPackJs = Unparsed("") {List("flot.js", "flot.navigate.js") map(name =>