Skip to content
Browse files

Add pan and zoom support to Flot widget, fixes #1130

  • Loading branch information...
1 parent 8194fb0 commit ddc2a93a1f305febff8ee699d35a1ac055d7081b @dcbriccetti dcbriccetti committed
View
1,416 widgets/src/main/resources/toserve/flot/jquery.flot.js
948 additions, 468 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
168 widgets/src/main/scala/net/liftweb/widgets/flot/Flot.scala
@@ -47,6 +47,7 @@ object Flot {
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
})
}
@@ -65,28 +66,19 @@ object Flot {
options: FlotOptions,
script: JsCmd,
caps: FlotCapability*
- ): NodeSeq =
- {
- val ieExcanvasPackJs = Unparsed("<!--[if IE]><script language=\"javascript\" type=\"text/javascript\" src=\"" +
- urlEncode(net.liftweb.http.S.contextPath) + "/" +
- urlEncode(LiftRules.resourceServerPath) + "/flot/excanvas.js\"></script><![endif]-->")
-
- // 27/06/2009 add style tag )See http://groups.google.com/group/liftweb/browse_thread/thread/5e0335583e2a248b?hl=en&pli=1)
-
-
+ ): NodeSeq = {
renderHead() ++ Script(_renderJs(idPlaceholder, datas, options, script, caps :_*))
}
- def renderHead(): NodeSeq = {
+ def renderHead(): NodeSeq = {
val ieExcanvasPackJs = Unparsed("<!--[if IE]><script language=\"javascript\" type=\"text/javascript\" src=\"" +
urlEncode(net.liftweb.http.S.contextPath) + "/" +
urlEncode(LiftRules.resourceServerPath) + "/flot/excanvas.js\"></script><![endif]-->")
- // 27/06/2009 add style tag )See http://groups.google.com/group/liftweb/browse_thread/thread/5e0335583e2a248b?hl=en&pli=1)
-
-
<head>
- <script type="text/javascript" src={"/" + LiftRules.resourceServerPath + "/flot/jquery.flot.js"}/>
+ {List("flot.js", "flot.navigate.js") map(name =>
+ <script type="text/javascript" src={"/" + LiftRules.resourceServerPath + "/flot/jquery." + name}/>
+ )}
{ieExcanvasPackJs}
<link rel="stylesheet" href={"/" + LiftRules.resourceServerPath + "/flot/jquery.flot.css"} type="text/css"/>
</head>
@@ -99,10 +91,6 @@ object Flot {
}
}
- /*
- *
- */
-
def renderCapability (fRender: FlotCapability => JsCmd, caps: FlotCapability *): JsCmd =
caps.foldLeft(Noop)((js, cap) => js & fRender(cap))
@@ -175,21 +163,6 @@ object Flot {
}
- /*
- private def renderJqueryScript (jqueryScript: Seq[Node]) : JsCmd = {
- jqueryScript.foldLeft ("") ( (sz,node) => {
- sz + (node match {
- case net.liftweb.util.PCData (_s) => _s
- case _ => node.toString
- })
- })
- }
-
- //
-
- val initFlot = "jQuery(function () {"
- val endFlot = "});"
- */
/**
* render a data value:<br/>
* [2, 10]
@@ -285,133 +258,4 @@ object Flot {
case (d, idx) => renderOneSerie(d, idPlaceholder, idx + 1)
} :_*)
-
- //
-
-
- //
- // min: 0, max: 10, tickDecimals: 0
- // mode: "time",
- // minTickSize: [1, "month"], // TODO
- //
- /*
- def renderAxisOptions (options: FlotAxisOptions): JsObj = {
- val info: List[Box[(String, JsExp)]] =
- List(options.min.map(v => ("min", v)),
- options.max.map(v => ("max", v)),
- options.tickDecimals.map(v => ("tickDecimals", v)),
- options.ticks match {
- case Nil => Empty
- case x :: Nil => Full(("ticks", x))
- case xs => Full(("ticks", JsArray(xs.map(d => Num(d)) :_*)))
- },
- options.mode.map(v => ("mode", v))
- )
-
- JsObj(info.flatten(_.toList) :_*)
- }*/
-
- //
- // xaxis: { tickDecimals: 0 },
- // yaxis: { min: 0, max: 10 },
- //
- /*
- def renderAxis (axis : String, options : FlotAxisOptions) : String = {
- axis + "axis: {" + renderAxisOptions (options) + "}"
- }
- */
-
- //
- //
- //
-
-
- //
- //
- //
-
-
-
-
- //
- // {
- // lines: { show: true},
- // points: { show: true}
- // xaxis: { tickDecimals: 0 },
- // yaxis: { min: 0, max: 10 },
- // selection: { mode: "x" }
- // legend: { noColumns: 2 },
- // }
- //
- /*
- def renderOptions(options: FlotOptions): JsExp = {
- var first = true
-
- def endOfLine () = {
- val ret = if (! first) ",\n " else " "
- first = false
- ret
- }
-
- val set_lines = options.lines match {
- case None => ""
- case Some (_lines) => {first=false; "lines: {" + renderLines (_lines) + "}"}
- }
-
- val set_points = options.points match {
- case None => ""
- case Some (_points) => {endOfLine + "points: {" + renderPoints (_points) + "}"}
- }
-
- val set_xaxis = options.xaxis match {
- case None => ""
- case Some (options) => {endOfLine + renderAxis ("x", options)}
- }
-
- val set_yaxis = options.yaxis match {
- case None => ""
- case Some (options) => {endOfLine + renderAxis ("y", options)}
- }
-
- val set_selection = options.modeSelection match {
- case None => ""
- case Some (mode) => {endOfLine + "selection: { mode: '" + mode + "'}"}
- }
-
- val set_legend = options.legend match {
- case None => ""
- case Some (_legend) => {endOfLine + "legend: {" + renderLegend (_legend) + "}"}
- }
-
- val set_shadowSize = options.shadowSize match {
- case None => ""
- case Some (_shadowSize) => {endOfLine + "shadowSize: " + _shadowSize}
- }
-
- val set_grid = options.grid match {
- case None => ""
- case Some (_grid) => {endOfLine + "grid: {" + renderGrid (_grid) + "}"}
- }
-
- if (! first)
- {
- "{\n" +
- set_lines +
- set_points +
- set_xaxis +
- set_yaxis +
- set_selection +
- set_legend +
- set_shadowSize +
- set_grid +
- " }"
- }
- else
- "{}"
- }
-
- def renderId (id : String) : String = {
- "'#" + id + "'"
- }
- */
}
View
30 widgets/src/main/scala/net/liftweb/widgets/flot/FlotOptions.scala
@@ -37,6 +37,8 @@ trait FlotAxisOptions extends BaseFlotOptions {
def max: Box[Double] = None
def mode: Box[String] = Empty
def ticks: List[Double] = Nil // null or number or ticks array or (fn: range -> ticks array)
+ def zoomRange: Box[Pair[Double, Double]] = Empty
+ def panRange: Box[Pair[Double, Double]] = Empty
protected def buildOptions =
List(c("min", min),
@@ -47,7 +49,10 @@ trait FlotAxisOptions extends BaseFlotOptions {
case Nil => Empty
case x :: Nil => Full(("ticks", x))
case xs => Full(("ticks", JsArray(xs.map(d => Num(d)) :_*)))
- })
+ },
+ zoomRange.map(r => ("zoomRange", JsArray(r._1, r._2))),
+ panRange .map(r => ("panRange" , JsArray(r._1, r._2)))
+ )
/* TODO
autoscaleMargin: null or number
labelWidth: null or number
@@ -160,6 +165,23 @@ trait FlotGridOptions extends BaseFlotOptions {
*/
}
+trait ZoomOptions extends BaseFlotOptions {
+ def interactive: Box[Boolean] = Empty
+ def amount: Box[Double] = Empty
+
+ def buildOptions =
+ List(
+ interactive.map(v => ("interactive", v)),
+ amount.map(v => ("amount", v)))
+}
+
+trait PanOptions extends BaseFlotOptions {
+ def interactive: Box[Boolean] = Empty
+
+ def buildOptions =
+ List(interactive.map(v => ("interactive", v)))
+}
+
/**
* Options
*/
@@ -174,6 +196,8 @@ trait FlotOptions extends BaseFlotOptions {
@deprecated def shadowSize: Box[Int] = Empty
def grid: Box[FlotGridOptions] = Empty
def series: Box[Map[String, JsExp]] = Empty
+ def zoomOptions: Box[ZoomOptions] = Empty
+ def panOptions: Box[PanOptions] = Empty
def buildOptions =
List(
@@ -185,7 +209,9 @@ trait FlotOptions extends BaseFlotOptions {
modeSelection.map(v => ("selection", JsObj("mode" -> v))),
c("shadowSize", shadowSize),
c("grid", grid),
- series.map(v => ("series", JsObj(v.toSeq: _*)))
+ series.map(v => ("series", JsObj(v.toSeq: _*))),
+ zoomOptions.map(v => ("zoom", v)),
+ panOptions.map(v => ("pan", v))
)
}

0 comments on commit ddc2a93

Please sign in to comment.
Something went wrong with that request. Please try again.