Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

大佬 对于updateItem更新节点的样式 不生效是啥原因 #50

Open
xiano5 opened this issue Jul 24, 2020 · 10 comments
Open

大佬 对于updateItem更新节点的样式 不生效是啥原因 #50

xiano5 opened this issue Jul 24, 2020 · 10 comments

Comments

@xiano5
Copy link

xiano5 commented Jul 24, 2020

No description provided.

@guozhaolong
Copy link
Owner

不应该啊,你触发updateItem的代码发来看看,或者你手动触发一下graph.refreshItem(item)试试?

@xiano5
Copy link
Author

xiano5 commented Jul 24, 2020

不应该啊,你触发updateItem的代码发来看看,或者你手动触发一下graph.refreshItem(item)试试?

网上说“graph.updateItem(item, style)更新样式只会对nodeStyle或graph.node(fn)中定义的default样式及配置起作用 ” 真的吗 我这是自定义节点 我代码确定updateItem是触发了的 能更改label x y 等属性 就是改不了style 求大佬解答 谢谢了

@xiano5
Copy link
Author

xiano5 commented Jul 24, 2020

{"id":"smNode1595562518126","clazz":"smNode","size":[80,44],"label":"测试","shape":"sms-node","x":165,"y":247,"style":{"stroke":"black","fill":"red"}} 我打印了节点的属性有我更改的style 但是却没有渲染

@xiano5
Copy link
Author

xiano5 commented Jul 24, 2020

`G6.registerNode('sms-node', {
shapeType: 'rect',
options:{
...taskDefaultOptions
},
getShapeStyle(cfg) {
cfg.size = [80, 44];
const width = cfg.size[0];
const height = cfg.size[1];
const style = {
x: 0 - width / 2,
y: 0 - height / 2,
width,
height,
fill: '#c8dff5',
stroke:'#1890FF',
cursor: 'default',

  };
  return style;
},
labelPosition: 'bottom',
getAnchorPoints() {
  return [
    [0.5, 0.01], // top
    [1, 0.5],
    [0.35, 1],
    [0.01, 0.5],
    [0.7,1]
  ]
}

}, 'base-node');`自定义节点代码

@wrh4585
Copy link

wrh4585 commented Jul 27, 2020

`G6.registerNode('sms-node', {
shapeType: 'rect',
options:{
...taskDefaultOptions
},
getShapeStyle(cfg) {
cfg.size = [80, 44];
const width = cfg.size[0];
const height = cfg.size[1];
const style = {
x: 0 - width / 2,
y: 0 - height / 2,
width,
height,
fill: '#c8dff5',
stroke:'#1890FF',
cursor: 'default',

  };
  return style;
},
labelPosition: 'bottom',
getAnchorPoints() {
  return [
    [0.5, 0.01], // top
    [1, 0.5],
    [0.35, 1],
    [0.01, 0.5],
    [0.7,1]
  ]
}

}, 'base-node');`自定义节点代码

你好,我这边也遇到这个问题,this.graph.updateItem方法调用后,控制台打印节点信息,可以看到节点的样式变化了,但是视图上没有变化。请问下,你这边怎么解决的呢?

@guozhaolong
Copy link
Owner

我测试了一下,通过this.graph.updateItem(item, {style :{"stroke":"black","fill":"red"}})调用的话,只能改边框的颜色,很奇怪;可以通过item.getKeyShape().attr({"stroke":"black","fill":"red"})直接改图形的style
image

@xiano5
Copy link
Author

xiano5 commented Jul 27, 2020

`G6.registerNode('sms-node', {
shapeType: 'rect',
options:{
...taskDefaultOptions
},
getShapeStyle(cfg) {
cfg.size = [80, 44];
const width = cfg.size[0];
const height = cfg.size[1];
const style = {
x: 0 - width / 2,
y: 0 - height / 2,
width,
height,
fill: '#c8dff5',
stroke:'#1890FF',
cursor: 'default',

  };
  return style;
},
labelPosition: 'bottom',
getAnchorPoints() {
  return [
    [0.5, 0.01], // top
    [1, 0.5],
    [0.35, 1],
    [0.01, 0.5],
    [0.7,1]
  ]
}

}, 'base-node');`自定义节点代码

你好,我这边也遇到这个问题,this.graph.updateItem方法调用后,控制台打印节点信息,可以看到节点的样式变化了,但是视图上没有变化。请问下,你这边怎么解决的呢?

this.graph.updateItem不能修改自定义节点的颜色 只能更改默认的节点颜色 我是通过setstateItem设置颜色的

@xiano5
Copy link
Author

xiano5 commented Jul 27, 2020

我测试了一下,通过this.graph.updateItem(item, {style :{"stroke":"black","fill":"red"}})调用的话,只能改边框的颜色,很奇怪;可以通过item.getKeyShape().attr({"stroke":"black","fill":"red"})直接改图形的style
image

感谢大佬

@wrh4585
Copy link

wrh4585 commented Jul 27, 2020

`G6.registerNode('sms-node', {
shapeType: 'rect',
options:{
...taskDefaultOptions
},
getShapeStyle(cfg) {
cfg.size = [80, 44];
const width = cfg.size[0];
const height = cfg.size[1];
const style = {
x: 0 - width / 2,
y: 0 - height / 2,
width,
height,
fill: '#c8dff5',
stroke:'#1890FF',
cursor: 'default',

  };
  return style;
},
labelPosition: 'bottom',
getAnchorPoints() {
  return [
    [0.5, 0.01], // top
    [1, 0.5],
    [0.35, 1],
    [0.01, 0.5],
    [0.7,1]
  ]
}

}, 'base-node');`自定义节点代码

你好,我这边也遇到这个问题,this.graph.updateItem方法调用后,控制台打印节点信息,可以看到节点的样式变化了,但是视图上没有变化。请问下,你这边怎么解决的呢?

this.graph.updateItem不能修改自定义节点的颜色 只能更改默认的节点颜色 我是通过setstateItem设置颜色的
我这边主要是要实现节点的拖放功能,先谢谢啦,后面应该也会对颜色进行修改

@xiano5
Copy link
Author

xiano5 commented Jul 27, 2020

`G6.registerNode('sms-node', {
shapeType: 'rect',
options:{
...taskDefaultOptions
},
getShapeStyle(cfg) {
cfg.size = [80, 44];
const width = cfg.size[0];
const height = cfg.size[1];
const style = {
x: 0 - width / 2,
y: 0 - height / 2,
width,
height,
fill: '#c8dff5',
stroke:'#1890FF',
cursor: 'default',

  };
  return style;
},
labelPosition: 'bottom',
getAnchorPoints() {
  return [
    [0.5, 0.01], // top
    [1, 0.5],
    [0.35, 1],
    [0.01, 0.5],
    [0.7,1]
  ]
}

}, 'base-node');`自定义节点代码

你好,我这边也遇到这个问题,this.graph.updateItem方法调用后,控制台打印节点信息,可以看到节点的样式变化了,但是视图上没有变化。请问下,你这边怎么解决的呢?

this.graph.updateItem不能修改自定义节点的颜色 只能更改默认的节点颜色 我是通过setstateItem设置颜色的
我这边主要是要实现节点的拖放功能,先谢谢啦,后面应该也会对颜色进行修改

楼主也说了一种方法 就在头上 你也可以看下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants