Skip to content

Commit

Permalink
fix: responsive overview
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiashader committed Oct 2, 2024
1 parent 9d0f5e0 commit d0539d3
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import { IxCard, IxCardContent, IxTypography } from "@siemens/ix-react";
import { getComputedCSSProperty } from "@siemens/ix-echarts";
import ReactEcharts from "echarts-for-react";
import { useTranslation } from "react-i18next";
import {useRef} from "react";
import {useResizeHandler} from "../../../../util/util.ts";
import EChartsReact from "echarts-for-react";

const data = [
{ value: 72.17, name: "Online" },
Expand All @@ -27,10 +30,9 @@ function getOption() {
trigger: "item",
},
legend: {
orient: "vertical",
orient: "horizontal",
icon: "rect",
right: "16",
top: "center",
bottom: "0",
textStyle: {
color: getComputedCSSProperty("color-std-text"),
},
Expand All @@ -45,7 +47,7 @@ function getOption() {
getComputedCSSProperty("color-neutral"),
getComputedCSSProperty("color-critical"),
],
radius: ["60%", "90%"],
radius: ["50%", "70%"],
label: {
show: false,
color: getComputedCSSProperty("color-neutral"),
Expand All @@ -68,12 +70,16 @@ function getOption() {

function DeviceStatus() {
const { t } = useTranslation();
const chartRef = useRef<EChartsReact>(null);

useResizeHandler(chartRef);

return (
<IxCard>
<IxCard className="w-100">
<IxCardContent>
<IxTypography format="h3">{t("device-status.title")}</IxTypography>
<ReactEcharts
ref={chartRef}
onChartReady={(echarts) => setTimeout(echarts.resize)}
className={styles.echarts}
option={getOption()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
.echarts {
position: relative;
width: 100%;
min-width: 24.75rem;
height: 100%;
padding-top: 1rem;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ device-status {
}
}

ix-card + ix-card {
margin-inline-start: 1rem;
}

ix-blind + ix-blind {
margin-block-start: 1rem;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ device-status {

.CardContainer {
display: flex;
gap: 1rem;

@media (max-width: 768px) {
flex-direction: column;
}
}

ix-card {
Expand All @@ -21,5 +26,4 @@ ix-card {

ix-card + ix-card {
flex-grow: 2;
margin-inline-start: 1rem;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import { IxCard, IxCardContent, IxTypography } from "@siemens/ix-react";
import { getComputedCSSProperty } from "@siemens/ix-echarts";
import ReactEcharts from "echarts-for-react";
import { useTranslation } from "react-i18next";
import { useRef } from "react";
import { useResizeHandler } from "../../../../util/util.ts";
import EChartsReact from "echarts-for-react";

const seriesOnline = {
name: "Online",
color: [getComputedCSSProperty("color-success")],
Expand Down Expand Up @@ -103,12 +107,16 @@ function getOption() {

function StatusHistory() {
const { t } = useTranslation();
const chartRef = useRef<EChartsReact>(null);

useResizeHandler(chartRef);

return (
<IxCard>
<IxCard className="w-100">
<IxCardContent>
<IxTypography format="h3">{t("status-history.title")}</IxTypography>
<ReactEcharts
ref={chartRef}
onChartReady={(echarts) => setTimeout(echarts.resize)}
className={styles.echarts}
option={getOption()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
.echarts {
position: relative;
width: 100%;
min-width: 24.75rem;
height: 100%;
padding-top: 1rem;
}
18 changes: 18 additions & 0 deletions apps/react-starter/src/util/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {showToast} from "@siemens/ix-react";
import {iconSingleCheck} from "@siemens/ix-icons/icons";
import {MutableRefObject, useEffect} from "react";
import EChartsReact from "echarts-for-react";

export function toKebabCase(normalString: string): string {
return normalString
Expand All @@ -16,4 +18,20 @@ export function showSuccessToast(message: string) {
icon: iconSingleCheck,
iconColor: "color-success",
});
}

export function useResizeHandler(chartRef: MutableRefObject<EChartsReact | null>) {
useEffect(() => {
const handleResize = () => {
if (chartRef.current) {
chartRef.current.getEchartsInstance().resize();
}
};

window.addEventListener("resize", handleResize);

return () => {
window.removeEventListener("resize", handleResize);
};
}, [chartRef]);
}

0 comments on commit d0539d3

Please sign in to comment.