Skip to content

Commit

Permalink
Merge pull request #1852 from Huuums/feature/brush-always-show-text-s…
Browse files Browse the repository at this point in the history
…upport

Always show text support for Brush
  • Loading branch information
xile611 committed Oct 16, 2019
2 parents c805aae + 3b82711 commit 422941a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/cartesian/Brush.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Brush extends PureComponent {
onChange: PropTypes.func,
updateId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
leaveTimeOut: PropTypes.number,
alwaysShowText: PropTypes.bool,
};

static defaultProps = {
Expand All @@ -55,6 +56,7 @@ class Brush extends PureComponent {
stroke: '#666',
padding: { top: 1, right: 1, bottom: 1, left: 1 },
leaveTimeOut: 1000,
alwaysShowText: false
};

constructor(props) {
Expand Down Expand Up @@ -427,7 +429,7 @@ class Brush extends PureComponent {
}

render() {
const { data, className, children, x, y, width, height } = this.props;
const { data, className, children, x, y, width, height, alwaysShowText } = this.props;
const { startX, endX, isTextActive, isSlideMoving, isTravellerMoving } = this.state;

if (!data || !data.length || !isNumber(x) || !isNumber(y) || !isNumber(width) ||
Expand All @@ -452,7 +454,7 @@ class Brush extends PureComponent {
{this.renderSlide(startX, endX)}
{this.renderTraveller(startX, 'startX')}
{this.renderTraveller(endX, 'endX')}
{(isTextActive || isSlideMoving || isTravellerMoving) && this.renderText()}
{(isTextActive || isSlideMoving || isTravellerMoving || alwaysShowText) && this.renderText()}
</Layer>
);
}
Expand Down
7 changes: 7 additions & 0 deletions test/specs/cartesian/BrushSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,11 @@ describe('<Brush />', () => {
wrapper.simulate('mouseMove');
wrapper.simulate('mouseLeave');
});

it('render text when alwaysShowText is true', () => {
const wrapper = mount(
<Brush x={100} y={50} width={400} height={40} data={data} alwaysShowText />
);
expect(wrapper.find('.recharts-layer.recharts-brush-texts').length).to.equal(1);
});
});

0 comments on commit 422941a

Please sign in to comment.