-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bubble): move Bubble legends in a dedicated component
- Loading branch information
Raphael Benitte
committed
Apr 21, 2016
1 parent
4c5f708
commit c54116d
Showing
3 changed files
with
116 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React, { Component, PropTypes } from 'react'; | ||
import invariant from 'invariant'; | ||
import Nivo from '../../Nivo'; | ||
import { getColorStyleObject } from '../../ColorUtils'; | ||
|
||
|
||
class BubbleLegends extends Component { | ||
static createBubbleLegendsFromReactElement(element) { | ||
const { props } = element; | ||
|
||
const { textColor, labelAccessor, skipRadius } = props; | ||
|
||
const textColorStyle = getColorStyleObject(textColor, 'fill'); | ||
|
||
return ({ element, data, width, height, transitionDuration, transitionEasing }) => { | ||
|
||
if (skipRadius > 0) { | ||
data = data.filter(d => d.r >= skipRadius); | ||
} | ||
|
||
const legends = element.selectAll('.bubble_legend').data(data); | ||
|
||
legends.enter().append('text') | ||
.attr('class', 'bubble_legend') | ||
.style('text-anchor', 'middle') | ||
.style(textColorStyle) | ||
.style('opacity', 0) | ||
.text(labelAccessor) | ||
.attr('transform', d => `translate(${d.x},${d.y})`) | ||
; | ||
|
||
legends | ||
.text(labelAccessor) | ||
.transition() | ||
.duration(transitionDuration) | ||
.ease(transitionEasing) | ||
.style(textColorStyle) | ||
.style('opacity', 1) | ||
.attr('transform', d => `translate(${d.x},${d.y})`) | ||
; | ||
|
||
legends.exit() | ||
.remove() | ||
; | ||
}; | ||
} | ||
|
||
render() { | ||
invariant( | ||
false, | ||
'<BubbleLegends> element is for Bubble configuration only and should not be rendered' | ||
); | ||
} | ||
} | ||
|
||
const { number, func, any } = PropTypes; | ||
|
||
BubbleLegends.propTypes = { | ||
labelAccessor: func.isRequired, | ||
textColor: any.isRequired, | ||
skipRadius: number.isRequired | ||
}; | ||
|
||
BubbleLegends.defaultProps = { | ||
labelAccessor: d => d.name, | ||
textColor: 'none', | ||
skipRadius: 0 | ||
}; | ||
|
||
|
||
export default BubbleLegends; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters