Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
remove .reduce functions. fix lint errors (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
tafsiri committed Aug 31, 2018
1 parent 55e2126 commit eb73515
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 49 deletions.
27 changes: 0 additions & 27 deletions demos/mnist/tufte.css
@@ -1,32 +1,5 @@
@charset "UTF-8";

/* Import ET Book styles
adapted from https://github.com/edwardtufte/et-book/blob/gh-pages/et-book.css */

@font-face { font-family: "et-book";
src: url("et-book/et-book-roman-line-figures/et-book-roman-line-figures.eot");
src: url("et-book/et-book-roman-line-figures/et-book-roman-line-figures.eot?#iefix") format("embedded-opentype"), url("et-book/et-book-roman-line-figures/et-book-roman-line-figures.woff") format("woff"), url("et-book/et-book-roman-line-figures/et-book-roman-line-figures.ttf") format("truetype"), url("et-book/et-book-roman-line-figures/et-book-roman-line-figures.svg#etbookromanosf") format("svg");
font-weight: normal;
font-style: normal; }

@font-face { font-family: "et-book";
src: url("et-book/et-book-display-italic-old-style-figures/et-book-display-italic-old-style-figures.eot");
src: url("et-book/et-book-display-italic-old-style-figures/et-book-display-italic-old-style-figures.eot?#iefix") format("embedded-opentype"), url("et-book/et-book-display-italic-old-style-figures/et-book-display-italic-old-style-figures.woff") format("woff"), url("et-book/et-book-display-italic-old-style-figures/et-book-display-italic-old-style-figures.ttf") format("truetype"), url("et-book/et-book-display-italic-old-style-figures/et-book-display-italic-old-style-figures.svg#etbookromanosf") format("svg");
font-weight: normal;
font-style: italic; }

@font-face { font-family: "et-book";
src: url("et-book/et-book-bold-line-figures/et-book-bold-line-figures.eot");
src: url("et-book/et-book-bold-line-figures/et-book-bold-line-figures.eot?#iefix") format("embedded-opentype"), url("et-book/et-book-bold-line-figures/et-book-bold-line-figures.woff") format("woff"), url("et-book/et-book-bold-line-figures/et-book-bold-line-figures.ttf") format("truetype"), url("et-book/et-book-bold-line-figures/et-book-bold-line-figures.svg#etbookromanosf") format("svg");
font-weight: bold;
font-style: normal; }

@font-face { font-family: "et-book-roman-old-style";
src: url("et-book/et-book-roman-old-style-figures/et-book-roman-old-style-figures.eot");
src: url("et-book/et-book-roman-old-style-figures/et-book-roman-old-style-figures.eot?#iefix") format("embedded-opentype"), url("et-book/et-book-roman-old-style-figures/et-book-roman-old-style-figures.woff") format("woff"), url("et-book/et-book-roman-old-style-figures/et-book-roman-old-style-figures.ttf") format("truetype"), url("et-book/et-book-roman-old-style-figures/et-book-roman-old-style-figures.svg#etbookromanosf") format("svg");
font-weight: normal;
font-style: normal; }

/* Tufte CSS styles */
html { font-size: 15px; }

Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -5,9 +5,9 @@
"license": "Apache-2.0",
"private": true,
"scripts": {
"build": "tsc && NODE_ENV=production webpack",
"build": "yarn lint && tsc && NODE_ENV=production webpack",
"lint": "tslint -p . -t verbose",
"test": "karma start"
"test": "yarn lint && karma start"
},
"dependencies": {
"d3-format": "^1.3.0",
Expand Down
6 changes: 3 additions & 3 deletions src/render/confusion_matrix_test.ts
Expand Up @@ -38,7 +38,7 @@ describe('renderConfusionMatrix', () => {
const data = {
values: [[4, 2, 8], [1, 7, 2], [3, 3, 20]],
labels: ['cheese', 'pig', 'font'],
}
};

const container = document.getElementById('container') as HTMLElement;
await renderConfusionMatrix(data, container, {shadeDiagonal: true});
Expand All @@ -61,7 +61,7 @@ describe('renderConfusionMatrix', () => {
let data = {
values: [[4, 2, 8], [1, 7, 2], [3, 3, 20]],
labels: ['cheese', 'pig', 'font'],
}
};

const container = document.getElementById('container') as HTMLElement;

Expand All @@ -71,7 +71,7 @@ describe('renderConfusionMatrix', () => {
data = {
values: [[43, 2, 8], [1, 7, 2], [3, 3, 20]],
labels: ['cheese', 'pig', 'font'],
}
};

await renderConfusionMatrix(data, container);
expect(document.querySelectorAll('.vega-embed').length).toBe(1);
Expand Down
7 changes: 4 additions & 3 deletions src/render/linechart.ts
Expand Up @@ -36,13 +36,14 @@ export async function renderLinechart(
inputArray = Array.isArray(inputArray[0]) ? inputArray as Point2D[][] :
[inputArray] as Point2D[][];

const values = inputArray.reduce((memo, seriesData, i) => {
const values: Point2D[] = [];
inputArray.forEach((seriesData, i) => {
const seriesName: string =
_series[i] != null ? _series[i] : `Series ${i + 1}`;
const seriesVals =
seriesData.map(v => Object.assign({}, v, {series: seriesName}));
return memo.concat(seriesVals);
}, []);
values.push(...seriesVals);
});

const drawArea = getDrawArea(container);
const options = Object.assign({}, defaultOpts, opts);
Expand Down
7 changes: 4 additions & 3 deletions src/render/scatterplot.ts
Expand Up @@ -36,13 +36,14 @@ export async function renderScatterplot(
_values = Array.isArray(_values[0]) ? _values as Point2D[][] :
[_values] as Point2D[][];

const values = _values.reduce((memo, seriesData, i) => {
const values: Point2D[] = [];
_values.forEach((seriesData, i) => {
const seriesName: string =
_series[i] != null ? _series[i] : `Series ${i + 1}`;
const seriesVals =
seriesData.map(v => Object.assign({}, v, {series: seriesName}));
return memo.concat(seriesVals);
}, []);
values.push(...seriesVals);
});

const drawArea = getDrawArea(container);
const options = Object.assign({}, defaultOpts, opts);
Expand Down
18 changes: 9 additions & 9 deletions src/show/history.ts
Expand Up @@ -27,12 +27,13 @@ export async function history(
let values: Point2D[][];
if (Array.isArray(history)) {
values = metrics.map(metric => {
return history.reduce((points: Point2D[], log: Logs, x: number) => {
const points: Point2D[] = [];
history.forEach((log: Logs, x: number) => {
if (log[metric] != null) {
points.push({x, y: log[metric]});
}
return points;
}, []);
});
return points;
});
} else {
values = metrics.map(metric => {
Expand Down Expand Up @@ -90,12 +91,11 @@ export function fitCallbacks(
};
}

return callbackNames.reduce(
(callbacks: FitCallbackHandlers, name: string) => {
callbacks[name] = makeCallbackFor(name);
return callbacks;
},
{});
const callbacks: FitCallbackHandlers = {};
callbackNames.forEach((name: string) => {
callbacks[name] = makeCallbackFor(name);
});
return callbacks;
}

type HistoryLike = Logs[]|{
Expand Down
1 change: 0 additions & 1 deletion src/types.ts
Expand Up @@ -153,7 +153,6 @@ export function isSurface(drawable: Drawable): drawable is Surface {
return false;
}


/**
* Common visualisation options for '.render' functions.
*/
Expand Down
9 changes: 8 additions & 1 deletion tslint.json
Expand Up @@ -33,7 +33,14 @@
],
[
"xitFakeAsync"
]
],
{
"name": [
"*",
"reduce"
],
"message": "Use forEach or a regular for loop instead."
}
],
"ban-types": [
true,
Expand Down

0 comments on commit eb73515

Please sign in to comment.