-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move histogram-related functions to their own file, start adding supp…
…ort for the 'explore' DSL parser, add a stub for iframe-specfic CSS.
- Loading branch information
1 parent
e9e6a76
commit 2c3c771
Showing
7 changed files
with
737 additions
and
73 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
function formatHistogramField(field) { | ||
return sprintf( | ||
'<li>' + | ||
'%(name)s' + | ||
'</li>', field); | ||
} | ||
|
||
function formatHistogramData(fields, data) { | ||
// TODO: Change data format to include context (for hovertips, etc.) | ||
var data = []; | ||
|
||
// XXX: Don't hardcode this? | ||
var path = $('#graph-fields input[data-field=value]').val(); | ||
|
||
var source = getSource(); | ||
|
||
_.each(source.data, function(datum) { | ||
data.push(propertyByPath(datum, path)); | ||
}); | ||
|
||
// Coerce strings to their length for XXX numeric fields | ||
data = _.map(data, function(datum) { | ||
if (typeof datum == "string") { | ||
return datum.length; | ||
} | ||
|
||
return datum; | ||
}); | ||
|
||
// Return the scrubbed data | ||
return _.without(data, undefined, null, false, NaN, ''); | ||
} | ||
|
||
function renderHistogram(data) { | ||
var uniqueValues = _.uniq(data).length; | ||
|
||
var settings = { | ||
data: data, | ||
height: 400, | ||
bins: Math.min(uniqueValues, 25), | ||
bottompad: 15, | ||
toppad: 25, | ||
labelsize: 10, | ||
labelGenerator: function(d, i) { | ||
var val = d3.round(d.y); | ||
|
||
if (val == 0) { | ||
return ''; | ||
} else { | ||
return val; | ||
} | ||
}, | ||
rangeGenerator: function(d) { | ||
return sprintf('%d', Math.ceil(d.x)); | ||
} | ||
}; | ||
|
||
// XXX: Don't hardcode this? | ||
var path = $('#graph-fields input[data-field=value]').val(); | ||
|
||
var source = getSource(); | ||
|
||
$('#title').html(sprintf('Histogram of <em>%s</em> data', source.name)); | ||
$('#sub-title').text(path); | ||
|
||
$('#canvas').d3histogram(settings); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
%lex | ||
|
||
%% | ||
|
||
\s+ /* skip */ | ||
"//".* /* ignore comment */ | ||
"/*"[\w\W]*?"*/" /* ignore comment */ | ||
"*" return '*'; | ||
"/" return '/'; | ||
"-" return '-'; | ||
"+" return '+'; | ||
"^" return '^'; | ||
"(" return '('; | ||
")" return ')'; | ||
"[" return '['; | ||
"]" return ']'; | ||
"," return ','; | ||
[a-zA-Z_]+[a-zA-Z0-9_]* return 'STRING'; | ||
[0-9]+("."[0-9]*)? return 'NUMBER'; | ||
"."[0-9]+ return 'NUMBER'; | ||
<<EOF>> return 'EOF'; | ||
|
||
/lex | ||
|
||
%left '+' '-' | ||
%left '*' '/' | ||
%left '^' | ||
%left NEG POS | ||
|
||
%% | ||
|
||
expressions | ||
: e EOF | ||
{ return $1; } | ||
; | ||
|
||
num | ||
: n | ||
| '+' n | ||
{ $$ = $2; } | ||
| '-' n | ||
{ $$ = -$2; } | ||
| '(' e ')' | ||
{ $$ = $2; } | ||
| function | ||
; | ||
|
||
e | ||
: n | ||
| e '+' e | ||
{ $$ = $1 + $3; } | ||
| e '-' e | ||
{ $$ = $1 - $3; } | ||
| e '*' e | ||
{ $$ = $1 * $3; } | ||
| e '/' e | ||
{ $$ = $1 / $3; } | ||
| e '^' e | ||
{ $$ = Math.pow($1, $3); } | ||
| '+' e %prec POS | ||
{ $$ = $2; } | ||
| '-' e %prec NEG | ||
{ $$ = -$2; } | ||
| '(' e ')' | ||
{ $$ = $2; } | ||
| variable | ||
| function | ||
; | ||
|
||
function | ||
: id '(' e ')' | ||
{{ | ||
switch ($1) { | ||
case 'cos': | ||
case 'sin': | ||
case 'tan': | ||
$$ = yy.apply($3, function(a) { return Math[$1](a * Math.PI / 180); }); | ||
break; | ||
case 'acos': | ||
case 'asin': | ||
case 'atan': | ||
$$ = yy.apply($3, function(a) { return Math[$1](a) / Math.PI * 180; }); | ||
break; | ||
case 'log': | ||
case 'exp': | ||
case 'sqrt': | ||
case 'abs': | ||
$$ = yy.apply($3, function(a) { return Math[$1](a); }); | ||
break; | ||
case 'log10': | ||
$$ = yy.apply($3, function(a) { return Math.log(a) * Math.LOG10E; }); | ||
break; | ||
case 'parseFloat': | ||
$$ = yy.apply($3, function(a) { return parseFloat(a, 10); }); | ||
break; | ||
case 'parseInt': | ||
$$ = yy.apply($3, function(a) { return parseInt(a, 10); }); | ||
break; | ||
case 'length': | ||
$$ = yy.apply($3, function(a) { return a.length; }); | ||
break; | ||
case 'uniqueCharacters': | ||
$$ = yy.apply($3, function(a) { return yy._(a.split('')).uniq().length; }); | ||
break; | ||
default: | ||
throw new Error('function \'' + $1 + '\' is not defined'); | ||
} | ||
}} | ||
| id '(' e ',' e ')' | ||
{{ | ||
switch ($1) { | ||
case 'add': | ||
$$ = yy.apply($3, function(a) { return a + $5; }); | ||
break; | ||
case 'subtract': | ||
$$ = yy.apply($3, function(a) { return a - $5; }); | ||
break; | ||
case 'atan2': | ||
$$ = Math.atan2($3, $5) / Math.PI * 180; | ||
break; | ||
case 'mod': | ||
$$ = $3 % $5; | ||
break; | ||
default: | ||
throw new Error('function \'' + $1 + '\' is not defined'); | ||
} | ||
}} | ||
; | ||
|
||
n | ||
: NUMBER | ||
{ $$ = parseFloat(yytext, 10); } | ||
; | ||
|
||
variable | ||
: id | ||
{ $$ = yy.data[$1]; } | ||
; | ||
|
||
id | ||
: STRING | ||
{ $$ = yytext; } | ||
; |
Oops, something went wrong.