Skip to content

Commit

Permalink
Labels
Browse files Browse the repository at this point in the history
  • Loading branch information
rodion committed Jan 1, 2019
1 parent 5bfba81 commit 61d2d69
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/components/bar-chart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { DEFAULT_THEME } from '../../constants';
import DataContainer from './data-container'
import Scroller from './scroller'
import Bar from './bar'
import Label from './label'
import { sum } from '../../utils'

const RootContainer = styled.div`
Expand All @@ -29,6 +30,12 @@ const LabelsContainer = styled.div`
user-select: none;
`

const Line = styled.div`
width: 100%;
height: 1px;
background-color: ${props => props.theme.mainColor};
`

export default class BarChart extends React.Component {
constructor(props) {
super(props)
Expand Down Expand Up @@ -60,9 +67,21 @@ export default class BarChart extends React.Component {
const dataConainerProps = { barTotalWidth, width, offset, oldOffset, totalWidth, startIndex }

const Labels = () => {
const labels = slicedBars.map(b => b.label)
if (labels.every(l => !l)) return null

return (
<LabelsContainer>

{labels.map((label, index) => (
<Label
width={barWidth}
space={barSpace}
selected={centerBarIndex === index + startIndex}
key={index + startIndex}
>
{label}
</Label>
))}
</LabelsContainer>
)
}
Expand Down Expand Up @@ -92,6 +111,7 @@ export default class BarChart extends React.Component {
<BarsView ref={el => this.barsContainer = el}>
<Bars/>
</BarsView>
{bars.length > 0 && <Line/>}
<Labels/>
</DataContainer>
{showScroller && <Scroller/>}
Expand Down
10 changes: 10 additions & 0 deletions src/components/bar-chart/label.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import styled from 'styled-components'

export default styled.p`
font-size: ${props => props.theme.labelFontSize * (props.selected ? 1.2 : 1)}px;
font-weight: ${props => props.selected ? 'bold': undefined};
width: ${props => props.width}px;
margin-left: ${props => props.space}px;
text-align: center;
color: ${props => props.theme.mainColor};
`

0 comments on commit 61d2d69

Please sign in to comment.