mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-22 14:47:56 +01:00
Add first SVG test
This commit is contained in:
parent
353d662963
commit
717f4e023b
@ -16,20 +16,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const innerXML = function (node) {
|
|
||||||
// summary:
|
|
||||||
// Implementation of MS's innerXML function.
|
|
||||||
if ($defined(node.innerXML)) {
|
|
||||||
return node.innerXML;
|
|
||||||
// string
|
|
||||||
} else if ($defined(node.xml)) {
|
|
||||||
return node.xml;
|
|
||||||
// string
|
|
||||||
} else if ($defined(XMLSerializer)) {
|
|
||||||
return new XMLSerializer().serializeToString(node);
|
|
||||||
// string
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cross-browser implementation of creating an XML document object.
|
* Cross-browser implementation of creating an XML document object.
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@wisemapping/core-js": "^0.4.0",
|
"@wisemapping/core-js": "^0.4.0",
|
||||||
"@wisemapping/web2d": "^0.4.0",
|
"@wisemapping/web2d": "^0.4.0",
|
||||||
"jest": "^27.4.3",
|
"jest": "^27.4.5",
|
||||||
"jquery": "3.6.0",
|
"jquery": "3.6.0",
|
||||||
"lodash": "^4.17.21"
|
"lodash": "^4.17.21"
|
||||||
},
|
},
|
||||||
|
14
packages/mindplot/src/components/export/FreemindExporter.ts
Normal file
14
packages/mindplot/src/components/export/FreemindExporter.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import Exporter from "./Exporter";
|
||||||
|
import Mindmap from "../model/Mindmap";
|
||||||
|
|
||||||
|
class FreemindExporter implements Exporter {
|
||||||
|
mindplot: Mindmap;
|
||||||
|
constructor(mindplot: Mindmap) {
|
||||||
|
this.mindplot = mindplot;
|
||||||
|
}
|
||||||
|
|
||||||
|
export(): string {
|
||||||
|
return "TBI";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default FreemindExporter;
|
@ -1,15 +0,0 @@
|
|||||||
|
|
||||||
import Exporter from "./Exporter";
|
|
||||||
|
|
||||||
class TextExporter implements Exporter {
|
|
||||||
svgElement: Element;
|
|
||||||
constructor(svgElement: Element) {
|
|
||||||
this.svgElement = svgElement;
|
|
||||||
}
|
|
||||||
|
|
||||||
export(): string {
|
|
||||||
return "TBI";
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
export default TextExporter;
|
|
23
packages/mindplot/src/components/export/SVGExporter.ts
Normal file
23
packages/mindplot/src/components/export/SVGExporter.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
|
||||||
|
import { Mindmap } from "../..";
|
||||||
|
import Exporter from "./Exporter";
|
||||||
|
|
||||||
|
class SVGExporter implements Exporter {
|
||||||
|
svgElement: Element;
|
||||||
|
constructor(mindmap: Mindmap, svgElement: Element) {
|
||||||
|
this.svgElement = svgElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
export(): string {
|
||||||
|
// Replace all images for in-line images ...
|
||||||
|
const imagesElements:HTMLCollection = this.svgElement.children
|
||||||
|
console.log(imagesElements.length);
|
||||||
|
Array.from(imagesElements).forEach((image) => {
|
||||||
|
console.log(image);
|
||||||
|
|
||||||
|
});
|
||||||
|
return "";
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default SVGExporter;
|
@ -233,7 +233,7 @@ class XMLSerializerPela {
|
|||||||
// Is a wisemap?.
|
// Is a wisemap?.
|
||||||
$assert(
|
$assert(
|
||||||
rootElem.tagName === XMLSerializerPela.MAP_ROOT_NODE,
|
rootElem.tagName === XMLSerializerPela.MAP_ROOT_NODE,
|
||||||
'This seem not to be a map document.',
|
`This seem not to be a map document. Found tag: ${rootElem.tagName}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
this._idsMap = {};
|
this._idsMap = {};
|
||||||
|
@ -1,23 +1,20 @@
|
|||||||
import PlainTextExporter from '../../../src/components/export/PlainTextExporter';
|
import PlainTextExporter from '../../../src/components/export/PlainTextExporter';
|
||||||
import Mindmap from '../../../src/components/model/Mindmap';
|
import Mindmap from '../../../src/components/model/Mindmap';
|
||||||
import XMLSerializerTango from '../../../src/components/persistence/XMLSerializerTango';
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import XMLSerializerFactory from '../../../src/components/persistence/XMLSerializerFactory';
|
||||||
|
|
||||||
test('mindplot generation of simple maps', () => {
|
test('mindplot generation of simple maps', () => {
|
||||||
|
|
||||||
// Load DOM ...
|
|
||||||
const mapStream =fs.readFileSync(path.resolve(__dirname, '../samples/welcome.xml'),{encoding: 'utf-8'});
|
|
||||||
const parser = new DOMParser();
|
const parser = new DOMParser();
|
||||||
|
|
||||||
|
// Load DOM ...
|
||||||
|
const mapStream =fs.readFileSync(path.resolve(__dirname, './samples/welcome.xml'),{encoding: 'utf-8'});
|
||||||
const document = parser.parseFromString(mapStream.toString(), 'text/xml')
|
const document = parser.parseFromString(mapStream.toString(), 'text/xml')
|
||||||
|
|
||||||
// Convert to mindmap ...
|
// Convert to mindmap ...
|
||||||
const serializer = new XMLSerializerTango();
|
const serializer = XMLSerializerFactory.getSerializerFromDocument(document);
|
||||||
const mindmap:Mindmap = serializer.loadFromDom(document,'welcome');
|
const mindmap:Mindmap = serializer.loadFromDom(document,'welcome');
|
||||||
|
|
||||||
// Inspect ...
|
|
||||||
console.log(mindmap);
|
|
||||||
|
|
||||||
const exporter = new PlainTextExporter(mindmap);
|
const exporter = new PlainTextExporter(mindmap);
|
||||||
console.log(exporter.export());
|
console.log(exporter.export());
|
||||||
});
|
});
|
@ -0,0 +1,26 @@
|
|||||||
|
import Mindmap from '../../../src/components/model/Mindmap';
|
||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
import XMLSerializerFactory from '../../../src/components/persistence/XMLSerializerFactory';
|
||||||
|
import SVGExporter from '../../../src/components/export/SVGExporter';
|
||||||
|
|
||||||
|
test('mindplot generation of simple maps', () => {
|
||||||
|
const parser = new DOMParser();
|
||||||
|
|
||||||
|
// Load DOM ...
|
||||||
|
const mapStream = fs.readFileSync(path.resolve(__dirname, './samples/welcome.xml'), { encoding: 'utf-8' });
|
||||||
|
const mapDocument = parser.parseFromString(mapStream.toString(), 'text/xml')
|
||||||
|
|
||||||
|
// Convert to mindmap ...
|
||||||
|
const serializer = XMLSerializerFactory.getSerializerFromDocument(mapDocument);
|
||||||
|
const mindmap: Mindmap = serializer.loadFromDom(mapDocument, 'welcome');
|
||||||
|
|
||||||
|
// Load SVG ...
|
||||||
|
const svgStream = fs.readFileSync(path.resolve(__dirname, './samples/welcome.svg'), { encoding: 'utf-8' });
|
||||||
|
const svgDocument = parser.parseFromString(svgStream.toString(), 'application/xml')
|
||||||
|
console.log(svgDocument);
|
||||||
|
|
||||||
|
// Inspect ...
|
||||||
|
const exporter = new SVGExporter(mindmap, svgDocument.documentElement);
|
||||||
|
console.log(exporter.export());
|
||||||
|
});
|
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 40 KiB |
@ -1,4 +1,4 @@
|
|||||||
/* eslint-disable import/prefer-default-export */
|
import { $defined } from '@wisemapping/core-js';
|
||||||
|
|
||||||
// quick hand-made version of $.css()
|
// quick hand-made version of $.css()
|
||||||
export const getStyle = (elem, prop) => {
|
export const getStyle = (elem, prop) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user