Skip to content

Commit

Permalink
Add a full screen button to chart (#934)
Browse files Browse the repository at this point in the history
* Add a full screen button to chart
- imcrement frontend version to 3.2
resolves #472

* with some transition

---------

Co-authored-by: Fred Lefévère-Laoide <[email protected]>
  • Loading branch information
FredLL-Avaiga and Fred Lefévère-Laoide authored Mar 5, 2024
1 parent a378d8c commit d681109
Show file tree
Hide file tree
Showing 7 changed files with 300 additions and 210 deletions.
2 changes: 1 addition & 1 deletion frontend/taipy-gui/dom/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "taipy-gui-dom",
"version": "3.1.0",
"version": "3.2.0",
"private": true,
"dependencies": {
"react": "^18.2.0",
Expand Down
423 changes: 226 additions & 197 deletions frontend/taipy-gui/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion frontend/taipy-gui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "taipy-gui",
"version": "3.1.0",
"version": "3.2.0",
"private": true,
"dependencies": {
"@emotion/react": "^11.10.0",
Expand Down
2 changes: 1 addition & 1 deletion frontend/taipy-gui/packaging/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "taipy-gui",
"version": "3.1.0",
"version": "3.2.0",
"private": true,
"main": "./taipy-gui.js",
"types": "./taipy-gui.d.ts"
Expand Down
14 changes: 14 additions & 0 deletions frontend/taipy-gui/public/stylekit/controls/chart.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,17 @@
.taipy-chart:not(.has-background) .main-svg {
background: transparent !important;
}

.js-plotly-plot.full-screen {
position: fixed !important;
height: 99vh !important;
width: 99vw !important;
display: block !important;
left: 0;
top: 0;
z-index: 99999;
overflow: hidden;
background-color: var(--color-background);
box-shadow: 10px 5px 5px var(--color-contrast);
transition: left 1s ease, width 1s ease, top 1s ease, height 1s ease;
}
65 changes: 56 additions & 9 deletions frontend/taipy-gui/src/components/Taipy/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,27 @@
* specific language governing permissions and limitations under the License.
*/

import React, { CSSProperties, useCallback, useEffect, useMemo, useRef, useState, lazy, Suspense } from "react";
import { Data, Layout, PlotDatum, PlotMarker, PlotRelayoutEvent, PlotSelectionEvent, ScatterLine } from "plotly.js";
import React, {
CSSProperties,
useCallback,
useEffect,
useMemo,
useRef,
useState,
lazy,
Suspense,
} from "react";
import {
Config,
Data,
Layout,
ModeBarButtonAny,
PlotDatum,
PlotMarker,
PlotRelayoutEvent,
PlotSelectionEvent,
ScatterLine,
} from "plotly.js";
import Skeleton from "@mui/material/Skeleton";
import Box from "@mui/material/Box";
import Tooltip from "@mui/material/Tooltip";
Expand Down Expand Up @@ -196,6 +215,29 @@ const defaultConfig = {
const emptyLayout = {} as Record<string, Record<string, unknown>>;
const emptyData = {} as Record<string, TraceValueType>;

const TaipyPlotlyButtons: ModeBarButtonAny[] = [
{
name: "Full screen",
title: "Full screen",
icon: {
height: 24,
width: 24,
path: "M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z",
},
click: function (gd: HTMLElement, evt: Event) {
const title = gd.classList.toggle("full-screen") ? "Exit Full screen" : "Full screen";
(evt.currentTarget as HTMLElement).setAttribute("data-title", title);
const {height} = gd.dataset;
if (height) {
gd.attributeStyleMap.set("height", height);
} else {
gd.setAttribute("data-height", getComputedStyle(gd.querySelector(".svg-container") || gd).height)
}
window.dispatchEvent(new Event('resize'));
},
},
];

const Chart = (props: ChartProp) => {
const {
title = "",
Expand Down Expand Up @@ -293,7 +335,7 @@ const Chart = (props: ChartProp) => {
useDispatchRequestUpdateOnFirstRender(dispatch, id, module, updateVars);

const layout = useMemo(() => {
const layout = {...baseLayout};
const layout = { ...baseLayout };
let template = undefined;
try {
const tpl = props.template && JSON.parse(props.template);
Expand All @@ -320,6 +362,7 @@ const Chart = (props: ChartProp) => {
}
return {
...layout,
autosize: true,
title: title || layout.title,
xaxis: {
title:
Expand Down Expand Up @@ -446,7 +489,7 @@ const Chart = (props: ChartProp) => {
}, [props.figure, selected, data, config, dataKey]);

const plotConfig = useMemo(() => {
let plconf = {};
let plconf: Partial<Config> = {};
if (props.plotConfig) {
try {
plconf = JSON.parse(props.plotConfig);
Expand All @@ -458,11 +501,13 @@ const Chart = (props: ChartProp) => {
plconf = {};
}
}
if (active) {
return plconf;
} else {
return { ...plconf, staticPlot: true };
plconf.modeBarButtonsToAdd = TaipyPlotlyButtons;
plconf.responsive = true;
plconf.autosizable = true;
if (!active) {
plconf.staticPlot = true;
}
return plconf;
}, [active, props.plotConfig]);

const onRelayout = useCallback(
Expand Down Expand Up @@ -558,7 +603,7 @@ const Chart = (props: ChartProp) => {
);

return render ? (
<Box id={id} key="div" data-testid={props.testId} className={className} ref={plotRef}>
<Box id={id} data-testid={props.testId} className={className} ref={plotRef}>
<Tooltip title={hover || ""}>
<Suspense fallback={<Skeleton key="skeleton" sx={skelStyle} />}>
{Array.isArray(props.figure) && props.figure.length && props.figure[0].data !== undefined ? (
Expand All @@ -571,6 +616,7 @@ const Chart = (props: ChartProp) => {
onSelected={onSelect}
onDeselect={onSelect}
config={plotConfig}
useResizeHandler
/>
) : (
<Plot
Expand All @@ -583,6 +629,7 @@ const Chart = (props: ChartProp) => {
onDeselect={isOnClick(config.types) ? undefined : onSelect}
onClick={isOnClick(config.types) ? onSelect : undefined}
config={plotConfig}
useResizeHandler
/>
)}
</Suspense>
Expand Down
2 changes: 1 addition & 1 deletion frontend/taipy/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "taipy-gui-core",
"version": "3.1.0",
"version": "3.2.0",
"private": true,
"devDependencies": {
"@types/react": "^18.0.15",
Expand Down

0 comments on commit d681109

Please sign in to comment.