Client - reformat js files w/ prettier
This commit is contained in:
@ -5,7 +5,7 @@ import { formatValue } from '../../../utils/stats'
|
||||
/**
|
||||
* @return {null}
|
||||
*/
|
||||
export default function CustomLabel (props) {
|
||||
export default function CustomLabel(props) {
|
||||
const { displayedData, x, y, width, value } = props
|
||||
if (!value) {
|
||||
return null
|
||||
|
@ -2,34 +2,32 @@ import React from 'react'
|
||||
|
||||
import { formatDuration } from '../../../utils/stats'
|
||||
|
||||
const formatValue = (displayedData, value) => displayedData === 'duration'
|
||||
? formatDuration(value, true)
|
||||
: displayedData === 'distance'
|
||||
const formatValue = (displayedData, value) =>
|
||||
displayedData === 'duration'
|
||||
? formatDuration(value, true)
|
||||
: displayedData === 'distance'
|
||||
? value.toFixed(2)
|
||||
: value
|
||||
|
||||
|
||||
/**
|
||||
* @return {null}
|
||||
*/
|
||||
export default function CustomTooltip (props) {
|
||||
export default function CustomTooltip(props) {
|
||||
const { active } = props
|
||||
if (active) {
|
||||
const { displayedData, payload, label } = props
|
||||
let total = 0
|
||||
payload.map(p => total += p.value)
|
||||
payload.map(p => (total += p.value))
|
||||
return (
|
||||
<div className="custom-tooltip">
|
||||
<p className="custom-tooltip-label">{label}</p>
|
||||
{payload.map(p => (
|
||||
<p key={p.name} style={{ color: p.fill }}>
|
||||
{p.name}: {formatValue(displayedData, p.value)} {p.unit}
|
||||
</p>))
|
||||
}
|
||||
{payload.length > 0 && (
|
||||
<p>
|
||||
Total: {formatValue(displayedData, total)}
|
||||
</p>
|
||||
))}
|
||||
{payload.length > 0 && (
|
||||
<p>Total: {formatValue(displayedData, total)}</p>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
|
@ -1,6 +1,11 @@
|
||||
import React from 'react'
|
||||
import {
|
||||
Bar, BarChart, ResponsiveContainer, Tooltip, XAxis, YAxis
|
||||
Bar,
|
||||
BarChart,
|
||||
ResponsiveContainer,
|
||||
Tooltip,
|
||||
XAxis,
|
||||
YAxis,
|
||||
} from 'recharts'
|
||||
|
||||
import { activityColors } from '../../../utils/activities'
|
||||
@ -8,17 +13,16 @@ import { formatValue } from '../../../utils/stats'
|
||||
import CustomTooltip from './CustomTooltip'
|
||||
import CustomLabel from './CustomLabel'
|
||||
|
||||
|
||||
export default class StatsCharts extends React.PureComponent {
|
||||
constructor(props, context) {
|
||||
super(props, context)
|
||||
this.state = {
|
||||
displayedData: 'distance'
|
||||
displayedData: 'distance',
|
||||
}
|
||||
}
|
||||
handleRadioChange (changeEvent) {
|
||||
handleRadioChange(changeEvent) {
|
||||
this.setState({
|
||||
displayedData: changeEvent.target.name
|
||||
displayedData: changeEvent.target.name,
|
||||
})
|
||||
}
|
||||
|
||||
@ -60,22 +64,14 @@ export default class StatsCharts extends React.PureComponent {
|
||||
</label>
|
||||
</div>
|
||||
<ResponsiveContainer height={300}>
|
||||
<BarChart
|
||||
data={stats[displayedData]}
|
||||
margin={{ top: 15, bottom: 0 }}
|
||||
>
|
||||
<BarChart data={stats[displayedData]} margin={{ top: 15, bottom: 0 }}>
|
||||
<XAxis
|
||||
dataKey="date"
|
||||
interval={0} // to force to display all ticks
|
||||
/>
|
||||
<YAxis
|
||||
tickFormatter={value => formatValue(displayedData, value)}
|
||||
/>
|
||||
<Tooltip content={
|
||||
<CustomTooltip
|
||||
displayedData={displayedData}
|
||||
/>
|
||||
}
|
||||
<YAxis tickFormatter={value => formatValue(displayedData, value)} />
|
||||
<Tooltip
|
||||
content={<CustomTooltip displayedData={displayedData} />}
|
||||
/>
|
||||
{sports.map((s, i) => (
|
||||
<Bar
|
||||
@ -86,9 +82,12 @@ export default class StatsCharts extends React.PureComponent {
|
||||
dataKey={s.label}
|
||||
stackId="a"
|
||||
fill={activityColors[i]}
|
||||
label={i === sports.length - 1
|
||||
? <CustomLabel displayedData={displayedData} />
|
||||
: ''
|
||||
label={
|
||||
i === sports.length - 1 ? (
|
||||
<CustomLabel displayedData={displayedData} />
|
||||
) : (
|
||||
''
|
||||
)
|
||||
}
|
||||
/>
|
||||
))}
|
||||
|
@ -6,14 +6,14 @@ import { getStats } from '../../../actions/stats'
|
||||
import { formatStats } from '../../../utils/stats'
|
||||
import StatsChart from './StatsChart'
|
||||
|
||||
|
||||
class Statistics extends React.PureComponent {
|
||||
componentDidMount() {
|
||||
this.updateData()
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
if ((this.props.user.id && (this.props.user.id !== prevProps.user.id)) ||
|
||||
if (
|
||||
(this.props.user.id && this.props.user.id !== prevProps.user.id) ||
|
||||
this.props.statsParams !== prevProps.statsParams
|
||||
) {
|
||||
this.updateData()
|
||||
@ -22,22 +22,23 @@ class Statistics extends React.PureComponent {
|
||||
|
||||
updateData() {
|
||||
if (this.props.user.id) {
|
||||
this.props.loadActivities(
|
||||
this.props.user.id,
|
||||
this.props.statsParams,
|
||||
)
|
||||
this.props.loadActivities(this.props.user.id, this.props.statsParams)
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
displayedSports, sports, statistics, statsParams, displayEmpty
|
||||
displayedSports,
|
||||
sports,
|
||||
statistics,
|
||||
statsParams,
|
||||
displayEmpty,
|
||||
} = this.props
|
||||
if (!displayEmpty && Object.keys(statistics).length === 0) {
|
||||
return 'No workouts'
|
||||
}
|
||||
const stats = formatStats(statistics, sports, statsParams, displayedSports)
|
||||
return (<StatsChart sports={sports} stats={stats} />)
|
||||
return <StatsChart sports={sports} stats={stats} />
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,7 +54,7 @@ export default connect(
|
||||
const params = {
|
||||
from: format(data.start, dateFormat),
|
||||
to: format(data.end, dateFormat),
|
||||
time: data.duration
|
||||
time: data.duration,
|
||||
}
|
||||
dispatch(getStats(userId, data.type, params))
|
||||
},
|
||||
|
Reference in New Issue
Block a user