Skip to content

Commit

Permalink
Merge pull request #1349 from Avaiga/1347-updating-stylekitcss-and-ho…
Browse files Browse the repository at this point in the history
…ver_text-for-metric-component

Updating stylekit & hover_text
  • Loading branch information
namnguyen20999 authored Jun 4, 2024
2 parents eb1a76c + 8487496 commit 89f60ea
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
26 changes: 26 additions & 0 deletions frontend/taipy-gui/public/stylekit/controls/metric.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2021-2024 Avaiga Private Limited
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* 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.
*/

/**************************************************************
TAIPY METRIC
***************************************************************/

/*************************************************
OVERRIDES / NORMALIZATION
**************************************************/

.taipy-metric {
max-width: 100%;
}
1 change: 1 addition & 0 deletions frontend/taipy-gui/public/stylekit/stylekit.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
@import 'controls/expandable.css';
@import 'controls/image.css';
@import 'controls/input.css';
@import 'controls/metric.css';
@import 'controls/navbar.css';
@import 'controls/number.css';
@import 'controls/slider.css';
Expand Down
20 changes: 12 additions & 8 deletions frontend/taipy-gui/src/components/Taipy/Metric.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
} from "./utils";
import Box from "@mui/material/Box";
import Skeleton from "@mui/material/Skeleton";
import Tooltip from "@mui/material/Tooltip";

const Plot = lazy(() => import("react-plotly.js"));

Expand Down Expand Up @@ -67,13 +68,14 @@ const Metric = (props: MetricProps) => {
const className = useClassNames(props.libClassName, props.dynamicClassName, props.className);
const baseLayout = useDynamicJsonProperty(props.layout, props.defaultLayout || "", emptyLayout);
const baseStyle = useDynamicJsonProperty(props.style, props.defaultStyle || "", defaultStyle);
const hover = useDynamicProperty(props.hoverText, props.defaultHoverText, undefined);

const data = useMemo(() => ([
{
domain: {x: [0, 1], y: [0, 1]},
value: value,
type: "indicator",
mode: "gauge" + (showValue ? "+number" : "") + (delta !== undefined ? "+delta" : ""),
mode: "gauge" + (showValue ? "+number" : "") + (delta !== undefined ? "+delta" : ""),
delta: {
reference: typeof value === 'number' && typeof delta === 'number' ? value - delta : undefined,
},
Expand Down Expand Up @@ -114,13 +116,15 @@ const Metric = (props: MetricProps) => {

return (
<Box data-testid={props.testId} className={className}>
<Suspense fallback={<Skeleton key="skeleton" sx={skelStyle}/>}>
<Plot
data={data as Data[]}
layout={baseLayout}
style={style}
/>
</Suspense>
<Tooltip title={hover || ""}>
<Suspense fallback={<Skeleton key="skeleton" sx={skelStyle}/>}>
<Plot
data={data as Data[]}
layout={baseLayout}
style={style}
/>
</Suspense>
</Tooltip>
</Box>
);
}
Expand Down

0 comments on commit 89f60ea

Please sign in to comment.