diff --git a/src/app/app.component.html b/src/app/app.component.html index 8dacc6d..8b3e3c9 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -33,6 +33,15 @@ + + + + + + + + @@ -42,6 +51,15 @@ + + + + + + + + diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 7e693d2..63f8bac 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -22,7 +22,9 @@ export class AppComponent implements OnInit, AfterContentInit, AfterViewInit, On menuSubscription: Subscription; displayAbout: boolean; + displayExportJPG: boolean; displayExportPNG: boolean; + displayExportSVG: boolean; displayPreferences: boolean; displayPrint: boolean; @@ -48,9 +50,15 @@ export class AppComponent implements OnInit, AfterContentInit, AfterViewInit, On case 'show-about': this.displayAbout = true; break; + case 'show-export-jpg': + this.displayExportJPG = true; + break; case 'show-export-png': this.displayExportPNG = true; break; + case 'show-export-svg': + this.displayExportSVG = true; + break; case 'show-preferences': this.displayPreferences = true; break; diff --git a/src/app/component/menu/export-jpg.component.html b/src/app/component/menu/export-jpg.component.html new file mode 100644 index 0000000..c4b25ec --- /dev/null +++ b/src/app/component/menu/export-jpg.component.html @@ -0,0 +1,4 @@ +
+ + Export JPG +
\ No newline at end of file diff --git a/src/app/component/menu/export-jpg.component.scss b/src/app/component/menu/export-jpg.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/component/menu/export-jpg.component.ts b/src/app/component/menu/export-jpg.component.ts new file mode 100644 index 0000000..6dc25be --- /dev/null +++ b/src/app/component/menu/export-jpg.component.ts @@ -0,0 +1,60 @@ +import { Component, OnInit, AfterContentInit, OnDestroy, } from '@angular/core'; +import { Store, select } from '@ngrx/store'; +import { take } from 'rxjs/operators'; + +import * as AppStore from '../../store'; +import { TargetDisplayType } from '../../core/type'; +import { Message } from 'primeng/primeng'; + +const { saveSvgAsPng, svgAsDataUri } = require('save-svg-as-png'); + +@Component({ + selector: 'app-menu-export-jpg', + templateUrl: './export-jpg.component.html', + styleUrls: ['./export-jpg.component.scss'], +}) +export class ExportJPGComponent implements OnInit, AfterContentInit, OnDestroy { + msgs: Message[] = []; + + constructor( + private store: Store, + ) { + } + + ngOnInit(): void { + } + + ngAfterContentInit(): void { + + } + + ngOnDestroy(): void { + + } + + export() { + const __this = this; + this.store.pipe( + take(1), + select((state) => { + const targetDisplayType = AppStore.TargetSelector.TargetSelector.selectTargetDisplayType(state); + const targetDisplayElementRef = AppStore.TargetSelector.TargetSelector.selectTargetDisplayElementRef(state); + + if (TargetDisplayType.MAP !== targetDisplayType) { + this.msgs = []; + this.msgs.push({ + severity: 'error', + summary: 'Invalid Display Type', + detail: 'Export JPEG is only supported for Map Display type' + }); + return; + } + + // svgAsDataUri(targetDisplayElementRef.nativeElement, {}, function (uri) { + // console.log(`uri: ${uri}`); + // }); + saveSvgAsPng(targetDisplayElementRef.nativeElement, 'diagram.jpg', { backgroundColor: '#ffffff', encoderType: 'image/jpeg' }); + }), + ).subscribe(); + } +} diff --git a/src/app/component/menu/export-svg.component.html b/src/app/component/menu/export-svg.component.html new file mode 100644 index 0000000..d281d2e --- /dev/null +++ b/src/app/component/menu/export-svg.component.html @@ -0,0 +1,4 @@ +
+ + Export SVG +
\ No newline at end of file diff --git a/src/app/component/menu/export-svg.component.scss b/src/app/component/menu/export-svg.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/component/menu/export-svg.component.ts b/src/app/component/menu/export-svg.component.ts new file mode 100644 index 0000000..4e53f8c --- /dev/null +++ b/src/app/component/menu/export-svg.component.ts @@ -0,0 +1,59 @@ +import { Component, OnInit, AfterContentInit, OnDestroy, } from '@angular/core'; +import { Store, select } from '@ngrx/store'; +import { take } from 'rxjs/operators'; + +import * as AppStore from '../../store'; +import { TargetDisplayType } from '../../core/type'; +import { Message } from 'primeng/primeng'; + +const { saveSvgAsPng, svgAsDataUri, download } = require('save-svg-as-png'); + +@Component({ + selector: 'app-menu-export-svg', + templateUrl: './export-svg.component.html', + styleUrls: ['./export-svg.component.scss'], +}) +export class ExportSVGComponent implements OnInit, AfterContentInit, OnDestroy { + msgs: Message[] = []; + + constructor( + private store: Store, + ) { + } + + ngOnInit(): void { + } + + ngAfterContentInit(): void { + + } + + ngOnDestroy(): void { + + } + + export() { + const __this = this; + this.store.pipe( + take(1), + select((state) => { + const targetDisplayType = AppStore.TargetSelector.TargetSelector.selectTargetDisplayType(state); + const targetDisplayElementRef = AppStore.TargetSelector.TargetSelector.selectTargetDisplayElementRef(state); + + if (TargetDisplayType.MAP !== targetDisplayType) { + this.msgs = []; + this.msgs.push({ + severity: 'error', + summary: 'Invalid Display Type', + detail: 'Export SVG is only supported for Map Display type' + }); + return; + } + + svgAsDataUri(targetDisplayElementRef.nativeElement, { backgroundColor: '#ffffff' }, function (uri) { + download('diagram.svg', uri); + }); + }), + ).subscribe(); + } +} diff --git a/src/app/component/menu/index.ts b/src/app/component/menu/index.ts index 4360d54..f9225ac 100644 --- a/src/app/component/menu/index.ts +++ b/src/app/component/menu/index.ts @@ -1,11 +1,15 @@ import { AboutComponent } from './about.component'; +import { ExportJPGComponent } from './export-jpg.component'; import { ExportPNGComponent } from './export-png.component'; +import { ExportSVGComponent } from './export-svg.component'; import { PreferencesComponent } from './preferences.component'; import { PrintComponent } from './print.component'; export const COMPONENTS = [ AboutComponent, + ExportJPGComponent, ExportPNGComponent, + ExportSVGComponent, PreferencesComponent, PrintComponent, ]; diff --git a/src/electron/menu/build-default.ts b/src/electron/menu/build-default.ts index 93cb6d5..702be53 100644 --- a/src/electron/menu/build-default.ts +++ b/src/electron/menu/build-default.ts @@ -65,13 +65,11 @@ export function buildDefaultMenu( label: __DARWIN__ ? 'JPG…' : 'JPG…', id: 'export-jpg', click: emit('show-export-jpg'), - enabled: false, }, { label: __DARWIN__ ? 'SVG…' : 'SVG…', id: 'export-svg', click: emit('show-export-svg'), - enabled: false, }, { label: __DARWIN__ ? 'CSV…' : 'CSV…',