You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2018/08/29 05:36:25 UTC

[GitHub] williaster commented on a change in pull request #5758: [SIP-5] Refactor and improve histogram

williaster commented on a change in pull request #5758: [SIP-5] Refactor and improve histogram
URL: https://github.com/apache/incubator-superset/pull/5758#discussion_r213549156
 
 

 ##########
 File path: superset/assets/src/visualizations/Histogram.jsx
 ##########
 @@ -0,0 +1,131 @@
+import PropTypes from 'prop-types';
+import React from 'react';
+import ReactDOM from 'react-dom';
+import { Histogram, BarSeries, XAxis, YAxis } from '@data-ui/histogram';
+import { chartTheme } from '@data-ui/theme';
+import { LegendOrdinal } from '@vx/legend';
+import { scaleOrdinal } from '@vx/scale';
+import { getColorFromScheme } from '../modules/colors';
+import './histogram.css';
+
+const propTypes = {
+  className: PropTypes.string,
+  data: PropTypes.arrayOf(PropTypes.shape({
+    key: PropTypes.string,
+    values: PropTypes.arrayOf(PropTypes.number),
+  })).isRequired,
+  width: PropTypes.number.isRequired,
+  height: PropTypes.number.isRequired,
+  colorScheme: PropTypes.string,
+  normalized: PropTypes.bool,
+  binCount: PropTypes.number,
+  opacity: PropTypes.number,
+  xAxisLabel: PropTypes.string,
+  yAxisLabel: PropTypes.string,
+};
+const defaultProps = {
+  className: '',
+  colorScheme: '',
+  normalized: false,
+  binCount: 15,
+  opacity: 1,
+  xAxisLabel: '',
+  yAxisLabel: '',
+};
+
+class CustomHistogram extends React.PureComponent {
+  render() {
+    const {
+      className,
+      data,
+      width,
+      height,
+      binCount,
+      colorScheme,
+      normalized,
+      opacity,
+      xAxisLabel,
+      yAxisLabel,
+    } = this.props;
+
+    const keys = data.map(d => d.key);
+    const colorScale = scaleOrdinal({
+      domain: keys,
+      range: keys.map(key => getColorFromScheme(key, colorScheme)),
+    });
+
+    return (
+      <div className={`histogram-chart ${className}`}>
+        <div className="legend-container">
+          <LegendOrdinal
+            scale={colorScale}
+            direction="row"
+            shape="rect"
 
 Review comment:
   I could see `rect` being better than circles given that bars are rectangle. If you _do_ want them to render as rects, you can do something like (example [here](https://github.com/williaster/data-ui/blob/master/packages/demo/examples/01-xy-chart/AreaDifferenceSeriesExample.jsx) / [storybook](https://williaster.github.io/data-ui/?selectedKind=xy-chart&selectedStory=AreaDifferenceSeries&full=0&addons=0&stories=1&panelRight=0)). 
   
   tldr
   
   ```javascript
   shape={({ fill, width, height }) => (
     <svg width={width} height={height}>
       <rect width={width} height={height} fill={fill} />
     </svg>
   )}
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org