antvis/G6

State style defined in the data should merge with state style defined globally. Not replace it. #4005

eakl posted onGitHub

Describe the bug

You can set the style in G6 globally or in the data.

Currently, stateStyles defined in the data replace the nodeStateStyle defined globally. It should behave like styles that merges with defaultNode.

Style defined globally

new G6.Graph({
  // previous options
  defaultNode: {
    style: {
      fill: "red",
      lineWidth: 2
    }
  },
  nodeStateStyles: {
    selected: {
      fill: "green",
      lineWidth: 2
    }
  },
  // following options
})

Style defined in the data

const data = {
  nodes: [
    {
      id: "1",
      label: "Label 1",
      style: {
        fill: "orange"
      },
      stateStyles: {
        selected: {
          fill: "yellow"
        }
      }
    }
    // following nodes
  ]
}   

When you look at the node model

graph.getNodes()[0].getModel().style

// What you get
{
  selected: {
    fill: 'yellow'
  },
  fill: 'orange',
  lineWidth: 2,
}

// What it should be to stay consistent
{
  selected: {
    fill: 'yellow',
    lineWidth: 2,
  }
  fill: 'orange',
  lineWidth: 2,
}

Your Example Website or App

https://codesandbox.io/s/g6-styles-8zpnzb

Steps to Reproduce the Bug or Issue

  1. Open the codeSandbox and look at the console.

Expected behavior

Styles should merge instead of override.

Possible issue identification

here

mix() is used instead of deepMix() here


In the latest G6 5.0, we have adjusted the style calculation strategy so that the final style of the element will merge the style in the data, the default style, and the state style

posted by Aarebecca 12 months ago

Fund this Issue

$0.00
Funded

Pull requests