G6.registerLayout

2 min read

G6.registerLayout(layoutName, layout)

When the built-in Layouts cannot satisfy your requirments, custom a type of Layout by G6.registerLayout(layoutName, layout).

Parameters

NameTypeRequiredDescription
layoutNameStringtrueThe name of the custom layout.
layoutObjecttrueThe configurations of the custom layout. For more information, please refer to Layout API.

Usage

G6.registerLayout('layoutName', {
  /**
   * The default configurations will be mixed by configurations from user
   */
  getDefaultCfg() {
    return {};
  },
  /**
   * Initialize
   * @param {Object} data The data
   */
  init(data) {
    const self = this;
    self.nodes = data.nodes;
    self.edges = data.edges;
  },
  /**
   * Execute the layout
   */
  execute() {
    // TODO
  },
  /**
   * Layout with the data
   * @param {Object} data The data
   */
  layout(data) {
    const self = this;
    self.init(data);
    self.execute();
  },
  /**
   * Update the configurations of the layout, but it does not execute the layout
   * @param {Object} cfg The new configurations
   */
  updateCfg(cfg) {
    const self = this;
    Util.mix(self, cfg);
  },
  /**
   * Destroy the layout
   */
  destroy() {
    const self = this;
    self.positions = null;
    self.nodes = null;
    self.edges = null;
    self.destroyed = true;
  },
});

Initialize

init(data)

Initialize the layout.

Paramter

NameTypeRequiredDescription
dataObjecttrueThe data for the layout

getDefaultCfg()

Get the default configurations of the layout.

Return

NameTypeRequiredDescription
cfgObjecttrueThe default configurations

Layout

execute()

Execute the layout.

layout(data)

Execute layout according to the data.

Paramter

NameTypeRequiredDescription
dataObjecttrueThe data to be arranged

Update

updateCfg(cfg)

Update the configurations for layout.

Paramter

NameTypeRequiredDescription
cfgObjecttrueNew configurations

Destroy

destroy()

Destroy the layout.