-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gantt-table): add width in gantt column
- Loading branch information
1 parent
7c0ee57
commit bdcaa88
Showing
14 changed files
with
254 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,4 @@ | |
height: 100%; | ||
margin: 20px; | ||
display: block; | ||
border: 1px solid #ddd; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.