Changed chart's color by theme
This commit is contained in:
@@ -9,11 +9,13 @@ const Chart = dynamic(() => import("react-apexcharts"), { ssr: false });
|
|||||||
type Props = {
|
type Props = {
|
||||||
priorityCounts: CasePriorityCountType[];
|
priorityCounts: CasePriorityCountType[];
|
||||||
messages: HomeMessages;
|
messages: HomeMessages;
|
||||||
|
theme: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function TestPriorityDonutChart({
|
export default function TestPriorityDonutChart({
|
||||||
priorityCounts,
|
priorityCounts,
|
||||||
messages,
|
messages,
|
||||||
|
theme,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const [chartData, setChartData] = useState({
|
const [chartData, setChartData] = useState({
|
||||||
series: [],
|
series: [],
|
||||||
@@ -33,16 +35,27 @@ export default function TestPriorityDonutChart({
|
|||||||
|
|
||||||
const labels = priorities.map((entry) => messages[entry.uid]);
|
const labels = priorities.map((entry) => messages[entry.uid]);
|
||||||
const colors = priorities.map((entry) => entry.chartColor);
|
const colors = priorities.map((entry) => entry.chartColor);
|
||||||
|
const legend = {
|
||||||
|
labels: {
|
||||||
|
colors: priorities.map((entry) => {
|
||||||
|
if (theme === "light") {
|
||||||
|
return "black";
|
||||||
|
} else {
|
||||||
|
return "white";
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
setChartData({
|
setChartData({
|
||||||
series,
|
series,
|
||||||
options: { labels, colors },
|
options: { labels, colors, legend },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
updateChartDate();
|
updateChartDate();
|
||||||
}, [priorityCounts]);
|
}, [priorityCounts, theme]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Chart
|
<Chart
|
||||||
|
|||||||
@@ -8,11 +8,13 @@ const Chart = dynamic(() => import("react-apexcharts"), { ssr: false });
|
|||||||
type Props = {
|
type Props = {
|
||||||
progressSeries: ProgressSeriesType[];
|
progressSeries: ProgressSeriesType[];
|
||||||
progressCategories: string[];
|
progressCategories: string[];
|
||||||
|
theme: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function TestProgressBarChart({
|
export default function TestProgressBarChart({
|
||||||
progressSeries,
|
progressSeries,
|
||||||
progressCategories,
|
progressCategories,
|
||||||
|
theme,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const [chartData, setChartData] = useState({
|
const [chartData, setChartData] = useState({
|
||||||
series: [],
|
series: [],
|
||||||
@@ -25,6 +27,16 @@ export default function TestProgressBarChart({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const updateChartDate = () => {
|
const updateChartDate = () => {
|
||||||
if (progressSeries) {
|
if (progressSeries) {
|
||||||
|
const legendsLabelColors = testRunCaseStatus.map((itr) => {
|
||||||
|
if (theme === "light") {
|
||||||
|
return "black";
|
||||||
|
} else {
|
||||||
|
return "white";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const xaxisLabelColor = theme === "light" ? "black" : "white";
|
||||||
|
|
||||||
setChartData({
|
setChartData({
|
||||||
series: progressSeries,
|
series: progressSeries,
|
||||||
options: {
|
options: {
|
||||||
@@ -36,6 +48,9 @@ export default function TestProgressBarChart({
|
|||||||
},
|
},
|
||||||
legend: {
|
legend: {
|
||||||
position: "right",
|
position: "right",
|
||||||
|
labels: {
|
||||||
|
colors: legendsLabelColors,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
colors: testRunCaseStatus.map((itr) => {
|
colors: testRunCaseStatus.map((itr) => {
|
||||||
return itr.chartColor;
|
return itr.chartColor;
|
||||||
@@ -43,6 +58,14 @@ export default function TestProgressBarChart({
|
|||||||
xaxis: {
|
xaxis: {
|
||||||
type: "datetime",
|
type: "datetime",
|
||||||
categories: progressCategories,
|
categories: progressCategories,
|
||||||
|
labels: {
|
||||||
|
style: {
|
||||||
|
colors: xaxisLabelColor,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
|
theme: theme,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -50,7 +73,7 @@ export default function TestProgressBarChart({
|
|||||||
};
|
};
|
||||||
|
|
||||||
updateChartDate();
|
updateChartDate();
|
||||||
}, [progressSeries, progressCategories]);
|
}, [progressSeries, progressCategories, theme]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Chart
|
<Chart
|
||||||
|
|||||||
@@ -9,9 +9,14 @@ const Chart = dynamic(() => import("react-apexcharts"), { ssr: false });
|
|||||||
type Props = {
|
type Props = {
|
||||||
typesCounts: CaseTypeCountType[];
|
typesCounts: CaseTypeCountType[];
|
||||||
messages: HomeMessages;
|
messages: HomeMessages;
|
||||||
|
theme: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function TestTypesDonutChart({ typesCounts, messages }: Props) {
|
export default function TestTypesDonutChart({
|
||||||
|
typesCounts,
|
||||||
|
messages,
|
||||||
|
theme,
|
||||||
|
}: Props) {
|
||||||
const [chartData, setChartData] = useState({
|
const [chartData, setChartData] = useState({
|
||||||
series: [],
|
series: [],
|
||||||
options: {
|
options: {
|
||||||
@@ -30,16 +35,27 @@ export default function TestTypesDonutChart({ typesCounts, messages }: Props) {
|
|||||||
|
|
||||||
const labels = testTypes.map((entry) => messages[entry.uid]);
|
const labels = testTypes.map((entry) => messages[entry.uid]);
|
||||||
const colors = testTypes.map((entry) => entry.chartColor);
|
const colors = testTypes.map((entry) => entry.chartColor);
|
||||||
|
const legend = {
|
||||||
|
labels: {
|
||||||
|
colors: testTypes.map((entry) => {
|
||||||
|
if (theme === "light") {
|
||||||
|
return "black";
|
||||||
|
} else {
|
||||||
|
return "white";
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
setChartData({
|
setChartData({
|
||||||
series,
|
series,
|
||||||
options: { labels, colors },
|
options: { labels, colors, legend },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
updateChartDate();
|
updateChartDate();
|
||||||
}, [typesCounts]);
|
}, [typesCounts, theme]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Chart
|
<Chart
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import TestTypesChart from "./TestTypesDonutChart";
|
|||||||
import TestPriorityChart from "./TestPriorityDonutChart";
|
import TestPriorityChart from "./TestPriorityDonutChart";
|
||||||
import TestProgressBarChart from "./TestProgressColumnChart";
|
import TestProgressBarChart from "./TestProgressColumnChart";
|
||||||
import Config from "@/config/config";
|
import Config from "@/config/config";
|
||||||
|
import { useTheme } from "next-themes";
|
||||||
const apiServer = Config.apiServer;
|
const apiServer = Config.apiServer;
|
||||||
|
|
||||||
async function fetchProject(url) {
|
async function fetchProject(url) {
|
||||||
@@ -45,6 +46,7 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function Home({ projectId, messages }: Props) {
|
export function Home({ projectId, messages }: Props) {
|
||||||
|
const { theme, setTheme } = useTheme();
|
||||||
const [project, setProject] = useState({
|
const [project, setProject] = useState({
|
||||||
name: "",
|
name: "",
|
||||||
detail: "",
|
detail: "",
|
||||||
@@ -123,7 +125,10 @@ export function Home({ projectId, messages }: Props) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{project.detail && (
|
{project.detail && (
|
||||||
<Card className="mt-3 bg-neutral-100" shadow="none">
|
<Card
|
||||||
|
className="mt-3 bg-neutral-100 dark:bg-neutral-700 dark:text-white"
|
||||||
|
shadow="none"
|
||||||
|
>
|
||||||
<CardBody>{project.detail}</CardBody>
|
<CardBody>{project.detail}</CardBody>
|
||||||
</Card>
|
</Card>
|
||||||
)}
|
)}
|
||||||
@@ -134,6 +139,7 @@ export function Home({ projectId, messages }: Props) {
|
|||||||
<TestProgressBarChart
|
<TestProgressBarChart
|
||||||
progressSeries={progressSeries}
|
progressSeries={progressSeries}
|
||||||
progressCategories={progressCategories}
|
progressCategories={progressCategories}
|
||||||
|
theme={theme}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -142,13 +148,18 @@ export function Home({ projectId, messages }: Props) {
|
|||||||
<div className="flex pb-20">
|
<div className="flex pb-20">
|
||||||
<div style={{ width: "32rem", height: "18rem" }}>
|
<div style={{ width: "32rem", height: "18rem" }}>
|
||||||
<h3>{messages.byType}</h3>
|
<h3>{messages.byType}</h3>
|
||||||
<TestTypesChart typesCounts={typesCounts} messages={messages} />
|
<TestTypesChart
|
||||||
|
typesCounts={typesCounts}
|
||||||
|
messages={messages}
|
||||||
|
theme={theme}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div style={{ width: "30rem", height: "18rem" }}>
|
<div style={{ width: "30rem", height: "18rem" }}>
|
||||||
<h3>{messages.byPriority}</h3>
|
<h3>{messages.byPriority}</h3>
|
||||||
<TestPriorityChart
|
<TestPriorityChart
|
||||||
priorityCounts={priorityCounts}
|
priorityCounts={priorityCounts}
|
||||||
messages={messages}
|
messages={messages}
|
||||||
|
theme={theme}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ import {
|
|||||||
} from "../runsControl";
|
} from "../runsControl";
|
||||||
import { fetchFolders } from "../../folders/foldersControl";
|
import { fetchFolders } from "../../folders/foldersControl";
|
||||||
import { fetchCases } from "../../folders/[folderId]/cases/caseControl";
|
import { fetchCases } from "../../folders/[folderId]/cases/caseControl";
|
||||||
|
import { useTheme } from "next-themes";
|
||||||
|
|
||||||
const defaultTestRun = {
|
const defaultTestRun = {
|
||||||
id: 0,
|
id: 0,
|
||||||
@@ -74,6 +75,7 @@ export default function RunEditor({
|
|||||||
messages,
|
messages,
|
||||||
locale,
|
locale,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
|
const { theme, setTheme } = useTheme();
|
||||||
const [testRun, setTestRun] = useState<RunType>(defaultTestRun);
|
const [testRun, setTestRun] = useState<RunType>(defaultTestRun);
|
||||||
const [folders, setFolders] = useState([]);
|
const [folders, setFolders] = useState([]);
|
||||||
const [runCases, setRunCases] = useState<RunCaseType[]>([]);
|
const [runCases, setRunCases] = useState<RunCaseType[]>([]);
|
||||||
@@ -273,6 +275,7 @@ export default function RunEditor({
|
|||||||
<RunProgressChart
|
<RunProgressChart
|
||||||
statusCounts={runStatusCounts}
|
statusCounts={runStatusCounts}
|
||||||
messages={messages}
|
messages={messages}
|
||||||
|
theme={theme}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -8,9 +8,14 @@ const Chart = dynamic(() => import("react-apexcharts"), { ssr: false });
|
|||||||
type Props = {
|
type Props = {
|
||||||
statusCounts: RunStatusCountType[];
|
statusCounts: RunStatusCountType[];
|
||||||
messages: RunMessages;
|
messages: RunMessages;
|
||||||
|
theme: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function RunProgressDounut({ statusCounts, messages }: Props) {
|
export default function RunProgressDounut({
|
||||||
|
statusCounts,
|
||||||
|
messages,
|
||||||
|
theme,
|
||||||
|
}: Props) {
|
||||||
const [chartData, setChartData] = useState({
|
const [chartData, setChartData] = useState({
|
||||||
series: [],
|
series: [],
|
||||||
options: {
|
options: {
|
||||||
@@ -29,16 +34,27 @@ export default function RunProgressDounut({ statusCounts, messages }: Props) {
|
|||||||
|
|
||||||
const labels = testRunCaseStatus.map((entry) => messages[entry.uid]);
|
const labels = testRunCaseStatus.map((entry) => messages[entry.uid]);
|
||||||
const colors = testRunCaseStatus.map((entry) => entry.chartColor);
|
const colors = testRunCaseStatus.map((entry) => entry.chartColor);
|
||||||
|
const legend = {
|
||||||
|
labels: {
|
||||||
|
colors: testRunCaseStatus.map((entry) => {
|
||||||
|
if (theme === "light") {
|
||||||
|
return "black";
|
||||||
|
} else {
|
||||||
|
return "white";
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
setChartData({
|
setChartData({
|
||||||
series,
|
series,
|
||||||
options: { labels, colors },
|
options: { labels, colors, legend },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
updateChartDate();
|
updateChartDate();
|
||||||
}, [statusCounts]);
|
}, [statusCounts, theme]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Chart
|
<Chart
|
||||||
|
|||||||
Reference in New Issue
Block a user