documentationfor yFiles for HTML 2.6

GenericLayoutData

This class provides a way to easily pass custom item-specific data from an IGraph to a LayoutGraph.

Inheritance Hierarchy
LayoutData
GenericLayoutData

Remarks

This is a generic implementation of the LayoutData class that can be used to conveniently configure a custom layout configuration and to attach arbitrary data to the LayoutGraph that is used during layout.

Instances of this type can be passed to LayoutExecutor and applyLayout. Instead of using one of the provided use-case specific LayoutData subclasses, this class can be used to provide various types of data to layout algorithms. The layout algorithms can then retrieve the data via the getDataProvider mechanism under the key used to register the data with instances of this class.

Use combineWith to create an instance that contains both the data for an existing instance and this instance. Alternatively add multiple layout data instances to instances of this type.

Examples

// create the container for the data
const layoutData = new GenericLayoutData()

// specify which nodes to fix
const fixedNodes = layoutData.addNodeItemCollection(
  OrganicRemoveOverlapsStage.FIXED_NODE_DP_KEY
).items
for (const node of graph.nodes) {
  if (node.labels.some((label) => label.text == 'Fix')) {
    fixedNodes.add(node)
  }
}

// specify port constraints for the edges
const affectedNodes = new ItemCollection((node) => isAffected(node))
// and register the information in the data
layoutData.addNodeItemCollection(
  LayoutKeys.AFFECTED_NODES_DP_KEY,
  affectedNodes
)

// run the custom layout, passing in the data
graph.applyLayout(new CustomLayout(), layoutData)// create the container for the data
const layoutData = new GenericLayoutData()

// specify which nodes to fix
const fixedNodes = layoutData.addNodeItemCollection(
  OrganicRemoveOverlapsStage.FIXED_NODE_DP_KEY
).items
for (const node of graph.nodes) {
  if (node.labels.some((label) => label.text == 'Fix')) {
    fixedNodes.add(node)
  }
}

// specify port constraints for the edges
const affectedNodes = new ItemCollection<INode>((node) => isAffected(node))
// and register the information in the data
layoutData.addNodeItemCollection(
  LayoutKeys.AFFECTED_NODES_DP_KEY,
  affectedNodes
)

// run the custom layout, passing in the data
graph.applyLayout(new CustomLayout(), layoutData)
/**
 * @param {!LayoutGraph} graph
 */
applyLayout(graph) {
  // get the data provider that was registered under the provided key
  const fixedNodes = graph.getDataProvider(
    OrganicRemoveOverlapsStage.FIXED_NODE_DP_KEY
  )

  if (fixedNodes != null) {
    for (const node of graph.nodes) {
      // check whether the node was marked as fixed or not
      const isFree = !fixedNodes.getBoolean(node)
      if (isFree) {
        // and use it
        graph.setLocation(node, new YPoint(1337, 42))
      }
    }
  }

  // get the data provider that was registered under the provided key for the constraints
  const affectedNodes = graph.getDataProvider(
    LayoutKeys.AFFECTED_NODES_DP_KEY
  )

  if (affectedNodes != null) {
    for (const node of graph.nodes) {
      // obtain the data for each edge
      if (affectedNodes.getBoolean(node)) {
        // and use it
        graph.setSize(node, 42, 42)
      }
    }
  }
}applyLayout(graph: LayoutGraph): void {
  // get the data provider that was registered under the provided key
  const fixedNodes = graph.getDataProvider(
    OrganicRemoveOverlapsStage.FIXED_NODE_DP_KEY
  )

  if (fixedNodes != null) {
    for (const node of graph.nodes) {
      // check whether the node was marked as fixed or not
      const isFree = !fixedNodes.getBoolean(node)
      if (isFree) {
        // and use it
        graph.setLocation(node, new YPoint(1337, 42))
      }
    }
  }

  // get the data provider that was registered under the provided key for the constraints
  const affectedNodes = graph.getDataProvider(
    LayoutKeys.AFFECTED_NODES_DP_KEY
  )

  if (affectedNodes != null) {
    for (const node of graph.nodes) {
      // obtain the data for each edge
      if (affectedNodes.getBoolean(node)) {
        // and use it
        graph.setSize(node, 42, 42)
      }
    }
  }
}
// create the container for the data
const layoutData = new GenericLayoutData()

