Chris Leonello avatar Chris Leonello committed a3e4c9d

In process mods for new merit order renderer.

Comments (0)

Files changed (3)

src/jqplot.core.js

     Axis.prototype = new $.jqplot.ElemContainer();
     Axis.prototype.constructor = Axis;
     
-    Axis.prototype.init = function() {
+    Axis.prototype.init = function(plot) {
         if ($.isFunction(this.renderer)) {
             this.renderer = new this.renderer();  
         }
         else if (this.syncTicks == null){
             this.syncTicks = false;
         }
-        this.renderer.init.call(this, this.rendererOptions);
+        this.renderer.init.call(this, this.rendererOptions, plot);
         
     };
     
                 name = _axisNames[i];
                 axis = this.axes[name];
                 axis._plotDimensions = this._plotDimensions;
-                axis.init();
+                axis.init(this);
                 if (this.axes[name].borderColor == null) {
                     if (name.charAt(0) !== 'x' && axis.useSeriesColor === true && axis.show) {
                         axis.borderColor = axis._series[0].color;

src/plugins/jqplot.meritOrderAxisRenderer.js

     };
     
     // called with scope of axis object.
-    $.jqplot.MeritOrderAxisRenderer.prototype.init = function(options){
+    $.jqplot.MeritOrderAxisRenderer.prototype.init = function(options, plot){
         // prop: tickMode
         // How to space the ticks on the axis.
         // 'bar' will place a tick at the width of each bar.  
         }
         var db = this._dataBounds;
         db.min = 0;
+
+        this._maxSeriesY = 0;
+
+        // first time an axis is called have to
         // for y axes, scale always go from 0 to 1 (0 to 100%)
         if (this.name == 'yaxis' || this.name == 'y2axis') {
             db.max = 100;
             this.tickMode = 'even';
+            for (var i=0; i<this._series.length; i++) {
+                this._maxSeriesY = Math.max(this._maxSeriesY, this._series[i]._sumy);
+            }
         }
-        // For x axes, scale goes from 0 to sum of all y values.
+        // For x axes, scale goes from 0 to sum of all x values.
         else if (this.name == 'xaxis'){
             this.tickMode = (this.tickMode == null) ? 'bar' : this.tickMode;
             for (var i=0; i<this._series.length; i++) {
-                db.max += this._series[i]._sumy;
+                db.max += this._series[i]._sumx;
             }
         }
         else if (this.name == 'x2axis'){
             this.tickMode = (this.tickMode == null) ? 'even' : this.tickMode;
             for (var i=0; i<this._series.length; i++) {
-                db.max += this._series[i]._sumy;
+                db.max += this._series[i]._sumx;
             }
         }
     };
                     var elem = this._barLabels[i].draw(ctx, plot);
                     elem.removeClass('jqplot-'+this.name+'-label');
                     elem.addClass('jqplot-'+this.name+'-tick');
-                    elem.addClass('jqplot-mekko-barLabel');
+                    elem.addClass('jqplot-meritOrder-barLabel');
                     elem.appendTo(this._elem);
                     elem = null;
                 }   

src/plugins/jqplot.meritOrdrerRenderer.js

         var opts = {lineJoin:'miter', lineCap:'butt', isarc:false, fillRect:this.fillRect, strokeRect:this.strokeRect};
         this.renderer.shapeRenderer.init(opts);
         plot.axes.x2axis._series.push(this);
-        this._type = 'mekko';
+        this._type = 'meritOrder';
+
+        plot.postInitHooks.addOnce(postInit);
     };
     
     // Method: setGridData
         var data = this._plotData;
         this.gridData = [];
         // figure out width on x axis.
-        // this._xwidth = this._sumy / plot._sumy * this.canvas.getWidth();
-        this._xwidth = xp(this._sumy) - xp(0);
-        if (this.index>0) {
-            this._xstart = plot.series[this.index-1]._xstart + plot.series[this.index-1]._xwidth;
-        }
-        var totheight = this.canvas.getHeight();
-        var sumy = 0;
-        var cury;
-        var curheight;
-        for (var i=0; i<data.length; i++) {
-            if (data[i] != null) {
-                sumy += data[i][1];
-                cury = totheight - (sumy / this._sumy * totheight);
-                curheight = data[i][1] / this._sumy * totheight;
-                this.gridData.push([this._xstart, cury, this._xwidth, curheight]);
-            }
-        }
+        this._xwidth = xp(this._sumx) - xp(this._xstart);
+        data = [[this._xstart, this.data[0][1]/this._yaxis._maxSeriesY]];
+        this._yhieght = yp(data[0][1]);
+
+        this.gridData.push(xp(data[0][0]), yp(data[0][1]), this._xwidth, this._yheight);
     };
     
     // Method: makeGridData
     $.jqplot.MeritOrderRenderer.prototype.makeGridData = function(data, plot) {
         // recalculate the grid data
         // figure out width on x axis.
+        // Here going to just reimplement setGridData
+        // since we have to know about data of previous series
+        // It doesn't really make any sense to use arbitrary
+        // data for this type of plot.
         var xp = this._xaxis.series_u2p;
-        var totheight = this.canvas.getHeight();
-        var sumy = 0;
-        var cury;
-        var curheight;
-        var gd = [];
-        for (var i=0; i<data.length; i++) {
-            if (data[i] != null) {
-                sumy += data[i][1];
-                cury = totheight - (sumy / this._sumy * totheight);
-                curheight = data[i][1] / this._sumy * totheight;
-                gd.push([this._xstart, cury, this._xwidth, curheight]);
-            }
-        }
+        var yp = this._yaxis.series_u2p;
+        data = this._plotData;
+        gd = [];
+        // figure out width on x axis.
+        this._xwidth = xp(this._sumx) - xp(this._xstart);
+        data = [[this._xstart, this.data[0][1]/this._yaxis._maxSeriesY]];
+        this._yhieght = yp(data[0][1]);
+
+        gd.push(xp(data[0][0]), yp(data[0][1]), this._xwidth, this._yheight);
+
         return gd;
     };
     
         }
         
         if (setopts) {
-            options.axesDefaults.renderer = $.jqplot.MekkoAxisRenderer;
-            options.legend.renderer = $.jqplot.MekkoLegendRenderer;
+            options.axesDefaults.renderer = $.jqplot.MeritOrderAxisRenderer;
+            // options.legend.renderer = $.jqplot.MeritOrderLegendRenderer;
             options.legend.preDraw = true;
         }
     }
     
-    $.jqplot.preInitHooks.push(preInit);
+    $.jqplot.preInitHooks.addOnce(preInit);
+
+    // called with scope of a plot.
+    function postInit(target, data, options) {
+        // go through series and set an ordering parameter on each
+        // order by y value of series data point, lowest to highest.
+        var series = this.series;
+        var s;
+        var order = [];
+        var ymax = 0;
+        for (var i=series.length; i--;) {
+            s = series[i];
+            order.unshift([i, s._sumy]);
+            ymax = Math.max(ymax, s._sumy);
+        }
+
+        order.sort(compare);
+
+        function compare(a, b) {
+            return a[1] - b[1];
+        }
+
+        var xtot = 0;
+
+        for (var i=order.length; i--;) {
+            s = series[order[i][0]];
+            s._meritOrder = i;
+            s._xstart = xtot;
+            xtot += s._sumx;
+        }
+    }
     
 })(jQuery);    
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.