Skip to content

Commit a2bf90f

Browse files
committed
Convert top and bottom compression into single compression variable
1 parent caea674 commit a2bf90f

File tree

4 files changed

+6
-9
lines changed

4 files changed

+6
-9
lines changed

spec/_constants/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ module.exports = {
1010
}
1111
return data;
1212
})(),
13-
pointsExtreme: [[0, 50], [10, 100], [20, 10], [30,110]],
13+
pointsExtreme: [[0, 50], [10, 100], [20, 10], [30,300]],
1414
};

src/components/App.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const App = () => {
77
const data = points.pointsExtreme; // Get random set of points
88
const props = {
99
data,
10-
smoothing: 0.4,
10+
smoothing: 0.3,
1111
hover: true,
1212
accent: 'rgb(73,88,209)',
1313
fillBelow: 'url(#grad1)',

src/components/LineGraph/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ LineGraph.defaultProps = {
8787
accent: 'black',
8888
strokeWidth: '0.5',
8989
onHover: () => {},
90-
compression: 0,
90+
compression: 0.1,
9191
};
9292

9393
export default LineGraph;

src/components/_helpers/line.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,13 @@ export const normalize = (points = [], compression = 0, xCeil = 0, yCeil = 0) =>
3030
Math.min(elem[0], accum[2]),
3131
Math.min(elem[1], accum[3]),
3232
]), [-Infinity, -Infinity, Infinity, Infinity]);
33-
// Top compression
34-
const topComp = 0.95;
35-
// Bottom compression
36-
const bottomComp = (1 - Math.min(Math.abs(compression), 1));
33+
const compFactor = (1 - Math.min(Math.abs(compression), 1));
3734
const xDiff = (xMax - xMin) || 1;
3835
const yDiff = (yMax - yMin) || 1;
3936
const xFactor = xCeil / xDiff;
40-
const yFactor = ((yCeil * topComp) / yDiff) * bottomComp;
37+
const yFactor = ((yCeil * compFactor) / yDiff) * compFactor;
4138
const xConst = xCeil - (xFactor * xMax);
42-
const yConst = yCeil * topComp - (yFactor * yMax);
39+
const yConst = yCeil * compFactor - (yFactor * yMax);
4340
return points.map(([x, y]) => [
4441
Number((x * xFactor + xConst).toFixed(2)),
4542
Number((y * yFactor + yConst).toFixed(2)),

0 commit comments

Comments
 (0)