Nic30 / d3-hwschematic

D3.js and ELK based schematic visualizer
Eclipse Public License 2.0
94 stars 13 forks source link

Custom node renderers don't get chance to be selected #16

Closed dkilfoyle closed 4 years ago

dkilfoyle commented 4 years ago

Hi. Registering a custom node renderer via HwSchematic.nodeRenderers.registerRenderer() pushes the new renderer to the end of the renderers array which already has GenericNodeRenderer as the last item. NodeRendererContainer.prepare will match GenericNodeRenderer (selector always returns true) and the custom renderer doesn't have a chance to get selected. Perhaps need NodeRendererContainer.registerCustomRenderer to insert the custom renderer before the GenericNodeRenderer?

registerCustomRenderer(renderer) {
  this.renderers.splice(this.renderers.length-1, 0, renderer);
}

Thanks.

PS: Awesome project!

Nic30 commented 4 years ago

Hello,

it makes sense.

Now user can move renderes in specified list freely, but user does not know why his/hers renderer "does not work" after registerCustomRenderer.

But we need to add new rendered before GenericNodeRenderer and not on pre-last index. I mean something like this:

registerCustomRenderer(renderer) {
  var rs = this.renderers;
  for (var i = 0; i < rs.length; i++) {
     var r = rs[i];
     if (r instanceof GenericNodeRenderer) {
        // pushing before GenericNodeRenderer before GenericNodeRenderer renders all remaining nodes
        // so we need to query a new renderer first
        rs.splice(i, 0, renderer);
        return;
     }
  }
  rs.push(renderer);
}

Can you send a pull request?

Nic30 commented 4 years ago

@dkilfoyle Also, remove "org.eclipse.elk.randomSeed": 0, from your project if you want to have a deterministic layout.

Nic30 commented 4 years ago

Also, let's rename registerCustomRenderer to registerRenderer so we have smaller api.