Pārlūkot izejas kodu

Merge pull request #1349 from Avaiga/1347-updating-stylekitcss-and-hover_text-for-metric-component

Updating stylekit & hover_text
Nam Nguyen 11 mēneši atpakaļ
vecāks
revīzija
89f60eaa70

+ 26 - 0
frontend/taipy-gui/public/stylekit/controls/metric.css

@@ -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 - 0
frontend/taipy-gui/public/stylekit/stylekit.css

@@ -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';

+ 12 - 8
frontend/taipy-gui/src/components/Taipy/Metric.tsx

@@ -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"));
 
@@ -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,
             },
@@ -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>
     );
 }