Skip to content

Commit

Permalink
options.type -> options.view
Browse files Browse the repository at this point in the history
  • Loading branch information
gribnoysup committed Mar 6, 2018
1 parent 54b2931 commit 427693d
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ process.stdin.on('data', chunk => {
});

process.stdin.on('end', () => {
const { type, sort, min, max, length } = mri(process.argv.slice(2));
const { view, sort, min, max, length } = mri(process.argv.slice(2));

const { chart, scale, legend } = draw(JSON.parse(data), {
type,
view,
sort,
min,
max,
Expand Down
6 changes: 3 additions & 3 deletions lib/const.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Chart print types:
* Chart print views:
* normal - one bar on one line
* condensed - two bars on one line
*/
const CHART_TYPES = {
const CHART_VIEWS = {
Normal: 'normal',
Condensed: 'condensed',
};
Expand All @@ -30,4 +30,4 @@ const SORT_METHODS = {
none: Function.prototype,
};

module.exports = { CHART_TYPES, SYMBOLS, SORT_METHODS };
module.exports = { CHART_VIEWS, SYMBOLS, SORT_METHODS };
10 changes: 5 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const chalk = require('chalk');
const randomColor = require('randomcolor');
const { width: terminalWidth } = require('window-size');

const { SYMBOLS, SORT_METHODS, CHART_TYPES } = require('./const');
const { SYMBOLS, SORT_METHODS, CHART_VIEWS } = require('./const');

const { condensedChartReducer, normalChartReducer } = require('./reducers');

Expand All @@ -19,7 +19,7 @@ const {
* @param {Array<{ value: number, color?: string, label?: string }>} values values to put on a chart
*
* @param {Object} [options] chart drawing options
* @param {string} [options.type="normal"] chart type, accepts two values: "normal" or "condensed", defaults to "normal"
* @param {string} [options.view="normal"] chart view, accepts two values: "normal" or "condensed", defaults to "normal"
* @param {number} [options.min] min chart value (inclusive), zero point for the chart, defaults to min value from values array
* @param {number} [options.max] max chart value (inclusive), maximum value on the chart, defaults to max value from values array
* @param {number} [options.length] chart length, defaults to all available space in terminal window
Expand All @@ -36,7 +36,7 @@ const {
function draw(values = [], options = {}) {
values = normalizeValues(values);

const { randomColorOptions, type, sort, min, max, length } = normalizeOptions(
const { randomColorOptions, view, sort, min, max, length } = normalizeOptions(
options
);

Expand Down Expand Up @@ -85,11 +85,11 @@ function draw(values = [], options = {}) {
.slice()
.sort(typeof sort === 'function' ? sort : SORT_METHODS[sort]);

if (type === CHART_TYPES.Normal) {
if (view === CHART_VIEWS.Normal) {
chart = chart.reduce(normalChartReducer, '');
}

if (type === CHART_TYPES.Condensed) {
if (view === CHART_VIEWS.Condensed) {
chart = chart.reduce(condensedChartReducer, '');
}

Expand Down
14 changes: 7 additions & 7 deletions lib/normalizers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { CHART_TYPES, SORT_METHODS } = require('./const');
const { CHART_VIEWS, SORT_METHODS } = require('./const');

const methods = Object.keys(SORT_METHODS);

Expand Down Expand Up @@ -35,13 +35,13 @@ const normalizeValues = values => {

const normalizeOptions = options => {
if (
options.type &&
options.type !== CHART_TYPES.Normal &&
options.type !== CHART_TYPES.Condensed
options.view &&
options.view !== CHART_VIEWS.Normal &&
options.view !== CHART_VIEWS.Condensed
) {
throw new TypeError(
`Unexpected options.type: ${prettify(
options.type
`Unexpected options.view: ${prettify(
options.view
)}. Expected "normal" | "condensed"`
);
}
Expand Down Expand Up @@ -91,7 +91,7 @@ const normalizeOptions = options => {
}

return {
type: options.type || CHART_TYPES.Normal,
view: options.view || CHART_VIEWS.Normal,
max: typeof options.max !== 'undefined' ? parseFloat(options.max) : void 0,
min: typeof options.min !== 'undefined' ? parseFloat(options.min) : void 0,
length:
Expand Down
10 changes: 5 additions & 5 deletions tests/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

exports[`draw should provide result with chart, scale and legend 1`] = `
"
█████████████████████
█████████
███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
███████████████████████████████████
█████████████████████████████████████████████████████████████████████████████████████████████
████████████████████████████████████████████████████████████████████████████████████████████████████
███████████████
███████████████████████████████████████
◺ 8131788.00 32601939.00 ◿
◺ 8131788.00 32601939.00 ◿
█ - 0-14 10333117.00
█ - 15-24 8131788.00
Expand Down
6 changes: 3 additions & 3 deletions tests/__snapshots__/normalizers.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Object {
"min": 1.23,
"randomColorOptions": Object {},
"sort": "none",
"type": "normal",
"view": "normal",
}
`;

Expand All @@ -28,7 +28,7 @@ Object {
"min": undefined,
"randomColorOptions": Object {},
"sort": "none",
"type": "normal",
"view": "normal",
}
`;

Expand All @@ -44,7 +44,7 @@ exports[`normalizers normalizeOptions should throw if sort is not a function 1`]

exports[`normalizers normalizeOptions should throw if sort type is not supported 1`] = `"Unexpected options.sort: \\"magic\\". Expected function or \\"min\\" | \\"max\\" | \\"none\\""`;

exports[`normalizers normalizeOptions should throw if type is not supported 1`] = `"Unexpected options.type: \\"boring\\". Expected \\"normal\\" | \\"condensed\\""`;
exports[`normalizers normalizeOptions should throw if view is not supported 1`] = `"Unexpected options.view: \\"boring\\". Expected \\"normal\\" | \\"condensed\\""`;

exports[`normalizers normalizeValues should normalize Array<number> to Array<{ value: number }> 1`] = `
Array [
Expand Down
2 changes: 1 addition & 1 deletion tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ describe('draw', () => {
};

it('should provide result with chart, scale and legend', () => {
expect(outputResult(data)).toMatchSnapshot();
expect(outputResult(data, { length: 100 })).toMatchSnapshot();
});
});
4 changes: 2 additions & 2 deletions tests/normalizers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ describe('normalizers', () => {
});

describe('normalizeOptions', () => {
it('should throw if type is not supported', () => {
it('should throw if view is not supported', () => {
expect(() =>
normalizeOptions({ type: 'boring' })
normalizeOptions({ view: 'boring' })
).toThrowErrorMatchingSnapshot();
});

Expand Down

0 comments on commit 427693d

Please sign in to comment.