Skip to content

How can I create a graph where I can move the position nodes and the unions (links) adapt??? #17635

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

Closed
baarbaracrr opened this issue Sep 8, 2022 · 2 comments
Labels
en This issue is in English support topic: graph

Comments

@baarbaracrr
Copy link

baarbaracrr commented Sep 8, 2022

Version

5.3

Current Behavior

I am not able to change the position of the nodes of a graph, and the only thing I can do is move the entire graph. I want each node to be in an exact position and to be able to move them and for the links to adapt (stretch or get smaller depending on the distance)

Expected Behavior

I want to do something like this https://echarts.apache.org/examples/en/editor.html?c=line-draggable but with a graph where i can manipulate the nodes and links.

Any additional comments?

btw i am using angular

No response

@baarbaracrr baarbaracrr added the bug label Sep 8, 2022
@echarts-bot echarts-bot bot added en This issue is in English pending We are not sure about whether this is a bug/new feature. labels Sep 8, 2022
@Ovilia
Copy link
Contributor

Ovilia commented Sep 9, 2022

You should follow the logic of https://echarts.apache.org/examples/en/editor.html?c=line-draggable and make sure the layout of your graph series should be 'none' and you need to provide x and y for each nodes.

@Ovilia Ovilia added support topic: graph waiting-for: author and removed bug pending We are not sure about whether this is a bug/new feature. labels Sep 9, 2022
@baarbaracrr
Copy link
Author

You should follow the logic of https://echarts.apache.org/examples/en/editor.html?c=line-draggable and make sure the layout of your graph series should be 'none' and you need to provide x and y for each nodes.

Hi Olivia, thanks for your answer, but I still can't get it. I have this in the HTML code:
<div echarts [options]="chartOption" (chartInit)="onChartInit($event)" id="main" class="mapDiagram nodes">

And in the Typescript code I have this:

import { Component, OnInit, AfterViewInit } from '@angular/core';
import { EChartsOption } from 'echarts';
import * as echarts from 'echarts';

@Component({
  selector: 'app-layout',
  templateUrl: './layout.component.html',
  styleUrls: ['./layout.component.css']
})
export class LayoutComponent implements AfterViewInit {

  public myChart: any;
  public chartOption: EChartsOption = {};
  public symbolSize = 20;
  public data = [
      [15, 0],
      [-50, 10],
      [-56.5, 20],
      [-46.5, 30],
      [-22.1, 40]
    ];

  constructor() { 
  }

  ngOnInit(): void {
  }

  ngAfterViewInit(): void {
    this.chartOption = {
      xAxis: {
        min: -100,
        max: 80,
        type: 'value',
        axisLine: { onZero: false }
      },
      yAxis: {
        min: -30,
        max: 60,
        type: 'value',
        axisLine: { onZero: false }
      },
      series: [
        {
          id: 'a',
          type: 'line',
          smooth: true,
          // Set a big symbolSize for dragging convenience.
          symbolSize: this.symbolSize,
          data: this.data
        }
      ]
    };
  }

  onChartInit(ec: any) {
    this.myChart = ec;

    let that = this;
    this.myChart.setOption({
      // Declare a graphic component, which contains some graphic elements
      // with the type of 'circle'.
      // Here we have used the method `echarts.util.map`, which has the same
      // behavior as Array.prototype.map, and is compatible with ES5-.
      graphic: echarts.util.map(this.data, function(dataItem, dataIndex) {
        return {
          // 'circle' means this graphic element is a shape of circle.
          type: 'circle',
    
          shape: {
            // The radius of the circle.
            r: that.symbolSize / 2
          },
          // Transform is used to located the circle. position:
          // [x, y] means translate the circle to the position [x, y].
          // The API `convertToPixel` is used to get the position of
          // the circle, which will introduced later.
          position: that.myChart.convertToPixel('grid', dataItem),
    
          // Make the circle invisible (but mouse event works as normal).
          invisible: true,
          // Make the circle draggable.
          draggable: true,
          // Give a big z value, which makes the circle cover the symbol
          // in line series.
          z: 100,
          // This is the event handler of dragging, which will be triggered
          // repeatly while dragging. See more details below.
          // A util method `echarts.util.curry` is used here to generate a
          // new function the same as `onPointDragging`, except that the
          // first parameter is fixed to be the `dataIndex` here.
          ondrag: function (dx: number, dy: number) {
            that.onPointDragging(dataIndex, [dx, dy]);
          }
        };
      })
    });
  }

  onPointDragging(dataIndex: any, pos: number[]) {
    // Here the `data` is declared in the code block in the beginning
    // of this article. The `this` refers to the dragged circle.
    // `this.position` is the current position of the circle.
    this.data[dataIndex] = this.myChart.convertFromPixel('grid', pos);
    // Re-render the chart based on the updated `data`.
    this.myChart.setOption({
      series: [
        {
          id: 'a',
          data: this.data
        }
      ]
    });
  }

}

But I can not resolve the next bug that appear in the console:
image
And the lines of the bug in my code is the next:
position: that.myChart.convertToPixel('grid', dataItem),
and
graphic: echarts.util.map(this.data, function(dataItem, dataIndex) {

@baarbaracrr baarbaracrr closed this as not planned Won't fix, can't repro, duplicate, stale Sep 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
en This issue is in English support topic: graph
Projects
None yet
Development

No branches or pull requests

2 participants