mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-11 09:53:24 +01:00
959a732999
Remove toolkit init
36 lines
1.4 KiB
TypeScript
36 lines
1.4 KiB
TypeScript
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', () => {
|
|
// Load mindmap DOM ...
|
|
const mindmapPath = path.resolve(__dirname, './samples/welcome.xml');
|
|
const mapDocument = parseXMLFile(mindmapPath, 'text/xml');
|
|
|
|
// Convert to mindmap ...
|
|
const serializer = XMLSerializerFactory.getSerializerFromDocument(mapDocument);
|
|
const mindmap: Mindmap = serializer.loadFromDom(mapDocument, 'welcome');
|
|
|
|
// Load SVG ...
|
|
const svgPath = path.resolve(__dirname, './samples/welcome.svg');
|
|
const svgDocument = parseXMLFile(svgPath, 'image/svg+xml');
|
|
|
|
// Inspect ...
|
|
const exporter = new SVGExporter(mindmap, svgDocument.documentElement);
|
|
console.log(exporter.export());
|
|
|
|
function parseXMLFile(filePath: fs.PathOrFileDescriptor, mimeType: DOMParserSupportedType) {
|
|
const parser = new DOMParser();
|
|
const stream = fs.readFileSync(filePath, { encoding: 'utf-8' });
|
|
const xmlDoc = parser.parseFromString(stream.toString(), mimeType);
|
|
|
|
// Is there any parsing error ?.
|
|
if (xmlDoc.getElementsByTagName("parsererror").length > 0) {
|
|
throw new Error(`Unexpected error parsing: ${filePath}. Error: ${new XMLSerializer().serializeToString(xmlDoc)}`);
|
|
}
|
|
return xmlDoc;
|
|
}
|
|
});
|