Commits

Chris Leonello committed c6b41c3

Removed makeTag function, just use jQuery!

Comments (0)

Files changed (2)

 		$(document).ready(function(){
 			// chart = $.jqplot('chartdiv', [[[1,1],[2,4], [3,5], [4,5], [6,12]], [[32,18],[46,32],[79,47]]], {series:[{}, {xaxis:'x2axis', yaxis:'y2axis'}], axes:{y2axis:{scale:1.5}}});
 			// chart = $.jqplot('chartdiv', [[[1,1],[2,4], [3,5], [4,5], [6,12]], [[32,18],[46,14],[79,55]]]);
-			chart = $.jqplot('chartdiv', [[[1,1],[2,4], [3,5], [4,1], null, [6,12]], [[32,18],[46,14],[79,55]]], {series:[{}, {xaxis:'x2axis', yaxis:'y2axis'}], axesDefaults:{ticks:{fontSize:'0.85em'}}, axes:{yaxis:{min:0, max:10}}, seriesDefaults:{lineWidth:2.5, shadowOffset:1, shadowDepth:3, shadowAlpha:0.07}});
+			// chart = $.jqplot('chartdiv', [[[1,1],[2,4], [3,5], [4,1], null, [6,12]], [[32,18],[46,14],[79,55]]], {series:[{}, {xaxis:'x2axis', yaxis:'y2axis'}], axesDefaults:{ticks:{fontSize:'0.85em'}}, axes:{yaxis:{min:0, max:15}}, seriesDefaults:{lineWidth:2.5, shadowOffset:1, shadowDepth:3, shadowAlpha:0.07}});
+        chart = $.jqplot('chartdiv', [[[1,1],[2,4], [3,5], [4,1], null, [6,12]]]);
 		});
 		</script>
 		<style type="text/css">
         this.equalYTicks = true;
         // borrowed colors from Flot.
         this.seriesColors = ["#edc240", "#afd8f8", "#cb4b4b", "#4da74d", "#9440ed"];
+        // hooks for plugins
+        this.preDrawHooks = [];
+        this.postDrawHooks = [];
             
         this.init = function(target, data, options) {
             this.targetId = target;
     
         // create the plot and add it do the dom
         this.draw = function(){
+            for (var i=0; i<this.preDrawHooks.length; i++) {
+                this.preDrawHooks[i].call(this);
+            }
             this.drawTitle();
             this.drawAxes();
             this.pack();
             this.makeCanvas();
             this.drawGrid();
             this.drawSeries();
+            for (var i=0; i<this.postDrawHooks.length; i++) {
+                this.postDrawHooks[i].call(this);
+            }
         };
     
         // Add the canvas element to the DOM
                     // Need to pregenerate each axis to get it's bounds and
                     // position it and the labels correctly on the plot.
                     var h, w;
-                    axis.elem = makeTag('div', {class:'jqplot', style:axis.style});
-                    // divs don't have dimensions untill added to dom
-                    this.target.append(axis.elem);
+                    
+                    axis.elem = $('<div class="jqplot-axis">').appendTo(this.target).get(0);
+                    for (var s in axis.style) $(axis.elem).css(s, axis.style[s]);
+
                     for (var i=0; i<axis.ticks.labels.length; i++) {
-                        var elem = makeTag('div', {class:'jqplot', style:axis.ticks.styles[i]}, axis.ticks.labels[i]);
-                        axis.elem.appendChild(elem);
+                        var elem = $('<div class="jqplot-axis-tick">').appendTo(axis.elem).get(0);
+                        
+                        for (var s in axis.ticks.styles[i]) $(elem).css(s, axis.ticks.styles[i][s]);
+                        $(elem).html(axis.ticks.labels[i]);
+                        
                         if (axis.ticks.fontFamily) elem.style.fontFamily = axis.ticks.fontFamily;
                         if (axis.ticks.fontSize) elem.style.fontSize = axis.ticks.fontSize;
+                        
                         h = $(elem).outerHeight();
                         w = $(elem).outerWidth();
+                        
                         if (axis.height < h) {
                             axis.height = h;
                             this.gridOffsets[axis.gridOffset] = h;
             yellow:[255,255,0]
         }; 
 
-    /**
-     * From "JavaScript: the Definitive Guide, by David Flanagan. Copyright 2006 O'Reilly Media, Inc."
-     * 
-     * make(tagname, attributes, children):
-     *   create an HTML element with specified tagname, attributes and children.
-     * 
-     * The attributes argument is a JavaScript object: the names and values of its
-     * properties are taken as the names and values of the attributes to set.
-     * If attributes is null, and children is an array or a string, the attributes 
-     * can be omitted altogether and the children passed as the second argument. 
-     *
-     * The children argument is normally an array of children to be added to 
-     * the created element.  If there are no children, this argument can be 
-     * omitted.  If there is only a single child, it can be passed directly 
-     * instead of being enclosed in an array. (But if the child is not a string
-     * and no attributes are specified, an array must be used.)
-     * 
-     * Example: make("p", ["This is a ", make("b", "bold"), " word."]);
-     *
-     * Inspired by the MochiKit library (http://mochikit.com) by Bob Ippolito
-     */
-    function makeTag(tagname, attributes, children) {
-
-        // If we were invoked with two arguments the attributes argument is
-        // an array or string, it should really be the children arguments.
-        if (arguments.length == 2 && 
-            (attributes instanceof Array || typeof attributes == "string")) {
-            children = attributes;
-            attributes = null;
-        }
-
-        // Create the element
-        var e = document.createElement(tagname);
-
-        // Set attributes
-        if (attributes) {
-            for(var name in attributes) {
-                if (name == 'style') {    // handle a style object
-                    for (var s in attributes[name]) {
-                        e.style[s] = attributes[name][s].toString();
-                    }
-                }
-                else e.setAttribute(name, attributes[name]);
-            }
-        }
-
-        // Add children, if any were specified.
-        if (children != null) {
-            if (children instanceof Array) {  // If it really is an array
-                for(var i = 0; i < children.length; i++) { // Loop through kids
-                    var child = children[i];
-                    if (typeof child == "string")          // Handle text nodes
-                        child = document.createTextNode(child);
-                    e.appendChild(child);  // Assume anything else is a Node
-                }
-            }
-            else if (typeof children == "string") // Handle single text child
-                e.appendChild(document.createTextNode(children));
-            else e.appendChild(children);         // Handle any other single child
-        }
-
-        // Finally, return the element.
-        return e;
-    };
 	
 	// Convienence function that won't hang IE.
 	function log(something) {