Template:Bluff
Template:BluffEdit

    Tabla de contenidos
    No hay encabezados
    // Bluff - A wrapper for the JavaScript Bluff Graphing package
    // by neilw, 2009
    //
    // Version history:
    //    0.5.0    20-Nov-2009    neilw        First beta version published
    
    var errors = [];
    var id = @id;
    
    //*****************
    // Process options
    //*****************
    
    // type
    var type = $0 ?? $type;
    var allowed_types = [
        /* "AccumulatorBar", */ "Area", "Bar", "Dot", "Line", "Mini.Bar", "Mini.Pie", "Mini.SideBar",
        /* "Net",*/ "Pie", "SideBar", "SideStackedBar", /* "Spider",*/ "StackedArea", "StackedBar"
    ];
    if (type is not str || !list.contains(allowed_types,type)) {
        if (type is not nil)
            let errors ..= [ "invalid graph type '"..type.."'; allowed types are "..string.join(allowed_types,", ") ];
        let type = "Line";
    }
    // types which require single datum per series: Pie, Mini.Pie
    
    // size
    var size = $1 ?? $size;
    if (size is num) let size = [ size, size*(3/4) ];
    if (size is not list || #size != 2 || size[0] is not num || size[1] is not num || size[0] <= 0 || size[1] <= 0) {
        if (size is not nil) let errors ..= [ "size must be a list of positive numbers" ];
        let size = [ 400, 300];
    }
    
    // theme
    var theme = $2 ?? $theme;
    var allowed_themes = [ "keynote", "37signals", "rails_keynote", "odeo", "pastel", "greyscale" ];
    if (theme is not str || !list.contains(allowed_themes, theme)) {
        if (theme is not nil)
            let errors ..= [ "invalid theme '"..theme.."'; allowed themes are "..string.join(allowed_themes,", ") ];
        let theme = "37signals";
    }
    
    // data
    var data = $3 ?? $data;
    if (data is not list) {
        if (data is not nil) let errors ..= [ "data must be a list of maps" ];
        let data = [];
    }
    
    // title
    var title = $4 ?? $title;
    if (title is not str) {
        if (title is not nil) let errors ..= [ "title must be a string" ];
        let title = "";
    }
    
    // labels
    var labels = $5 ?? $labels;
    if (labels is not list && labels is not map) {
        if (labels is not nil) let errors ..= [ "labels must be a list or map" ];
        let labels = {};
    }
    if (labels is list)
        let labels = { (i):labels[i] foreach var i in num.series(0,#labels-1) where labels[i] is not nil };
    
    // y
    var y = $6 ?? $y;
    if (y is not map) {
        if (y is not nil) let errors ..= [ "y must be a map" ];
        let y = {};
    }
    
    //****************************
    // Output the HTML/Javascript
    //****************************
    <html>
    <head>
    <script type="text/javascript" src="http://developer.mindtouch.com/@api/deki/files/4948/=excanvas.js" ></script>;
    <script type="text/javascript" src="http://developer.mindtouch.com/@api/deki/files/4949/=js-class.js" ></script>;
    <script type="text/javascript" src="http://developer.mindtouch.com/@api/deki/files/4947/=bluff-min.js" ></script>;
    
    <script type="text/javascript"> "
    Deki.$(document).ready(function($) {
        var g = new Bluff."..type.."('"..id.."','"..string.join(size,"x").."');
        g.theme_"..theme.."();
        g.title = '"..title.."';
    ";
    // output the data
    foreach (var d in data)
        "g.data("..json.emit(d.name??"")..","..json.emit(d.data)..(d.color ? ","..json.emit(d.color):"").."); ";
    // y axis parameters
    if (y.inc is not nil) "g.y_axis_increment = ".. y.inc .. ";";
    if (y.min is not nil) "g.minimum_value = "   .. y.min .. ";";
    if (y.max is not nil) "g.maximum_value = "   .. y.max .. ";";
    // resume script
    "
        g.labels = " .. json.emit(labels) .. ";
        g.tooltips = true;
        g.draw();
    });
    " </script>
    </head>;
    <body>
    if (#errors) <div style="color:red">
        <strong> "ERRORS:" </strong>;
        <ul> foreach (var e in errors) <li> e </li>; </ul>;
    </div>;
    <canvas id=(id) width=(size[0] .. "px") height=(size[1] .. "px")> </canvas>;
    </body>
    </html>
    
    Etiquetas (Edit tags)
    • No tags
    Debe inicie sesión para enviar un comentario.