GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Home Home
Andy Clement edited this page
Spring Flo is a set of Angular JS directives for a diagram editor able to represent a DSL graphically and synchronize graphical and textual representation of that DSL. Graphical representation is done with a Joint JS graph object, textual representation can be either a plain HTML element (such as Spring Flo can be used in any angular application via the There is a sample project in the samples subfolder of the spring-flo repo: https://github.com/spring-projects/spring-flo/tree/master/samples/spring-flo-sample - this sample will be referenced throughout the documentation below to give a pointer to a real use of each feature. The initial step of embedding Flo into angular application is simply to use the <flo-editor></flo-editor> The above results in a page with a skeleton for the editor: empty palette and empty canvas. See the sample usage for a more sophisticated configuration. Flo defines UI for the editor and graph interactions but needs domain knowledge from the client to be actually useful. There are actually three services the consuming client can provide to control the behaviour of Flo, only one of which is mandatory:
Implementations should be provided by the client as angular services that adhere to a specific contract as detailed in Extension Points. The services are: Metamodel Service (required), Render Service and Editor Service. Many of the service functions have sensible defaults. In this section we will discuss the important ones, only some of which are mandatory. In order to populate the palette with content, Flo needs to know about your domain. What are the 'things' you are linking together in your graph? Implementing the Metamodel Service load() function will provide that information to Flo. app.factory('MyPageMetamodelService', ['$log', function($log) { return { load: function() { $log.info('Return descriptions of the domain specific model elements'); } }; }]); The sample includes a more complete metamodel service. Once defined, the services can be supplied by name to the parents scope (via parent controller <flo-editor metamodel-service-name="MyPageMetamodelService"> </flo-editor> This is also how the sample index.html does it. Once the Metamodel Service is hooked up to the editor the palette will be populated based on the metamodel object obtained from the Metamodel Service. You should then be able to drop nodes on the canvas, connect nodes with links, move them around. Note that visual representation of nodes and links might be far from what is desired. Implementing a Render Service enables you to customize that look and feel (in the absence of a provided render service, Flo performs some very basic rendering). A basic render service will implement the createNode() and createLink() functions (see also Joint JS API Docs) to get the right look and feel for the shapes on the palette and canvas. app.factory('MyPageRenderService', ['$log', function($log) { return { createNode: function(metadata) { $log.info('Create and return new Joint JS joint.dia.Element for a graph node'); }, createLink: function(source, target, metadata, props) { $log.info('Create and return new Joint JS joint.dia.Link for a link between graph nodes'); } }; }]); The sample includes a more complete render service. As with the metamodel service, connect it to the <flo-editor metamodel-service-name="MyPageMetamodelService" render-service-name="MyPageRenderService"> </flo-editor> With basic rendering taken care of, we could further customize:
Some of these features are supported by implementing more functions on the render-service but some require implementing the final key service, the Editor Service: app.factory('MyPageEditorService', ['$log', function($log) { return { createHandles: function(flo, createHandle, selected) { $log.info('Create handles around selected element'); }, validateLink: function(flo, cellViewS, portS, cellViewT, portT, end, linkView) { $log.info('Validate link');}, validateNode: function(flo, node) { $log.info('Validate Node'); }, preDelete: function(flo, deletedElement) { $log.info('Delete links incident with element being deleted '); }, interactive: true, /* Consult Joint JS Paper #interactive property doc. Make elements interactive */ allowLinkVertexEdit: false /* Disallow creation and editing of 'bend-points' in links */ }; }]); The sample includes a more complete editor service. Rendering for handles and validation markers (decorations) must be provided by the Render Service since they are required by Editor Service. There is no out-of-the-box rendering defined in Spring-Flo for rendering handles and error marker decoration shapes. Consequently, if you define app.factory('MyPageRenderService', ['$log', function($log) { return { createHandle: function(kind, parent) { $log.info('Implement handle node creation'); }, createDecoration: function(kind, parent) { $log.info('Implement error decoration node creation'); }, createNode: function(metadata) { $log.info('Create and return new Joint JS joint.dia.Element for a graph node'); }, createLink: function(source, target, metadata, props) { $log.info('Create and return new Joint JS joint.dia.Link for a link between graph nodes'); } }; }]); New toolbar actions can be added in HTML in the <flo-editor metamodel-service-name="MyPageMetamodelService" render-service-name="MyPageRenderService" editor-service-name="MyPageEditorService"> <div> <button ng-click="flo.deleteSelectedNode()" ng-disabled="!flo.getSelection()">Delete</button> <button ng-click="flo.noPalette = !flo.noPalette" ng-class="{on:!flo.noPalette}">Palette</button> </div> </flo-editor> Note the The graph editor should be fully functional at this stage, but what about the text DSL? Functions converting graph to text DSL and text DSL to graph must be provided by the client in order for this to work. These two function (graphToText() and textToGraph()) must be implemented inside the Metamodel Service, let's add them to the definition we had earlier: app.factory('MyPageMetamodelService', ['$log', function($log) { return { load: function() { $log.info('Implement load and return metamodel object!'); }, textToGraph: function(flo, definition) { $log.info('Convert text (definition.text) to graph (flo.getGraph())'); }, graphToText: function(flo, definition) { $log.info('Convert graph (flo.getGraph()) to text (definition.text)'); } }; }]); The sample includes basic implementations of graph-to-text and text-to-graph for a 'demo' DSL, those are used by the sample metamodel service.
The Flo editor internally maintains the text DSL in the <flo-editor metamodel-service-name="MyPageMetamodelService" render-service-name="MyPageRenderService" editor-service-name="MyPageEditorService"> <div> <button ng-click="flo.deleteSelectedNode()" ng-disabled="!flo.getSelection()">Delete</button> <button ng-click="flo.noPalette = !flo.noPalette" ng-class="{on:!flo.noPalette}">Palette</button> </div> <textarea dsl-editor></textarea> </flo-editor> The HTML above translates into a page with toolbar for buttons (Layout and Show/Hide Palette), text area for DSL and the Flo editor for graph representation of the DSL. This service enables the domain in which Flo is being used to specify what kinds of element are being connected together in the graph and also how the graph should be converted to-and-from a textual representation. Sample metamodel service is here. Sets the graph contents for the Convert the current graph available from the Returns a promise that resolves to a Refreshes the meta-model and returns a promise that is resolved to the same result as load(). Refresh should also fire event to Encodes DSL element property value text to the DSL required format. Example is converting multiline text into a single line required by the DSL format. Used to display the property value in a human readable format. Decodes DSL element property value text from DSL format. Example is converting single line text into a multiline text, i.e. replacing escaped line breaks. Used to set a property value for DSL element entered by the user via UI. Adds a listener to Removes Check if the the value being specified for the key on the specified element is allowed. For example: if the key takes an integer, don't allow alphabetic characters. The service is responsible for visual representation of graph elements based on the metadata (coming from Metamodel Service). This service is optional. Sample render service is here. Creates an instance of Joint JS graph node model object ( Creates an instance of Joint JS graph link model object ( Creates an instance of Joint JS graph node model object ( Creates an instance of Joint JS graph node model object ( Performs any additional initialization of a newly created graph Performs any additional initialization of a newly created graph Performs any additional initialization of a newly created graph Performs any additional initialization of a newly created graph Returns instance of Returns instance of Joint JS Responsible for laying out the Joint JS graph that can be derived from passed in Responsible for handling Returns Performs some visual update of the graph or, which is more likely, the passed in This function allows you to customize what are the anchor points of links. The function must return a point (with The service responsible for providing Flo editor with rich editing capabilities such as handles around selected shapes, custom drag and drop behaviour, live and static validation. This service is optional. Sample editor service is here Called when node is selected and handles can be displayed. Handles are usually small shapes around the Decide whether to create a link if the user clicks a port. The Decide whether to allow or disallow a connection between the source view/port ( Called when dragging of a node Performs necessary graph manipulations when the node being dragged is dropped. The Any custom visual feedback when dragging a node over some graph element (node or link) can be drawn by this function. Removes any custom visual feedback drawn by showDragFeedback(). Has the same parameters. Returns a Called prior to removal of the specified If set to If set to This object is created by the Schedules an asynchronous update of the graph DSL representation based on the text DSL representation. Asynchronously update the graph DSL representation based on the text DSL representation. A promise is returned which gets resolved when the update completes. Asynchronously update the text DSL representation ( Arranges nodes and links of the graph on the canvas. Clears out canvas of all nodes and links. With syncing on this also causes the text DSL representation to clear. Returns a reference to Returns a reference to joint.dia.Paper object instance of the canvas (The graph view object, see Joint JS Paper API Enables or disables textual and graph DSL representation synchronization mechanism based on the passed Returns currently selected graph model element (node or link) on the canvas Angular getter/setter function for the zoom value on the canvas. Sets zoom percent value if the integer Angular getter/setter function for the canvas grid size in pixels. Sets grid width value if the integer Returns integer Returns integer Returns integer Fits the whole graph into canvas's viewport (i.e. no need to scroll to look for content on the canvas). Adjusts the zoom level and scroll position appropriately Angular getter/setter function for the canvas "read-only" property. Read-only canvas does not allow for any user editing interaction of any shapes on the canvas. Sets the read-only property based on the passed in Creates and returns the newly created Joint JS graph node (instance of Creates and returns the newly created Joint JS graph link (instance of This object holds data related to DSL's textual representation. Typically this object should at least have Typically Metamodel object is loaded asynchronously via HTTP request. If metadata is cached by the service then it might be useful to register listeners. Flo editor palette would automatically rebuild itself if metamodel has changed { metadataError: function(data) { /* Error loading metadata has occurred */ }, metadataRefresh: function() { /* Metadata is about to be refreshed */ }, metadataChanged: function(data) { /* New metadata is available */ } } API client is free to add extra properties to this object (i.e. may help drawing visual feedback) { context: context, /* String 'palette' or 'canvas' */ source: { cell: draggedNode, /* Joint JS graph node being dragged */ selector: selector, /* Optional. Joint JS CSS class selector for the subelement of the dragged node*/, port: portType /* Optional. Involved port DOM element type attribute value == port Joint JS markup 'type' property */ }, target: { cell: targetNode, /* Joint JS graph node target under mouse element */ selector: selector, /* Optional. Joint JS CSS class selector for the element under mouse within the targetNode */ port: portType /* Optional. Sub-element under mouse is a port. Port DOM element type attribute value == port Joint JS markup 'type' property */ }, }; model: /* Joint JS model object for a module shape */ ... attributes: ... angle: 0, /* Joint JS property - rotation angle */ id: "02be8001-ea1e-4f30-a94e-9503da5964b5" /* Joint JS property - element model UUID position: /* Joint JS property - coordinates of the shape's bounding rectangle */ x: 119 y: 46 size: /* Joint JS property - size of the shape's bounding rectangle */ height: 40 width: 120 type: "sinspctr.IntNode" /* Flo property - internal, type (node, link, handle, decoration, etc) */ z: 1 /* Joint JS property - z-index of the shape ports: /* Joint JS property - internal, ports available on the shape */ input: id: "input" output: id: "output" tap: id: "tap" attrs: /* Joint JS property - user defined rendering constructs and semantic properties */ . /*\ */ .border /* \ */ .box /* \ */ .input-port /* \ */ .label1 /* \___User defined rendering constructs implied by the markup */ .label2 /* / */ .output-port /* / */ .shape /* / */ .stream-label /* / */ .tap-port /*/ */ metadata: /* Flo property. Node metadata supplied by Metamodel Service */ props: /* Flo property. Semantic properties of the element. Name <-> value pair map */ dir: "/Users/x/tmp" file: "temp.tmp" debug: true ... ... ... Graphical element metadata supplied by Metamodel Service metadata: { get: function(), /* function taking property key string as a parameter */ /* Returns promise that resolves to the metadata object of the property */ /* See snippet below showing the format of a property metadata */ group: "source", /* Category/Group of an element. Translates into palette groups of elements */ name: "file", /* Name or Type of an element (should be unique within its group) */ metadata: { /* Additional metadata for the element */ titleProperty: 'props/title', /* Property to be displayed at the top of all properties in properties Div */ noEditableProps: false, /* If true then element doesn't have properties to edit and properties Div is not shown */ allow-additional-properties: true, /* Allows user to create new properties for element in the properties Div */ } } Element's property metadata is expected to be as follows properties: { info: { defaultValue: null, description: "General information about the file", id: "info", name: "info", shortDescription: "File Info" }, language: { defaultValue: "English" description: "Language of the file contents", id: "language", name: "language", shortDescription: "Text Language" }, ... Clone this wiki locally |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |