如何在Angular 8中创建属性之间的关系图?

huangapple go评论62阅读模式
英文:

How to make a relationship diagram between attributes in Angular 8?

问题

我是新手使用Angular 8,需要一些帮助...

我有三个数据库表格,如下所示:

Entities表格
Entity_id Entity_name
1 first_entity
2 second_entity....以此类推

Attributes表格
attribute_id attribute_name
1 first_attr
2 second_attr....以此类推

Entity_attribute Mapping表格
id Entity_id attribute_id
1 1 2
2 1 3
3 1 4
4 2 5
5 2 6
6 2 7等等...

如您所见,一个实体具有多个属性。在前端,我正在列出所有实体在左侧,单击任何实体将显示相关属性。

如何在Angular 8中创建属性之间的关系图?

还有一个来自API的表格数据:

Attributes relations表格
id entity_id attribute_id entity_foreign_key_id attributed_foreign_key_id
1 1 2 3 5
2 1 3 4 7

在上面的表格中,我获取了不同实体的属性之间的关系。我想要在属性之间绘制图像或线条,如下图所示。

如何在Angular 8中创建属性之间的关系图?

当单击任何实体时,我调用此方法:

showAttributes(entityId) {
    this.entandApi.getAttributes_by_entity(entityId).subscribe((data: any) => {
      let getAttributeResp = data;
    })
  }

我尝试使用jQuery的以下代码:

var line = $('#line');
var div1 = $('#first-div');
var div2 = $('#second-div');

var x1 = div1.offset().left + (div1.width());
var y1 = div1.offset().top + (div1.height()/2);
var x2 = div2.offset().left;
var y2 = div2.offset().top+ (div1.height()/2);

line.attr('x1',x1).attr('y1',y1).attr('x2',x2).attr('y2',y2);

但不确定如何在Angular 8中实现这一点。

任何帮助将不胜感激。

英文:

I am new to angular 8 and need some help...

I have 3 database tables like below:

**Entities table**
Entity_id  Entity_name
  1         first_entity
  2         second_entity....and so on
**Attributes table**
attribute_id  attribute_name
  1           first_attr
  2           second_attr....and so on
**Enitity_attribute Mapping**   
  id          Entity_id                      attribute_id               
  1           1                                2
  2           1                                3
  3           1                                4
  4           2                                5
  5           2                                6
  6           2                                7 and so on...

As you can see one entity has multiple attributes. In the front end, I am listing down all the entities in the left side and clicking on any entity will show related attribute

如何在Angular 8中创建属性之间的关系图?

one more table data coming from api:

**Attributes relations**
 id           entity_id        attribute_id   entity_foreign_key_id  attributed_foreign_key_id
  1           1                 2                  3                     5
  2           1                 3                  4                     7

In above table I am getting the relation between the attributes of different entities. I want draw image or line between the attributes as shown in below picture.如何在Angular 8中创建属性之间的关系图?

I am calling this method when any entity is clicked:

showAttributes(entityId) {
    this.entandApi.getAttributes_by_entity(entityId).subscribe((data: any) => {
      let getAttributeResp = data;
    })
  }

I have tried below code using jquery:

var line = $('#line');
var div1 = $('#first-div');
var div2 = $('#second-div');

var x1 = div1.offset().left + (div1.width());
var y1 = div1.offset().top + (div1.height()/2);
var x2 = div2.offset().left;
var y2 = div2.offset().top+ (div1.height()/2);

line.attr('x1',x1).attr('y1',y1).attr('x2',x2).attr('y2',y2);

But not sure how to achieve this in Angular 8.

Any help would be appreciated.

答案1

得分: 1

我已使用这个库 https://anseki.github.io/leader-line/,并且它按预期工作。以下是我使用的代码:

<div id="start">start</div>
<div id="end">end</div>

new LeaderLine(
  document.getElementById('start'),
  document.getElementById('end')
);
英文:

I have used this library https://anseki.github.io/leader-line/ and it is working as expected. Below is the code I used

&lt;div id=&quot;start&quot;&gt;start&lt;/div&gt;
&lt;div id=&quot;end&quot;&gt;end&lt;/div&gt;

new LeaderLine(
  document.getElementById(&#39;start&#39;),
  document.getElementById(&#39;end&#39;)
);

huangapple
  • 本文由 发表于 2020年1月3日 21:29:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/59579454.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定