forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request apache#101 from kristw/kristw-cherry-aug27v2
Cherry-picks: Sunburst, Horizon, Treemap and a few small updates from community
- Loading branch information
Showing
21 changed files
with
696 additions
and
505 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
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,17 @@ | ||
.horizon-chart { | ||
overflow: auto; | ||
} | ||
|
||
.horizon-chart .horizon-row { | ||
border-bottom: solid 1px #ddd; | ||
border-top: 0px; | ||
padding: 0px; | ||
margin: 0px; | ||
} | ||
|
||
.horizon-row span { | ||
position: absolute; | ||
color: #333; | ||
font-size: 0.8em; | ||
text-shadow: 1px 1px rgba(255, 255, 255, 0.75); | ||
} |
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,103 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import PropTypes from 'prop-types'; | ||
import d3 from 'd3'; | ||
import HorizonRow, { DEFAULT_COLORS } from './HorizonRow'; | ||
import './HorizonChart.css'; | ||
|
||
const propTypes = { | ||
className: PropTypes.string, | ||
width: PropTypes.number, | ||
seriesHeight: PropTypes.number, | ||
data: PropTypes.arrayOf(PropTypes.shape({ | ||
key: PropTypes.arrayOf(PropTypes.string), | ||
values: PropTypes.arrayOf(PropTypes.shape({ | ||
y: PropTypes.number, | ||
})), | ||
})).isRequired, | ||
// number of bands in each direction (positive / negative) | ||
bands: PropTypes.number, | ||
colors: PropTypes.arrayOf(PropTypes.string), | ||
colorScale: PropTypes.string, | ||
mode: PropTypes.string, | ||
offsetX: PropTypes.number, | ||
}; | ||
const defaultProps = { | ||
className: '', | ||
width: 800, | ||
seriesHeight: 20, | ||
bands: Math.floor(DEFAULT_COLORS.length / 2), | ||
colors: DEFAULT_COLORS, | ||
colorScale: 'series', | ||
mode: 'offset', | ||
offsetX: 0, | ||
}; | ||
|
||
class HorizonChart extends React.PureComponent { | ||
render() { | ||
const { | ||
className, | ||
width, | ||
data, | ||
seriesHeight, | ||
bands, | ||
colors, | ||
colorScale, | ||
mode, | ||
offsetX, | ||
} = this.props; | ||
|
||
let yDomain; | ||
if (colorScale === 'overall') { | ||
const allValues = data.reduce( | ||
(acc, current) => acc.concat(current.values), | ||
[], | ||
); | ||
yDomain = d3.extent(allValues, d => d.y); | ||
} | ||
|
||
return ( | ||
<div className={`horizon-chart ${className}`}> | ||
{data.map(row => ( | ||
<HorizonRow | ||
key={row.key} | ||
width={width} | ||
height={seriesHeight} | ||
title={row.key[0]} | ||
data={row.values} | ||
bands={bands} | ||
colors={colors} | ||
colorScale={colorScale} | ||
mode={mode} | ||
offsetX={offsetX} | ||
yDomain={yDomain} | ||
/> | ||
))} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
HorizonChart.propTypes = propTypes; | ||
HorizonChart.defaultProps = defaultProps; | ||
|
||
function adaptor(slice, payload) { | ||
const { selector, formData } = slice; | ||
const element = document.querySelector(selector); | ||
const { | ||
horizon_color_scale: colorScale, | ||
series_height: seriesHeight, | ||
} = formData; | ||
|
||
ReactDOM.render( | ||
<HorizonChart | ||
data={payload.data} | ||
width={slice.width()} | ||
seriesHeight={parseInt(seriesHeight, 10)} | ||
colorScale={colorScale} | ||
/>, | ||
element, | ||
); | ||
} | ||
|
||
export default adaptor; |
Oops, something went wrong.