preview rendered
This commit is contained in:
@@ -93,26 +93,28 @@ const faDiagrams = require('fa-diagrams');
|
||||
|
||||
const data = {
|
||||
options: {
|
||||
font: 'Courier New'
|
||||
rendering:{
|
||||
icons:{
|
||||
color:'#4E342E'
|
||||
}
|
||||
}
|
||||
},
|
||||
nodes: [
|
||||
{
|
||||
name: 'node1',
|
||||
icon: 'server',
|
||||
bottom: {text: 'myserver' },
|
||||
top: {icon: 'node'}
|
||||
},
|
||||
{
|
||||
name: 'node2',
|
||||
icon: 'globe',
|
||||
bottom: {text: 'world'}
|
||||
color:'#455A64',
|
||||
}
|
||||
],
|
||||
links: [
|
||||
{
|
||||
from: 'node1',
|
||||
to: 'node2',
|
||||
bottom: {text: 'Hello World!'}
|
||||
color:'#333333',
|
||||
}
|
||||
]
|
||||
};
|
||||
@@ -132,7 +134,7 @@ svg2img(svg, function(error, buffer) {
|
||||
|
||||
Will produce the following diagram:
|
||||
|
||||

|
||||

|
||||
|
||||
### Html script
|
||||
|
||||
|
||||
@@ -34,3 +34,35 @@ const g = [];
|
||||
});
|
||||
|
||||
fs.writeFileSync(`preview/links.svg`, rendering.toXML({'g': g}, {w: 1536 * 2, h: 4 * 712 + 100}), {encoding: 'utf-8'});
|
||||
|
||||
const faDiagrams = require('./src/index');
|
||||
|
||||
const data = {
|
||||
options: {
|
||||
rendering: {
|
||||
icons: {
|
||||
color: '#4E342E'
|
||||
}
|
||||
}
|
||||
},
|
||||
nodes: [
|
||||
{
|
||||
name: 'node1',
|
||||
icon: 'server',
|
||||
},
|
||||
{
|
||||
name: 'node2',
|
||||
icon: 'globe',
|
||||
color: '#455A64',
|
||||
}
|
||||
],
|
||||
links: [
|
||||
{
|
||||
from: 'node1',
|
||||
to: 'node2',
|
||||
color: '#333333',
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
fs.writeFileSync('preview/sample.svg', faDiagrams.compute(data), {encoding: 'utf-8'});
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 3072 2948" width="384.00000000000006" height="368.5">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 3072 2948" width="384.00000000000006" height="368.5" stroke="black"
|
||||
fill="black">
|
||||
<g>
|
||||
<g transform="translate(256 150)">
|
||||
<path d="M12 216c-6.627 0-12 5.373-12 12v56c0 6.627 5.373 12 12 12h877.941v46.059c0 21.382 25.851 32.09 40.971 16.971 l86.059 -86.059c9.373-9.373 9.373-24.569 0-33.941l-86.059-86.059c-15.119-15.119-40.971-4.411-40.971 16.971v46.059z"/>
|
||||
|
||||
|
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 6.5 KiB |
@@ -24,6 +24,7 @@ try {
|
||||
*/
|
||||
|
||||
const SUB_DEF = {
|
||||
'_': 'string',
|
||||
'text': 'string',
|
||||
'icon': 'string',
|
||||
'color': 'string',
|
||||
|
||||
+2
-2
@@ -28,7 +28,7 @@ const self = {
|
||||
* @returns {null|string}
|
||||
*/
|
||||
isValid: (obj, def) => {
|
||||
const keys = Object.keys(def);
|
||||
const keys = Object.keys(def).filter(k => k !== '_');
|
||||
let key;
|
||||
let type;
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
@@ -37,7 +37,7 @@ const self = {
|
||||
if (type === 'object' && obj[key].length > 0)
|
||||
type = 'array';
|
||||
if (typeof def[key] === 'object') {
|
||||
if (type && type !== 'object')
|
||||
if (type && type !== 'object' && type !== def[key]['_'])
|
||||
return key;
|
||||
const res = self.isValid(type ? obj[key] : undefined, def[key]);
|
||||
if (res)
|
||||
|
||||
@@ -71,6 +71,12 @@ describe('isValid', () => {
|
||||
test('invalid sub-object', () => {
|
||||
expect(utils.isValid({a: 5}, {a: {b: 'number'}})).toBe('a');
|
||||
});
|
||||
test('valid alternative sub-object', () => {
|
||||
expect(utils.isValid({a: 5}, {a: {b: 'number', '_': 'number'}})).toBe(null);
|
||||
});
|
||||
test('invalid alternative sub-object', () => {
|
||||
expect(utils.isValid({a: 'hello'}, {a: {b: 'number', '_': 'number'}})).toBe('a');
|
||||
});
|
||||
test('undefined not required sub-object', () => {
|
||||
expect(utils.isValid({}, {a: {b: 'number'}})).toBe(null);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user