From d8314eeb0d8afd4797b5b7ccce1b0c4fb1c16d0d Mon Sep 17 00:00:00 2001 From: oashton Date: Fri, 26 Jun 2020 11:12:53 -0500 Subject: [PATCH] Add maximize and minimize feature to charts (#9210) * Add maximize and minimize feature to charts * Fixed lint issues * Update superset-frontend/src/dashboard/components/SliceHeaderControls.jsx Add translation function Co-Authored-By: David Aaron Suddjian <1858430+suddjian@users.noreply.github.com> * Remove resizeEvent property, change condition to use the nextProps * Minor changes, improve source code * Fixed lint issues * Remove unnecessary resizeEvent props * Move inline style to css class style * Minor fixes, improvements css Co-authored-by: David Aaron Suddjian <1858430+suddjian@users.noreply.github.com> --- .../src/dashboard/components/SliceHeader.jsx | 5 +++ .../components/SliceHeaderControls.jsx | 10 +++++ .../components/gridComponents/Chart.jsx | 11 ++++++ .../components/gridComponents/ChartHolder.jsx | 38 ++++++++++++++----- .../stylesheets/components/chart.less | 7 ++++ 5 files changed, 61 insertions(+), 10 deletions(-) diff --git a/superset-frontend/src/dashboard/components/SliceHeader.jsx b/superset-frontend/src/dashboard/components/SliceHeader.jsx index a1fb9f39d..07fba4993 100644 --- a/superset-frontend/src/dashboard/components/SliceHeader.jsx +++ b/superset-frontend/src/dashboard/components/SliceHeader.jsx @@ -47,6 +47,7 @@ const propTypes = { dashboardId: PropTypes.number.isRequired, filters: PropTypes.object.isRequired, addDangerToast: PropTypes.func.isRequired, + handleToggleFullSize: PropTypes.func.isRequired, }; const defaultProps = { @@ -97,6 +98,8 @@ class SliceHeader extends React.PureComponent { componentId, dashboardId, addDangerToast, + handleToggleFullSize, + isFullSize, } = this.props; return ( @@ -149,6 +152,8 @@ class SliceHeader extends React.PureComponent { componentId={componentId} dashboardId={dashboardId} addDangerToast={addDangerToast} + handleToggleFullSize={handleToggleFullSize} + isFullSize={isFullSize} /> )} diff --git a/superset-frontend/src/dashboard/components/SliceHeaderControls.jsx b/superset-frontend/src/dashboard/components/SliceHeaderControls.jsx index 1322207d4..50fc8a754 100644 --- a/superset-frontend/src/dashboard/components/SliceHeaderControls.jsx +++ b/superset-frontend/src/dashboard/components/SliceHeaderControls.jsx @@ -78,6 +78,8 @@ class SliceHeaderControls extends React.PureComponent { this.props.slice.slice_id, ); + this.handleToggleFullSize = this.handleToggleFullSize.bind(this); + this.state = { showControls: false, }; @@ -106,6 +108,10 @@ class SliceHeaderControls extends React.PureComponent { }); } + handleToggleFullSize() { + this.props.handleToggleFullSize(); + } + render() { const { slice, @@ -114,12 +120,14 @@ class SliceHeaderControls extends React.PureComponent { updatedDttm, componentId, addDangerToast, + isFullSize, } = this.props; const cachedWhen = moment.utc(cachedDttm).fromNow(); const updatedWhen = updatedDttm ? moment.utc(updatedDttm).fromNow() : ''; const refreshTooltip = isCached ? t('Cached %s', cachedWhen) : (updatedWhen && t('Fetched %s', updatedWhen)) || ''; + const resizeLabel = isFullSize ? t('Minimize') : t('Maximize'); return ( )} + {resizeLabel} + {/* diff --git a/superset-frontend/src/dashboard/components/gridComponents/ChartHolder.jsx b/superset-frontend/src/dashboard/components/gridComponents/ChartHolder.jsx index 75ab291ea..57a00b5c4 100644 --- a/superset-frontend/src/dashboard/components/gridComponents/ChartHolder.jsx +++ b/superset-frontend/src/dashboard/components/gridComponents/ChartHolder.jsx @@ -108,11 +108,13 @@ class ChartHolder extends React.Component { outlinedComponentId: null, outlinedColumnName: null, directPathLastUpdated: 0, + isFullSize: false, }; this.handleChangeFocus = this.handleChangeFocus.bind(this); this.handleDeleteComponent = this.handleDeleteComponent.bind(this); this.handleUpdateSliceName = this.handleUpdateSliceName.bind(this); + this.handleToggleFullSize = this.handleToggleFullSize.bind(this); } componentDidMount() { @@ -160,9 +162,12 @@ class ChartHolder extends React.Component { }); } + handleToggleFullSize() { + this.setState(() => ({ isFullSize: !this.state.isFullSize })); + } + render() { const { isFocused } = this.state; - const { component, parentComponent, @@ -185,6 +190,23 @@ class ChartHolder extends React.Component { ? parentComponent.meta.width || GRID_MIN_COLUMN_COUNT : component.meta.width || GRID_MIN_COLUMN_COUNT; + let chartWidth = 0; + let chartHeight = 0; + + if (this.state.isFullSize) { + chartWidth = document.body.clientWidth - CHART_MARGIN; + chartHeight = document.body.clientHeight - CHART_MARGIN; + } else { + chartWidth = Math.floor( + widthMultiple * columnWidth + + (widthMultiple - 1) * GRID_GUTTER_SIZE - + CHART_MARGIN, + ); + chartHeight = Math.floor( + component.meta.height * GRID_BASE_UNIT - CHART_MARGIN, + ); + } + return ( {!editMode && ( {!editMode && ( diff --git a/superset-frontend/src/dashboard/stylesheets/components/chart.less b/superset-frontend/src/dashboard/stylesheets/components/chart.less index 44ef5dc06..25fb2066c 100644 --- a/superset-frontend/src/dashboard/stylesheets/components/chart.less +++ b/superset-frontend/src/dashboard/stylesheets/components/chart.less @@ -148,3 +148,10 @@ .time-filter-tabs > .nav-tabs > li > a { padding: 4px; } + +.full-size { + position: fixed; + z-index: @z-index-max; + left: 0; + top: 0; +}