Skip to content

Commit

Permalink
feat: #129 disables legend strategy by data items for single value,…
Browse files Browse the repository at this point in the history
… pivot table, bar, gauge, and column chart
  • Loading branch information
redet-G committed Nov 19, 2024
1 parent 19dd829 commit b0998f7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
27 changes: 17 additions & 10 deletions src/Components/DashboardItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as React from "react";
import PropTypes from "prop-types";
import Typography from "@mui/material/Typography";

import { axisClasses } from "@mui/x-charts/ChartsAxis";
import {
PieChart,
BarChart,
Expand All @@ -22,7 +21,6 @@ import {
lineElementClasses,
markElementClasses,
} from "@mui/x-charts/LineChart";
import { barElementClasses } from "@mui/x-charts/BarChart";
import ShowChartIcon from "@mui/icons-material/ShowChart";
import FormatListBulletedOutlinedIcon from "@mui/icons-material/FormatListBulletedOutlined";
import SplitscreenIcon from "@mui/icons-material/Splitscreen";
Expand Down Expand Up @@ -522,14 +520,16 @@ function DashboardItem(props) {
}
if (chartType === "text") return <TextChart item={item} />;
if (chartType === "bar") {
console.log("bar label:", chartInfo);
//find the longest text in the series
let longestText = 0;
chartConfig.yAxis.categories.forEach((text) => {
if (text.length > longestText) longestText = text.length;
});

if (chartInfo.legend?.set?.legends.length > 0) {
if (
chartInfo.legend?.set?.legends.length > 0 &&
chartInfo.legend?.strategy != "BY_DATA_ITEM"
) {
let legendValues = chartInfo?.legend?.set?.legends.map(
(leg) => leg.endValue
);
Expand Down Expand Up @@ -639,7 +639,10 @@ function DashboardItem(props) {
},
};

if (chartInfo.legend?.set?.legends.length > 0) {
if (
chartInfo.legend?.set?.legends.length > 0 &&
chartInfo.legend?.strategy != "BY_DATA_ITEM"
) {
let legendValues = chartInfo?.legend?.set?.legends.map(
(leg) => leg.endValue
);
Expand Down Expand Up @@ -828,10 +831,13 @@ function DashboardItem(props) {
<TableCell
sx={{
backgroundColor:
chartInfo?.legend?.set?.legends.find(
(leg) =>
data >= leg.startValue && data < leg.endValue
)?.color ?? "white",
chartInfo?.legend?.strategy != "BY_DATA_ITEM"
? chartInfo?.legend?.set?.legends.find(
(leg) =>
data >= leg.startValue &&
data < leg.endValue
)?.color ?? "lightgray"
: "white",
}}
key={"data" + i}
align="right"
Expand Down Expand Up @@ -868,7 +874,8 @@ function DashboardItem(props) {
let argLength = chartInfo?.legend?.set?.legends.map(
(leg) => (leg.endValue - leg.startValue) / 100
);
let colors = chartInfo?.legend?.set?.legends.map((leg) => leg.color);
let colors =
chartInfo?.legend?.set?.legends.map((leg) => leg.color) ?? [];
let needleColor =
chartInfo?.legend?.set?.legends.find(
(leg) => value >= leg.startValue && value < leg.endValue
Expand Down
22 changes: 13 additions & 9 deletions src/Components/SingleValueChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@ const SingleValueChart = ({ chartData, componentRef, chartInfo }) => {
try {
let value = chartData?.rows[0][1];
let dataElement = chartData?.rows[0][0];
let textColor = "black";
let color = "primary";

let color = chartInfo?.legend?.set?.legends.find(
(leg) => value >= leg.startValue && value < leg.endValue
)?.color;
if (chartInfo.legend?.strategy != "BY_DATA_ITEM") {
color = chartInfo?.legend?.set?.legends.find(
(leg) => value >= leg.startValue && value < leg.endValue
)?.color;

let textColor =
chartInfo?.legend?.style == "FILL" ? "black" : color || "black";
if (chartInfo?.legend?.style == "FILL") {
componentRef.current.style.backgroundColor = color;
componentRef.current.firstChild.firstChild.firstChild.style.color =
"black";
textColor =
chartInfo?.legend?.style == "FILL" ? "black" : color || "black";
if (chartInfo?.legend?.style == "FILL") {
componentRef.current.style.backgroundColor = color;
componentRef.current.firstChild.firstChild.firstChild.style.color =
"black";
}
}

let title =
Expand Down

0 comments on commit b0998f7

Please sign in to comment.