Skip to content

Commit

Permalink
Merge branch 'develop' into fix/remove-C416-rule
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinAV authored Mar 5, 2024
2 parents 60830e9 + f510037 commit 8b1f675
Show file tree
Hide file tree
Showing 9 changed files with 321 additions and 218 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
20 changes: 18 additions & 2 deletions taipy/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@

import markdown as md_lib
import tzlocal
from flask import Blueprint, Flask, g, has_app_context, jsonify, request, send_file, send_from_directory
from flask import (
Blueprint,
Flask,
g,
has_app_context,
has_request_context,
jsonify,
request,
send_file,
send_from_directory,
)
from werkzeug.utils import secure_filename

import __main__ # noqa: F401
Expand Down Expand Up @@ -1002,7 +1012,13 @@ def __send_var_list_update( # noqa C901
elif isinstance(newvalue, _TaipyToJson):
newvalue = newvalue.get()
if isinstance(newvalue, (dict, _MapDict)):
continue # this var has no transformer
# Skip in taipy-gui, available in custom frontend
resource_handler_id = None
with contextlib.suppress(Exception):
if has_request_context():
resource_handler_id = request.cookies.get(_Server._RESOURCE_HANDLER_ARG, None)
if resource_handler_id is None:
continue # this var has no transformer
if isinstance(newvalue, float) and math.isnan(newvalue):
# do not let NaN go through json, it is not handle well (dies silently through websocket)
newvalue = None
Expand Down
9 changes: 3 additions & 6 deletions tests/core/config/test_core_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.

from unittest.mock import patch
from unittest import mock

import pytest

Expand All @@ -24,18 +24,15 @@

@pytest.fixture(scope="function", autouse=True)
def mock_core_version():
with patch("taipy.core.config.core_section._read_version") as mock_read_version:
with mock.patch("taipy.core.config.core_section._read_version") as mock_read_version:
mock_read_version.return_value = _MOCK_CORE_VERSION
CoreSection._CURRENT_CORE_VERSION = _MOCK_CORE_VERSION
Config.unique_sections[CoreSection.name] = CoreSection.default_config()
Config._default_config._unique_sections[CoreSection.name] = CoreSection.default_config()
Config._python_config._unique_sections[CoreSection.name] = CoreSection.default_config()

yield


@pytest.fixture(scope="session", autouse=True)
def reset_core_version():
yield
CoreSection._CURRENT_CORE_VERSION = _read_version()


Expand Down

0 comments on commit 8b1f675

Please sign in to comment.