Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/abstract-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
} from 'react-native-svg'

class AbstractChart extends Component {
calcScaler = data => (Math.max(...data) - Math.min(...data)) || 1

renderHorizontalLines = config => {
const { count, width, height, paddingTop, paddingRight } = config
return [...new Array(count)].map((_, i) => {
Expand Down Expand Up @@ -39,7 +41,7 @@ class AbstractChart extends Component {
y={(height * 3 / 4) - ((height - paddingTop) / count * i) + 12}
fontSize={12}
fill={this.props.chartConfig.color(0.5)}
>{count === 1 ? data[0].toFixed(2) : (((Math.max(...data) - Math.min(...data)) / (count - 1)) * i + Math.min(...data)).toFixed(2)}
>{count === 1 ? data[0].toFixed(2) : ((this.calcScaler(data) / (count - 1)) * i + Math.min(...data)).toFixed(2)}
</Text>
)
})
Expand Down
4 changes: 2 additions & 2 deletions src/bar-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class BarChart extends AbstractChart {
renderBars = config => {
const { data, width, height, paddingTop, paddingRight } = config
return data.map((x, i) => {
const barHeight = height / 4 * 3 * ((x - Math.min(...data)) / (Math.max(...data) - Math.min(...data)))
const barHeight = height / 4 * 3 * ((x - Math.min(...data)) / this.calcScaler(data))
const barWidth = 32
return (
<Rect
Expand All @@ -29,7 +29,7 @@ class BarChart extends AbstractChart {
renderBarTops = config => {
const { data, width, height, paddingTop, paddingRight } = config
return data.map((x, i) => {
const barHeight = height / 4 * 3 * ((x - Math.min(...data)) / (Math.max(...data) - Math.min(...data)))
const barHeight = height / 4 * 3 * ((x - Math.min(...data)) / this.calcScaler(data))
return (
<Rect
key={Math.random()}
Expand Down
1 change: 0 additions & 1 deletion src/line-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
import AbstractChart from './abstract-chart'

class LineChart extends AbstractChart {
calcScaler = data => (Math.max(...data) - Math.min(...data)) || 1

renderDots = config => {
const { data, width, height, paddingTop, paddingRight } = config
Expand Down