|
@@ -45,8 +45,6 @@ interface MetricProps extends TaipyBaseProps, TaipyHoverProps {
|
|
testId?: string;
|
|
testId?: string;
|
|
layout?: string;
|
|
layout?: string;
|
|
defaultLayout?: string;
|
|
defaultLayout?: string;
|
|
- style?: string;
|
|
|
|
- defaultStyle?: string;
|
|
|
|
width?: string | number;
|
|
width?: string | number;
|
|
height?: string | number;
|
|
height?: string | number;
|
|
template?: string;
|
|
template?: string;
|
|
@@ -55,10 +53,12 @@ interface MetricProps extends TaipyBaseProps, TaipyHoverProps {
|
|
}
|
|
}
|
|
|
|
|
|
const emptyLayout = {} as Partial<Layout>;
|
|
const emptyLayout = {} as Partial<Layout>;
|
|
-const defaultStyle = { position: "relative", display: "inline-block" };
|
|
|
|
|
|
+const defaultStyle = { position: "relative", display: "inline-block", width: "100%" } as CSSProperties;
|
|
|
|
+const skeletonStyle = { ...defaultStyle, minHeight: "7em" };
|
|
|
|
+const plotConfig = { displaylogo: false };
|
|
|
|
|
|
const Metric = (props: MetricProps) => {
|
|
const Metric = (props: MetricProps) => {
|
|
- const { width = "100%", height, showValue = true, deltaColor, negativeDeltaColor } = props;
|
|
|
|
|
|
+ const { showValue = true } = props;
|
|
const value = useDynamicProperty(props.value, props.defaultValue, 0);
|
|
const value = useDynamicProperty(props.value, props.defaultValue, 0);
|
|
const threshold = useDynamicProperty(props.threshold, props.defaultThreshold, undefined);
|
|
const threshold = useDynamicProperty(props.threshold, props.defaultThreshold, undefined);
|
|
const delta = useDynamicProperty(props.delta, props.defaultDelta, undefined);
|
|
const delta = useDynamicProperty(props.delta, props.defaultDelta, undefined);
|
|
@@ -90,18 +90,18 @@ const Metric = (props: MetricProps) => {
|
|
const mode = props.type === "none" ? [] : ["gauge"];
|
|
const mode = props.type === "none" ? [] : ["gauge"];
|
|
showValue && mode.push("number");
|
|
showValue && mode.push("number");
|
|
delta !== undefined && mode.push("delta");
|
|
delta !== undefined && mode.push("delta");
|
|
- const deltaIncreasing = deltaColor
|
|
|
|
|
|
+ const deltaIncreasing = props.deltaColor
|
|
? {
|
|
? {
|
|
- color: deltaColor == "invert" ? "#FF4136" : deltaColor,
|
|
|
|
|
|
+ color: props.deltaColor == "invert" ? "#FF4136" : props.deltaColor,
|
|
}
|
|
}
|
|
: undefined;
|
|
: undefined;
|
|
const deltaDecreasing =
|
|
const deltaDecreasing =
|
|
- deltaColor == "invert"
|
|
|
|
|
|
+ props.deltaColor == "invert"
|
|
? {
|
|
? {
|
|
color: "#3D9970",
|
|
color: "#3D9970",
|
|
}
|
|
}
|
|
- : negativeDeltaColor
|
|
|
|
- ? { color: negativeDeltaColor }
|
|
|
|
|
|
+ : props.negativeDeltaColor
|
|
|
|
+ ? { color: props.negativeDeltaColor }
|
|
: undefined;
|
|
: undefined;
|
|
return [
|
|
return [
|
|
{
|
|
{
|
|
@@ -145,8 +145,8 @@ const Metric = (props: MetricProps) => {
|
|
props.type,
|
|
props.type,
|
|
props.min,
|
|
props.min,
|
|
props.max,
|
|
props.max,
|
|
- deltaColor,
|
|
|
|
- negativeDeltaColor,
|
|
|
|
|
|
+ props.deltaColor,
|
|
|
|
+ props.negativeDeltaColor,
|
|
threshold,
|
|
threshold,
|
|
props.format,
|
|
props.format,
|
|
props.deltaFormat,
|
|
props.deltaFormat,
|
|
@@ -155,18 +155,12 @@ const Metric = (props: MetricProps) => {
|
|
colorMap,
|
|
colorMap,
|
|
]);
|
|
]);
|
|
|
|
|
|
- const style = useMemo(
|
|
|
|
- () =>
|
|
|
|
- height === undefined
|
|
|
|
- ? ({ ...defaultStyle, width: width } as CSSProperties)
|
|
|
|
- : ({ ...defaultStyle, width: width, height: height } as CSSProperties),
|
|
|
|
- [height, width]
|
|
|
|
- );
|
|
|
|
-
|
|
|
|
- const skelStyle = useMemo(() => ({ ...style, minHeight: "7em" }), [style]);
|
|
|
|
-
|
|
|
|
const layout = useMemo(() => {
|
|
const layout = useMemo(() => {
|
|
- const layout = { ...baseLayout };
|
|
|
|
|
|
+ const layout = {
|
|
|
|
+ ...baseLayout,
|
|
|
|
+ height: baseLayout.height !== undefined ? baseLayout.height : props.height,
|
|
|
|
+ width: baseLayout.width !== undefined ? baseLayout.width : props.width,
|
|
|
|
+ };
|
|
let template = undefined;
|
|
let template = undefined;
|
|
try {
|
|
try {
|
|
const tpl = props.template && JSON.parse(props.template);
|
|
const tpl = props.template && JSON.parse(props.template);
|
|
@@ -189,14 +183,22 @@ const Metric = (props: MetricProps) => {
|
|
}
|
|
}
|
|
|
|
|
|
return layout as Partial<Layout>;
|
|
return layout as Partial<Layout>;
|
|
- }, [props.title, props.template, props.template_Dark_, props.template_Light_, theme.palette.mode, baseLayout]);
|
|
|
|
|
|
+ }, [
|
|
|
|
+ props.title,
|
|
|
|
+ props.height,
|
|
|
|
+ props.width,
|
|
|
|
+ props.template,
|
|
|
|
+ props.template_Dark_,
|
|
|
|
+ props.template_Light_,
|
|
|
|
+ theme.palette.mode,
|
|
|
|
+ baseLayout,
|
|
|
|
+ ]);
|
|
|
|
|
|
- const plotConfig = {displaylogo: false}
|
|
|
|
return (
|
|
return (
|
|
<Tooltip title={hover || ""}>
|
|
<Tooltip title={hover || ""}>
|
|
<Box data-testid={props.testId} className={className}>
|
|
<Box data-testid={props.testId} className={className}>
|
|
- <Suspense fallback={<Skeleton key="skeleton" sx={skelStyle} />}>
|
|
|
|
- <Plot data={data} layout={layout} style={style} config={plotConfig} useResizeHandler />
|
|
|
|
|
|
+ <Suspense fallback={<Skeleton key="skeleton" sx={skeletonStyle} />}>
|
|
|
|
+ <Plot data={data} layout={layout} style={defaultStyle} config={plotConfig} useResizeHandler />
|
|
</Suspense>
|
|
</Suspense>
|
|
</Box>
|
|
</Box>
|
|
</Tooltip>
|
|
</Tooltip>
|