Skip to content

Commit

Permalink
feat(container): add ability to disable interactivity
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Benitte committed Aug 10, 2017
1 parent c3a997b commit 73a33f9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
31 changes: 26 additions & 5 deletions src/components/charts/Container.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/*
* This file is part of the nivo project.
*
* Copyright 2016-present, Raphaël Benitte.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import React, { Component } from 'react'
import PropTypes from 'prop-types'

Expand All @@ -11,24 +19,35 @@ const tooltipStyle = {
zIndex: 10,
top: 0,
left: 0,
borderRadius: '3px',
borderRadius: '2px',
boxShadow: '0 1px 2px rgba(0, 0, 0, 0.25)',
padding: '7px 12px',
padding: '5px 9px',
fontSize: '14px',
}

const Tooltip = ({ x, y, children }) =>
<div style={{ ...tooltipStyle, top: y, left: x }}>
{children}
</div>

const noop = {
showTooltip: () => {},
hideTooltip: () => {},
}

export default class Container extends Component {
static propTypes = {
children: PropTypes.func.isRequired,
isInteractive: PropTypes.bool.isRequired,
}

static defaultProps = {
isInteractive: true,
}

state = {
isTooltipVisible: true,
tooltipContent: 'crap',
isTooltipVisible: false,
tooltipContent: null,
tooltipX: 0,
tooltipY: 0,
}
Expand All @@ -50,9 +69,11 @@ export default class Container extends Component {
}

render() {
const { children } = this.props
const { children, isInteractive } = this.props
const { isTooltipVisible, tooltipContent, tooltipX, tooltipY } = this.state

if (!isInteractive) return children(noop)

return (
<div
style={containerStyle}
Expand Down
2 changes: 1 addition & 1 deletion src/components/charts/stream/Stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const Stream = ({
/>
<Axes
xScale={xScale}
yScale={yScale.domain([0, Math.abs(minValue) + Math.abs(maxValue)])}
yScale={yScale}
width={width}
height={height}
theme={theme}
Expand Down
2 changes: 1 addition & 1 deletion src/props/stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const stackOrderPropMapping = {
descending: stackOrderDescending,
insideOut: stackOrderInsideOut,
none: stackOrderNone,
revers: stackOrderReverse,
reverse: stackOrderReverse,
}

export const stackOrderPropKeys = Object.keys(stackOrderPropMapping)
Expand Down

0 comments on commit 73a33f9

Please sign in to comment.