Skip to content

Commit

Permalink
feat(gantt-table): add width in gantt column
Browse files Browse the repository at this point in the history
  • Loading branch information
HandsomeButterball authored and walkerkay committed May 29, 2020
1 parent 7c0ee57 commit bdcaa88
Show file tree
Hide file tree
Showing 14 changed files with 254 additions and 120 deletions.
4 changes: 2 additions & 2 deletions example/src/app/examples/examples.component.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<ngx-gantt start="1514736000" end="1609430400" [items]="items" [groups]="groups" [draggable]="true">
<ngx-gantt-column name="标题">
<ngx-gantt-column width="100px" name="标题">
<ng-template #cell let-row>
{{ row.title }}
</ng-template>
</ngx-gantt-column>
<ngx-gantt-column name="开始时间">
<ngx-gantt-column width="400px" name="开始时间">
<ng-template #cell let-row>
{{ row.start * 1000 | date }}
</ng-template>
Expand Down
1 change: 0 additions & 1 deletion example/src/app/examples/examples.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
height: 100%;
margin: 20px;
display: block;
border: 1px solid #ddd;
}
23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"date-fns": "^2.14.0",
"rxjs": "~6.4.0",
"tslib": "^1.10.0",
"zone.js": "~0.9.1"
"zone.js": "~0.9.1",
"html2canvas": "^1.0.0-rc.5"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.803.25",
Expand Down
80 changes: 80 additions & 0 deletions packages/gantt/src/gantt-print.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { Injectable } from '@angular/core';
import { GanttDomService } from './gantt-dom.service';
import html2canvas from 'html2canvas';

