root/extensions/agile_pm/public/javascripts/plus_chart.js

Download in other formats: Raw | Text
Revisions
Dimitrij Denissenko
Dimitrij Denissenko
Sep 12 2009 * 10:58
(12 months ago)

Revision c6ea8aef0cef1ec0ec0dc42a0c5d2972b6fbfaf1

Merge AgilePM into the main distribution Fixed AgilePM permission for Backlog viewing

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
PlusChart = {};

PlusChart.Base = Class.create({
  
});

PlusChart.Stack = Class.create(PlusChart.Base, {
  
  initialize: function(element, total, items) {
    this.element = $(element);
    this.total = total;    
    this.element.
      addClassName('plus-chart').    
      addClassName('plus-chart-stack');
    
    this.dimensions = this.element. 
      update(new Element('div').update(' ')).
      down('div').getDimensions();
    this.remaining = this.dimensions.width;
    
    this.element.update('');    
    if (items) items.each(function(item) { this.insertItem(item) }.bind(this)); 
  },
  
  insertItem: function(item) {
    if (this.total == 0) return;

    var width = Math.round(this.dimensions.width * item.value / this.total);
    if (width > this.remaining) width = this.remaining;
    if (width < 1) return;
    
    var label = item.label || item.value;        
    var slice = new Element('div', {
      className: 'plus-chart-stack-item' 
    }).setStyle({ 'float': 'left'}).update(label); 
    this.element.insert(slice);
    
    if (item.className) slice.addClassName(item.className);
    if (item.title) slice.title = item.title;    
    if (slice.getWidth() > width) {
      slice.update('&nbsp;');
      slice.title = slice.title ? slice.title + ' - ' + label : label;   
    }
    slice.setStyle({ 'width': (width - 1) + 'px' });    
    this.remaining = this.remaining - width;
  }

});