-
-
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(treemap): add SVG based TreeMap
- Loading branch information
Raphael Benitte
committed
Oct 3, 2016
1 parent
ae77d43
commit de08c6b
Showing
7 changed files
with
252 additions
and
86 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,31 @@ | ||
/* | ||
* This file is part of the nivo project. | ||
* | ||
* (c) Raphaël Benitte | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
'use strict' | ||
|
||
import React, { Component, PropTypes } from 'react' | ||
import TreeMapHTML from './TreeMapHTML' | ||
import Dimensions from 'react-dimensions' | ||
|
||
|
||
class ResponsiveTreeMapHTML extends Component { | ||
render() { | ||
const { containerWidth, containerHeight } = this.props | ||
|
||
return ( | ||
<TreeMapHTML | ||
width={containerWidth} | ||
height={containerHeight} | ||
{...this.props} | ||
/> | ||
) | ||
} | ||
} | ||
|
||
|
||
export default Dimensions()(ResponsiveTreeMapHTML) |
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,109 @@ | ||
/* | ||
* This file is part of the nivo project. | ||
* | ||
* (c) 2016 Raphaël Benitte | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
'use strict' | ||
|
||
import React, { Component } from 'react' | ||
import { findDOMNode } from 'react-dom' | ||
import _ from 'lodash' | ||
import { convertLabel } from '../../../lib/propertiesConverters' | ||
import { treeMapPropTypes, treeMapDefaultProps } from './TreeMapProps' | ||
import TreeMapPlaceholders from './TreeMapPlaceholders' | ||
import { getColorGenerator } from '../../../ColorUtils' | ||
|
||
|
||
const createNodes = ({ | ||
borderWidth, | ||
borderColor, | ||
enableLabels, | ||
label: _label, | ||
labelFormat, | ||
orientLabels, | ||
labelSkipSize, | ||
labelTextColor, | ||
}) => { | ||
const label = convertLabel(_label, labelFormat) | ||
const borderColorFn = getColorGenerator(borderColor) | ||
const textColorFn = getColorGenerator(labelTextColor) | ||
|
||
return nodes => { | ||
const renderedNodes = [] | ||
|
||
nodes.forEach(node => { | ||
const shouldRenderLabel = enableLabels && | ||
node.data.height === 0 && | ||
(labelSkipSize === 0 || Math.min(node.style.width, node.style.height) > labelSkipSize) | ||
|
||
const rotate = shouldRenderLabel && | ||
orientLabels && | ||
node.style.height > node.style.width | ||
|
||
renderedNodes.push( | ||
<div | ||
key={node.key} | ||
className="nivo_treemap_node" | ||
style={{ | ||
boxSizing: 'border-box', | ||
position: 'absolute', | ||
top: node.style.y, | ||
left: node.style.x, | ||
width: node.style.width, | ||
height: node.style.height, | ||
background: node.style.color, | ||
overflow: 'hidden', | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
borderWidth: borderWidth, | ||
borderStyle: 'solid', | ||
borderColor: borderColorFn(node.data), | ||
}} | ||
> | ||
{shouldRenderLabel && ( | ||
<span | ||
className="nivo_treemap_node_label" | ||
style={{ | ||
color: textColorFn(node.data), | ||
transform: `rotate(${rotate ? '-90' : '0'}deg)` | ||
}} | ||
> | ||
{label(node.data.data)} | ||
</span> | ||
)} | ||
</div> | ||
) | ||
}) | ||
|
||
return renderedNodes | ||
} | ||
} | ||
|
||
|
||
class TreeMapHTML extends Component { | ||
render() { | ||
return ( | ||
<TreeMapPlaceholders | ||
{...this.props} | ||
namespace="html" | ||
> | ||
{createNodes(this.props)} | ||
</TreeMapPlaceholders> | ||
) | ||
} | ||
} | ||
|
||
TreeMapHTML.propTypes = _.omit(treeMapPropTypes, [ | ||
'children', | ||
'namespace', | ||
]) | ||
|
||
TreeMapHTML.defaultProps = _.omit(treeMapDefaultProps, [ | ||
]) | ||
|
||
|
||
export default TreeMapHTML |
Oops, something went wrong.