Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
Add support for setting variables on a per chart basis
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashid Khan committed Nov 3, 2015
1 parent 2df68ce commit 6641cb9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
10 changes: 9 additions & 1 deletion handlers/chain_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ function invoke(fnName, args) {
}
return invoke(item.function, item.arguments);
case 'reference':
var reference = sheet[item.plot - 1][item.series - 1];
var reference;
if (item.series) {
reference = sheet[item.plot - 1][item.series - 1]
} else {
reference = {
type: 'chainList',
list: sheet[item.plot - 1]
}
}
return invoke('first', [reference]);
case 'chain':
return invokeChain(item);
Expand Down
36 changes: 30 additions & 6 deletions public/chain.peg
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@

var functions = [];
var args = [];
var variables = {};

}

start
= tree:series+ {
return {
tree: tree,
tree: tree.filter(function (o) {return o != null}),
functions: functions,
args: args
args: args,
variables: variables
}
}

Expand All @@ -38,7 +40,6 @@ more_args

argument
= name:function_name '=' value:arg_type {

return {
type: 'namedArg',
name: name,
Expand All @@ -50,16 +51,32 @@ argument
/ element:arg_type {return element}

arg_type
= series_type
= variable_get
/ series_type
/ literal:literal {
var result = ltoo(literal);
result.location = simpleLocation(location()),
result.text = text();
return result;
}

variable_get
= '$' name:function_name {
if (variables[name]) {
return variables[name];
} else {
error('$' + name + ' is not defined')
}
}

variable_set
= '$' name:function_name space? '=' space? value:arg_type {
variables[name] = value;
}

series_type
= group
= variable_set
/ group
/ chain
/ reference

Expand Down Expand Up @@ -98,13 +115,20 @@ function "function"
}

reference
= plot:integer ':' series:integer {
= '@' plot:integer ':' series:integer {
return {
type: 'reference',
plot: plot,
series: series
}
}
/ '@' plot:integer {
return {
type: 'reference',
plot: plot
}
}


chain
= func:function rest:function* {return {type: 'chain', chain: [func].concat(rest)}}
Expand Down

0 comments on commit 6641cb9

Please sign in to comment.