Iterate to change color

Hi,

I succesfully implemented the spectrum as in your example of html implementation.

Now I’m trying to change the colors of all nodes when several are implemented.
This is what I have so far:

http://pastebin.com/iSGqqGq7

For some reason only the first selected changes color.

I know something is not right in the code as I’m initializing the spectrum probably several times.
But I’m lost on how to fix this.

I believe that sample is assuming there is only one part that is selected. For your purposes the code needs to iterate over the Diagram.selection collection, finding and modifying a named Shape inside each Part.

Isn’t that what I’ve done in my code? (check pastebin link)

But you need to do that loop in the event handler, not outside the invocation of the spectrum control.

aaah k thx wasn’t thinking straight :)

but the addChangedListener does seem to give me a problem when manual linking two nodes.

This is the error I get:
Uncaught TypeError: Cannot read property ‘fill’ of null

This is thrown on the color: shape.fill from the spectrum.
See here: http://pastebin.com/Yt9E1ny5

So you are saying that the value of Panel.findObject(“shape”), called on the Node, is returning null? I cannot explain that. I don’t understand why you are talking about linking two nodes.

Is the problem that the selected Part is a Link, not a Node? If so, you just need to make sure that the main link Shape is named “shape” too.

Well here is my example:
http://scripttesting.com/mindmapping/

this is for my school project. When you click on the plus sign after selecting a node, it all goes as expected. When you double click to create a new node and link those 2 I get that error as stated before. My gojs templating code can be found here: http://scripttesting.com/mindmapping/assets/js/diagram/diagram.js

Drawing a new link does cause that new Link to be selected.

You’ll need to debug that yourself.

Well I kind of fixed it using the following:

var elem = sel.first();
var link = elem.findObject(“link”);
if(link != null){
return;
}

seems to work perfectly :) Thanks for the info, didnt know creating a link, selected it.

To see if something is a Link, you should use:

  elem instanceof go.Link