/* This script uses: 
 * MochiKit - http://mochikit.com/
 * PlotKit - http://www.liquidx.net/plotkit/
 * though note, the plotkit used is modified in many places,
 * as the original did not properly adress many of the MochiKit
 * functions it used. This may not usually be a problem, but
 * they were not externalized to the same extent when used
 * inside of ubiquity - or that is at least the conclusion I drew.
 *
 * */
/* temporarily disabled, throws exceptions in latest trunk
_plot = new Object();
jQuery.get("http://ubiquity.skumleren.net/plot/MochiKit-1.3.1/packed/MochiKit/MochiKit.js", 
           null, 
           function(r,t,x){_plot.MochiKit=r;});
jQuery.get("http://ubiquity.skumleren.net/plot/plotkit-0.9.1/PlotKit/excanvas.js", 
           null, 
           function(r,t,x){_plot.excanvas=r;});
jQuery.get("http://ubiquity.skumleren.net/plot/plotkit-0.9.1/PlotKit/PlotKit_Packed.js", 
           null, 
           function(r,t,x){_plot.PlotKit=r;});


CmdUtils.CreateCommand({
    name: "plot",
    icon: "http://ubiquity.skumleren.net/plot/plot.png",
    homepage: "http://ubiquity.skumleren.net/",
    author: { name: "Christian Sonne", email: "cers@geeksbynature.dk"},
    license: "GPL",
    description: "Generates a plot from selected data",
    help: "Generates a plot from selected data",
    takes: {"data": noun_arb_text},
    _plot: null, // temporary plot holder
    _plotParser: function(data, limit) {
        var no       = 0;
        var maybe    = 1;
        var probably = 2;
        var yes      = 3;

        var html = data.html;
        var text = data.text;

        if (data.html.toLowerCase().indexOf("<table") != -1) {
            return this._plotParserTable(html);
        } else {
            return this._plotParserText(text);
        }
    },
    _plotParserTable: function(data) {
        return "table!";
    },
    _plotParserText: function(data) {
        return "text!";
    },
    preview: function(pblock,data) {
// Using a sandbox doesn't seem to work - document is not defined inside it, 
// which is needed by at least one of my libs
//
//        libs = Components.utils.Sandbox("chrome://ubiquity/content/browser.xul");
//        Components.utils.evalInSandbox(_plot.MochiKit,libs);
//        Components.utils.evalInSandbox(_plot.excanvas,libs);
//        Components.utils.evalInSandbox(_plot.PlotKit,libs);
        data = this._plotParser(data);
        var navigator = CmdUtils.getWindow().navigator;
        var document = window.document;
        pblock.document = document;
        eval(_plot.MochiKit);
        eval(_plot.excanvas);
        eval(_plot.PlotKit);
        try {
            pblock.innerHTML = "<p>"+data+"</p>";
            plot_div = MochiKit.DOM.DIV({"id":"plot_div", "style":"position: relative; float: left;"});
            pblock.appendChild(plot_div);

            var layout = new PlotKit.Layout("line");
            var simpleData = [[1,1],[2,4],[3,9],[4,16]];
            layout.addDataset("dataset", simpleData);
            layout.evaluate();
            var svg = PlotKit.SVGRenderer.SVG({"width": 500, "height": 300, "id":"chart"});
            plot_div.appendChild(svg);
            var chart = new PlotKit.SweetSVGRenderer(svg, layout);
            chart.render();
            var msg = "";
            pblock.appendChild(MochiKit.DOM.A(null,"Click here to add plot to document"));
        } catch (e) {
            if (e instanceof ReferenceError)
                pblock.innerHTML = "Cached preview doesn't work!<br />Please retype the command.";
            else throw e;
        }
    },
    execute: function(pblock, data) {
        CmdUtils.setSelection("<textarea>"+data.direct_object.html+"</textarea>");
//        CmdUtils.setSelection(this._plot);
    }
})*/ 
