Skip to content

Commit

Permalink
fix: fix split lineDash config
Browse files Browse the repository at this point in the history
  • Loading branch information
Rui-Sun committed May 7, 2024
1 parent 46c7907 commit ca18e24
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type { BaseTableAPI } from '../../../ts-types/base-table';
import { getQuadProps } from '../../utils/padding';
import { getCellMergeInfo } from '../../utils/get-cell-merge';
import { InteractionState } from '../../../ts-types';
import { isArray } from '@visactor/vutils';

// const highlightDash: number[] = [];

Expand Down Expand Up @@ -502,6 +503,9 @@ export class DashGroupAfterRenderContribution implements IGroupRenderContributio
return;
}

// convert lineDash to number[][]
const splitLineDash = isArray(lineDash[0]) ? getQuadLineDash(lineDash) : [lineDash, lineDash, lineDash, lineDash];

// const { width = groupAttribute.width, height = groupAttribute.height } = group.attribute;
let { width = groupAttribute.width, height = groupAttribute.height } = group.attribute;
width = Math.ceil(width);
Expand Down Expand Up @@ -553,31 +557,31 @@ export class DashGroupAfterRenderContribution implements IGroupRenderContributio
context.moveTo(x, y);
context.lineTo(x + widthForStroke, y);
context.lineDashOffset = context.currentMatrix.e / context.currentMatrix.a;
context.setLineDash(lineDash[0] ?? []);
context.setLineDash(splitLineDash[0] ?? []);
context.stroke();

// right
context.beginPath();
context.moveTo(x + widthForStroke, y);
context.lineTo(x + widthForStroke, y + heightForStroke);
context.lineDashOffset = context.currentMatrix.f / context.currentMatrix.d;
context.setLineDash(lineDash[1] ?? []);
context.setLineDash(splitLineDash[1] ?? []);
context.stroke();

// bottom
context.beginPath();
context.moveTo(x, y + heightForStroke);
context.lineTo(x + widthForStroke, y + heightForStroke);
context.lineDashOffset = context.currentMatrix.e / context.currentMatrix.a;
context.setLineDash(lineDash[2] ?? []);
context.setLineDash(splitLineDash[2] ?? []);
context.stroke();

// left
context.beginPath();
context.moveTo(x, y);
context.lineTo(x, y + heightForStroke);
context.lineDashOffset = context.currentMatrix.f / context.currentMatrix.d;
context.setLineDash(lineDash[3] ?? []);
context.setLineDash(splitLineDash[3] ?? []);
context.stroke();

context.lineDashOffset = 0;
Expand Down Expand Up @@ -1002,3 +1006,13 @@ function getCellSizeForDraw(group: any, width: number, height: number) {
}
return { width, height };
}

function getQuadLineDash(lineDash: number[][]) {
if (lineDash.length === 1) {
return [lineDash[0], lineDash[0], lineDash[0], lineDash[0]];
} else if (lineDash.length === 2) {
return [lineDash[0], lineDash[1], lineDash[0], lineDash[1]];
}
// 不考虑三个数的情况,三个数是用户传错了
return lineDash;
}

0 comments on commit ca18e24

Please sign in to comment.