@Injectable()
export class GanttPrintService {
constructor(private ganttDomService: GanttDomService) {}

private root = this.ganttDomService.root as HTMLElement;

private viewer = this.ganttDomService.viewer as HTMLElement;

private calendarOverlay = this.ganttDomService.calendarOverlay as HTMLElement;

private setInlineStyles(targetElem: Element) {
const svgElements = Array.from(targetElem.getElementsByTagName('svg'));
for (const svgElement of svgElements) {
this.recursElementChildren(svgElement);
}
}

private recursElementChildren(node: SVGSVGElement | HTMLElement) {
const transformProperties = [
'fill',
'color',
'font-size',
'stroke',
'font',
'text-anchor',
'stroke-dasharray',
'shape-rendering',
'stroke-width'
];
if (!node.style) {
return;
}
const styles = getComputedStyle(node);
for (const transformProperty of transformProperties) {
node.style[transformProperty] = styles[transformProperty];
}
for (const child of Array.from(node.childNodes)) {
this.recursElementChildren(child as SVGSVGElement);
}
}

print(name: string = 'download') {
// set print width
const printWidth = this.viewer.scrollWidth - this.viewer.offsetWidth + this.root.offsetWidth;

// set print height
const printHeight = this.viewer.scrollHeight + this.calendarOverlay.offsetHeight;

html2canvas(this.root, {
// scale: 2,
logging: false,
allowTaint: true,
width: printWidth,
height: printHeight,
onclone: (cloneDocument: Document) => {
const ganttClass = this.root.className;
const cloneGanttDom = cloneDocument.querySelector(`.${ganttClass.replace(/\s+/g, '.')}`) as HTMLElement;

// change targetDom width
cloneGanttDom.style.width = `${printWidth}px`;
cloneGanttDom.style.height = `${printHeight}px`;
cloneGanttDom.style.overflow = 'unset';
cloneGanttDom.style.flex = 'none';

// setInlineStyles for svg
this.setInlineStyles(cloneGanttDom);
}
}).then((canvas: HTMLCanvasElement) => {
const link = document.createElement('a');
const dataUrl = canvas.toDataURL('image/png');
link.download = `${name}.png`;
link.href = dataUrl;
link.click();
});
}
}
118 changes: 64 additions & 54 deletions packages/gantt/src/gantt.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,76 +17,86 @@ $gantt-date-secondary-color: #333 !default;
$gantt-date-secondary-font-size: 14px !default;
$gantt-date-secondary-weekend-color: #aaa !default;
$gantt-date-secondary-border-color: #ddd !default;
$gantt-date-week-backdrop-bg: rgba($color: #f3f3f3, $alpha: 0.5) !default;
$gantt-date-week-backdrop-bg: rgba(
$color: #f3f3f3,
$alpha: 0.5
) !default;
$gantt-date-today-color: #ff9f73 !default;

@import './calendar/calendar.component.scss';
@import './table/gantt-table.component.scss';
@import './bar/bar.component.scss';

.gantt {
width: 100%;
height: 100%;
background-color: $gantt-bg-color;
position: relative;
overflow: hidden;
display: flex;
width: 100%;
height: 100%;
background-color: $gantt-bg-color;
position: relative;
overflow: hidden;
display: flex;
border: 1px solid #eee;
border-bottom: none;

.gantt-side {
width: 400px;
border-right: 1px solid $gantt-border-color;
overflow: auto;
.gantt-side-scrolling {
box-shadow: 10px 0 0 0 #ccc;
}

.gantt-side-header {
box-sizing: border-box;
height: $gantt-header-height;
width: min-content;
}

.gantt-side {
width: 400px;
.gantt-side-container {
height: calc(100% - #{$gantt-header-height});
overflow: auto;
width: min-content;

.gantt-side-header {
box-sizing: border-box;
height: $gantt-header-height;
overflow: hidden;
border-bottom: 1px solid #eee;
}
&::-webkit-scrollbar {
display: none;
}
}
}

.gantt-side-container {
height: calc(100% - #{$gantt-header-height});
overflow: auto;
.gantt-container {
flex: 1;
position: relative;
display: flex;
overflow: hidden;
}

&::-webkit-scrollbar {
display: none;
}
}
.gantt-main-container {
width: 100%;
height: calc(100% - 44px);
flex: 1;
position: absolute;
top: 44px;
bottom: 0;
left: 0;
right: 0;
overflow: auto;

.gantt-main-groups .gantt-main-items {
height: 100%;
}

.gantt-container {
flex: 1;
position: relative;
display: flex;
overflow: hidden;
.gantt-group {
height: 44px;
box-sizing: border-box;
background: #fafafa;
}

.gantt-main-container {
width: 100%;
height: calc(100% - 44px);
flex: 1;
position: absolute;
top: 44px;
bottom: 0;
left: 0;
right: 0;
overflow: auto;

.gantt-main-groups .gantt-main-items {
height: 100%;
}

.gantt-group {
height: 44px;
box-sizing: border-box;
background: #fafafa;
}

.gantt-item {
height: 44px;
border-bottom: 1px solid $gantt-border-color;
box-sizing: border-box;
position: relative;
}
.gantt-item {
height: 44px;
border-bottom: 1px solid $gantt-border-color;
box-sizing: border-box;
position: relative;
}
}
}

// .gantt-container {
Expand Down
1 change: 1 addition & 0 deletions packages/gantt/src/table/column/column.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class GanttTableColumnComponent implements OnInit {

@Input('width')
set width(width: number | string) {
console.log(width);
this.columnWidth = coerceCssPixelValue(width);
}

Expand Down
7 changes: 4 additions & 3 deletions packages/gantt/src/table/gantt-table.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<div class="gantt-side-header" *ngIf="columns?.length">
<table>
<colgroup>
<col [style.width]="column.columnWidth" [style.minWidth]="column.columnWidth" *ngFor="let column of columns" />
</colgroup>
<thead>
<th *ngFor="let column of columns" [title]="column.name">
{{ column.name }}
Expand All @@ -9,9 +12,7 @@
</div>
<div class="gantt-side-container">
<ng-container *ngIf="groups.length; else itemsTemplate">
<gantt-table-group *ngFor="let group of groups" [group]="group" [groupHeader]="groupTemplate">
<gantt-table-items [items]="group.items" [columns]="columns"></gantt-table-items>
</gantt-table-group>
<gantt-table-group *ngFor="let group of groups" [group]="group" [columns]="columns" [groupHeader]="groupTemplate"> </gantt-table-group>
</ng-container>
<ng-template #itemsTemplate>
<gantt-table-items [items]="items" [columns]="columns"></gantt-table-items>
Expand Down
Loading

0 comments on commit bdcaa88

Please sign in to comment.