Last active
September 25, 2019 09:52
-
-
Save Fohlen/9acb8609ae3474a011df297134f5cbd8 to your computer and use it in GitHub Desktop.
Custom formatter for IGraph
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PROPERTY_WHITELIST = [ // decides whether or not consecutive items will be added | |
'graph', | |
'nodes', | |
'edges', | |
'labels', | |
'tag', | |
'text' | |
] | |
anonymous = ($class) => $class.isAnonymous || $class.namespace.startsWith('yfiles._R'); | |
collection = ($class) => $class.implementedInterfacesList && $class.implementedInterfacesList.some((interface) => interface.namespace === 'yfiles.collections') | |
yFilesClass = (object) => typeof object.getClass === 'function'; | |
window.devtoolsFormatters = [ | |
{ | |
header (object) { | |
if (!yFilesClass(object)) return; | |
let $class = object.getClass(); | |
// TODO: Properly display anonymous description | |
return ['span', {}, (anonymous($class)) ? $class.implementedInterfacesList[0].fullName : $class.fullName]; | |
}, | |
hasBody (object) { | |
if (!yFilesClass(object)) return; | |
let $class = object.getClass(); | |
return $class.getProperties().some((property) => PROPERTY_WHITELIST.includes(property.name)) || collection($class); | |
}, | |
body (object) { | |
if (!yFilesClass(object)) return; | |
let $class = object.getClass(); | |
if (collection($class)) { | |
// TODO: Think about LARGE collections. Can we use the iterator protocol here? | |
return ['object', {'object': object.toArray()}] | |
} else { | |
return ['object', {'object': $class | |
.getProperties() | |
.filter((property) => PROPERTY_WHITELIST.includes(property.name)) | |
.reduce((acc, property) => { | |
if (object[property.name] !== null) { | |
acc[property.name] = object[property.name] | |
} | |
return acc | |
}, {}) | |
}] | |
} | |
} | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment