Skip to content

Commit 1f5560f

Browse files
committed
Update package environment for NPM publishing
1 parent a2bf90f commit 1f5560f

File tree

9 files changed

+51
-22
lines changed

9 files changed

+51
-22
lines changed

.npmignore

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
# Development
12
src
23
demo
34
.babelrc
45
.eslintrc
6+
7+
# Webpack
58
webpack.config.js
6-
index.html
9+
webpack.config.base.js
10+
webpack.config.dev.js
11+
webpack.config.prod.js
12+
13+
# Testing
14+
index.html
15+
coverage

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ _This renders a smooth graph with hovering enabled. The y-value is passed down t
8686
| debug | Boolean | false | Displays debug information on graph, including anchor and control points. |
8787
| width | String | '100%' | The width of the component within a container element. |
8888
| height | String | '100%' | The height of the component within a container element. |
89-
| compression| Number | 0 | The compression factor of the data-set from 0 to 1. Compresses data along the Y-axis. |
89+
| compression| Number | 0.1 | The compression factor of the data-set from 0 to 1. Compresses data linearly from top and bottom along the Y-axis. |
9090
| onHover| Function | () => {} | The callback function to which an array containing currently hovered point ([x, y]) is passed when the user hovers. Useful for displaying the hovered value in the parent component (the one you write). Only active when 'hover' is set to true. |
9191
9292
_For more examples and usage, please refer to the [Wiki][wiki] (under development)._
@@ -148,6 +148,7 @@ Distributed under the MIT license. See ``LICENSE`` for more information.
148148
- Publish on NPM, update README tags
149149
- Allow multiple transformation functions in drawPath function, using piping
150150
- Add X-Y padding option
151+
- Prevent re-run of findCtrlPoint function upon hover
151152
152153
## Challenges
153154
- Make hovering compatible with responsive height/width: need 3 data points per axis (viewBox dimension, cursor position, current dimension)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"test": "jest --coverage --verbose --watch",
88
"start": "webpack-dev-server --open --env=dev",
9-
"build": "webpack -d --watch --env=dev"
9+
"build": "webpack -d --watch --env=prod"
1010
},
1111
"repository": {
1212
"type": "git",

spec/_constants/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
module.exports = {
2-
pointsWithIntegers: [[0, 10], [10, 70], [20, 45], [30, 100], [40, 10], [60, 80]],
3-
pointsWithNegatives: [[0, -10], [-10, -70], [20, -45], [-30, 100], [40, -10], [-60, 80]],
4-
pointsWithDecimals: [[0.001, -10.92], [-10, -7230.87], [20.21, -45.0]],
5-
pointsUnordered: [[20, 45], [0, 10], [40, 10], [10, 70], [60, 80], [30, 100]],
6-
pointsRandom: (() => {
2+
integers: [[0, 10], [10, 70], [20, 45], [30, 100], [40, 10], [60, 80]],
3+
negative: [[0, -10], [-10, -70], [20, -45], [-30, 100], [40, -10], [-60, 80]],
4+
decimals: [[0.001, -10.92], [-10, -7230.87], [20.21, -45.0]],
5+
unordered: [[20, 45], [0, 10], [40, 10], [10, 70], [60, 80], [30, 100]],
6+
random: (() => {
77
const data = [];
88
for (let i = 0; i < 100; i += 1) {
99
data.push([i, Math.random() * 20]);
1010
}
1111
return data;
1212
})(),
13-
pointsExtreme: [[0, 50], [10, 100], [20, 10], [30,300]],
13+
extreme: [[0, 0], [28, 0.97], [29, 19.69], [30, 19.63], [31, 7.96], [60, 0]],
1414
};

spec/_services-spec/drawPath.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,36 @@ const CONSTANTS = require('../_constants');
33

44
describe('Basic functionality of drawPath', () => {
55
it('draws a path given integer coordinates', () => {
6-
const integerPath = drawPath(CONSTANTS.pointsWithIntegers);
6+
const integerPath = drawPath(CONSTANTS.integers);
77
expect(integerPath).toBe('M0,10 L10,70 L20,45 L30,100 L40,10 L60,80');
88
});
99

1010
it('draws a valid path upon given an unordered dataset', () => {
11-
const integerPath = drawPath(CONSTANTS.pointsUnordered);
11+
const integerPath = drawPath(CONSTANTS.unordered);
1212
expect(integerPath).toBe('M0,10 L10,70 L20,45 L30,100 L40,10 L60,80');
1313
});
1414

1515
it('draws a path given negative coordinates', () => {
16-
const negativePath = drawPath(CONSTANTS.pointsWithNegatives);
16+
const negativePath = drawPath(CONSTANTS.negatives);
1717
expect(negativePath).toBe('M-60,80 L-30,100 L-10,-70 L0,-10 L20,-45 L40,-10');
1818
});
1919

2020
it('draws a path given decimal coordinates', () => {
21-
const decimalPath = drawPath(CONSTANTS.pointsWithDecimals);
21+
const decimalPath = drawPath(CONSTANTS.decimals);
2222
expect(decimalPath).toBe('M-10,-7230.87 L0.001,-10.92 L20.21,-45');
2323
});
2424
});
2525

2626
describe('Advanced functionality of drawPath', () => {
2727
it('draws a transformed path given a transformation function', () => {
2828
const transform = (point) => `H${point[0]}`;
29-
const integerPath = drawPath(CONSTANTS.pointsWithIntegers, transform);
29+
const integerPath = drawPath(CONSTANTS.integers, transform);
3030
expect(integerPath).toBe('M0,10 H10 H20 H30 H40 H60');
3131
});
3232

3333
it('passes in a payload to the transformation function', () => {
3434
const transform = (point, _index, _points, payload) => `H${point[0] + payload}`;
35-
const integerPath = drawPath(CONSTANTS.pointsWithIntegers, transform, 10);
35+
const integerPath = drawPath(CONSTANTS.integers, transform, 10);
3636
expect(integerPath).toBe('M0,10 H20 H30 H40 H50 H70');
3737
});
3838
});

src/components/App.jsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
import React, { useState } from 'react';
22
import LineGraph from './LineGraph';
3-
import points from '../../spec/_constants';
3+
import POINTS from '../../spec/_constants';
44

55
const App = () => {
66
const [hovered, onHover] = useState([0, 0]);
7-
const data = points.pointsExtreme; // Get random set of points
7+
const data = POINTS.extreme;
88
const props = {
99
data,
10-
smoothing: 0.3,
10+
smoothing: 1,
1111
hover: true,
1212
accent: 'rgb(73,88,209)',
1313
fillBelow: 'url(#grad1)',
1414
strokeWidth: 3,
1515
onHover,
16-
compression: 0,
16+
compression: 0.3,
1717
};
1818

1919
return (
2020
<div id="test">
21+
<h1 id="logo">{Number(hovered[0]).toFixed(2)}</h1>
2122
<h1 id="logo">{Number(hovered[1]).toFixed(2)}</h1>
2223
<LineGraph {...props} />
2324
</div>

src/components/_services/findCtrlPoint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const findCtrlPoint = (smoothing = 0, ...args) => {
2828
// Apply smoothing ratio
2929
let [outX] = parse(midPoint);
3030
const [anchor] = parse(startPoint);
31-
const proximity = outX - anchor;
31+
const proximity = (outX - anchor) * 0.5;
3232
outX -= Math.min(Math.abs(smoothing), 1) * proximity;
3333
const outY = slope * outX + intercept;
3434

src/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ import React from 'react';
22
import ReactDOM from 'react-dom';
33
import App from './components/App';
44

5-
ReactDOM.render(<App />, document.getElementById('main'));
5+
ReactDOM.render(<App />, document.getElementById('main'));

webpack.config.prod.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const path = require('path');
12
const base = require('./webpack.config.base');
23

34
module.exports = {
@@ -7,6 +8,23 @@ module.exports = {
78
libraryTarget: 'commonjs2',
89
},
910
externals: {
10-
react: 'commonjs react',
11+
react: {
12+
commonjs: 'react',
13+
commonjs2: 'react',
14+
amd: 'React',
15+
root: 'React',
16+
},
17+
'react-dom': {
18+
commonjs: 'react-dom',
19+
commonjs2: 'react-dom',
20+
amd: 'ReactDOM',
21+
root: 'ReactDOM',
22+
},
23+
},
24+
resolve: {
25+
alias: {
26+
react: path.resolve(__dirname, './node_modules/react'),
27+
'react-dom': path.resolve(__dirname, './node_modules/react-dom'),
28+
},
1129
},
1230
};

0 commit comments

Comments
 (0)