Skip to content

Commit

Permalink
Merge pull request #2022 from VisActor/fix/shrink-sparkline
Browse files Browse the repository at this point in the history
fix: fix width computation in shrinkSparklineFirst mode
  • Loading branch information
Rui-Sun committed Jul 2, 2024
2 parents 1836897 + 2dd940c commit af6a74d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vtable",
"comment": "fix: fix width computation in shrinkSparklineFirst mode",
"type": "none"
}
],
"packageName": "@visactor/vtable"
}
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ export function renderStroke(
// if (isHighlight) {
// context.setLineDash(highlightDash);
// }
const oldLineCap = context.lineCap;
context.lineCap = 'square';
// const oldLineCap = context.lineCap;
// context.lineCap = 'square';

const { lineDash = groupAttribute.lineDash } = group.attribute as any;
// const lineDash = context.getLineDash();
Expand All @@ -290,8 +290,8 @@ export function renderStroke(
// top
if (strokeTop) {
// context.lineTo(x + width, y);
const deltaLeft = strokeLeft ? 0 : (isWidthNumber ? widthInfo.width : strokeArrayWidth[3]) / 2;
const deltaRight = strokeRight ? 0 : (isWidthNumber ? widthInfo.width : strokeArrayWidth[1]) / 2;
const deltaLeft = (isWidthNumber ? widthInfo.width : strokeArrayWidth[0]) / 2;
const deltaRight = (isWidthNumber ? widthInfo.width : strokeArrayWidth[0]) / 2;
if (isPart && Array.isArray(part[0])) {
context.moveTo(x - deltaLeft + (width + deltaLeft + deltaRight) * part[0][0], y);
context.lineTo(x - deltaLeft + (width + deltaLeft + deltaRight) * (part[0][1] - part[0][0]), y);
Expand Down Expand Up @@ -323,8 +323,8 @@ export function renderStroke(
// right
if (strokeRight) {
// context.lineTo(x + width, y + height);
const deltaTop = strokeTop ? 0 : (isWidthNumber ? widthInfo.width : strokeArrayWidth[0]) / 2;
const deltaBottom = strokeBottom ? 0 : (isWidthNumber ? widthInfo.width : strokeArrayWidth[2]) / 2;
const deltaTop = (isWidthNumber ? widthInfo.width : strokeArrayWidth[1]) / 2;
const deltaBottom = (isWidthNumber ? widthInfo.width : strokeArrayWidth[1]) / 2;
if (isPart && Array.isArray(part[1])) {
context.moveTo(x + width, y - deltaTop + height * part[1][0]);
context.lineTo(x + width, y - deltaTop + (height + deltaTop + deltaBottom) * (part[1][1] - part[1][0]));
Expand Down Expand Up @@ -356,8 +356,8 @@ export function renderStroke(
// bottom
if (strokeBottom) {
// context.lineTo(x, y + height);
const deltaLeft = strokeLeft ? 0 : (isWidthNumber ? widthInfo.width : strokeArrayWidth[3]) / 2;
const deltaRight = strokeRight ? 0 : (isWidthNumber ? widthInfo.width : strokeArrayWidth[1]) / 2;
const deltaLeft = (isWidthNumber ? widthInfo.width : strokeArrayWidth[2]) / 2;
const deltaRight = (isWidthNumber ? widthInfo.width : strokeArrayWidth[2]) / 2;
if (isPart && Array.isArray(part[2])) {
context.moveTo(x - deltaLeft + (width + deltaLeft + deltaRight) * part[2][0], y + height);
context.lineTo(x - deltaLeft + (width + deltaLeft + deltaRight) * (part[2][1] - part[2][0]), y + height);
Expand Down Expand Up @@ -389,8 +389,8 @@ export function renderStroke(
// left
if (strokeLeft) {
// context.lineTo(x, y);
const deltaTop = strokeTop ? 0 : (isWidthNumber ? widthInfo.width : strokeArrayWidth[0]) / 2;
const deltaBottom = strokeBottom ? 0 : (isWidthNumber ? widthInfo.width : strokeArrayWidth[2]) / 2;
const deltaTop = (isWidthNumber ? widthInfo.width : strokeArrayWidth[3]) / 2;
const deltaBottom = (isWidthNumber ? widthInfo.width : strokeArrayWidth[3]) / 2;
if (isPart && Array.isArray(part[3])) {
context.moveTo(x, y - deltaTop + (height + deltaTop + deltaBottom) * part[3][0]);
context.lineTo(x, y - deltaTop + (height + deltaTop + deltaBottom) * (part[3][1] - part[3][0]));
Expand Down Expand Up @@ -428,7 +428,7 @@ export function renderStroke(
context.stroke();
}
context.lineDashOffset = 0;
context.lineCap = oldLineCap;
// context.lineCap = oldLineCap;
context.setLineDash([]);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/vtable/src/scenegraph/layout/compute-col-width.ts
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ export function getAdaptiveWidth(
if (
table.options.customConfig?.shrinkSparklineFirst &&
factor < 1 &&
totalDrawWidth - actualWidth < totalSparklineAbleWidth
actualWidth - totalDrawWidth < totalSparklineAbleWidth
) {
// only shrink sparkline column
for (let i = 0; i < sparklineColumns.length; i++) {
Expand Down

0 comments on commit af6a74d

Please sign in to comment.