Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: React version of visualizations #2988

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
c5cb705
new visualization components
Oct 16, 2018
56dbc0c
temporary angular glue
Oct 17, 2018
c417004
remove angular versions of visualizations
Oct 17, 2018
d11af59
add proptypes
Oct 19, 2018
288ebc8
address review comments
Oct 25, 2018
742a065
fixes from #2840
Oct 25, 2018
8563280
register new visualization components
Oct 26, 2018
ee37ff9
catch up with #2982
Oct 26, 2018
c5137b1
catch up with #2080
Oct 27, 2018
48077f8
bump heap size
Oct 19, 2018
964f39d
fix more bugs found in review
Oct 30, 2018
69cf95c
fix series type/name editing
Oct 31, 2018
ed67dc0
fix misc chart/table nits
Nov 5, 2018
7c73d5e
more proptypes
Nov 6, 2018
36f7dce
catch up with #2745
Nov 6, 2018
c069765
fix filters
Nov 6, 2018
a00ffc9
more nits
Nov 8, 2018
43801a1
fix multifilter
Nov 8, 2018
ad39f8a
hook up table search
Nov 8, 2018
e36c39d
fix plotly legend click
Nov 8, 2018
926f573
fix navbar button styling
Nov 14, 2018
8ca8c46
fix pagination after adjusting items per page
Nov 28, 2018
212e65c
typo
Nov 28, 2018
d1f2c4e
fix select box width
Nov 29, 2018
7f9060f
update react
Dec 5, 2018
8ce0e32
Resize Sankey visualizations, show more informative error messages
Dec 5, 2018
b0ddc34
fix filters
Dec 6, 2018
aecb48e
fix up counter editor
Dec 6, 2018
62452df
catch up with #3102
Dec 10, 2018
9438e2a
general resize support
Dec 12, 2018
1b19b75
render counters properly
Dec 12, 2018
f62d5bf
apply z-index fix to ant select
Dec 12, 2018
076069f
Better fix for resizing
Dec 13, 2018
5d975a9
fixes for multiple Y columns
Dec 18, 2018
11be560
choropleth fixes
Dec 20, 2018
1884f15
use autosizer to scale counter
Jan 2, 2019
d4702ba
display vis name in dashboard
Jan 2, 2019
90555d7
catch up with #3206
Jan 3, 2019
ca4653e
handle resize/move of counter vis
Jan 5, 2019
c41ffbf
match original bounds/zoom behavior
Jan 8, 2019
50f70a3
proper display in editor
Jan 8, 2019
31e733d
update choropleth vis in editor
Jan 9, 2019
46fc934
enable pace
Jan 10, 2019
4626ee4
ant-compatible footer
Jan 10, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ module.exports = {
"react/forbid-prop-types": "warn",
"react/prop-types": "warn",
"jsx-a11y/anchor-is-valid": "off",
"jsx-a11y/label-has-for": "off",
"jsx-a11y/no-static-element-interactions": "off",
"max-len": ['error', 120, 2, {
ignoreUrls: true,
ignoreComments: false,
Expand Down
1 change: 0 additions & 1 deletion client/app/assets/less/inc/footer.less
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#footer {
position: absolute;
bottom: 0;
text-align: center;
width: 100%;
Expand Down
18 changes: 9 additions & 9 deletions client/app/assets/less/inc/visualizations/counter-render.less
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
counter-renderer {
.counter-renderer {
display: block;
text-align: center;
padding: 15px 10px;
overflow: hidden;

counter {
.counter {
margin: 0;
padding: 0;
font-size: 80px;
Expand All @@ -14,31 +14,31 @@ counter-renderer {
align-items: center;
justify-content: center;

value,
counter-target {
.value,
.counter-target {
font-size: 1em;
display: block;
}

counter-name {
.counter-name {
font-size: 0.5em;
display: block;
}

&.positive value {
&.positive .value {
color: #5cb85c;
}

&.negative value {
&.negative .value {
color: #d9534f;
}
}

counter-target {
.counter-target {
color: #ccc;
}

counter-name {
.counter-name {
font-size: 0.5em;
display: block;
}
Expand Down
1 change: 1 addition & 0 deletions client/app/assets/less/inc/visualizations/map.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.map-visualization-container {
width: 100%;
height: 500px;

> div:first-child {
Expand Down
8 changes: 8 additions & 0 deletions client/app/assets/less/redash/ant.less
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
@import '~antd/lib/date-picker/style/index.less';
@import '~antd/lib/modal/style/index.less';
@import '~antd/lib/tooltip/style/index.less';
@import '~antd/lib/pagination/style/index.less';
@import '~antd/lib/popover/style/index.less';
@import '~antd/lib/select/style/index.less';
@import '~antd/lib/button/style/index.less';
@import '~antd/lib/radio/style/index.less';
@import '~antd/lib/tabs/style/index.less';
@import '~antd/lib/time-picker/style/index.less';

// Overwritting Ant Design defaults to fit into Redash current style
Expand All @@ -19,6 +22,11 @@

@primary-color : @blue;

// make placeholders in select boxes visible
.ant-select {
min-width: 150px;
}

// Fix for disabled button styles inside Tooltip component.
// Tooltip wraps disabled buttons with `<span>` and moves all styles
// and classes to that `<span>`. This resets all button styles and
Expand Down
6 changes: 6 additions & 0 deletions client/app/assets/less/redash/query.less
Original file line number Diff line number Diff line change
Expand Up @@ -675,3 +675,9 @@ nav .rg-bottom {

}
}
.sortable-helper {
z-index: 1100;
}
.ant-popover {
z-index: 1200;
}
6 changes: 2 additions & 4 deletions client/app/components/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
import { react2angular } from 'react2angular';

import frontendVersion from '../version.json';
import { ClientConfig } from '@/components/proptypes';

export function Footer({ clientConfig, currentUser }) {
const backendVersion = clientConfig.version;
Expand Down Expand Up @@ -32,10 +33,7 @@ export function Footer({ clientConfig, currentUser }) {
}

Footer.propTypes = {
clientConfig: PropTypes.shape({
version: PropTypes.string,
newVersionAvailable: PropTypes.bool,
}).isRequired,
clientConfig: ClientConfig.isRequired,
currentUser: PropTypes.shape({
isAdmin: PropTypes.bool,
}).isRequired,
Expand Down
4 changes: 2 additions & 2 deletions client/app/components/app-header/app-header.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<ul class="nav navbar-nav nav__main">
<li class="dropdown btn-group" ng-show="$ctrl.showDashboardsMenu" uib-dropdown>
<a class="btn" href="dashboards">Dashboards</a>
<a type="button" class="btn hidden-xs" uib-dropdown-toggle>
<a class="btn hidden-xs" uib-dropdown-toggle>
<span class="caret caret--nav"></span>
</a>
<ul class="dropdown-menu" uib-dropdown-menu>
Expand All @@ -39,7 +39,7 @@
</li>
<li class="dropdown btn-group" ng-show="$ctrl.showQueriesMenu" uib-dropdown>
<a class="btn" href="queries">Queries</a>
<a type="button" class="btn hidden-xs" uib-dropdown-toggle>
<a class="btn hidden-xs" uib-dropdown-toggle>
<span class="caret caret--nav"></span>
</a>
<ul class="dropdown-menu" uib-dropdown-menu>
Expand Down
9 changes: 8 additions & 1 deletion client/app/components/dashboards/widget.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@
<div class="alert alert-danger m-5" ng-show="$ctrl.widget.getQueryResult().getError()">Error running query: <strong>{{$ctrl.widget.getQueryResult().getError()}}</strong></div>
</div>
<div ng-switch-when="done" class="body-row-auto scrollbox">
<visualization-renderer visualization="$ctrl.widget.visualization" query-result="$ctrl.widget.getQueryResult()" class="t-body"></visualization-renderer>
<visualization-renderer
visualization="$ctrl.widget.visualization"
update-options="$ctrl.widget.updateOptions"
data="{ rows: $ctrl.widget.getQueryResult().getData(), columns: $ctrl.widget.getQueryResult().getColumns() }"
filters="$ctrl.widget.getQueryResult().getFilters()"
set-filters="$ctrl.widget.updateFilters"
listen-for-resize="$ctrl.listenForResize"
class="t-body"></visualization-renderer>
</div>
<div ng-switch-default class="body-row-auto spinner-container">
<div class="spinner">
Expand Down
4 changes: 3 additions & 1 deletion client/app/components/dashboards/widget.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { onResize } from '@/directives/resize-event';
import template from './widget.html';
import editTextBoxTemplate from './edit-text-box.html';
import widgetDialogTemplate from './widget-dialog.html';
Expand Down Expand Up @@ -51,7 +52,7 @@ const EditTextBoxComponent = {
},
};

function DashboardWidgetCtrl($location, $uibModal, $window, Events, currentUser) {
function DashboardWidgetCtrl($element, $location, $uibModal, $window, Events, currentUser) {
this.canViewQuery = currentUser.hasPermission('view_query');

this.editTextBox = () => {
Expand Down Expand Up @@ -119,6 +120,7 @@ function DashboardWidgetCtrl($location, $uibModal, $window, Events, currentUser)
} else {
this.type = 'textbox';
}
this.listenForResize = f => onResize($element.parent().parent()[0], f);
}

export default function init(ngModule) {
Expand Down
64 changes: 64 additions & 0 deletions client/app/components/proptypes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import PropTypes from 'prop-types';

export const ClientConfig = PropTypes.shape({
dateFormat: PropTypes.string,
dateTimeFormat: PropTypes.string,
integerFormat: PropTypes.string,
floatFormat: PropTypes.string,
booleanValues: PropTypes.arrayOf(PropTypes.string),
version: PropTypes.string,
newVersionAvailable: PropTypes.bool,
});

export const DataSource = PropTypes.shape({
syntax: PropTypes.string,
options: PropTypes.shape({
Expand All @@ -14,3 +24,57 @@ export const Table = PropTypes.shape({
});

export const Schema = PropTypes.arrayOf(Table);

export const QueryData = PropTypes.exact({
rows: PropTypes.arrayOf(PropTypes.object).isRequired,
columns: PropTypes.arrayOf(PropTypes.shape({
friendly_name: PropTypes.string.isRequired,
type: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
})),
});

export const SeriesOptions = PropTypes.objectOf(PropTypes.exact({
yAxis: PropTypes.number.isRequired,
zIndex: PropTypes.number.isRequired,
index: PropTypes.number.isRequired,
type: PropTypes.string.isRequired,
name: PropTypes.string,
color: PropTypes.string,
}));

export const ValuesOptions = PropTypes.objectOf(PropTypes.exact({ color: PropTypes.string.isRequired }));

export const Visualization = PropTypes.shape({
name: PropTypes.string.isRequired,
type: PropTypes.string.isRequired,
options: PropTypes.object.isRequired,
});

export const ColumnDetail = PropTypes.exact({
alignContent: PropTypes.string.isRequired,
allowHTML: PropTypes.bool.isRequired,
allowSearch: PropTypes.bool.isRequired,
booleanValues: PropTypes.arrayOf(PropTypes.string).isRequired,
dateTimeFormat: PropTypes.string,
displayAs: PropTypes.string.isRequired,
formatFunction: PropTypes.func,
friendly_name: PropTypes.string,
highlightLinks: PropTypes.bool.isRequired,
imageHeight: PropTypes.string.isRequired,
imageTitleTemplate: PropTypes.string.isRequired,
imageUrlTemplate: PropTypes.string.isRequired,
imageWidth: PropTypes.string.isRequired,
linkOpenInNewTab: PropTypes.bool.isRequired,
linkTextTemplate: PropTypes.string.isRequired,
linkTitleTemplate: PropTypes.string.isRequired,
linkUrlTemplate: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
numberFormat: PropTypes.string,
order: PropTypes.number.isRequired,
title: PropTypes.string.isRequired,
type: PropTypes.string.isRequired,
visible: PropTypes.bool.isRequired,
});

export const Row = PropTypes.object;
8 changes: 7 additions & 1 deletion client/app/components/queries/visualization-embed.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ <h3>
</div>

<div class="col-md-12 query__vis">
<visualization-renderer visualization="$ctrl.visualization" query-result="$ctrl.queryResult" class="t-body">
<visualization-renderer
visualization="$ctrl.visualization"
set-filters="$ctrl.setFilters"
filters="$ctrl.queryResult.getFilters()"
data="{ rows: $ctrl.queryResult.getData(), columns: $ctrl.queryResult.getColumns() }"
update-options="$ctrl.updateOptions"
class="t-body">
</visualization-renderer>
</div>

Expand Down
19 changes: 16 additions & 3 deletions client/app/components/queries/visualization-embed.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { find } from 'lodash';
import { findIndex } from 'lodash';
import logoUrl from '@/assets/images/redash_icon_small.png';
import template from './visualization-embed.html';

Expand All @@ -16,9 +16,22 @@ const VisualizationEmbed = {
this.apiKey = $routeParams.api_key;
this.logoUrl = logoUrl;
this.query = new Query(this.data[0]);
const visIndex = findIndex(
this.query.visualizations,
visualization => visualization.id === visualizationId,
);
this.queryResult = new QueryResult(this.data[1]);
this.visualization =
find(this.query.visualizations, visualization => visualization.id === visualizationId);
this.visualization = this.query.visualizations[visIndex];
this.updateVisualization = (o) => {
this.query.visualizations[visIndex] = {
...this.visualization,
options: {
...this.visualization.options,
...o,
},
};
};
this.setFilters = (f) => { this.query.filters = f; };
},
};

Expand Down
3 changes: 2 additions & 1 deletion client/app/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Pace.options.shouldHandlePushState = (prevUrl, newUrl) => {
const [newPrefix] = newUrl.split('?');
return prevPrefix !== newPrefix;
};
Pace.start();

const requirements = [
ngRoute,
Expand Down Expand Up @@ -96,7 +97,7 @@ function registerServices() {
}

function registerVisualizations() {
const context = require.context('@/visualizations', true, /^((?![\\/.]test[\\./]).)*\.jsx?$/);
const context = require.context('@/visualizations', true, /^((?![\\/.]test[\\./]).)*\.js?$/);
registerAll(context);
}

Expand Down
8 changes: 8 additions & 0 deletions client/app/directives/resize-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ function resizeEvent() {
};
}

export function onResize(node, f) {
if (!items.has(node)) {
items.set(node, {
callback: f,
});
}
}

export default function init(ngModule) {
ngModule.directive('resizeEvent', resizeEvent);
}
Expand Down
11 changes: 9 additions & 2 deletions client/app/pages/dashboards/dashboard.less
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
overflow: visible;
}

visualization-renderer > .counter-renderer {
overflow: hidden;
}

&.preview-mode {
.widget-menu-regular {
display: block;
Expand Down Expand Up @@ -53,6 +57,10 @@
flex-grow: 1;
position: relative;
}
.counter-renderer {
flex-grow: 0;
position: static;
}
}

.sunburst-visualization-container,
Expand All @@ -69,14 +77,13 @@
overflow: hidden;
}

counter {
.counter {
position: absolute;
left: 10px;
top: 15px;
right: 10px;
bottom: 15px;
height: auto;
overflow: hidden;
padding: 0;
}
}
Expand Down
Loading