-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chart: Improve render performance (#27606)
This PR refactors the Chart component to be a PureComponent. This prevents unnecessary re-renders when mousing over the chart bars (and triggering a re-render of each `<Bar />` in addition to the new `<Tooltip />`). - Chart: Clean up xAxis - Chart: Clean up barContainer, convert to PureComp - Chart: Modularize bar tooltip into separate comp - Chart: Remove Chart.componentWillReceiveProps - Chart: Convert Label into PureComponent - Chart: Modularize LegendItem, convert to PureComp
- Loading branch information
Showing
8 changed files
with
139 additions
and
125 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,32 @@ | ||
/** @format */ | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
import Gridicon from 'gridicons'; | ||
|
||
export default class ChartBarTooltip extends React.PureComponent { | ||
static propTypes = { | ||
className: PropTypes.string, | ||
icon: PropTypes.string, | ||
label: PropTypes.string, | ||
value: PropTypes.string, | ||
}; | ||
|
||
render() { | ||
return ( | ||
<li className={ classNames( 'module-content-list-item', this.props.className ) }> | ||
<span className="chart__tooltip-wrapper wrapper"> | ||
<span className="chart__tooltip-value value">{ this.props.value }</span> | ||
<span className="chart__tooltip-label label"> | ||
{ this.props.icon && <Gridicon icon={ this.props.icon } size={ 18 } /> } | ||
{ this.props.label } | ||
</span> | ||
</span> | ||
</li> | ||
); | ||
} | ||
} |
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
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,37 @@ | ||
/** @format */ | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
|
||
export default class ChartLegendItem extends React.PureComponent { | ||
static propTypes = { | ||
attr: PropTypes.string.isRequired, | ||
changeHandler: PropTypes.func.isRequired, | ||
checked: PropTypes.bool.isRequired, | ||
label: PropTypes.oneOfType( [ PropTypes.object, PropTypes.string ] ), | ||
}; | ||
|
||
clickHandler = () => { | ||
this.props.changeHandler( this.props.attr ); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<li className="chart__legend-option"> | ||
<label className="chart__legend-label is-selectable"> | ||
<input | ||
checked={ this.props.checked } | ||
className="chart__legend-checkbox" | ||
onChange={ this.clickHandler } | ||
type="checkbox" | ||
/> | ||
<span className={ this.props.className } /> | ||
{ this.props.label } | ||
</label> | ||
</li> | ||
); | ||
} | ||
} |
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
Oops, something went wrong.