// specify halos for each node, letting the data create the mapping for us
const halos = layoutData.addNodeItemMapping(NodeHalo.NODE_HALO_DP_KEY).mapper
const labelHalo = NodeHalo.create(10, 10, 10, 10)
for (const node of graph.nodes) {
  halos.set(node, node.labels.size > 0 ? labelHalo : NodeHalo.ZERO_HALO)
}

// specify port constraints for the edges
const fixedPortConstraint = PortConstraint.create(PortSide.NORTH, true)
const portConstraintMapping = new ItemMapping((edge) =>
  isFixedEdge(edge) ? fixedPortConstraint : null
)
// and register the information in the data
layoutData.addEdgeItemMapping(
  PortConstraintKeys.SOURCE_PORT_CONSTRAINT_DP_KEY,
  portConstraintMapping
)

// run the custom layout, passing in the data
graph.applyLayout(new MyLayout(), layoutData)// create the container for the data
const layoutData = new GenericLayoutData()

// specify halos for each node, letting the data create the mapping for us
const halos = layoutData.addNodeItemMapping(NodeHalo.NODE_HALO_DP_KEY).mapper
const labelHalo = NodeHalo.create(10, 10, 10, 10)
for (const node of graph.nodes) {
  halos.set(node, node.labels.size > 0 ? labelHalo : NodeHalo.ZERO_HALO)
}

// specify port constraints for the edges
const fixedPortConstraint = PortConstraint.create(PortSide.NORTH, true)
const portConstraintMapping = new ItemMapping<IEdge, PortConstraint | null>(
  (edge) => (isFixedEdge(edge) ? fixedPortConstraint : null)
)
// and register the information in the data
layoutData.addEdgeItemMapping(
  PortConstraintKeys.SOURCE_PORT_CONSTRAINT_DP_KEY,
  portConstraintMapping
)

// run the custom layout, passing in the data
graph.applyLayout(new MyLayout(), layoutData)
/**
 * @param {!LayoutGraph} graph
 */
applyLayout(graph) {
  // get the data provider that was registered under the provided key
  const nodeHalos = graph.getDataProvider(NodeHalo.NODE_HALO_DP_KEY)

  if (nodeHalos != null) {
    for (const node of graph.nodes) {
      // obtain the data for each node from the provider
      const halo = nodeHalos.get(node)
      if (halo instanceof NodeHalo) {
        // and use it
        graph.setLocation(node, new YPoint(halo.left, halo.top))
      }
    }
  }

  // get the data provider that was registered under the provided key for the constraints
  const sourcePortConstraints = graph.getDataProvider(
    PortConstraintKeys.SOURCE_PORT_CONSTRAINT_DP_KEY
  )

  if (sourcePortConstraints != null) {
    for (const edge of graph.edges) {
      // obtain the data for each edge
      const spc = sourcePortConstraints.get(edge)
      if (spc instanceof PortConstraint && !spc.strong) {
        // and use it
        graph.setSourcePointRel(edge, YPoint.ORIGIN)
      }
    }
  }
}applyLayout(graph: LayoutGraph) {
  // get the data provider that was registered under the provided key
  const nodeHalos = graph.getDataProvider(NodeHalo.NODE_HALO_DP_KEY)

  if (nodeHalos != null) {
    for (const node of graph.nodes) {
      // obtain the data for each node from the provider
      const halo = nodeHalos.get(node)
      if (halo instanceof NodeHalo) {
        // and use it
        graph.setLocation(node, new YPoint(halo.left, halo.top))
      }
    }
  }

  // get the data provider that was registered under the provided key for the constraints
  const sourcePortConstraints = graph.getDataProvider(
    PortConstraintKeys.SOURCE_PORT_CONSTRAINT_DP_KEY
  )

  if (sourcePortConstraints != null) {
    for (const edge of graph.edges) {
      // obtain the data for each edge
      const spc = sourcePortConstraints.get(edge)
      if (spc instanceof PortConstraint && !spc.strong) {
        // and use it
        graph.setSourcePointRel(edge, YPoint.ORIGIN)
      }
    }
  }
}

Type Details

yfiles module
view-layout-bridge
yfiles-umd modules
view-layout-bridge
Legacy UMD name
yfiles.layout.GenericLayoutData

See Also

Constructors

Methods