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

Network Graph - Cannot remove a node #10565

Closed
jeffersonswartz opened this issue Apr 16, 2019 · 6 comments

Comments

Projects
None yet
2 participants
@jeffersonswartz
Copy link

commented Apr 16, 2019

Expected behaviour

The removePoint is not removing the exact node.

Actual behaviour

It is removing the link alone not the node

Live demo with steps to reproduce

Try clicking the remove point button
https://jsfiddle.net/jeffersonswartz/o89Lrq6s/11/

Product version

Highcharts - 7.1.0

Affected browser(s)

Chrome - Windows - Version 73.0.3683.86 (Official Build) (64-bit)

@pawelfus

This comment has been minimized.

Copy link
Contributor

commented Apr 16, 2019

Thanks for reporting @jeffersonswartz

Workaround:
Use series.points[index].remove() instead: https://jsfiddle.net/BlackLabel/04xcy37m/

@pawelfus pawelfus added the Type: Bug label Apr 16, 2019

@jeffersonswartz

This comment has been minimized.

Copy link
Author

commented Apr 16, 2019

Thanks for the super quick reply @pawelfus :)

But it still removes the link not the node. What should I do to remove the node completely?

@pawelfus

This comment has been minimized.

Copy link
Contributor

commented Apr 16, 2019

Good point! This should be possible by calling chart.series[index].nodes[index].remove(), but apparently it's broken too.

@pawelfus pawelfus self-assigned this Apr 16, 2019

@jeffersonswartz

This comment has been minimized.

Copy link
Author

commented Apr 16, 2019

That's Unfortunate.

Actually what I am trying to achieve is When we click a node all the child nodes will be hidden and when we click again it will be shown. It is just like collapsing and expanding a node.

Is there a workaround to achieve this?

@pawelfus

This comment has been minimized.

Copy link
Contributor

commented Apr 17, 2019

With the snippet below, series.nodes[index].remove() will be supported. Could you @jeffersonswartz test this solution? I have tested some basic operations and it looks promising. Please, let me me know if you find any bugs, I will try to fix this asap.

Workaround:
Demo: https://jsfiddle.net/BlackLabel/u0d2eky8/

Highcharts.seriesTypes.networkgraph.prototype.pointClass.prototype.remove = function(redraw, animation) {
  var point = this,
    series = point.series,
    dataOptions = series.options.data,
    nodesOptions = series.options.nodes || [],
    links = series.points,
    index,
    i = nodesOptions.length;

  // For nodes, remove all connected links:
  if (point.isNode) {
    // Temporrary disable series.points array, beacuse
    // Series.removePoint() modifies it
    series.points = [];

    // Remove link from all nodes collections:
    [].concat(point.linksFrom)
      .concat(point.linksTo)
      .forEach(
        function(linkFromTo) {
          // Incoming links
          index = linkFromTo.fromNode.linksFrom.indexOf(
            linkFromTo
          );
          if (index > -1) {
            linkFromTo.fromNode.linksFrom.splice(
              index,
              1
            );
          }

          // Outcoming links
          index = linkFromTo.toNode.linksTo.indexOf(
            linkFromTo
          );
          if (index > -1) {
            linkFromTo.toNode.linksTo.splice(
              index,
              1
            );
          }

          // Remove link from data/points collections
          Highcharts.Series.prototype.removePoint.call(
            series,
            series.data.indexOf(linkFromTo),
            false,
            false
          );
        }
      );

    // Restore points array, after links are removed
    series.points = series.data.slice();

    // Proceed with removing node. It's similar to
    // Series.removePoint() method, but don't modify other arrays
    series.nodes.splice(series.nodes.indexOf(point), 1);

    // Remove node options from config
    while (i--) {
      if (nodesOptions[i].id === point.options.id) {
        series.options.nodes.splice(i, 1);
        break;
      }
    }

    if (point) {
      point.destroy();
    }

    // Run redraw if requested
    series.isDirty = true;
    series.isDirtyData = true;
    if (redraw) {
      series.chart.redraw(redraw);
    }
  } else {
    series.removePoint(
      series.data.indexOf(point),
      redraw,
      animation
    );
  }
};

pawelfus added a commit that referenced this issue Apr 17, 2019

Added `series.nodes[index].remove()` method to networkgraph series to…
… remove a node with all connected links. Closes #10565.
@jeffersonswartz

This comment has been minimized.

Copy link
Author

commented Apr 26, 2019

@pawelfus Sorry for the late reply and Thanks for the workaround, It works fine in all the cases that I have tested.

@ghost ghost added the Status: Pending review label Apr 26, 2019

TorsteinHonsi added a commit that referenced this issue Apr 29, 2019

Added `series.nodes[index].remove()` method to networkgraph series to…
… remove a node with all connected links. Closes #10565.

@ghost ghost removed the Status: Pending review label Apr 29, 2019

activist added a commit that referenced this issue Apr 29, 2019

Added `series.nodes[index].remove()` method to networkgraph series to…
… remove a node with all connected links. Closes #10565.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.