public void generate() { if (diagram != null) out.onNewLine().comment("Data structures for a", vis.tDiagram, "diagram"); ElementDetails details = makeDetails(); // Create the details of what the element should be ElementDefinition elementDef = buildElementDefinition(); // And the coordinate definitions // Define paths needed in the element, and make data splits if (details.producesPath) definePathsAndSplits(elementDef); if (labelBuilder.needed()) labelBuilder.defineLabeling(details, vis.itemsLabel, false); // Labels modifyGroupStyleName(); // Diagrams change the name so CSS style sheets will work well // Define the data and main element into which shapes will be placed out.add("var d3Data =", details.dataSource).endStatement(); out.add("var element = main.selectAll('*').data(d3Data,", getKeyFunction(), ")").endStatement(); // Define what happens when data is added ('enter') out.add("element.enter().append('" + details.elementType + "')"); out.add(".attr('class', ", details.classes, ")"); if (diagram != null) diagram.writeDiagramEnter(); else writeCoordEnter(); // When data changes (including being added) update the items // These fire for both 'enter' and 'update' data if (diagram != null) { out.add("BrunelD3.trans(element,transitionMillis)"); diagram.writeDefinition(details); } else { writeCoordinateDefinition(details, elementDef); writeCoordinateLabelingAndAesthetics(details); } // This fires when items leave the system out.onNewLine().ln().add("BrunelD3.trans(element.exit(),transitionMillis/3)"); out.addChained("style('opacity', 0.5).remove()").endStatement(); }