Skip to content

Commit 6096fe7

Browse files
committed
Updgrade dependencies. Fix bugs
1 parent 87c49f0 commit 6096fe7

File tree

4 files changed

+1670
-1028
lines changed

4 files changed

+1670
-1028
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-sparklines",
3-
"version": "1.6.0",
3+
"version": "1.7.0",
44
"description": "Beautiful and expressive Sparklines component for React ",
55
"main": "build/index.js",
66
"directories": {
@@ -36,23 +36,23 @@
3636
"devDependencies": {
3737
"babel": "^6.5.2",
3838
"babel-core": "^6.8.0",
39-
"babel-loader": "^6.2.4",
39+
"babel-loader": "7.1.1",
4040
"babel-plugin-transform-object-assign": "^6.8.0",
4141
"babel-preset-es2015": "^6.6.0",
4242
"babel-preset-react": "^6.5.0",
4343
"babel-preset-stage-1": "^6.5.0",
4444
"babel-runtime": "^6.6.1",
45-
"chai": "^3.5.0",
45+
"chai": "^4.1.0",
4646
"enzyme": "^2.2.0",
4747
"hiff": "^0.3.0",
4848
"line-by-line": "^0.1.4",
4949
"mocha": "^3.2.0",
5050
"react": "^15.0.2",
5151
"react-addons-test-utils": "^15.0.2",
5252
"react-dom": "^15.0.2",
53-
"react-element-to-jsx-string": "=2.6.1",
53+
"react-element-to-jsx-string": "11.0.1",
5454
"replaceall": "^0.1.6",
55-
"webpack": "^2.1.0-beta.22",
55+
"webpack": "^3.4.1",
5656
"webpack-dev-server": "^2.2.0"
5757
},
5858
"peerDependencies": {

src/SparklinesBars.js

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,43 @@ import PropTypes from 'prop-types';
22
import React from 'react';
33

44
export default class SparklinesBars extends React.Component {
5+
static propTypes = {
6+
points: PropTypes.arrayOf(PropTypes.object),
7+
height: PropTypes.number,
8+
style: PropTypes.object,
9+
barWidth: PropTypes.number,
10+
margin: PropTypes.number,
11+
onMouseMove: PropTypes.func,
12+
};
513

6-
static propTypes = {
7-
points: PropTypes.arrayOf(PropTypes.object),
8-
height: PropTypes.number,
9-
style: PropTypes.object,
10-
barWidth: PropTypes.number,
11-
margin: PropTypes.number,
12-
onMouseMove: PropTypes.func
13-
};
14+
static defaultProps = {
15+
style: { fill: 'slategray' },
16+
};
1417

15-
static defaultProps = {
16-
style: { fill: 'slategray' }
17-
};
18+
render() {
19+
const { points, height, style, barWidth, margin, onMouseMove } = this.props;
20+
const strokeWidth = 1 * ((style && style.strokeWidth) || 0);
21+
const marginWidth = margin ? 2 * margin : 0;
22+
const width =
23+
barWidth ||
24+
(points && points.length >= 2
25+
? Math.max(0, points[1].x - points[0].x - strokeWidth - marginWidth)
26+
: 0);
1827

19-
render() {
20-
21-
const { points, height, style, barWidth, margin, onMouseMove } = this.props;
22-
const strokeWidth = 1 * ((style && style.strokeWidth) || 0);
23-
const marginWidth = margin ? 2*margin : 0;
24-
const width = barWidth || (points && points.length >= 2 ? Math.max(0, points[1].x - points[0].x - strokeWidth - marginWidth) : 0);
25-
26-
return (
27-
<g transform = "scale(1,-1)">
28-
{points.map((p, i) =>
29-
<rect
30-
key={i}
31-
x={p.x - (width + strokeWidth)/2}
32-
y={-height}
33-
width={width}
34-
height={Math.max(0, height-p.y)}
35-
style={style}
36-
onMouseMove={onMouseMove.bind(this, p)}/>
37-
)}
38-
</g>
39-
)
40-
}
28+
return (
29+
<g transform="scale(1,-1)">
30+
{points.map((p, i) =>
31+
<rect
32+
key={i}
33+
x={p.x - (width + strokeWidth) / 2}
34+
y={-height}
35+
width={width}
36+
height={Math.max(0, height - p.y)}
37+
style={style}
38+
onMouseMove={onMouseMove && onMouseMove.bind(this, p)}
39+
/>,
40+
)}
41+
</g>
42+
);
43+
}
4144
}

src/SparklinesLine.js

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,63 +2,67 @@ import PropTypes from 'prop-types';
22
import React from 'react';
33

44
export default class SparklinesLine extends React.Component {
5+
static propTypes = {
6+
color: PropTypes.string,
7+
style: PropTypes.object,
8+
};
59

6-
static propTypes = {
7-
color: PropTypes.string,
8-
style: PropTypes.object
9-
};
10-
11-
static defaultProps = {
12-
style: {}
13-
};
10+
static defaultProps = {
11+
style: {},
12+
onMouseMove: () => {},
13+
};
1414

15-
render() {
16-
const { data, points, width, height, margin, color, style, onMouseMove } = this.props;
15+
render() {
16+
const { data, points, width, height, margin, color, style, onMouseMove } = this.props;
1717

18-
const linePoints = points
19-
.map((p) => [p.x, p.y])
20-
.reduce((a, b) => a.concat(b));
18+
const linePoints = points.map(p => [p.x, p.y]).reduce((a, b) => a.concat(b));
2119

22-
const closePolyPoints = [
23-
points[points.length - 1].x, height - margin,
24-
margin, height - margin,
25-
margin, points[0].y
26-
];
20+
const closePolyPoints = [
21+
points[points.length - 1].x,
22+
height - margin,
23+
margin,
24+
height - margin,
25+
margin,
26+
points[0].y,
27+
];
2728

28-
const fillPoints = linePoints.concat(closePolyPoints);
29+
const fillPoints = linePoints.concat(closePolyPoints);
2930

30-
const lineStyle = {
31-
stroke: color || style.stroke || 'slategray',
32-
strokeWidth: style.strokeWidth || '1',
33-
strokeLinejoin: style.strokeLinejoin || 'round',
34-
strokeLinecap: style.strokeLinecap || 'round',
35-
fill: 'none'
36-
};
37-
const fillStyle = {
38-
stroke: style.stroke || 'none',
39-
strokeWidth: '0',
40-
fillOpacity: style.fillOpacity || '.1',
41-
fill: style.fill || color || 'slategray',
42-
pointerEvents: 'auto'
43-
};
31+
const lineStyle = {
32+
stroke: color || style.stroke || 'slategray',
33+
strokeWidth: style.strokeWidth || '1',
34+
strokeLinejoin: style.strokeLinejoin || 'round',
35+
strokeLinecap: style.strokeLinecap || 'round',
36+
fill: 'none',
37+
};
38+
const fillStyle = {
39+
stroke: style.stroke || 'none',
40+
strokeWidth: '0',
41+
fillOpacity: style.fillOpacity || '.1',
42+
fill: style.fill || color || 'slategray',
43+
pointerEvents: 'auto',
44+
};
4445

45-
const tooltips = points.map((p, i) => {
46-
return (<circle
47-
cx={p.x}
48-
cy={p.y}
49-
r={2}
50-
style={fillStyle}
51-
onMouseEnter={(e) => onMouseMove('enter', data[i], p)}
52-
onClick={(e) => onMouseMove('click', data[i], p)}
53-
/>)
54-
});
46+
const tooltips = points.map((p, i) => {
47+
return (
48+
<circle
49+
key={i}
50+
cx={p.x}
51+
cy={p.y}
52+
r={2}
53+
style={fillStyle}
54+
onMouseEnter={e => onMouseMove('enter', data[i], p)}
55+
onClick={e => onMouseMove('click', data[i], p)}
56+
/>
57+
);
58+
});
5559

56-
return (
57-
<g>
58-
{tooltips}
59-
<polyline points={fillPoints.join(' ')} style={fillStyle}/>
60-
<polyline points={linePoints.join(' ')} style={lineStyle}/>
61-
</g>
62-
)
63-
}
60+
return (
61+
<g>
62+
{tooltips}
63+
<polyline points={fillPoints.join(' ')} style={fillStyle} />
64+
<polyline points={linePoints.join(' ')} style={lineStyle} />
65+
</g>
66+
);
67+
}
6468
}

0 commit comments

Comments
 (0)