Skip to content

Commit

Permalink
Merge pull request #2897 from VisActor/2892-bug-gantt-setRecords
Browse files Browse the repository at this point in the history
2892 bug gantt set records
  • Loading branch information
fangsmile authored Nov 26, 2024
2 parents 1a2e2d4 + dbc7c51 commit 1e41abc
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: when not set minDate maxDate call setRecords render error #2892\n\n",
"type": "none",
"packageName": "@visactor/vtable"
}
],
"packageName": "@visactor/vtable",
"email": "[email protected]"
}
58 changes: 33 additions & 25 deletions packages/vtable-gantt/src/Gantt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,31 +547,35 @@ export class Gantt extends EventTarget {
}

_generateTimeLineDateMap() {
const startDate = createDateAtMidnight(this.parsedOptions.minDate);
const endDate = createDateAtMidnight(this.parsedOptions.maxDate);
let colWidthIncludeDays = 1000000;
// Iterate over each scale
for (const scale of this.parsedOptions.reverseSortedTimelineScales) {
// Generate the sub-columns for each step within the scale
const currentDate = createDateAtMidnight(startDate);
// const timelineDates: any[] = [];
scale.timelineDates = generateTimeLineDate(currentDate, endDate, scale);
}
if (this.parsedOptions.minDate && this.parsedOptions.maxDate) {
const startDate = createDateAtMidnight(this.parsedOptions.minDate);
const endDate = createDateAtMidnight(this.parsedOptions.maxDate);
let colWidthIncludeDays = 1000000;
// Iterate over each scale
for (const scale of this.parsedOptions.reverseSortedTimelineScales) {
// Generate the sub-columns for each step within the scale
const currentDate = createDateAtMidnight(startDate);
// const timelineDates: any[] = [];
scale.timelineDates = generateTimeLineDate(currentDate, endDate, scale);
}

const firstScale = this.parsedOptions.reverseSortedTimelineScales[0];
const { unit, step } = firstScale;
if (unit === 'day') {
colWidthIncludeDays = step;
} else if (unit === 'month') {
colWidthIncludeDays = 30;
} else if (unit === 'week') {
colWidthIncludeDays = 7;
} else if (unit === 'quarter') {
colWidthIncludeDays = 90;
} else if (unit === 'year') {
colWidthIncludeDays = 365;
const firstScale = this.parsedOptions.reverseSortedTimelineScales[0];
const { unit, step } = firstScale;
if (unit === 'day') {
colWidthIncludeDays = step;
} else if (unit === 'month') {
colWidthIncludeDays = 30;
} else if (unit === 'week') {
colWidthIncludeDays = 7;
} else if (unit === 'quarter') {
colWidthIncludeDays = 90;
} else if (unit === 'year') {
colWidthIncludeDays = 365;
}
this.parsedOptions.colWidthPerDay = this.parsedOptions.timelineColWidth / colWidthIncludeDays;
} else {
this.parsedOptions.colWidthPerDay = 0;
}
this.parsedOptions.colWidthPerDay = this.parsedOptions.timelineColWidth / colWidthIncludeDays;
}
getAllRowsHeight() {
return this.getAllHeaderRowsHeight() + this.itemCount * this.parsedOptions.rowHeight;
Expand Down Expand Up @@ -758,10 +762,14 @@ export class Gantt extends EventTarget {
}
setRecords(records: any[]) {
this.records = records;
this.data.setRecords(records);
this.taskListTableInstance.setRecords(records);
this._syncPropsFromTable();
this._generateTimeLineDateMap();
this.timeLineHeaderLevel = this.parsedOptions.sortedTimelineScales.length;
this._updateSize();
this.scenegraph.refreshAll();
this.verticalSplitResizeLine.style.height = this.drawHeight + 'px'; //'100%';
this.scenegraph.refreshTaskBarsAndGrid();
const left = this.stateManager.scroll.horizontalBarPos;
const top = this.stateManager.scroll.verticalBarPos;
this.scenegraph.setX(-left);
Expand Down Expand Up @@ -791,7 +799,7 @@ export class Gantt extends EventTarget {
}
/** 滚动到scrollToMarkLineDate所指向的日期 */
_scrollToMarkLine() {
if (this.parsedOptions.scrollToMarkLineDate) {
if (this.parsedOptions.scrollToMarkLineDate && this.parsedOptions.minDate) {
const minDate = this.parsedOptions.minDate;
const targetDayDistance =
((this.parsedOptions.scrollToMarkLineDate.getTime() - minDate.getTime()) / (1000 * 60 * 60 * 24)) *
Expand Down
6 changes: 5 additions & 1 deletion packages/vtable-gantt/src/data/DataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class DataSource {

let minDate = Number.MAX_SAFE_INTEGER;
let maxDate = Number.MIN_SAFE_INTEGER;
if (needMinDate || needMaxDate) {
if ((needMinDate || needMaxDate) && this.records.length) {
for (let i = 0; i < this.records.length; i++) {
const record = this.records[i];
if (needMinDate) {
Expand All @@ -40,4 +40,8 @@ export class DataSource {
this._gantt.parsedOptions._maxDateTime = this._gantt.parsedOptions.maxDate.getTime();
}
}
setRecords(records: any[]) {
this.records = records;
this.processRecords();
}
}
2 changes: 1 addition & 1 deletion packages/vtable-gantt/src/scenegraph/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class Grid {
if (this.gridStyle?.verticalLine.lineWidth & 1) {
x = 0.5;
}
for (let i = 0; i < this.timelineDates.length - 1; i++) {
for (let i = 0; i < this.timelineDates?.length - 1; i++) {
const dateline = this.timelineDates[i];
x = x + Math.floor(this.colWidthPerDay * dateline.days);
const line = createLine({
Expand Down
4 changes: 4 additions & 0 deletions packages/vtable-gantt/src/scenegraph/scenegraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,14 @@ export class Scenegraph {

refreshAll() {
this.tableGroupHeight = Math.min(this._gantt.tableNoFrameHeight, this._gantt.drawHeight);
this.tableGroupWidth = this._gantt.tableNoFrameWidth;
this.tableGroup.setAttribute('height', this.tableGroupHeight);
this.tableGroup.setAttribute('width', this.tableGroupWidth);
this.timelineHeader.refresh();
this.grid.refresh();
this.taskBar.refresh();
this.markLine.refresh();
this.dependencyLink.refresh();
this.frameBorder.resize();
this.scrollbarComponent.updateScrollBar();
this.updateNextFrame();
Expand Down Expand Up @@ -160,6 +163,7 @@ export class Scenegraph {

updateTableSize() {
this.tableGroupHeight = Math.min(this._gantt.tableNoFrameHeight, this._gantt.drawHeight);
this.tableGroupWidth = this._gantt.tableNoFrameWidth;
this.tableGroup.setAttributes({
x: this._gantt.tableX,
y: this._gantt.tableY,
Expand Down
2 changes: 1 addition & 1 deletion packages/vtable-gantt/src/scenegraph/timeline-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class TimelineHeader {

const { unit, timelineDates, customLayout } = scene._gantt.parsedOptions.sortedTimelineScales[i];
let x = 0;
for (let j = 0; j < timelineDates.length; j++) {
for (let j = 0; j < timelineDates?.length; j++) {
const { days, endDate, startDate, title, dateIndex } = timelineDates[j];
const date = new Group({
x,
Expand Down

0 comments on commit 1e41abc

Please sign in to comment.