|
| 1 | +/* |
| 2 | + * This file is part of the nivo project. |
| 3 | + * |
| 4 | + * Copyright 2016-present, Raphaël Benitte. |
| 5 | + * |
| 6 | + * For the full copyright and license information, please view the LICENSE |
| 7 | + * file that was distributed with this source code. |
| 8 | + */ |
| 9 | +import React, { Component } from 'react' |
| 10 | +import setDisplayName from 'recompose/setDisplayName' |
| 11 | +import { Container, SvgWrapper } from '@nivo/core' |
| 12 | +import { enhanceSvg } from './enhance' |
| 13 | +import { RosePropTypes } from './props' |
| 14 | + |
| 15 | +class Rose extends Component { |
| 16 | + static propTypes = RosePropTypes |
| 17 | + |
| 18 | + handleMouseEnter = showTooltip => (point, event) => { |
| 19 | + const { isInteractive, onMouseEnter } = this.props |
| 20 | + |
| 21 | + if (!isInteractive) return |
| 22 | + |
| 23 | + onMouseEnter && onMouseEnter(point, event) |
| 24 | + this.showTooltip(showTooltip, point, event) |
| 25 | + } |
| 26 | + |
| 27 | + handleMouseMove = showTooltip => (point, event) => { |
| 28 | + const { isInteractive, onMouseMove } = this.props |
| 29 | + |
| 30 | + if (!isInteractive) return |
| 31 | + |
| 32 | + onMouseMove && onMouseMove(point, event) |
| 33 | + this.showTooltip(showTooltip, point, event) |
| 34 | + } |
| 35 | + |
| 36 | + handleMouseLeave = hideTooltip => (point, event) => { |
| 37 | + const { isInteractive, onMouseLeave } = this.props |
| 38 | + |
| 39 | + if (!isInteractive) return |
| 40 | + |
| 41 | + onMouseLeave && onMouseLeave(point, event) |
| 42 | + hideTooltip() |
| 43 | + } |
| 44 | + |
| 45 | + handleClick = (point, event) => { |
| 46 | + const { isInteractive, onClick } = this.props |
| 47 | + if (!isInteractive || onClick === undefined) return |
| 48 | + |
| 49 | + onClick(point.data, event) |
| 50 | + } |
| 51 | + |
| 52 | + render() { |
| 53 | + console.log(this.props) |
| 54 | + const { |
| 55 | + arcs, |
| 56 | + arcGenerator, |
| 57 | + centerX, |
| 58 | + centerY, |
| 59 | + |
| 60 | + borderWidth, |
| 61 | + |
| 62 | + margin, |
| 63 | + outerWidth, |
| 64 | + outerHeight, |
| 65 | + |
| 66 | + theme, |
| 67 | + getColor, |
| 68 | + |
| 69 | + animate, |
| 70 | + motionStiffness, |
| 71 | + motionDamping, |
| 72 | + |
| 73 | + isInteractive, |
| 74 | + } = this.props |
| 75 | + |
| 76 | + const motionProps = { |
| 77 | + animate, |
| 78 | + motionDamping, |
| 79 | + motionStiffness, |
| 80 | + } |
| 81 | + const springConfig = { |
| 82 | + damping: motionDamping, |
| 83 | + stiffness: motionStiffness, |
| 84 | + } |
| 85 | + |
| 86 | + return ( |
| 87 | + <Container isInteractive={isInteractive} theme={theme}> |
| 88 | + {({ showTooltip, hideTooltip }) => { |
| 89 | + const onMouseEnter = this.handleMouseEnter(showTooltip) |
| 90 | + const onMouseMove = this.handleMouseMove(showTooltip) |
| 91 | + const onMouseLeave = this.handleMouseLeave(hideTooltip) |
| 92 | + |
| 93 | + return ( |
| 94 | + <SvgWrapper |
| 95 | + width={outerWidth} |
| 96 | + height={outerHeight} |
| 97 | + margin={margin} |
| 98 | + theme={theme} |
| 99 | + > |
| 100 | + <g transform={`translate(${centerX}, ${centerY})`}> |
| 101 | + {arcs.map(arc => { |
| 102 | + return ( |
| 103 | + <path |
| 104 | + key={arc.id} |
| 105 | + d={arcGenerator(arc)} |
| 106 | + fill={getColor(arc)} |
| 107 | + stroke={"white"} |
| 108 | + strokeWidth={borderWidth} |
| 109 | + onClick={() => { |
| 110 | + console.log(arc) |
| 111 | + }} |
| 112 | + /> |
| 113 | + ) |
| 114 | + })} |
| 115 | + </g> |
| 116 | + </SvgWrapper> |
| 117 | + ) |
| 118 | + }} |
| 119 | + </Container> |
| 120 | + ) |
| 121 | + } |
| 122 | +} |
| 123 | + |
| 124 | +export default setDisplayName('Rose')(enhanceSvg(Rose)) |
0 commit comments