Skip to content

Commit

Permalink
Add PropTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
kristw committed Aug 20, 2018
1 parent 8d5f0a8 commit 58d8821
Showing 1 changed file with 32 additions and 13 deletions.
45 changes: 32 additions & 13 deletions superset/assets/src/visualizations/chord.jsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
/* eslint-disable no-param-reassign */
import d3 from 'd3';
import PropTypes from 'prop-types';
import { getColorFromScheme } from '../modules/colors';
import './chord.css';

function chordViz(element, data, {
width,
height,
yAxisFormat,
colorScheme,
}) {
const propTypes = {
data: PropTypes.shape({
nodes: PropTypes.arrayOf(PropTypes.string),
matrix: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.number)),
}),
width: PropTypes.number,
height: PropTypes.number,
numberFormat: PropTypes.string,
colorScheme: PropTypes.string,
};

function chordVis(element, props) {
PropTypes.checkPropTypes(propTypes, props, 'prop', 'ChordVis');

const {
data,
width,
height,
numberFormat,
colorScheme,
} = props;

element.innerHTML = '';

const div = d3.select(element);
const nodes = data.nodes;
const f = d3.format(yAxisFormat);
const { nodes, matrix } = data;
const f = d3.format(numberFormat);

const outerRadius = Math.min(width, height) / 2 - 10;
const innerRadius = outerRadius - 24;
Expand Down Expand Up @@ -44,7 +61,7 @@ function chordViz(element, data, {
.attr('r', outerRadius);

// Compute the chord layout.
layout.matrix(data.matrix);
layout.matrix(matrix);

const group = svg.selectAll('.group')
.data(layout.groups)
Expand Down Expand Up @@ -99,16 +116,18 @@ function chordViz(element, data, {
});
}

chordVis.propTypes = propTypes;

function adaptor(slice, payload) {
const { selector, formData } = slice;
const { y_axis_format: yAxisFormat, color_scheme: colorScheme } = formData;
const { y_axis_format: numberFormat, color_scheme: colorScheme } = formData;
const element = document.querySelector(selector);
const { data } = payload;

return chordViz(element, data, {
return chordVis(element, {
data: payload.data,
width: slice.width(),
height: slice.height(),
yAxisFormat,
numberFormat,
colorScheme,
});
}
Expand Down

0 comments on commit 58d8821

Please sign in to comment.