react-sparklines
Advanced tools
Comparing version 0.8.1 to 0.8.3
@@ -6,3 +6,3 @@ describe('Sparklines', function() { | ||
let sparklines = TestUtils.renderIntoDocument(<Sparklines/>); | ||
const sparklines = TestUtils.renderIntoDocument(<Sparklines/>); | ||
@@ -9,0 +9,0 @@ expect(sparklines.type).toBe('svg'); |
@@ -185,9 +185,9 @@ import React from 'react'; | ||
<br/> | ||
<Sparklines data={this.sampleData}> | ||
<Sparklines data={this.sampleData} height={40}> | ||
<SparklinesLine style={{ stroke: "#559500", fill: "#8fc638", fillOpacity: "1" }} /> | ||
</Sparklines> | ||
<Sparklines data={this.sampleData} style={{background: "#272727"}} margin={10} > | ||
<Sparklines data={this.sampleData} style={{background: "#272727"}} margin={10} height={40}> | ||
<SparklinesLine style={{ stroke: "none", fill: "#d2673a", fillOpacity: ".5" }} /> | ||
</Sparklines> | ||
<Sparklines data={this.sampleData} style={{background: "#00bdcc"}} margin={10} > | ||
<Sparklines data={this.sampleData} style={{background: "#00bdcc"}} margin={10} height={40}> | ||
<SparklinesLine style={{ stroke: "white", fill: "none" }} /> | ||
@@ -194,0 +194,0 @@ <SparklinesReferenceLine style={{ stroke: 'white', strokeOpacity: .75, strokeDasharray: '2, 2' }} /> |
{ | ||
"name": "react-sparklines", | ||
"version": "0.8.1", | ||
"version": "0.8.3", | ||
"description": "Beautiful and expressive Sparklines React component", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -9,7 +9,8 @@ export default class DataProcessor { | ||
let max = this.max(data); | ||
let min = this.min(data); | ||
const max = this.max(data); | ||
const min = this.min(data); | ||
let vfactor = (height - margin * 2) / ((max - min) || 1); | ||
let hfactor = (width - margin * 2) / ((limit || data.length) - 1); | ||
const vfactor = (height - margin * 2) / ((max - min) || 1); | ||
const hfactor = (width - margin * 2) / ((limit || data.length) - 1); | ||
return data.map((d, i) => { | ||
@@ -44,4 +45,4 @@ return { | ||
static variance(data) { | ||
let mean = this.mean(data); | ||
let sq = data.map(n => Math.pow(n - mean, 2)); | ||
const mean = this.mean(data); | ||
const sq = data.map(n => Math.pow(n - mean, 2)); | ||
return this.mean(sq); | ||
@@ -51,6 +52,6 @@ } | ||
static stdev(data) { | ||
let avg = this.avg(data); | ||
let mean = this.mean(data); | ||
let sqDiff = data.map(n => Math.pow(n - mean, 2)); | ||
let avgSqDiff = this.avg(sqDiff); | ||
const avg = this.avg(data); | ||
const mean = this.mean(data); | ||
const sqDiff = data.map(n => Math.pow(n - mean, 2)); | ||
const avgSqDiff = this.avg(sqDiff); | ||
return Math.sqrt(avgSqDiff); | ||
@@ -57,0 +58,0 @@ } |
@@ -12,2 +12,18 @@ import React from 'react'; | ||
static propTypes = { | ||
data: React.PropTypes.array, | ||
limit: React.PropTypes.number, | ||
width: React.PropTypes.number, | ||
height: React.PropTypes.number, | ||
margin: React.PropTypes.number, | ||
style: React.PropTypes.object | ||
}; | ||
static defaultProps = { | ||
data: [], | ||
width: 120, | ||
height: 30, | ||
margin: 2 | ||
}; | ||
constructor (props) { | ||
@@ -23,6 +39,8 @@ super(props); | ||
let { data, limit, width, height, margin, style } = this.props; | ||
const { data, limit, width, height, margin, style } = this.props; | ||
let points = DataProcessor.dataToPoints(data, limit, width, height, margin); | ||
if (data.length === 0) return false; | ||
const points = DataProcessor.dataToPoints(data, limit, width, height, margin); | ||
return ( | ||
@@ -39,17 +57,3 @@ <svg width={width} height={height} style={style}> | ||
} | ||
Sparklines.propTypes = { | ||
data: React.PropTypes.array, | ||
limit: React.PropTypes.number, | ||
width: React.PropTypes.number, | ||
height: React.PropTypes.number, | ||
margin: React.PropTypes.number, | ||
style: React.PropTypes.object | ||
}; | ||
Sparklines.defaultProps = { | ||
data: [], | ||
width: 120, | ||
height: 30, | ||
margin: 2 | ||
}; | ||
export { Sparklines, SparklinesLine, SparklinesBars, SparklinesSpots, SparklinesReferenceLine, SparklinesNormalBand } |
@@ -5,6 +5,14 @@ import React from 'react'; | ||
static propTypes = { | ||
style: React.PropTypes.object | ||
}; | ||
static defaultProps = { | ||
style: { fill: 'slategray' } | ||
}; | ||
render() { | ||
let { points, width, height, margin, style } = this.props; | ||
let barWidth = points.length >= 2 ? points[1].x - points[0].x : 0; | ||
const { points, width, height, margin, style } = this.props; | ||
const barWidth = points.length >= 2 ? points[1].x - points[0].x : 0; | ||
@@ -24,9 +32,3 @@ return ( | ||
} | ||
SparklinesBars.propTypes = { | ||
style: React.PropTypes.object | ||
}; | ||
SparklinesBars.defaultProps = { | ||
style: { fill: 'slategray' } | ||
}; | ||
export default SparklinesBars; |
@@ -5,9 +5,18 @@ import React from 'react'; | ||
static propTypes = { | ||
color: React.PropTypes.string, | ||
style: React.PropTypes.object | ||
}; | ||
static defaultProps = { | ||
style: {} | ||
}; | ||
render() { | ||
let { points, width, height, margin, color, style } = this.props; | ||
const { points, width, height, margin, color, style } = this.props; | ||
let linePoints = points | ||
const linePoints = points | ||
.map((p) => [p.x, p.y]) | ||
.reduce((a, b) => a.concat(b)); | ||
let closePolyPoints = [ | ||
const closePolyPoints = [ | ||
points[points.length - 1].x, height - margin, | ||
@@ -17,4 +26,5 @@ margin, height - margin, | ||
]; | ||
let fillPoints = linePoints.concat(closePolyPoints); | ||
let lineStyle = { | ||
const fillPoints = linePoints.concat(closePolyPoints); | ||
const lineStyle = { | ||
stroke: color || style.stroke || 'slategray', | ||
@@ -26,3 +36,3 @@ strokeWidth: style.strokeWidth || '1', | ||
}; | ||
let fillStyle = { | ||
const fillStyle = { | ||
stroke: style.stroke || 'none', | ||
@@ -42,10 +52,3 @@ strokeWidth: '0', | ||
} | ||
SparklinesLine.propTypes = { | ||
color: React.PropTypes.string, | ||
style: React.PropTypes.object | ||
}; | ||
SparklinesLine.defaultProps = { | ||
style: {} | ||
}; | ||
export default SparklinesLine; |
@@ -6,9 +6,19 @@ import React from 'react'; | ||
static propTypes = { | ||
type: React.PropTypes.string, | ||
style: React.PropTypes.object | ||
}; | ||
static defaultProps = { | ||
points: [], | ||
style: { fill: 'red', fillOpacity: .1 } | ||
}; | ||
render() { | ||
let { points, margin, type, style } = this.props; | ||
const { points, margin, type, style } = this.props; | ||
let ypoints = points.map(p => p.y); | ||
let mean = DataProcessor.calculateFromData(ypoints, 'mean'); | ||
let stdev = DataProcessor.calculateFromData(ypoints, 'stdev'); | ||
const ypoints = points.map(p => p.y); | ||
const mean = DataProcessor.calculateFromData(ypoints, 'mean'); | ||
const stdev = DataProcessor.calculateFromData(ypoints, 'stdev'); | ||
@@ -22,11 +32,3 @@ return ( | ||
} | ||
SparklinesNormalBand.propTypes = { | ||
type: React.PropTypes.string, | ||
style: React.PropTypes.object | ||
}; | ||
SparklinesNormalBand.defaultProps = { | ||
points: [], | ||
style: { fill: 'red', fillOpacity: .1 } | ||
}; | ||
export default SparklinesNormalBand; |
@@ -6,8 +6,18 @@ import React from 'react'; | ||
static propTypes = { | ||
type: React.PropTypes.string, | ||
style: React.PropTypes.object | ||
}; | ||
static defaultProps = { | ||
type: 'mean', | ||
style: { stroke: 'red', strokeOpacity: .75, strokeDasharray: '2, 2' } | ||
}; | ||
render() { | ||
let { points, margin, type, style } = this.props; | ||
const { points, margin, type, style } = this.props; | ||
let ypoints = points.map(p => p.y); | ||
let y = DataProcessor.calculateFromData(ypoints, type); | ||
const ypoints = points.map(p => p.y); | ||
const y = DataProcessor.calculateFromData(ypoints, type); | ||
@@ -22,11 +32,3 @@ return ( | ||
} | ||
SparklinesReferenceLine.propTypes = { | ||
type: React.PropTypes.string, | ||
style: React.PropTypes.object | ||
}; | ||
SparklinesReferenceLine.defaultProps = { | ||
type: 'mean', | ||
style: { stroke: 'red', strokeOpacity: .75, strokeDasharray: '2, 2' } | ||
}; | ||
export default SparklinesReferenceLine; |
@@ -5,2 +5,17 @@ import React from 'react'; | ||
static propTypes = { | ||
size: React.PropTypes.number, | ||
style: React.PropTypes.object, | ||
spotColors: React.PropTypes.object | ||
}; | ||
static defaultProps = { | ||
size: 2, | ||
spotColors: { | ||
'-1': 'red', | ||
'0': 'black', | ||
'1': 'green' | ||
} | ||
}; | ||
lastDirection(points) { | ||
@@ -15,5 +30,5 @@ | ||
let { points, width, height, size, style, spotColors } = this.props; | ||
const { points, width, height, size, style, spotColors } = this.props; | ||
let startSpot = <circle | ||
const startSpot = <circle | ||
cx={points[0].x} | ||
@@ -24,3 +39,3 @@ cy={points[0].y} | ||
let endSpot = <circle | ||
const endSpot = <circle | ||
cx={points[points.length - 1].x} | ||
@@ -30,7 +45,6 @@ cy={points[points.length - 1].y} | ||
style={style || { fill: spotColors[this.lastDirection(points)] }} /> | ||
return ( | ||
<g> | ||
{style ? startSpot : ''} | ||
{endSpot} | ||
{style ? startSpot + endSpot : endSpot} | ||
</g> | ||
@@ -40,16 +54,3 @@ ) | ||
} | ||
SparklinesSpots.propTypes = { | ||
size: React.PropTypes.number, | ||
style: React.PropTypes.object, | ||
spotColors: React.PropTypes.object | ||
}; | ||
SparklinesSpots.defaultProps = { | ||
size: 2, | ||
spotColors: { | ||
'-1': 'red', | ||
'0': 'black', | ||
'1': 'green' | ||
} | ||
}; | ||
export default SparklinesSpots; |
@@ -15,3 +15,3 @@ var webpack = require('webpack'), | ||
exclude: /(node_modules)/, | ||
loader: 'babel' | ||
loader: 'babel?stage=0' | ||
}] | ||
@@ -18,0 +18,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21505