Permalink
Browse files

Made type an instantiation argument instead of an option.

  • Loading branch information...
1 parent 1de6e29 commit 9b24dd2b98c8b79418dba701065e6f9f19e097f3 @ChiperSoft committed Jun 13, 2011
Showing with 37 additions and 29 deletions.
  1. +18 −6 Proto.Visualize.js
  2. +4 −4 index.html
  3. +15 −19 interactive.html
View
@@ -17,20 +17,32 @@
window.Proto = window.Proto || {};
window.Proto.Visualize = Class.create({
- initialize: function(table, container, options) {
+ initialize: function(table, type, container, options) {
table = $(table);
- if (arguments.length==2) {
- options = container;
+ switch (arguments.length) {
+ case 2:
container = null;
- } else {
+ options = {};
+ break;
+ case 3:
+ if (Object.isString(container) || Object.isElement(container)) {
+ container = $(container);
+ options = {};
+ } else {
+ options = container;
+ container = null;
+ }
+ break;
+ case 4:
container = $(container);
+ break;
}
//configuration
var o = Object.extend({
- type: 'bar', //also available: area, pie, line
+ type: type || 'bar', //also available: area, pie, line
width: table.getWidth(), //height of canvas - defaults to table height
height: table.getHeight(), //height of canvas - defaults to table height
appendTitle: true, //table caption text is added to chart
@@ -56,7 +68,7 @@
yLabelInterval: 30, //distance between y labels
interaction: false, // only used for lineDots != false -- triggers mouseover and mouseout on original table
debug: false
- },options);
+ },options || {});
//reset width, height to numbers
o.width = parseInt(o.width,10);
View
@@ -11,10 +11,10 @@
<script type="text/javascript">
Event.observe(window,'dom:loaded', function(){
//make some charts
- $$('table.pie').each(function (table) {new Proto.Visualize(table, {type: 'pie', pieMargin: 10, title: '2009 Total Sales by Individual'});});
- $$('table.line').each(function (table) {new Proto.Visualize(table, {type: 'line'});});
- $$('table.area').each(function (table) {new Proto.Visualize(table, {type: 'area'});});
- $$('table.bar').each(function (table) {new Proto.Visualize(table, {type: 'bar', barDirection: 'horizontal'});});
+ $$('table.pie').each(function (table) {new Proto.Visualize(table, 'pie', {pieMargin: 10, title: '2009 Total Sales by Individual'});});
+ $$('table.line').each(function (table) {new Proto.Visualize(table, 'line');});
+ $$('table.area').each(function (table) {new Proto.Visualize(table, 'area');});
+ $$('table.bar').each(function (table) {new Proto.Visualize(table, 'bar', {barDirection: 'horizontal'});});
});
</script>
</head>
View
@@ -13,36 +13,33 @@
Event.observe(window,'dom:loaded', function(){
//make some charts
- $$('table.pie').each(function (table) {new Proto.Visualize(table, {
- type: 'pie',
+ $$('table.pie').each(function (table) {new Proto.Visualize(table, 'pie', {
pieMargin: 10,
title: '2009 Total Sales by Individual',
interaction: true,
tooltip: true
});});
- $$('table.line').each(function (table) {new Proto.Visualize(table, {
- type: 'line',
+ $$('table.line').each(function (table) {new Proto.Visualize(table, 'line', {
lineDots: 'double',
lineMargin: 0,
interaction: true,
tooltip: true
});});
- // Modify point scaling based on the table data
- $('us2').observe('vizualize:beforeUpdate',function marginBeforeDraw(e){
- var data = e.memo;
- var item,i,j,len = data.tableData.allItems.length;
- var multiplier;
- for(i=0;i<len;i+=1) { item = data.tableData.allItems[i];
- multiplier = 0.2+parseFloat(item.xLabels[1],10)/2;
- item.dotSize = item.dotSize*multiplier;
- item.dotInnerSize = item.dotSize-Math.PI/2*data.options.lineWeight;
- }
- });
+ // Modify point scaling based on the table data - DISABLED UNTIL FUTURE ADDITION
+ // $('us2').observe('vizualize:beforeUpdate',function marginBeforeDraw(e){
+ // var data = e.memo;
+ // var item,i,j,len = data.tableData.allItems.length;
+ // var multiplier;
+ // for(i=0;i<len;i+=1) { item = data.tableData.allItems[i];
+ // multiplier = 0.2+parseFloat(item.xLabels[1],10)/2;
+ // item.dotSize = item.dotSize*multiplier;
+ // item.dotInnerSize = item.dotSize-Math.PI/2*data.options.lineWeight;
+ // }
+ // });
- new Proto.Visualize('us2', {
- type: 'line',
+ new Proto.Visualize('us2', 'line', {
lineDots: 'double',
width: 600,
interaction: true,
@@ -60,8 +57,7 @@
}
});
- new Proto.Visualize('us', {
- type: 'line',
+ new Proto.Visualize('us', 'line', {
width:1300,
height:300,
lineWeight:1,

0 comments on commit 9b24dd2

Please sign in to comment.