Add first SVG test

This commit is contained in:
Paulo Gustavo Veiga 2021-12-29 17:10:28 -08:00
parent 353d662963
commit 717f4e023b
11 changed files with 72 additions and 40 deletions

View File

@ -16,20 +16,7 @@
* 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.

View File

@ -34,7 +34,7 @@
"dependencies": {
"@wisemapping/core-js": "^0.4.0",
"@wisemapping/web2d": "^0.4.0",
"jest": "^27.4.3",
"jest": "^27.4.5",
"jquery": "3.6.0",
"lodash": "^4.17.21"
},

View 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;

View File

@ -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;

View 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;

View File

@ -233,7 +233,7 @@ class XMLSerializerPela {
// Is a wisemap?.
$assert(
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 = {};

View File

@ -1,23 +1,20 @@
import PlainTextExporter from '../../../src/components/export/PlainTextExporter';
import Mindmap from '../../../src/components/model/Mindmap';
import XMLSerializerTango from '../../../src/components/persistence/XMLSerializerTango';
import fs from 'fs';
import path from 'path';
import XMLSerializerFactory from '../../../src/components/persistence/XMLSerializerFactory';
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 parser = new DOMParser();
const mapStream =fs.readFileSync(path.resolve(__dirname, './samples/welcome.xml'),{encoding: 'utf-8'});
const document = parser.parseFromString(mapStream.toString(), 'text/xml')
// Convert to mindmap ...
const serializer = new XMLSerializerTango();
const serializer = XMLSerializerFactory.getSerializerFromDocument(document);
const mindmap:Mindmap = serializer.loadFromDom(document,'welcome');
// Inspect ...
console.log(mindmap);
const exporter = new PlainTextExporter(mindmap);
console.log(exporter.export());
});

View File

@ -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());
});

View File

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 40 KiB

View File

@ -1,4 +1,4 @@
/* eslint-disable import/prefer-default-export */
import { $defined } from '@wisemapping/core-js';
// quick hand-made version of $.css()
export const getStyle = (elem, prop) => {