';
}
tip.style('display', null);
} else {
@@ -196,48 +258,50 @@ function heatmapVis(slice, payload) {
});
const rect = svg.append('g')
- .attr('transform', `translate(${margin.left}, ${margin.top})`)
+ .attr('transform', `translate(${margin.left}, ${margin.top})`)
.append('rect')
- .attr('pointer-events', 'all')
- .on('mousemove', tip.show)
- .on('mouseout', tip.hide)
- .style('fill-opacity', 0)
- .attr('stroke', 'black')
- .attr('width', hmWidth)
- .attr('height', hmHeight);
+ .classed('background-rect', true)
+ .on('mousemove', tip.show)
+ .on('mouseout', tip.hide)
+ .attr('width', hmWidth)
+ .attr('height', hmHeight);
rect.call(tip);
const xAxis = d3.svg.axis()
.scale(xRbScale)
+ .outerTickSize(0)
.tickValues(xRbScale.domain().filter(
function (d, i) {
- return !(i % (parseInt(fd.xscale_interval, 10)));
+ return !(i % (xScaleInterval));
}))
.orient('bottom');
const yAxis = d3.svg.axis()
.scale(yRbScale)
+ .outerTickSize(0)
.tickValues(yRbScale.domain().filter(
function (d, i) {
- return !(i % (parseInt(fd.yscale_interval, 10)));
+ return !(i % (yScaleInterval));
}))
.orient('left');
svg.append('g')
.attr('class', 'x axis')
.attr('transform', 'translate(' + margin.left + ',' + (margin.top + hmHeight) + ')')
- .call(xAxis)
+ .call(xAxis)
.selectAll('text')
- .style('text-anchor', 'end')
- .attr('transform', 'rotate(-45)');
+ .attr('x', -4)
+ .attr('y', 10)
+ .attr('dy', '0.3em')
+ .style('text-anchor', 'end')
+ .attr('transform', 'rotate(-45)');
svg.append('g')
.attr('class', 'y axis')
.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')')
.call(yAxis);
-
const context = canvas.node().getContext('2d');
context.imageSmoothingEnabled = false;
@@ -246,8 +310,8 @@ function heatmapVis(slice, payload) {
const imageObj = new Image();
const image = context.createImageData(heatmapDim[0], heatmapDim[1]);
const pixs = {};
- data.forEach((d) => {
- const c = d3.rgb(colorScaler(fd.normalized ? d.rank : d.perc));
+ records.forEach((d) => {
+ const c = d3.rgb(colorScaler(normalized ? d.rank : d.perc));
const x = xScale(d.x);
const y = yScale(d.y);
pixs[x + (y * xScale.domain().length)] = c;
@@ -278,4 +342,53 @@ function heatmapVis(slice, payload) {
createImageObj();
}
-module.exports = heatmapVis;
+Heatmap.propTypes = propTypes;
+
+function adaptor(slice, payload) {
+ const { selector, formData } = slice;
+ const {
+ bottom_margin: bottomMargin,
+ canvas_image_rendering: canvasImageRendering,
+ all_columns_x: columnX,
+ all_columns_y: columnY,
+ linear_color_scheme: colorScheme,
+ left_margin: leftMargin,
+ metric,
+ normalized,
+ show_legend: showLegend,
+ show_perc: showPercentage,
+ show_values: showValues,
+ sort_x_axis: sortXAxis,
+ sort_y_axis: sortYAxis,
+ xscale_interval: xScaleInterval,
+ yscale_interval: yScaleInterval,
+ y_axis_bounds: yAxisBounds,
+ y_axis_format: numberFormat,
+ } = formData;
+ const element = document.querySelector(selector);
+
+ return Heatmap(element, {
+ data: payload.data,
+ width: slice.width(),
+ height: slice.height(),
+ bottomMargin,
+ canvasImageRendering,
+ colorScheme,
+ columnX,
+ columnY,
+ leftMargin,
+ metric,
+ normalized,
+ numberFormat,
+ showLegend,
+ showPercentage,
+ showValues,
+ sortXAxis,
+ sortYAxis,
+ xScaleInterval: parseInt(xScaleInterval, 10),
+ yScaleInterval: parseInt(yScaleInterval, 10),
+ yAxisBounds,
+ });
+}
+
+export default adaptor;
diff --git a/superset/assets/src/visualizations/index.js b/superset/assets/src/visualizations/index.js
index df24b67158128..bb878bd700e6c 100644
--- a/superset/assets/src/visualizations/index.js
+++ b/superset/assets/src/visualizations/index.js
@@ -89,7 +89,7 @@ const vizMap = {
[VIZ_TYPES.line_multi]: () =>
loadVis(import(/* webpackChunkName: "line_multi" */ './line_multi.js')),
[VIZ_TYPES.time_pivot]: loadNvd3,
- [VIZ_TYPES.mapbox]: () => loadVis(import(/* webpackChunkName: "mapbox" */ './mapbox.jsx')),
+ [VIZ_TYPES.mapbox]: () => loadVis(import(/* webpackChunkName: "mapbox" */ './MapBox/MapBox.jsx')),
[VIZ_TYPES.markup]: () => loadVis(import(/* webpackChunkName: "markup" */ './markup.js')),
[VIZ_TYPES.para]: () =>
loadVis(import(/* webpackChunkName: "parallel_coordinates" */ './parallel_coordinates.js')),
diff --git a/superset/assets/src/visualizations/mapbox.css b/superset/assets/src/visualizations/mapbox.css
deleted file mode 100644
index babb33be0eace..0000000000000
--- a/superset/assets/src/visualizations/mapbox.css
+++ /dev/null
@@ -1,16 +0,0 @@
-.mapbox div.widget .slice_container {
- cursor: grab;
- cursor: -moz-grab;
- cursor: -webkit-grab;
- overflow: hidden;
-}
-
-.mapbox div.widget .slice_container:active {
- cursor: grabbing;
- cursor: -moz-grabbing;
- cursor: -webkit-grabbing;
-}
-
-.mapbox .slice_container div {
- padding-top: 0px;
-}
diff --git a/superset/assets/src/visualizations/partition.css b/superset/assets/src/visualizations/partition.css
index e23cca795203f..a0fdaedea0064 100644
--- a/superset/assets/src/visualizations/partition.css
+++ b/superset/assets/src/visualizations/partition.css
@@ -1,3 +1,7 @@
+.partition {
+ position: relative;
+}
+
.partition .chart {
display: block;
margin: auto;
@@ -18,10 +22,25 @@
.partition g text {
font-weight: bold;
- pointer-events: none;
fill: rgba(0, 0, 0, 0.8);
}
.partition g:hover text {
fill: rgba(0, 0, 0, 1);
}
+
+.partition .partition-tooltip {
+ position: absolute;
+ top: 0;
+ left: 0;
+ opacity: 0;
+ padding: 5px;
+ pointer-events: none;
+ background-color: rgba(255,255,255, 0.75);
+ border-radius: 5px;
+}
+
+.partition-tooltip td {
+ padding-left: 5px;
+ font-size: 11px;
+}
diff --git a/superset/assets/src/visualizations/partition.js b/superset/assets/src/visualizations/partition.js
index 23e4474e62606..fa7bbad869aeb 100644
--- a/superset/assets/src/visualizations/partition.js
+++ b/superset/assets/src/visualizations/partition.js
@@ -1,19 +1,14 @@
/* eslint no-param-reassign: [2, {"props": false}] */
-/* eslint no-use-before-define: ["error", { "functions": false }] */
import d3 from 'd3';
-import {
- d3TimeFormatPreset,
-} from '../modules/utils';
+import PropTypes from 'prop-types';
+import { hierarchy } from 'd3-hierarchy';
+import { d3TimeFormatPreset } from '../modules/utils';
import { getColorFromScheme } from '../modules/colors';
-
import './partition.css';
-d3.hierarchy = require('d3-hierarchy').hierarchy;
-d3.partition = require('d3-hierarchy').partition;
-
+// Compute dx, dy, x, y for each node and
+// return an array of nodes in breadth-first order
function init(root) {
- // Compute dx, dy, x, y for each node and
- // return an array of nodes in breadth-first order
const flat = [];
const dy = 1.0 / (root.height + 1);
let prev = null;
@@ -33,36 +28,85 @@ function init(root) {
return flat;
}
+// Declare PropTypes for recursive data structures
+// https://github.com/facebook/react/issues/5676
+const lazyFunction = f => (() => f().apply(this, arguments));
+ const leafType = PropTypes.shape({
+ name: PropTypes.string,
+ val: PropTypes.number.isRequired,
+});
+ const parentShape = {
+ name: PropTypes.string,
+ val: PropTypes.number.isRequired,
+ children: PropTypes.arrayOf(PropTypes.oneOfType([
+ PropTypes.shape(lazyFunction(() => parentShape)),
+ leafType,
+ ])),
+};
+ const nodeType = PropTypes.oneOfType([
+ PropTypes.shape(parentShape),
+ leafType,
+]);
+
+const propTypes = {
+ data: PropTypes.arrayOf(nodeType), // array of rootNode
+ width: PropTypes.number,
+ height: PropTypes.number,
+ colorScheme: PropTypes.string,
+ dateTimeFormat: PropTypes.string,
+ equalDateSize: PropTypes.bool,
+ groupBy: PropTypes.arrayOf(PropTypes.string),
+ useLogScale: PropTypes.bool,
+ metrics: PropTypes.arrayOf(PropTypes.oneOfType([
+ PropTypes.string,
+ PropTypes.object,
+ ])),
+ numberFormat: PropTypes.string,
+ partitionLimit: PropTypes.number,
+ partitionThreshold: PropTypes.number,
+ useRichTooltip: PropTypes.bool,
+ timeSeriesOption: PropTypes.string,
+};
+
// This vis is based on
// http://mbostock.github.io/d3/talk/20111018/partition.html
-function partitionVis(slice, payload) {
- const data = payload.data;
- const fd = slice.formData;
- const div = d3.select(slice.selector);
- const metrics = fd.metrics || [];
+function Icicle(element, props) {
+ PropTypes.checkPropTypes(propTypes, props, 'prop', 'Icicle');
+
+ const {
+ width,
+ height,
+ data,
+ colorScheme,
+ dateTimeFormat,
+ equalDateSize,
+ groupBy,
+ useLogScale = false,
+ metrics = [],
+ numberFormat,
+ partitionLimit,
+ partitionThreshold,
+ useRichTooltip,
+ timeSeriesOption = 'not_time',
+ } = props;
+
+ const div = d3.select(element);
// Chart options
- const logScale = fd.log_scale || false;
- const chartType = fd.time_series_option || 'not_time';
+ const chartType = timeSeriesOption;
const hasTime = ['adv_anal', 'time_series'].indexOf(chartType) >= 0;
- const format = d3.format(fd.number_format);
- const timeFormat = d3TimeFormatPreset(fd.date_time_format);
+ const format = d3.format(numberFormat);
+ const timeFormat = d3TimeFormatPreset(dateTimeFormat);
div.selectAll('*').remove();
- d3.selectAll('.nvtooltip').remove();
- const tooltip = d3
- .select('body')
+ const tooltip = div
.append('div')
- .attr('class', 'nvtooltip')
- .style('opacity', 0)
- .style('top', 0)
- .style('left', 0)
- .style('position', 'fixed');
+ .classed('partition-tooltip', true);
function drawVis(i, dat) {
const datum = dat[i];
- const w = slice.width();
- const h = slice.height() / data.length;
+ const w = width;
+ const h = height / data.length;
const x = d3.scale.linear().range([0, w]);
const y = d3.scale.linear().range([0, h]);
@@ -83,7 +127,7 @@ function partitionVis(slice, payload) {
viz.style('padding-top', '3px');
}
- const root = d3.hierarchy(datum);
+ const root = hierarchy(datum);
function hasDateNode(n) {
return metrics.indexOf(n.data.name) >= 0 && hasTime;
@@ -103,12 +147,12 @@ function partitionVis(slice, payload) {
// the time column, perform a date-time format
if (n.parent && hasDateNode(n.parent)) {
// Format timestamp values
- n.weight = fd.equal_date_size ? 1 : n.value;
+ n.weight = equalDateSize ? 1 : n.value;
n.value = n.name;
n.name = timeFormat(n.name);
}
- if (logScale) n.weight = Math.log(n.weight + 1);
- n.disp = n.disp && !isNaN(n.disp) && isFinite(n.disp) ? format(n.disp) : '';
+ if (useLogScale) n.weight = Math.log(n.weight + 1);
+ n.disp = n.disp && !Number.isNaN(n.disp) && isFinite(n.disp) ? format(n.disp) : '';
});
// Perform sort by weight
root.sort((a, b) => {
@@ -121,20 +165,20 @@ function partitionVis(slice, payload) {
// Prune data based on partition limit and threshold
// both are applied at the same time
- if (fd.partition_threshold && fd.partition_threshold >= 0) {
+ if (partitionThreshold && partitionThreshold >= 0) {
// Compute weight sums as we go
root.each((n) => {
n.sum = n.children ? n.children.reduce((a, v) => a + v.weight, 0) || 1 : 1;
if (n.children) {
// Dates are not ordered by weight
if (hasDateNode(n)) {
- if (fd.equal_date_size) {
+ if (equalDateSize) {
return;
}
const removeIndices = [];
// Keep at least one child
for (let j = 1; j < n.children.length; j++) {
- if (n.children[j].weight / n.sum < fd.partition_threshold) {
+ if (n.children[j].weight / n.sum < partitionThreshold) {
removeIndices.push(j);
}
}
@@ -145,7 +189,7 @@ function partitionVis(slice, payload) {
// Find first child that falls below the threshold
let j;
for (j = 1; j < n.children.length; j++) {
- if (n.children[j].weight / n.sum < fd.partition_threshold) {
+ if (n.children[j].weight / n.sum < partitionThreshold) {
break;
}
}
@@ -154,11 +198,11 @@ function partitionVis(slice, payload) {
}
});
}
- if (fd.partition_limit && fd.partition_limit >= 0) {
+ if (partitionLimit && partitionLimit >= 0) {
root.each((n) => {
- if (n.children && n.children.length > fd.partition_limit) {
+ if (n.children && n.children.length > partitionLimit) {
if (!hasDateNode(n)) {
- n.children = n.children.slice(0, fd.partition_limit);
+ n.children = n.children.slice(0, partitionLimit);
}
}
});
@@ -168,7 +212,6 @@ function partitionVis(slice, payload) {
n.sum = n.children ? n.children.reduce((a, v) => a + v.weight, 0) || 1 : 1;
});
- const verboseMap = slice.datasource.verbose_map;
function getCategory(depth) {
if (!depth) {
return 'Metric';
@@ -176,8 +219,7 @@ function partitionVis(slice, payload) {
if (hasTime && depth === 1) {
return 'Date';
}
- const col = fd.groupby[depth - (hasTime ? 2 : 1)];
- return verboseMap[col] || col;
+ return groupBy[depth - (hasTime ? 2 : 1)];
}
function getAncestors(d) {
@@ -192,55 +234,65 @@ function partitionVis(slice, payload) {
function positionAndPopulate(tip, d) {
let t = '
';
- if (!fd.rich_tooltip) {
- t += (
- '' +
- `${getCategory(d.depth)}` +
- ' |
'
- );
- t += (
- '' +
- '' +
- `' +
- ' | ' +
- `${d.name} | ` +
- `${d.disp} | ` +
- '
'
- );
- } else {
+ if (useRichTooltip) {
const nodes = getAncestors(d);
- nodes.forEach((n) => {
+ nodes.reverse().forEach((n) => {
const atNode = n.depth === d.depth;
t += '';
t += (
- `` +
- `` +
+ ' |
' +
+ '' +
'' +
' | ' +
+ `${getCategory(n.depth)} | ` +
`${n.name} | ` +
`${n.disp} | ` +
- `${getCategory(n.depth)} | ` +
'
'
);
});
+ } else {
+ t += (
+ '' +
+ `${getCategory(d.depth)}` +
+ ' |
'
+ );
+ t += (
+ '' +
+ '' +
+ `' +
+ ' | ' +
+ `${d.name} | ` +
+ `${d.disp} | ` +
+ '
'
+ );
}
t += '
';
+ const [tipX, tipY] = d3.mouse(element);
tip.html(t)
- .style('left', (d3.event.pageX + 13) + 'px')
- .style('top', (d3.event.pageY - 10) + 'px');
+ .style('left', (tipX + 15) + 'px')
+ .style('top', (tipY) + 'px');
+ }
+
+ const nodes = init(root);
+
+ let zoomX = w / root.dx;
+ let zoomY = h / 1;
+
+ // Keep text centered in its division
+ function transform(d) {
+ return `translate(8,${d.dx * zoomY / 2})`;
}
const g = viz
.selectAll('g')
- .data(init(root))
- .enter()
+ .data(nodes)
+ .enter()
.append('svg:g')
.attr('transform', d => `translate(${x(d.y)},${y(d.x)})`)
- .on('click', click)
.on('mouseover', (d) => {
tooltip
.interrupt()
@@ -260,40 +312,6 @@ function partitionVis(slice, payload) {
.style('opacity', 0);
});
- let kx = w / root.dx;
- let ky = h / 1;
-
- g.append('svg:rect')
- .attr('width', root.dy * kx)
- .attr('height', d => d.dx * ky);
-
- g.append('svg:text')
- .attr('transform', transform)
- .attr('dy', '0.35em')
- .style('opacity', d => d.dx * ky > 12 ? 1 : 0)
- .text((d) => {
- if (!d.disp) {
- return d.name;
- }
- return `${d.name}: ${d.disp}`;
- });
-
- // Apply color scheme
- g.selectAll('rect')
- .style('fill', (d) => {
- d.color = getColorFromScheme(d.name, fd.color_scheme);
- return d.color;
- });
-
- // Zoom out when clicking outside vis
- // d3.select(window)
- // .on('click', () => click(root));
-
- // Keep text centered in its division
- function transform(d) {
- return `translate(8,${d.dx * ky / 2})`;
- }
-
// When clicking a subdivision, the vis will zoom in to it
function click(d) {
if (!d.children) {
@@ -303,8 +321,8 @@ function partitionVis(slice, payload) {
}
return false;
}
- kx = (d.y ? w - 40 : w) / (1 - d.y);
- ky = h / d.dx;
+ zoomX = (d.y ? w - 40 : w) / (1 - d.y);
+ zoomY = h / d.dx;
x.domain([d.y, 1]).range([d.y ? 40 : 0, w]);
y.domain([d.x, d.x + d.dx]);
@@ -314,20 +332,83 @@ function partitionVis(slice, payload) {
.attr('transform', nd => `translate(${x(nd.y)},${y(nd.x)})`);
t.select('rect')
- .attr('width', d.dy * kx)
- .attr('height', nd => nd.dx * ky);
+ .attr('width', d.dy * zoomX)
+ .attr('height', nd => nd.dx * zoomY);
t.select('text')
.attr('transform', transform)
- .style('opacity', nd => nd.dx * ky > 12 ? 1 : 0);
+ .style('opacity', nd => nd.dx * zoomY > 12 ? 1 : 0);
d3.event.stopPropagation();
return true;
}
+
+ g.on('click', click);
+
+ g.append('svg:rect')
+ .attr('width', root.dy * zoomX)
+ .attr('height', d => d.dx * zoomY);
+
+ g.append('svg:text')
+ .attr('transform', transform)
+ .attr('dy', '0.35em')
+ .style('opacity', d => d.dx * zoomY > 12 ? 1 : 0)
+ .text((d) => {
+ if (!d.disp) {
+ return d.name;
+ }
+ return `${d.name}: ${d.disp}`;
+ });
+
+ // Apply color scheme
+ g.selectAll('rect')
+ .style('fill', (d) => {
+ d.color = getColorFromScheme(d.name, colorScheme);
+ return d.color;
+ });
}
+
for (let i = 0; i < data.length; i++) {
drawVis(i, data);
}
}
-module.exports = partitionVis;
+Icicle.propTypes = propTypes;
+
+function adaptor(slice, payload) {
+ const { selector, formData, datasource } = slice;
+ const {
+ color_scheme: colorScheme,
+ date_time_format: dateTimeFormat,
+ equal_date_size: equalDateSize,
+ groupby: groupBy,
+ log_scale: useLogScale,
+ metrics,
+ number_format: numberFormat,
+ partition_limit: partitionLimit,
+ partition_threshold: partitionThreshold,
+ rich_tooltip: useRichTooltip,
+ time_series_option: timeSeriesOption,
+ } = formData;
+ const { verbose_map: verboseMap } = datasource;
+ const element = document.querySelector(selector);
+
+ return Icicle(element, {
+ data: payload.data,
+ width: slice.width(),
+ height: slice.height(),
+ colorScheme,
+ dateTimeFormat,
+ equalDateSize,
+ groupBy: groupBy.map(g => verboseMap[g] || g),
+ useLogScale,
+ metrics,
+ numberFormat,
+ partitionLimit: partitionLimit && parseInt(partitionLimit, 10),
+ partitionThreshold: partitionThreshold && parseInt(partitionThreshold, 10),
+ useRichTooltip,
+ timeSeriesOption,
+ });
+}
+
+export default adaptor;
diff --git a/superset/assets/src/visualizations/rose.js b/superset/assets/src/visualizations/rose.js
index a0a545aae028f..875e748b5ef34 100644
--- a/superset/assets/src/visualizations/rose.js
+++ b/superset/assets/src/visualizations/rose.js
@@ -1,11 +1,27 @@
/* eslint no-use-before-define: ["error", { "functions": false }] */
import d3 from 'd3';
+import PropTypes from 'prop-types';
import nv from 'nvd3';
import { d3TimeFormatPreset } from '../modules/utils';
import { getColorFromScheme } from '../modules/colors';
-
import './rose.css';
+const propTypes = {
+ // Data is an object hashed by numeric value, perhaps timestamp
+ data: PropTypes.objectOf(PropTypes.arrayOf(PropTypes.shape({
+ key: PropTypes.arrayOf(PropTypes.string),
+ name: PropTypes.arrayOf(PropTypes.string),
+ time: PropTypes.number,
+ value: PropTypes.number,
+ }))),
+ width: PropTypes.number,
+ height: PropTypes.number,
+ dateTimeFormat: PropTypes.string,
+ numberFormat: PropTypes.string,
+ useRichTooltip: PropTypes.bool,
+ useAreaProportions: PropTypes.bool,
+};
+
function copyArc(d) {
return {
startAngle: d.startAngle,
@@ -22,10 +38,21 @@ function sortValues(a, b) {
return b.value - a.value;
}
-function roseVis(slice, payload) {
- const data = payload.data;
- const fd = slice.formData;
- const div = d3.select(slice.selector);
+function Rose(element, props) {
+ PropTypes.checkPropTypes(propTypes, props, 'prop', 'Rose');
+
+ const {
+ data,
+ width,
+ height,
+ colorScheme,
+ dateTimeFormat,
+ numberFormat,
+ useRichTooltip,
+ useAreaProportions,
+ } = props;
+
+ const div = d3.select(element);
const datum = data;
const times = Object.keys(datum)
@@ -33,8 +60,8 @@ function roseVis(slice, payload) {
.sort((a, b) => a - b);
const numGrains = times.length;
const numGroups = datum[times[0]].length;
- const format = d3.format(fd.number_format);
- const timeFormat = d3TimeFormatPreset(fd.date_time_format);
+ const format = d3.format(numberFormat);
+ const timeFormat = d3TimeFormatPreset(dateTimeFormat);
d3.select('.nvtooltip').remove();
div.selectAll('*').remove();
@@ -43,12 +70,12 @@ function roseVis(slice, payload) {
const legend = nv.models.legend();
const tooltip = nv.models.tooltip();
const state = { disabled: datum[times[0]].map(() => false) };
- const color = name => getColorFromScheme(name, fd.color_scheme);
+ const color = name => getColorFromScheme(name, colorScheme);
const svg = div
.append('svg')
- .attr('width', slice.width())
- .attr('height', slice.height());
+ .attr('width', width)
+ .attr('height', height);
const g = svg
.append('g')
@@ -68,7 +95,7 @@ function roseVis(slice, payload) {
function tooltipData(d, i, adatum) {
const timeIndex = Math.floor(d.arcId / numGroups);
- const series = fd.rich_tooltip ?
+ const series = useRichTooltip ?
adatum[times[timeIndex]]
.filter(v => !state.disabled[v.id % numGroups])
.map(v => ({
@@ -85,8 +112,8 @@ function roseVis(slice, payload) {
}
legend
- .width(slice.width())
- .color(d => getColorFromScheme(d.key, fd.color_scheme));
+ .width(width)
+ .color(d => getColorFromScheme(d.key, colorScheme));
legendWrap
.datum(legendData(datum))
.call(legend);
@@ -96,16 +123,15 @@ function roseVis(slice, payload) {
.valueFormatter(format);
// Compute max radius, which the largest value will occupy
- const width = slice.width();
- const height = slice.height() - legend.height();
+ const roseHeight = height - legend.height();
const margin = { top: legend.height() };
const edgeMargin = 35; // space between outermost radius and slice edge
- const maxRadius = Math.min(width, height) / 2 - edgeMargin;
+ const maxRadius = Math.min(width, roseHeight) / 2 - edgeMargin;
const labelThreshold = 0.05;
const gro = 8; // mouseover radius growth in pixels
const mini = 0.075;
- const centerTranslate = `translate(${width / 2},${height / 2 + margin.top})`;
+ const centerTranslate = `translate(${width / 2},${roseHeight / 2 + margin.top})`;
const roseWrap = g
.append('g')
.attr('transform', centerTranslate)
@@ -146,7 +172,7 @@ function roseVis(slice, payload) {
// Compute proportion
const P = maxRadius / maxSum;
const Q = P * maxRadius;
- const computeOuterRadius = (value, innerRadius) => fd.rose_area_proportion ?
+ const computeOuterRadius = (value, innerRadius) => useAreaProportions ?
Math.sqrt(Q * value + innerRadius * innerRadius) :
P * value + innerRadius;
@@ -537,4 +563,29 @@ function roseVis(slice, payload) {
});
}
-module.exports = roseVis;
+Rose.propTypes = propTypes;
+
+function adaptor(slice, payload) {
+ const { selector, formData } = slice;
+ const {
+ color_scheme: colorScheme,
+ date_time_format: dateTimeFormat,
+ number_format: numberFormat,
+ rich_tooltip: useRichTooltip,
+ rose_area_proportion: useAreaProportions,
+ } = formData;
+ const element = document.querySelector(selector);
+
+ return Rose(element, {
+ data: payload.data,
+ width: slice.width(),
+ height: slice.height(),
+ colorScheme,
+ dateTimeFormat,
+ numberFormat,
+ useRichTooltip,
+ useAreaProportions,
+ });
+}
+
+export default adaptor;
diff --git a/superset/assets/src/visualizations/sankey.js b/superset/assets/src/visualizations/sankey.js
index bb08fb3caab16..29ed2e2ffa18e 100644
--- a/superset/assets/src/visualizations/sankey.js
+++ b/superset/assets/src/visualizations/sankey.js
@@ -1,28 +1,47 @@
/* eslint-disable no-param-reassign */
import d3 from 'd3';
+import PropTypes from 'prop-types';
+import { sankey as d3Sankey } from 'd3-sankey';
import { getColorFromScheme } from '../modules/colors';
import './sankey.css';
-d3.sankey = require('d3-sankey').sankey;
-
-
-function sankeyVis(slice, payload) {
- const div = d3.select(slice.selector);
+const propTypes = {
+ data: PropTypes.arrayOf(PropTypes.shape({
+ source: PropTypes.string,
+ target: PropTypes.string,
+ value: PropTypes.number,
+ })),
+ width: PropTypes.number,
+ height: PropTypes.number,
+ colorScheme: PropTypes.string,
+};
+
+const formatNumber = d3.format(',.2f');
+
+function Sankey(element, props) {
+ PropTypes.checkPropTypes(propTypes, props, 'prop', 'Sankey');
+
+ const {
+ data,
+ width,
+ height,
+ colorScheme,
+ } = props;
+
+ const div = d3.select(element);
const margin = {
top: 5,
right: 5,
bottom: 5,
left: 5,
};
- const width = slice.width() - margin.left - margin.right;
- const height = slice.height() - margin.top - margin.bottom;
-
- const formatNumber = d3.format(',.2f');
+ const innerWidth = width - margin.left - margin.right;
+ const innerHeight = height - margin.top - margin.bottom;
div.selectAll('*').remove();
const svg = div.append('svg')
- .attr('width', width + margin.left + margin.right)
- .attr('height', height + margin.top + margin.bottom)
+ .attr('width', innerWidth + margin.left + margin.right)
+ .attr('height', innerHeight + margin.top + margin.bottom)
.append('g')
.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
@@ -30,16 +49,16 @@ function sankeyVis(slice, payload) {
.attr('class', 'sankey-tooltip')
.style('opacity', 0);
- const sankey = d3.sankey()
+ const sankey = d3Sankey()
.nodeWidth(15)
.nodePadding(10)
- .size([width, height]);
+ .size([innerWidth, innerHeight]);
const path = sankey.link();
let nodes = {};
// Compute the distinct nodes from the links.
- const links = payload.data.map(function (row) {
+ const links = data.map(function (row) {
const link = Object.assign({}, row);
link.source = nodes[link.source] || (nodes[link.source] = { name: link.source });
link.target = nodes[link.target] || (nodes[link.target] = { name: link.target });
@@ -120,13 +139,9 @@ function sankeyVis(slice, payload) {
.enter()
.append('g')
.attr('class', 'node')
- .attr('transform', function (d) {
- return 'translate(' + d.x + ',' + d.y + ')';
- })
+ .attr('transform', d => 'translate(' + d.x + ',' + d.y + ')')
.call(d3.behavior.drag()
- .origin(function (d) {
- return d;
- })
+ .origin(d => d)
.on('dragstart', function () {
this.parentNode.appendChild(this);
})
@@ -138,31 +153,38 @@ function sankeyVis(slice, payload) {
.attr('width', sankey.nodeWidth())
.style('fill', function (d) {
const name = d.name || 'N/A';
- d.color = getColorFromScheme(name.replace(/ .*/, ''), slice.formData.color_scheme);
+ d.color = getColorFromScheme(name.replace(/ .*/, ''), colorScheme);
return d.color;
})
- .style('stroke', function (d) {
- return d3.rgb(d.color).darker(2);
- })
+ .style('stroke', d => d3.rgb(d.color).darker(2))
.on('mouseover', onmouseover)
.on('mouseout', onmouseout);
node.append('text')
.attr('x', -6)
- .attr('y', function (d) {
- return d.dy / 2;
- })
+ .attr('y', d => d.dy / 2)
.attr('dy', '.35em')
.attr('text-anchor', 'end')
.attr('transform', null)
- .text(function (d) {
- return d.name;
- })
- .filter(function (d) {
- return d.x < width / 2;
- })
+ .text(d => d.name)
+ .filter(d => d.x < innerWidth / 2)
.attr('x', 6 + sankey.nodeWidth())
.attr('text-anchor', 'start');
}
-module.exports = sankeyVis;
+Sankey.propTypes = propTypes;
+
+function adaptor(slice, payload) {
+ const { selector, formData } = slice;
+ const { color_scheme: colorScheme } = formData;
+ const element = document.querySelector(selector);
+
+ return Sankey(element, {
+ data: payload.data,
+ width: slice.width(),
+ height: slice.height(),
+ colorScheme,
+ });
+}
+
+export default adaptor;
diff --git a/superset/assets/src/visualizations/world_map.js b/superset/assets/src/visualizations/world_map.js
index e7c1047ca7e9d..6c4948a7dd6c1 100644
--- a/superset/assets/src/visualizations/world_map.js
+++ b/superset/assets/src/visualizations/world_map.js
@@ -1,51 +1,67 @@
-// JS
-const d3 = require('d3');
-const Datamap = require('datamaps');
+import d3 from 'd3';
+import PropTypes from 'prop-types';
+import Datamap from 'datamaps';
+import './world_map.css';
-// CSS
-require('./world_map.css');
+const propTypes = {
+ data: PropTypes.arrayOf(PropTypes.shape({
+ country: PropTypes.string,
+ latitude: PropTypes.number,
+ longitude: PropTypes.number,
+ name: PropTypes.string,
+ m1: PropTypes.number,
+ m2: PropTypes.number,
+ })),
+ height: PropTypes.number,
+ maxBubbleSize: PropTypes.number,
+ showBubbles: PropTypes.bool,
+};
-function worldMapChart(slice, payload) {
- const container = slice.container;
- const div = d3.select(slice.selector);
+const formatter = d3.format('.3s');
- container.css('height', slice.height());
+function WorldMap(element, props) {
+ PropTypes.checkPropTypes(propTypes, props, 'prop', 'WorldMap');
+
+ const {
+ data,
+ height,
+ maxBubbleSize,
+ showBubbles,
+ } = props;
+
+ const div = d3.select(element);
+
+ const container = element;
+ container.style.height = `${height}px`;
div.selectAll('*').remove();
- const fd = slice.formData;
+
// Ignore XXX's to get better normalization
- let data = payload.data.filter(d => (d.country && d.country !== 'XXX'));
+ const filteredData = data.filter(d => (d.country && d.country !== 'XXX'));
- const ext = d3.extent(data, function (d) {
- return d.m1;
- });
- const extRadius = d3.extent(data, function (d) {
- return d.m2;
- });
+ const ext = d3.extent(filteredData, d => d.m1);
+ const extRadius = d3.extent(filteredData, d => d.m2);
const radiusScale = d3.scale.linear()
.domain([extRadius[0], extRadius[1]])
- .range([1, fd.max_bubble_size]);
+ .range([1, maxBubbleSize]);
const colorScale = d3.scale.linear()
.domain([ext[0], ext[1]])
.range(['#FFF', 'black']);
- data = data.map(d => Object.assign({}, d, {
+ const processedData = filteredData.map(d => ({
+ ...d,
radius: radiusScale(d.m2),
fillColor: colorScale(d.m1),
}));
const mapData = {};
- data.forEach((d) => {
+ processedData.forEach((d) => {
mapData[d.country] = d;
});
- const formatter = d3.format('.3s');
-
- container.show();
-
const map = new Datamap({
- element: slice.container.get(0),
- data,
+ element,
+ data: processedData,
fills: {
defaultFill: '#ddd',
},
@@ -85,10 +101,28 @@ function worldMapChart(slice, payload) {
map.updateChoropleth(mapData);
- if (fd.show_bubbles) {
- map.bubbles(data);
+ if (showBubbles) {
+ map.bubbles(processedData);
div.selectAll('circle.datamaps-bubble').style('fill', '#005a63');
}
}
-module.exports = worldMapChart;
+WorldMap.propTypes = propTypes;
+
+function adaptor(slice, payload) {
+ const { selector, formData } = slice;
+ const {
+ max_bubble_size: maxBubbleSize,
+ show_bubbles: showBubbles,
+ } = formData;
+ const element = document.querySelector(selector);
+
+ return WorldMap(element, {
+ data: payload.data,
+ height: slice.height(),
+ maxBubbleSize: parseInt(maxBubbleSize, 10),
+ showBubbles,
+ });
+}
+
+export default adaptor;
diff --git a/superset/assets/vendor/cal-heatmap/cal-heatmap.css b/superset/assets/vendor/cal-heatmap/cal-heatmap.css
index 068997c19a184..d6e18bc7dc49d 100644
--- a/superset/assets/vendor/cal-heatmap/cal-heatmap.css
+++ b/superset/assets/vendor/cal-heatmap/cal-heatmap.css
@@ -4,11 +4,6 @@
display: block;
}
-.cal-heatmap-container .graph
-{
- font-family: "Lucida Grande", Lucida, Verdana, sans-serif;
-}
-
.cal-heatmap-container .graph-label
{
fill: #999;