提升、漂浮和jQuery
我是 Lift 框架的新手,在过去的几天里我一直在使用 Flot 小部件。我真的很喜欢这样一个事实:我有一个用 Scala 编写的 Flot javascript 的外观。但是,当我尝试向图表添加更多交互功能时遇到了一些问题。
我试图做的是允许用户放大图表中的数据点。基本上我正在尝试完成这个示例,但是在电梯中: http://people .iola.dk/olau/flot/examples/zooming.html。
缩放的核心部分由以下 javascript 处理:
$("#placeholder").bind("plotselected", function (event, ranges) {
// do some checks on the ranges...
// do the zooming
$.plot($("#placeholder"), getData(...),
$.extend(true, {}, options, {
xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to },
yaxis: { min: ranges.yaxis.from, max: ranges.yaxis.to }
}));
What's the best way to do this in Lift?在上面的代码中,我用纯 JavaScript 生成了绘图,但 flot-widget 应该为我做这个。两次使用该代码似乎是不正确的,一次使用 Flot-widget,一次使用原始 JavaScript。我不确定是否应该将上面的代码块移到 Scala 中。此外,我还没有找到任何有关如何在 Scala DSL 中进行 jQuery 绑定的文档。任何帮助/建议将不胜感激!
谢谢!
最后一个小问题... 需要 jquery.flot.selection 插件来进行缩放,因此我必须手动将其添加到我的 Lift 项目中。没问题,只是 jquery.flot.js 是自动内置的。当我添加 flot.selection 插件时,我的插件版本对于 Lift 中包含的 jquery.flot.js 来说太新了。我必须深入研究罐子才能找出我需要哪个版本的选择插件。
我已经被 Maven 烧伤了很多次,一个库自动为我包含另一个库......我意识到 JavaScript 可能有所不同,但当涉及到包括其他库在内的库时,我仍然很害羞。
好吧...我现在就停止咆哮:) 再次感谢您的帮助。
I'm new to the Lift framework, and for the past couple of days I've been playing around with the Flot widget. I really like the fact that I have a facade to the Flot javascript written in Scala. However, I ran into some issues when I tried to add more interactive features to the graph.
What I'm attempting to do is allow the user to zoom in on data-points in the graph. Basically I'm trying to accomplish this example, but in lift: http://people.iola.dk/olau/flot/examples/zooming.html.
The meat of the zoom is handled by this javascript:
$("#placeholder").bind("plotselected", function (event, ranges) {
// do some checks on the ranges...
// do the zooming
$.plot($("#placeholder"), getData(...),
$.extend(true, {}, options, {
xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to },
yaxis: { min: ranges.yaxis.from, max: ranges.yaxis.to }
}));
What's the best way to do this in Lift? In the code above I'm generating the plot in pure-javascript, but the flot-widget is supposed to do this for me. It seems incorrect to have that code twice, once using the Flot-widget and once again here in raw javascript. I'm not sure if I should move the chunk of code above into Scala. Futhermore, I haven't found any documentation on how to do a jQuery bind in the Scala DSL. Any help/advice would be greatly appreciated!
Thanks!
One final niggle...
The jquery.flot.selection plugin is required to do zooming, so I had to add that into my Lift project manually. That's fine, except that the jquery.flot.js is built-in automatically. When I added the flot.selection plugin, my plugin version was too new for the jquery.flot.js included with Lift. I had to go spelunking through the jars to figure out which version of the selection plugin I needed.
I've gotten burned by maven quite a number of times where one library included another library automatically for me...I realize JavaScript may be different but I'm still gun-shy when it comes to libraries including other libraries.
Okay...I'll stop ranting now :)
Thanks again for the help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我无法评论 Lift 平台方面,但对于 flot 本身,无法使用几乎相同的选项和数据集重新调用绘图。
如果您自己编写整个内容,我会说只需编写一个函数,该函数接受范围对象并为您调用绘图,然后在页面加载时和在
plotselected
函数中调用它。事实上,两次通话是你唯一合适的选择。I can't comment on the Lift platform aspect, but for flot itself, there is no way around the need to re-call plot with nearly the same set of options and data.
If you were writing the whole thing yourself, I'd say just write a function that takes the ranges object and calls plot for you, and call that on page load and in the
plotselected
function. As it is, two calls is your only decent option.