You could do something like the tinymce plugin, or the jsmath_imagefonts
spkg. Basically, test for the existence of the spkg, and then do the
FLOT plotting if the spkg exists. You can see an example in the code
for jsmath_imagefonts, I believe, in the top of notebook.py.
Jason
I should add that FLOT has been discussed before and I think lots of
people would like to see FLOT plotting in Sage. So keep up the good work!
See
http://groups.google.com/group/sage-devel/search?group=sage-devel&q=FLOT&qt_g=Search+this+group
for previous discussions involving FLOT.
Jason
http://code.google.com/p/protochart/
Maurizio,
I think that I would start out by getting a working example using
html(), so that other people could easily try it. Here's what I would do:
* upgrade to sage 3.3, since a lot of the locations of javascript
things changed in 3.3.
* Put the javascript library into $SAGE_ROOT/local/notebook/javascript
(you can see the other javascript libraries are in that directory too).
* Now you can load a javascript library by doing
<script type="text/javascript"
src="/javascript_local/my_js_dir/my_js_file.js"></script>
(/javascript_local is mapped to $SAGE_ROOT/local/notebook/javascript)
* Do an example using html() to load the javascript library and call
the necessary javascript functions. This keeps everything in the
notebook so people get a feel for how to interact with the library, and
it saves you from having to dig into the internals of how Sage Graphics
objects are displayed.
Thanks,
Jason
Right now, I think the best solution for us would be some sort of html
canvas backend for matplotlib. However, I haven't looked closely at the
javascript plotters (just played with them for a bit).
Having a canvas dependency isn't a showstopper, I don't think. IE
doesn't support it, but there are multiple solutions to bring canvas to
IE, including at least a javascript library
(http://code.google.com/p/explorercanvas/) and an activex control
(http://blog.vlad1.com/2008/07/30/no-browser-left-behind/). According
to
http://arstechnica.com/software/news/2008/08/mozilla-drags-ie-into-the-future-with-canvas-element-plugin.ars,
the javascript library is what makes google maps work with IE, so I'd
guess it's pretty well tested and it works.
Jason
As I understand it, matplotlib can do those sorts of things with an
interactive backend (i.e., wxwindows, gtk, qt, etc.). However, none of
those work with the web-based notebook, but the pieces are there. It
would be *cool* if someone would write the necessary
javascript/canvas/html code to make those tools available in a "canvas"
backend. Again, something like the gnuplot canvas backend. You might
be able to even reuse code from the gnuplot canvas backend.
That said, it may be less effort to make an optional flot spkg.
However, for advanced plotting and deep integration with Sage, as you
are seeing, leveraging the power of matplotlib by just writing another
backend may be the best way to go in the end.
I've looked at writing a matplotlib backend, and it didn't look
extremely difficult. There are examples in the backends/ directory, and
it looks like you can get a minimal backend up and running by just
writing a few functions.
You're doing some great work on getting Flot working too! I think
exploring the options is what is most valuable at this point. I just
think that the matplotlib backend is one of the most valuable options
that can be explored.
> Today we (Kenny and me) have a working alpha. It is unfinished, but we
> think that these added capabilities show the possible advantages, if
[snip]
>
> We hope to send you some example ASAP, so that you can judge yourself
> and the decide what to do.
I look forward to seeing what you have!
Jason
On Mon, Feb 23, 2009 at 8:55 AM, Kenny <masso...@gmail.com> wrote:
>
> Is there any good reason for using flotr, protochart or any other
> instead of flot??
Just wanted to point out some other libraries available. I was under
the impression you
just started looking at some way of doing this, but I see in emails
from Maurizio in this
thread that you have some code already with Flot. These are some of
the libraries
I have looked at before (some with 3D capabilities) to do some
plotting for Axiom, but did
not get to decide on one (including Flot). Good luck on your work.
Regards,
Alfredo
I know. We all face constraints on our time. We *really* appreciate
you looking at all of this!
>
> Before starting to write down some lines of code, we had a look at the
> gnuplot Canvas page (http://skuld.bmsc.washington.edu/~merritt/gnuplot/
> canvas_demos/ ) , and I was disappointed by not seeing a single
> example (there are more than 20, I certainly not looked at them all),
> about fast and useful interaction with the plots. I mean, apart from
> enabling a grid, what's the big deal (from my point of view, as a
> user) in having such a Canvas thing, if the result is having a static
> image? What do I know that the interaction is still possible, if they
> don't show in any way its possibilities? Panning, zooming, turning 3d
> objects, and other stuff should be the real target in my opinion!
I agree. The grid and the clicking is a start (i.e., it's getting input
from the browser and using that to change something, the mouse
coordinates displayed). I hope my comments helped us realize that, with
other interactive backends, matplotlib does do panning, zooming, etc. I
hope that a canvas backend for matplotlib would implement the exact same
sort of features. I saw the gnuplot demo as just a proof-of-concept
demo showing that it was possible to automatically generate an
interactive graph for a web browser.
>
> Have a look at the FLOT example page: http://people.iola.dk/olau/flot/examples/
> .. Apart from the very basic ones, the selection tool, zooming tool,
> online enabling of series, etc, looks very attractive to my eyes!
> Moreover, if it hadn't been for the fact of semilog or loglog plots,
> the work of including the plot in the sage notebook was done by this
> morning!!
>
> So at the end of this long day, my thoughts are:
> - FLOT is not so powerful, and the other derivatives (FLOTR,
> Protochart, etc) don't seem to be any better ( I can hardly recognize
> the differences), but still it is very fast to develop with in simple
> cases
I agree that FLOT isn't that powerful compared to matplotlib, but the
functionality is much, much easier to access. I look forward to seeing
a demo of what you've done.
> - matplotlib is obviously the most powerful and well integrated (my
> previous bode plot function relied on matplotlib), but I have some
> doubts about whether the rendering time would be small enough to
> provide a sufficiently satisfying user experience
I see the "canvas" backend to matplotlib being just like the FLOT tool
(indeed, maybe one could even use the FLOT library to do it!). The
matplotlib backend just needs to be able to draw some basic shapes (like
lines and text) and provide some sort of interface for interaction. All
of this should be documented in the matplotlib docs and/or code, and
help is available on the matplotlib list.
That said, I haven't actually developed a matplotlib backend. If one
were interested in working on a canvas (or even a FLOT) backend to
matplotlib, it would probably be best to take things to the matplotlib list.
We really, really appreciate the work you've done in getting FLOT to
work. I think it's a great thing to have available, and FLOT certainly
looks nice. My comments were just to point out that, with more work
than FLOT entails, we could have maybe the best of both worlds
(functionality and javascript/canvas goodness).
Anyways, I look forward to seeing what you have with FLOT.
Jason
Mike Hansen played with doing graphs in SVG a while back and had a nice
little javascript thing that let you drag vertices around. That's
something that is immediately usable, but it didn't do graph creation.
That seems just a bit harder (i.e., Mike's thing is an output thing that
doesn't have to communicate back with Sage, while what you are proposing
is an alternative input mechanism to Sage).
Jason
I think having a viewer='flot' would work well, so that you would do:
p=plot(x^2, (x,0,10))
show(p, viewer='flot')
Jason
(speaking for myself) I think for right now, we aren't considering it
being default, at least until we see it. However, we do eventually want
to have some sort of nice plotting be default in the notebook, but at
the same time we don't want to give up all of the nice powerful plotting
that is available currently through matplotlib.
I see it eventually as an option someone could give to show, just like
now we can do show(..., viewer='tachyon') and get a raytraced image.
Since it is javascript, I think it would only make sense in the notebook.
So:
* not default, but we may consider it if it could replace the
functionality of matplotlib
* only for the notebook
That's my take, anyway.
Jason
That demo is stunningly gorgeous.
William
I agree. It's beautiful and functional. Good job!
Jason
I posted a message to the matplotlib-devel list, and the reply is here:
Jason
Wow! That is awesome!
I would love to have that kind of plotting available to me in Sage.
Dan
--
--- Dan Drake <dr...@kaist.edu>
----- KAIST Department of Mathematical Sciences
------- http://mathsci.kaist.ac.kr/~drake
1) apply http://sage.math.washington.edu/home/boothby/timer.patch
2) upload jquery.flot_r135.js into the data directory of a worksheet
3) paste the attached into a worksheet (in edit mode)
4) Press "start"
Currently, changing more than one @interact widget at a time
"forgets", everything but the first. So, to play with the slider while
the timer is running, you might have to change the "t=timer(1000)" in
the @interact to "t=timer(2000)" or bigger, depending on processor
speed / network latency.
>
> I've done as you told me...
>
> http://sagenb.org/home/pub/285/
>
> this is the public worksheet. It launch a popup windows so pls enable
> popup to see it working. I tested it under Firefox and google chrome.
> It does NOT work with IE, think the bug is in the excanvas.js or
> something
> similar. Nothing that cannot be fixed.
>
> Select an area to interact with the graph. If you hover with the mouse
> on the data series you'll get a tip showing the values of the data.
>
> The x axis shows only the exponent of the base 10 of the log scale.
> This
> far from perfect :) but it looks pretty and enable user interaction
> with the
> graph.
>
> Hope some developer find it interesting and star working with us on
> this!
>
> Bye Rob.
>
I really like this overall, but I found that it's kind of hit and miss
with respect to showing points on the graphs. I'd like to get the point
at the intersection of two lines, but I can't seem to get it to show me
the point. This is using Safari 3.2.1.
Cheers,
Tim.