Example #1
0
  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();
  }
Example #2
0
 public D3ElementBuilder(
     VisSingle vis,
     ScriptWriter out,
     D3ScaleBuilder scales,
     PositionFields positionFields,
     Dataset data) {
   this.vis = vis;
   this.out = out;
   this.scales = scales;
   this.positionFields = positionFields;
   this.data = data;
   this.labelBuilder = new D3LabelBuilder(vis, out, data);
   this.diagram = D3Diagram.make(vis, data, out);
 }
Example #3
0
 private ElementDetails makeDetails() {
   // When we create diagrams this has the side effect of writing the data calls needed
   return diagram == null
       ? ElementDetails.makeForCoordinates(vis, getSymbol())
       : diagram.writeDataConstruction();
 }
Example #4
0
 /* The key function ensure we have object constancy when animating */
 private String getKeyFunction() {
   String content = diagram != null ? diagram.getRowKey() : "d.key";
   return "function(d) { return " + content + "}";
 }
Example #5
0
 private void modifyGroupStyleName() {
   // Define the main element class
   if (diagram != null)
     out.add("main.attr('class',", diagram.getStyleClasses(), ")").endStatement();
 }