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

Add a full screen button to chart #934

Merged
merged 2 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 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 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) {

Check warning on line 227 in frontend/taipy-gui/src/components/Taipy/Chart.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
const title = gd.classList.toggle("full-screen") ? "Exit Full screen" : "Full screen";

Check warning on line 228 in frontend/taipy-gui/src/components/Taipy/Chart.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 228 in frontend/taipy-gui/src/components/Taipy/Chart.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 228 in frontend/taipy-gui/src/components/Taipy/Chart.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
(evt.currentTarget as HTMLElement).setAttribute("data-title", title);

Check warning on line 229 in frontend/taipy-gui/src/components/Taipy/Chart.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
const {height} = gd.dataset;

Check warning on line 230 in frontend/taipy-gui/src/components/Taipy/Chart.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
if (height) {
gd.attributeStyleMap.set("height", height);

Check warning on line 232 in frontend/taipy-gui/src/components/Taipy/Chart.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
} else {
gd.setAttribute("data-height", getComputedStyle(gd.querySelector(".svg-container") || gd).height)

Check warning on line 234 in frontend/taipy-gui/src/components/Taipy/Chart.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 234 in frontend/taipy-gui/src/components/Taipy/Chart.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 234 in frontend/taipy-gui/src/components/Taipy/Chart.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
}

Check warning on line 235 in frontend/taipy-gui/src/components/Taipy/Chart.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 235 in frontend/taipy-gui/src/components/Taipy/Chart.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 235 in frontend/taipy-gui/src/components/Taipy/Chart.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
window.dispatchEvent(new Event('resize'));

Check warning on line 236 in frontend/taipy-gui/src/components/Taipy/Chart.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
},
},
];

const Chart = (props: ChartProp) => {
const {
title = "",
Expand Down Expand Up @@ -293,7 +335,7 @@
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 @@
}
return {
...layout,
autosize: true,
title: title || layout.title,
xaxis: {
title:
Expand Down Expand Up @@ -446,7 +489,7 @@
}, [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 @@
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,19 +603,20 @@
);

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 ? (
<Plot
data={props.figure[0].data as Data[]}
layout={layout}
style={style}
onRelayout={onRelayout}
onAfterPlot={onAfterPlot}
onSelected={onSelect}
onDeselect={onSelect}
config={plotConfig}
useResizeHandler

Check warning on line 619 in frontend/taipy-gui/src/components/Taipy/Chart.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
/>
) : (
<Plot
Expand All @@ -583,6 +629,7 @@
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
Loading