Skip to content

Commit

Permalink
fix: lineDash支持多位数组 (#1867)
Browse files Browse the repository at this point in the history
  • Loading branch information
HuangLiangchen authored Dec 12, 2024
1 parent db6f50b commit e80c0fe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
3 changes: 2 additions & 1 deletion packages/g-lite/src/css/StyleValueRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -698,9 +698,10 @@ export class DefaultStyleValueRegistry implements StyleValueRegistry {
}
// Polyline
if (list.has('lineDash') && !isNil(attributes.lineDash)) {
// dom标准自动转化奇数长度数组,webgl需要手动处理
object.parsedStyle.lineDash = parseDimensionArrayFormat(
attributes.lineDash,
2,
'even',
);
}
// @ts-ignore
Expand Down
24 changes: 15 additions & 9 deletions packages/g-lite/src/css/parser/dimension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export function convertAngleUnit(value: CSSUnitValue) {

export function parseDimensionArrayFormat(
string: string | number | (string | number)[],
size: number,
size?: 2 | 4 | 'even',
): number[] {
let parsed: number[];

Expand All @@ -185,16 +185,22 @@ export function parseDimensionArrayFormat(
}
return [parsed[0], parsed[1]];
}
if (parsed.length === 1) {
return [parsed[0], parsed[0], parsed[0], parsed[0]];
}
if (parsed.length === 2) {
return [parsed[0], parsed[1], parsed[0], parsed[1]];
if (size === 4) {
if (parsed.length === 1) {
return [parsed[0], parsed[0], parsed[0], parsed[0]];
}
if (parsed.length === 2) {
return [parsed[0], parsed[1], parsed[0], parsed[1]];
}
if (parsed.length === 3) {
return [parsed[0], parsed[1], parsed[2], parsed[1]];
}
return [parsed[0], parsed[1], parsed[2], parsed[3]];
}
if (parsed.length === 3) {
return [parsed[0], parsed[1], parsed[2], parsed[1]];
if (size === 'even' && parsed.length % 2 === 1) {
return [...parsed, ...parsed];
}
return [parsed[0], parsed[1], parsed[2], parsed[3]];
return parsed;
}

export function parseDimensionArray(
Expand Down

0 comments on commit e80c0fe

Please sign in to comment.