Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds multiply,add to 'sweep' #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 50 additions & 8 deletions src/tools/adjust_tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,35 @@ phantasus.AdjustDataTool.prototype = {

this.sweepAction.on('change', function (e) {
var action = e.currentTarget.value;
var firstDividerText = (function(op) {
switch(op){
case 'Subtract':
return 'from each'
case 'Divide':
return 'each'
case 'Add':
return 'to each'
case 'Multiply':
return 'each'
}})(action);

var secondDividerText = (function(op) {
switch(op){
case 'Subtract':
return 'field'
case 'Divide':
return 'by field'
case 'Add':
return 'field'
case 'Multiply':
return 'by field'
}})(action);

form.$form.find('#Sweep-first-divider').text(
action === 'Divide' ? 'each' : 'from each'
firstDividerText
);
form.$form.find('#Sweep-second-divider').text(
action === 'Divide' ? 'by field:' : 'field:'
secondDividerText
);
});

Expand Down Expand Up @@ -90,7 +114,7 @@ phantasus.AdjustDataTool.prototype = {
name: 'Sweep',
type: 'triple-select',
firstName: 'sweep-action',
firstOptions: ['Divide', 'Subtract'],
firstOptions: ['Divide', 'Subtract', 'Add', 'Multiply'],
firstDivider: 'each',
secondName: 'sweep-target',
secondOptions: ['row', 'column'],
Expand Down Expand Up @@ -236,10 +260,18 @@ phantasus.AdjustDataTool.prototype = {

if (sweepBy !== '(None)') {
functions.sweep = {};

var op = this.sweepAction[0].value === 'Subtract' ?
function (a,b) {return a - b; } :
function (a,b) {return a / b; } ;

var op = (function(op) {
switch(op){
case 'Subtract':
return function (a,b) {return a - b; };
case 'Divide':
return function(a,b) {return a / b; };
case 'Add':
return function(a,b) {return a + b; };
case 'Multiply':
return function(a,b) {return a * b; };
}})(this.sweepAction[0].value);

var mode = this.sweepTarget[0].value;
var sweepVector = mode === 'row' ?
Expand All @@ -248,7 +280,17 @@ phantasus.AdjustDataTool.prototype = {

functions.sweep.mode = mode;
functions.sweep.name = sweepBy;
functions.sweep.op = this.sweepAction[0].value === 'Subtract' ? '-':'/';
functions.sweep.op = (function(op) {
switch(op) {
case 'Subtract':
return '-';
case 'Divide':
return '/';
case 'Add':
return '+';
case 'Multiply':
return '*';
}})(this.sweepAction[0].value);

for (var j = 0, ncols = dataset.getColumnCount(); j < ncols; j++) {
for (var i = 0, nrows = dataset.getRowCount(); i < nrows; i++) {
Expand Down