Table of contents
    No headers
    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*.75 ];
    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 = {};
    }
    <html>
    <head>
    <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-src.js" ></script>;
    <script type="text/javascript" src="http://developer.mindtouch.com/@api/deki/files/4948/=excanvas.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):"")..");\n";
    // y axis parameters
    if (y.inc is not nil) "    g.y_axis_increment = ".. y.inc .. ";\n";
    if (y.min is not nil) "    g.minimum_value = "   .. y.min .. ";\n";
    if (y.max is not nil) "    g.maximum_value = "   .. y.max .. ";\n";
    // 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>
    
    Tag page

    Files 3

    FileVersionSizeModified 
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by