mirror of
https://github.com/apache/superset.git
synced 2026-04-21 09:04:38 +00:00
* [event-flow] add event flow visualizaton type from @data-ui/event-flow. * [event-flow] update vis thumbnail * [event-flow] update row limit label, remove duplicate chart controls * [dependencies] add @data-ui/event-flow 0.0.2 * [linting] fix multiple imports * [deps] bump mapbox-gl and react-map-gl to fix build * [event-flow] bump to 0.0.3 for es2015 + stage-0 babel presets * [deps] revert mapbox version bumps * [event-flow] update png, bump to newest version, address reviewer comments, add min event count form. * [event-flow] pin version * [event-flow][spec] add test for coveralls * [event-flow] revert spec
62 lines
1.7 KiB
JavaScript
62 lines
1.7 KiB
JavaScript
import React from 'react';
|
|
import ReactDOM from 'react-dom';
|
|
|
|
import {
|
|
App,
|
|
withParentSize,
|
|
cleanEvents,
|
|
TS,
|
|
EVENT_NAME,
|
|
ENTITY_ID,
|
|
} from '@data-ui/event-flow';
|
|
|
|
/*
|
|
* This function takes the slice object and json payload as input and renders a
|
|
* responsive <EventFlow /> component using the json data.
|
|
*/
|
|
function renderEventFlow(slice, json) {
|
|
const container = document.querySelector(slice.selector);
|
|
const hasData = json.data && json.data.length > 0;
|
|
|
|
// the slice container overflows ~80px in explorer, so we have to correct for this
|
|
const isExplorer = (/explore/).test(window.location.pathname);
|
|
|
|
const ResponsiveVis = withParentSize(({
|
|
parentWidth,
|
|
parentHeight,
|
|
...rest
|
|
}) => (
|
|
<App
|
|
width={parentWidth}
|
|
height={parentHeight - (isExplorer ? 80 : 0)}
|
|
{...rest}
|
|
/>
|
|
));
|
|
|
|
// render the component if we have data, otherwise render a no-data message
|
|
let Component;
|
|
if (hasData) {
|
|
const userKey = json.form_data.entity;
|
|
const eventNameKey = json.form_data.all_columns_x;
|
|
|
|
// map from the Superset form fields to <EventFlow />'s expected data keys
|
|
const accessorFunctions = {
|
|
[TS]: datum => new Date(datum.__timestamp), // eslint-disable-line no-underscore-dangle
|
|
[EVENT_NAME]: datum => datum[eventNameKey],
|
|
[ENTITY_ID]: datum => String(datum[userKey]),
|
|
};
|
|
|
|
const dirtyData = json.data;
|
|
const cleanData = cleanEvents(dirtyData, accessorFunctions);
|
|
const minEventCount = slice.formData.min_leaf_node_event_count;
|
|
|
|
Component = <ResponsiveVis data={cleanData} initialMinEventCount={minEventCount} />;
|
|
} else {
|
|
Component = <div>Sorry, there appears to be no data</div>;
|
|
}
|
|
|
|
ReactDOM.render(Component, container);
|
|
}
|
|
|
|
module.exports = renderEventFlow;
|