Library neutral patch for Canviz

85 views
Skip to first unread message

Xavier

unread,
Oct 5, 2011, 12:34:46 PM10/5/11
to canviz
Hello,

I need to use Canviz for some project of mine, in which I already use
the jQuery library. I didn't want to use both jQuery and Prorotype
though, so what I did is change the latest SVN version of Canviz so it
can be used with any library, including jQuery.

What I did is translate simple Prototype calls (like
Object.isUndefined) into their native javascript equivalents, and
transfer more complex code (like Class.create or Ajax.Request) into a
separate file that may use another library to do the work. What that
means in practice is that to use Canviz i'll have to include the core
files (canviz.js and path.js), which will call functions defined in a
separate adapter file (let's call it adapters/jQuery.js), which in
turn will call the big libraries like jQuery or Prototype. Because
adapter files contains exactly the same function definitions
(implemented differently), it is easy to switch adapter files if you
want to switch from Prototype to jQuery or Dojo.

So I made this change, without altering any other behavior of Canviz
(yet :), and I thought that maybe you guys would be interested; in
which case you can find the patch file here :

http://www.sprods.net/canviz/canviz-libneutral.diff

It contains the modified core files, as well as adapter files (in an
"adapters" folder) for Prototype and jQuery. It's easy to create other
adapters just by creating a copy of the prototype adapter and changing
the functions contents.

I also have a modified index.html file I used to test the changes.
Didn't put it in the patch but I can send it on demand.

I'll most likely be improving the library in the following month to
add some features required by my project (like node selection, panning/
zooming, etc...), and if you integrate this library neutral patch, i'd
be happy to keep pushing any change you might find interesting in the
project.



Cheers,

Xavier

Ryan Schmidt

unread,
Oct 5, 2011, 9:34:06 PM10/5/11
to can...@googlegroups.com
On Oct 5, 2011, at 11:34, Xavier wrote:

> I need to use Canviz for some project of mine, in which I already use
> the jQuery library. I didn't want to use both jQuery and Prorotype
> though, so what I did is change the latest SVN version of Canviz so it
> can be used with any library, including jQuery.

Thank you! I am interested in being library-neutral; see issue 66:

http://code.google.com/p/canviz/issues/detail?id=66

See my comments there about the direction I'd like to go with this and some questions I have.

In short I would like to:

* not use any JavaScript framework library at all, if possible
* hear how (or whether) other JavaScript (non-framework) libraries do this
* accept patches that make single-purpose changes, so the diffs remain short and understandable

Xavier Roger-Machart

unread,
Oct 6, 2011, 6:13:45 AM10/6/11
to can...@googlegroups.com
It is possible to make a completely framework-independant canviz with
my system, and actually I initially planned to release the patch with
a third "vanilla" adapter, that did not use any framework. The only
reason why I didn't put it in in the end is that I was too lazy to
write the asynchronous loading code (used by canviz for loading the
xdot files). While making a very straightforward implementation would
have been quick, it wouldn't have been as compatible as the
implementations provided by Prototype and jQuery, and I didn't want to
introduce any kind of regression.

This ajax loading method is the only real issue that needs to be
solved to create a completely framework independent version of canviz.
There are some other methods that uses frameworks and will also need
to be rewritten using native javascript stuff, but I don't think
they'll be very hard to do. Maybe I can finish that vanilla adapter if
I get bored some day :)

About the patches, the only quick simplification I can think of is
removing the jQuery adapter. One could create simpler patches by
removing the prototype calls one at a time but that would be pretty
time consuming.

2011/10/6 Ryan Schmidt <googl...@ryandesign.com>:

Xavier Roger-Machart

unread,
Oct 7, 2011, 10:23:15 AM10/7/11
to can...@googlegroups.com
Hello again,

I've done the vanilla (no-framework) adapter. It should work on all
modern browsers.

The archive in the following link contains :
- Three modified index.html files (indexP.html, indexJ.html and
indexV.html) that can be used to test the library with the three
available adapters (prototype, jquery and vanilla respectively). Just
open them in your regular test environment instead of the usual
index.html.
- The vanilla adapter (vanilla.js). Again, it should work with most
modern browsers, but some older ones that works with prototype might
break with the Vanilla adapter. Also, there is a risk that some input
files breaks the page as content escaping might be less complete than
what the frameworks did. Nothing too hard to fix in the future though.

You can find the files here (not a patch, I just put them in an
archive for reference) :
www.sprods.net/canviz/canviz-vanilla-and-tests.zip

Cheers,

Xavier

2011/10/6 Xavier Roger-Machart <xroger...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages