Skip to content

Commit 1ddd139

Browse files
committed
Implemented gradient background color again.
1 parent 006ab19 commit 1ddd139

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

client/packages/lowcoder-comps/src/comps/funnelChartComp/funnelChartUtils.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ export function getEchartsConfig(
134134
chartSize?: ChartSize,
135135
theme?: any,
136136
): EChartsOptionWithMap {
137+
const backgroundColor = props?.chartStyle?.background || theme?.chartStyle?.backgroundColor;
138+
const gradientColor = props?.chartStyle?.gradientBackground || theme?.chartStyle?.gradientColor;
139+
const opacity = props?.chartStyle?.opacity || theme?.chartStyle?.opacity;
140+
const direction = props?.chartStyle?.direction || theme?.chartStyle?.direction;
137141

138142
console.log("props", props);
139143
console.log("theme", theme);
@@ -156,18 +160,18 @@ export function getEchartsConfig(
156160
"textShadowOffsetY": props?.titleStyle?.boxShadow?.split('px')[2] || theme?.titleStyle?.boxShadow.split('px')[2]
157161
}
158162
},
159-
"backgroundColor": props?.chartStyle?.background || theme?.chartStyle?.backgroundColor,
160-
// ? {
161-
// "x": props?.chartStyle?.direction?.split(' ')[0],
162-
// "y": props?.chartStyle?.direction?.split(' ')[1],
163-
// "x2": props?.chartStyle?.direction?.split(' ')[2],
164-
// "y2": props?.chartStyle?.direction?.split(' ')[3],
165-
// "colorStops": [
166-
// { "offset": 0, "color": props?.chartStyle?.opacity ? props?.chartStyle?.background + opacityToHex(props?.chartStyle?.opacity) : props?.chartStyle?.background},
167-
// { "offset": 1, "color": props?.chartStyle?.opacity ? props?.chartStyle?.gradientBackground + opacityToHex(props?.chartStyle?.opacity) : props?.chartStyle?.gradientBackground}
168-
// ]
169-
// }
170-
// : props?.chartStyle?.opacity ? (props?.chartStyle?.background) + opacityToHex(props?.chartStyle?.opacity) : props?.chartStyle?.background,
163+
"backgroundColor": gradientColor && backgroundColor
164+
? {
165+
"x": direction?.split(' ')[0],
166+
"y": direction?.split(' ')[1],
167+
"x2": direction?.split(' ')[2],
168+
"y2": direction?.split(' ')[3],
169+
"colorStops": [
170+
{ "offset": 0, "color": opacity ? backgroundColor + opacityToHex(opacity) : backgroundColor || "#FFFFFF" },
171+
{ "offset": 1, "color": opacity ? gradientColor + opacityToHex(opacity) : gradientColor || "#FFFFFF" }
172+
]
173+
}
174+
: backgroundColor + opacityToHex(opacity),
171175
"color": props.echartsOption.data?.map(data => data.color),
172176
"tooltip": props.tooltip&&{
173177
"trigger": "item",
Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
export default function opacityToHex(opacity) {
2-
opacity = Math.max(0, Math.min(1, opacity));
3-
const decimalValue = Math.round(opacity * 255);
4-
const hexValue = decimalValue.toString(16).toUpperCase();
5-
return hexValue.padStart(2, '0');
6-
}
1+
export default function opacityToHex(opacity: any) {
2+
if (opacity === undefined)
3+
return 'FF'
4+
try {
5+
// Ensure opacity is clamped between 0 and 1
6+
opacity = Math.max(0, Math.min(1, opacity));
7+
const decimalValue = Math.round(opacity * 255);
8+
const hexValue = decimalValue.toString(16).toUpperCase();
9+
return hexValue.padStart(2, '0');
10+
} catch (error) {
11+
// Return 'FF' if an exception occurs
12+
return 'FF';
13+
}
14+
}

0 commit comments

Comments
 (0)