Skip to content

Commit

Permalink
#48 removing key from group params
Browse files Browse the repository at this point in the history
  • Loading branch information
tracend committed Jul 18, 2013
1 parent fe8145d commit 8ecfe3b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 47 deletions.
4 changes: 2 additions & 2 deletions build/cloudvisio-min.js

Large diffs are not rendered by default.

28 changes: 12 additions & 16 deletions build/cloudvisio.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @name cloudvisio - 0.6.0 (Wed, 17 Jul 2013 12:30:20 GMT)
// @name cloudvisio - 0.6.0 (Thu, 18 Jul 2013 06:27:33 GMT)
// @url https://github.com/makesites/cloudvisio

// @author makesites
Expand Down Expand Up @@ -578,30 +578,26 @@ Cloudvisio.prototype.find = function( query, options ){
// create an axis by grouping the raw data
Cloudvisio.prototype.group = function(){
// for no arguments (or more arguments) just exit
if( !arguments.length ) return this;
//if( !arguments.length ) return this;
// variables
var key, groups, options, field;
var field, groups, options;
// count arguments (groups are optional)
switch( arguments.length ){
case 1:
key = arguments[0];
break;
case 2:
key = arguments[0];
if( arguments[1] instanceof Array ){
groups = arguments[1];
if( arguments[0] instanceof Array ){
groups = arguments[0];
} else {
options = arguments[1];
options = arguments[0];
}
break;
default:
key = arguments[0];
groups = arguments[1];
options = arguments[2];
groups = arguments[0];
options = arguments[1];
break;
}
// fallbacks
options = options || {};
field = this._selectedField || options.field || false;
// get the (working) data
var data = this.data();
//
Expand All @@ -612,15 +608,15 @@ Cloudvisio.prototype.group = function(){
groups = groups.join("`").toLowerCase().split("`");
options.fixed = true; // fixed groups
} else {
groups = this._getValues( key, data );
groups = this._getValues( field, data );
}
// save the query
var id = this.queries({ field: key, type: "group", query: groups }, options);
var id = this.queries({ field: field, type: "group", query: groups }, options);
//

for( var i in data ){
// convert any value to string
var value = (data[i][key] instanceof Object) ? utils.toArray( data[i][key] ).join(",") : ""+data[i][key]+"";
var value = (data[i][field] instanceof Object) ? utils.toArray( data[i][field] ).join(",") : ""+data[i][field]+"";
var opt = {
silent: true,
key: i
Expand Down
28 changes: 14 additions & 14 deletions examples/income.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
// source: http://api.worldbank.org/countries?format=json&per_page=300&json
d3.json("data/income.json", function( data ){
//
vis.data( data[1] );
console.log("available keys: ", vis.keys() );
vis.set({ layout: "force" });
vis.axis("radius", 5);
// create a new axis
vis.axis("name");
vis.group("incomeLevel", ["High", "Medium", "Low"]);
vis
.data( data[1] )
.set({ layout: "force" })
.axis("radius", 5)
.axis("name")
.select("incomeLevel")
.group(["High", "Medium", "Low"]);

vis.render();
});
Expand Down Expand Up @@ -64,13 +64,13 @@ <h3>countries split in high/medium/low groups</h3>

d3.json("data/income.json", function( data ){

vis.data( data[1] );

vis.set({ layout: "force" });
vis.axis("radius", 5);

vis.axis("name");
vis.group("incomeLevel", ["High", "Medium", "Low"]);
vis
.data( data[1] )
.set({ layout: "force" })
.axis("radius", 5)
.axis("name")
.select("incomeLevel")
.group(["High", "Medium", "Low"]);

vis.render();
});
Expand Down
26 changes: 11 additions & 15 deletions lib/regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,26 @@ Cloudvisio.prototype.find = function( query, options ){
// create an axis by grouping the raw data
Cloudvisio.prototype.group = function(){
// for no arguments (or more arguments) just exit
if( !arguments.length ) return this;
//if( !arguments.length ) return this;
// variables
var key, groups, options, field;
var field, groups, options;
// count arguments (groups are optional)
switch( arguments.length ){
case 1:
key = arguments[0];
break;
case 2:
key = arguments[0];
if( arguments[1] instanceof Array ){
groups = arguments[1];
if( arguments[0] instanceof Array ){
groups = arguments[0];
} else {
options = arguments[1];
options = arguments[0];
}
break;
default:
key = arguments[0];
groups = arguments[1];
options = arguments[2];
groups = arguments[0];
options = arguments[1];
break;
}
// fallbacks
options = options || {};
field = this._selectedField || options.field || false;
// get the (working) data
var data = this.data();
//
Expand All @@ -86,15 +82,15 @@ Cloudvisio.prototype.group = function(){
groups = groups.join("`").toLowerCase().split("`");
options.fixed = true; // fixed groups
} else {
groups = this._getValues( key, data );
groups = this._getValues( field, data );
}
// save the query
var id = this.queries({ field: key, type: "group", query: groups }, options);
var id = this.queries({ field: field, type: "group", query: groups }, options);
//

for( var i in data ){
// convert any value to string
var value = (data[i][key] instanceof Object) ? utils.toArray( data[i][key] ).join(",") : ""+data[i][key]+"";
var value = (data[i][field] instanceof Object) ? utils.toArray( data[i][field] ).join(",") : ""+data[i][field]+"";
var opt = {
silent: true,
key: i
Expand Down

0 comments on commit 8ecfe3b

Please sign in to comment.