g6/packages/site/docs/manual/middle/elements/methods/updateElement.en.md
2023-02-02 10:31:36 +08:00

1.3 KiB

title order
Update Item Style 1

There are three ways to modify the styles for items in G6.

Configure When Instantiating Graph

When instantiating a Graph, assign style in defaultNode or defaultEdge to configure the styles for global nodes and global edges respectively.

const graph = new G6.Graph({
  container: 'mountNode',
  width: 1000,
  height: 800,
  defaultNode: {
    type: 'circle',
    style: {
      fill: '#fff',
      fontSize: 14,
    },
  },
  defaultEdge: {
    type: 'line-with-arrow',
    style: {
      fill: '#fff',
      fontSize: 14,
    },
  },
});

Configure style in Data

By this way, you can configure the different nodes and edges in different styles.

const data = {
  nodes: [
    {
      id: 'node1',
      label: 'node1',
      style: {
        fill: '#fff',
        fontSize: 12,
      },
    },
  ],
};

update / updateItem

This is a way for updating the keyShape of a node or an edge.

graph.updateItem(node, {
  // The node style
  style: {
    stroke: 'blue',
  },
});

For more information about the styles, refer to Node Style Properties.