react-sparklines
Advanced tools
Comparing version 1.0.3 to 1.1.0
@@ -157,6 +157,8 @@ module.exports = | ||
var style = _props.style; | ||
var max = _props.max; | ||
var min = _props.min; | ||
if (data.length === 0) return false; | ||
var points = _DataProcessor2['default'].dataToPoints(data, limit, width, height, margin); | ||
var points = _DataProcessor2['default'].dataToPoints(data, limit, width, height, margin, max, min); | ||
@@ -561,19 +563,20 @@ return _react2['default'].createElement( | ||
value: function dataToPoints(data, limit, width, height, margin) { | ||
var max = arguments.length <= 5 || arguments[5] === undefined ? this.max(data) : arguments[5]; | ||
var min = arguments.length <= 6 || arguments[6] === undefined ? this.min(data) : arguments[6]; | ||
return (function () { | ||
if (limit && limit < data.length) { | ||
data = data.slice(data.length - limit); | ||
} | ||
if (limit && limit < data.length) { | ||
data = data.slice(data.length - limit); | ||
} | ||
var max = this.max(data); | ||
var min = this.min(data); | ||
var vfactor = (height - margin * 2) / (max - min || 1); | ||
var hfactor = (width - margin * 2) / ((limit || data.length) - 1); | ||
var vfactor = (height - margin * 2) / (max - min || 1); | ||
var hfactor = (width - margin * 2) / ((limit || data.length) - 1); | ||
return data.map(function (d, i) { | ||
return { | ||
x: i * hfactor + margin, | ||
y: (max - data[i]) * vfactor + margin | ||
}; | ||
}); | ||
return data.map(function (d, i) { | ||
return { | ||
x: i * hfactor + margin, | ||
y: (max - data[i]) * vfactor + margin | ||
}; | ||
}); | ||
})(); | ||
} | ||
@@ -580,0 +583,0 @@ }, { |
@@ -122,2 +122,13 @@ import React from 'react'; | ||
class Bounds1 extends React.Component { | ||
render() { | ||
return ( | ||
<Sparklines data={sampleData} max={0.5}> | ||
<SparklinesLine /> | ||
</Sparklines> | ||
); | ||
} | ||
} | ||
class Spots1 extends React.Component { | ||
@@ -482,2 +493,3 @@ | ||
'spots3': Spots3, | ||
'bounds1': Bounds1, | ||
'bars1': Bars1, | ||
@@ -484,0 +496,0 @@ 'bars2': Bars2, |
{ | ||
"name": "react-sparklines", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "Beautiful and expressive Sparklines component for React ", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
@@ -41,3 +41,5 @@ # Beautiful and expressive sparklines component for React | ||
min, max - optional, bound the chart | ||
#### Basic Sparkline | ||
@@ -44,0 +46,0 @@ |
export default class DataProcessor { | ||
static dataToPoints(data, limit, width, height, margin) { | ||
static dataToPoints(data, limit, width, height, margin, max = this.max(data), min = this.min(data)) { | ||
@@ -9,5 +9,2 @@ if (limit && limit < data.length) { | ||
const max = this.max(data); | ||
const min = this.min(data); | ||
const vfactor = (height - margin * 2) / ((max - min) || 1); | ||
@@ -14,0 +11,0 @@ const hfactor = (width - margin * 2) / ((limit || data.length) - 1); |
@@ -37,7 +37,7 @@ import React from 'react'; | ||
const { data, limit, width, height, margin, style } = this.props; | ||
const { data, limit, width, height, margin, style, max, min } = this.props; | ||
if (data.length === 0) return false; | ||
const points = DataProcessor.dataToPoints(data, limit, width, height, margin); | ||
const points = DataProcessor.dataToPoints(data, limit, width, height, margin, max, min); | ||
@@ -44,0 +44,0 @@ return ( |
Sorry, the diff of this file is not supported yet
72602
1306
100