Changeset 13713

Show
Ignore:
Timestamp:
05/13/08 00:54:33 (2 months ago)
Author:
elazutkin
Message:

dojox.charting: refactoring axis code to work with the possible window
instead of min/max values. !strict

Location:
dojox/trunk/charting
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • dojox/trunk/charting/axis2d/Default.js

    r13563 r13713  
    66 
    77dojo.require("dojo.colors"); 
     8dojo.require("dojo.string"); 
    89dojo.require("dojox.gfx"); 
    910dojo.require("dojox.lang.functional"); 
     
    3435                }, 
    3536                optionalParams: { 
    36                         "min":           0,             // minimal value on this axis 
    37                         "max":           1,             // maximal value on this axis 
    38                         "majorTickStep": 4,             // major tick step 
    39                         "minorTickStep": 2,             // minor tick step 
    40                         "microTickStep": 1,             // micro tick step 
    41                         "labels":        [],    // array of labels for major ticks 
    42                                                                         // with corresponding numeric values 
    43                                                                         // ordered by values 
     37                        min:           0,       // minimal value on this axis 
     38                        max:           1,       // maximal value on this axis 
     39                        from:          0,       // visible from this value 
     40                        to:            1,       // visible to this value 
     41                        majorTickStep: 4,       // major tick step 
     42                        minorTickStep: 2,       // minor tick step 
     43                        microTickStep: 1,       // micro tick step 
     44                        labels:        [],      // array of labels for major ticks 
     45                                                                // with corresponding numeric values 
     46                                                                // ordered by values 
    4447                        // theme components 
    45                         "stroke":        {},    // stroke for an axis 
    46                         "majorTick":     {},    // stroke + length for a tick 
    47                         "minorTick":     {},    // stroke + length for a tick 
    48                         "font":          "",    // font for labels 
    49                         "fontColor":     ""             // color for labels as a string 
     48                        stroke:        {},      // stroke for an axis 
     49                        majorTick:     {},      // stroke + length for a tick 
     50                        minorTick:     {},      // stroke + length for a tick 
     51                        font:          "",      // font for labels 
     52                        fontColor:     ""       // color for labels as a string 
    5053                }, 
    5154 
     
    7073                        if(this.initialized()){ return this; } 
    7174                        this.labels = "labels" in this.opt ? this.opt.labels : labels; 
    72                         if("min" in this.opt){ min = this.opt.min; } 
    73                         if("max" in this.opt){ max = this.opt.max; } 
    74                         if(this.opt.includeZero){ 
    75                                 if(min > 0){ min = 0; } 
    76                                 if(max < 0){ max = 0; } 
    77                         } 
     75                        this.scaler = lin.buildScaler(min, max, span, this.opt); 
    7876                        var minMinorStep = 0, ta = this.chart.theme.axis,  
    7977                                taFont = "font" in this.opt ? this.opt.font : ta.font, 
     
    9189                                                }), "Math.max(a, b)", 0); 
    9290                                        }else{ 
    93                                                 var labelLength = Math.ceil(Math.log(Math.max(Math.abs(min), Math.abs(max))) / Math.LN10), t = []; 
    94                                                 if(min < 0 || max < 0){ t.push("-"); } 
    95                                                 for(i = 0; i < labelLength; ++i){ t.push("9"); } 
    96                                                 var precision = Math.floor(Math.log(max - min) / Math.LN10); 
     91                                                var labelLength = Math.ceil(Math.log(Math.max(Math.abs(this.scaler.min), 
     92                                                                Math.abs(this.scaler.max))) / Math.LN10), 
     93                                                        t = []; 
     94                                                if(this.scaler.min < 0 || this.scaler.max < 0){ t.push("-"); } 
     95                                                t.push(dojo.string.rep("9", labelLength)); 
     96                                                var precision = Math.floor(Math.log(this.scaler.max - this.scaler.min) / Math.LN10); 
    9797                                                if(precision > 0){ 
    9898                                                        t.push("."); 
     
    104104                                } 
    105105                        } 
    106                         this.scaler = lin.buildScaler(min, max, span, this.opt); 
    107106                        this.scaler.minMinorStep = minMinorStep; 
    108107                        this.ticks = lin.buildTicks(this.scaler, this.opt); 
  • dojox/trunk/charting/scaler/linear.js

    r13563 r13713  
    8181                        microPerMinor:  microPerMinor, 
    8282                        scale:                  scale, 
    83                         span:                   span 
     83                        span:                   span, 
     84                        min:                    min, 
     85                        max:                    max 
    8486                }; 
    8587        }; 
     
    9496                        } 
    9597                         
     98                        // update bounds, if needed 
     99                        var includeZeroFlag = false; 
     100                        if("from" in kwArgs){ 
     101                                min = kwArgs.from; 
     102                                h.fixLower = "none"; 
     103                                h.natural = false; 
     104                        }else{ 
     105                                if("min" in kwArgs){ min = kwArgs.min; } 
     106                                includeZeroFlag = true; 
     107                        } 
     108                        if("to" in kwArgs){ 
     109                                max = kwArgs.from; 
     110                                h.fixUpper = "none"; 
     111                                h.natural = false; 
     112                        }else{ 
     113                                if("max" in kwArgs){ max = kwArgs.max; } 
     114                                includeZeroFlag = true; 
     115                        } 
     116                        if(includeZeroFlag && kwArgs.includeZero){ 
     117                                if(min > 0){ min = 0; } 
     118                                if(max < 0){ max = 0; } 
     119                        } 
     120                         
     121                        // check for erroneous condition 
    96122                        if(max <= min){ 
    97123                                return calcTicks(min, max, h, 0, 0, 0, span);   // Object