Skip to content

Commit

Permalink
Merge branch 'release/0.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
crucialfelix committed May 28, 2017
2 parents 4dc84c9 + abb588e commit 2947992
Show file tree
Hide file tree
Showing 97 changed files with 3,262 additions and 4,666 deletions.
5 changes: 4 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"stage-0",
"react"
],
"plugins": ["add-module-exports"],
"plugins": [
"add-module-exports",
"lodash"
],
"env": {
"development": {
"presets": ["react-hmre"]
Expand Down
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
"rules": {
"arrow-body-style": 0,
"arrow-parens": 0,
"comma-dangle": 0,
"comma-dangle": ["error", "never"],
"consistent-return": 0,
"func-names": 1,
"max-len": 1,
"new-cap": 0,
"no-else-return": 0,
"no-mixed-operators": 1,
"no-return-assign": 1,
"no-underscore-dangle": 0,
"no-use-before-define": 0,
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ This will compile and open an Electron app in development mode with hot loading

`Alt-Command-i` will open Chrome Devtools

`Ctrl-h` will open the [Redux-Devtools](https://github.com/gaearon/redux-devtools)

To install the extra devtools, open a console inside the Electron app and run:

```
Expand Down
49 changes: 0 additions & 49 deletions app/actionTypes.js

This file was deleted.

113 changes: 29 additions & 84 deletions app/actions/datasets.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,36 @@
import fs from 'fs';
import { extname, basename, join } from 'path';
import Miso from 'miso.dataset';
import jetpack from 'fs-jetpack';
import _ from 'lodash';
import { project } from 'data-projector';

import {
SELECT_DATASET,
ADD_DATASET_PATHS,
OPEN_DATASET_DIALOG
} from '../actionTypes';
import callActionOnMain from '../ipc/callActionOnMain';
import {
notify
} from './ui';
import {
clipLoopBox
} from './interaction';
import { notify } from './ui';
import { clipLoopBox } from './interaction';

/**
* setDataset - having loaded and parsed a dataset, put that into the redux state
*
* @param {String} path Path the dataset was loaded from
* @param {Miso.Dataset} data The data itself
* @param {Object} metadata Database metadata information (from Miso. often blank)
* @param {Object} dataset data-projector dataset
*/
export function setDataset(path, data, metadata) {
const name = basename(path, extname(path));
export function setDataset(dataset) {
return {
type: SELECT_DATASET,
payload: {
name,
path,
data,
metadata
}
type: 'setDataset',
payload: _.assign({}, dataset, {
name: basename(dataset.path, extname(dataset.path))
})
};
}

/**
* Call the main process to open a select file dialog
*/
export function openDatasetDialog() {
return () => {
callActionOnMain({
type: OPEN_DATASET_DIALOG
});
};
return () => callActionOnMain({ type: 'openDatasetDialog' });
}

const parsers = {
'.json': Miso.Dataset.Parsers.Obj, // already parsed to data
'.csv': Miso.Dataset.Parsers.Delimited
// '.json': true,
'.csv': true
};

/**
Expand All @@ -58,53 +39,19 @@ const parsers = {
* path should be a resolved
*/
export function loadDataset(path) {
return (dispatch) => {
const ext = extname(path);
const parser = parsers[ext];

function fail(message) {
dispatch(notify('error', message));
}

if (!parser) {
return fail(`Filetype not supported: ${ext}`);
}

return dispatch => {
dispatch(notify('inform', 'Loading...'));

fs.readFile(path, {encoding: 'utf8'}, (err, data) => {
if (err) {
return fail(err.message);
}

if (!data) {
return fail(`No data loaded from ${path}`);
}

let data2;
if (ext === '.json') {
try {
data2 = JSON.parse(data);
} catch (e) {
return fail(e);
}
} else {
data2 = String(data);
}

const ds = new Miso.Dataset({
data: data2,
parser
});

// This can fail inside here but it will not
// reject the Promise. It only posts the error to console.
ds.fetch().then((data3) => {
project({}, path, {}, []).then(
dataset => {
dispatch(notify());
dispatch(setDataset(path, data3));
dispatch(setDataset(dataset));
dispatch(clipLoopBox());
}, (error) => fail(error));
});
},
error => {
console.error(error);
dispatch(notify('error', error.message));
}
);
};
}

Expand All @@ -114,13 +61,13 @@ export function loadDataset(path) {
* This is called at startup.
*/
export function readDefaultDatasets(datasetsDir, thenLoadPath) {
return (dispatch) => {
jetpack.listAsync(datasetsDir).then((paths) => {
return dispatch => {
jetpack.listAsync(datasetsDir).then(paths => {
if (paths) {
const dp = paths
// only show those that have a parser
.filter((p) => Boolean(parsers[extname(p)]))
.map((p) => {
.filter(p => Boolean(parsers[extname(p)]))
.map(p => {
return {
name: p,
path: join(datasetsDir, p)
Expand All @@ -142,9 +89,7 @@ export function readDefaultDatasets(datasetsDir, thenLoadPath) {

export function addDatasetPaths(paths) {
return {
type: ADD_DATASET_PATHS,
payload: {
paths
}
type: 'addDatasetPaths',
payload: { paths }
};
}
39 changes: 22 additions & 17 deletions app/actions/interaction.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import _ from 'lodash';
import {
SHOW_BRUSH,
SET_POINTS_UNDER_BRUSH,
TOGGLE_LOOP_MODE,
SET_LOOP_BOX,
SET_LOOP_TIME
} from '../actionTypes';

export function showBrush(show, x, y) {
return {
type: SHOW_BRUSH,
type: 'showBrush',
payload: {
show,
x,
Expand All @@ -18,7 +11,6 @@ export function showBrush(show, x, y) {
};
}


/**
* setPointsUnderBrush - Called when moving the brush over points.
*
Expand All @@ -33,10 +25,10 @@ export function showBrush(show, x, y) {
export function setPointsUnderBrush(m, n, indices) {
return (dispatch, getState) => {
const s = getState().interaction;
const same = (_.isEqual(s.pointsUnderBrush, indices));
const same = _.isEqual(s.pointsUnderBrush, indices);
if (!same) {
dispatch({
type: SET_POINTS_UNDER_BRUSH,
type: 'setPointsUnderBrush',
payload: {
indices,
m,
Expand All @@ -47,7 +39,6 @@ export function setPointsUnderBrush(m, n, indices) {
};
}


/**
* setLoopBox - Start loop at box, or change loop to box, toggle loop off if already playing.
*
Expand All @@ -57,7 +48,7 @@ export function setPointsUnderBrush(m, n, indices) {
*/
export function setLoopBox(m, n) {
return {
type: SET_LOOP_BOX,
type: 'setLoopBox',
payload: {
m,
n
Expand All @@ -84,7 +75,7 @@ export function clipLoopBox() {

const maxDim = dataset.data.columnNames().length - 1;
dispatch({
type: SET_LOOP_BOX,
type: 'setLoopBox',
payload: {
m: Math.min(loopBox.m, maxDim),
n: Math.min(loopBox.n, maxDim)
Expand All @@ -98,11 +89,10 @@ export function clipLoopBox() {
*/
export function toggleLoopMode() {
return {
type: TOGGLE_LOOP_MODE
type: 'toggleLoopMode'
};
}


/**
* setLoopTime - Set time of loop in seconds.
*
Expand All @@ -111,9 +101,24 @@ export function toggleLoopMode() {
*/
export function setLoopTime(loopTime) {
return {
type: SET_LOOP_TIME,
type: 'setLoopTime',
payload: {
loopTime
}
};
}

/**
* setLoopTimeDimension - Set the feature/dimension to be used for loop mode.
*
* @param {number|null} index
* @return {Object} action
*/
export function setLoopTimeDimension(index) {
return {
type: 'setLoopTimeDimension',
payload: {
index
}
};
}
Loading

0 comments on commit 2947992

Please sign in to comment.