Drawing arrows on an HTML page to visualize semantic links between textual spans

前端 未结 10 1538
轮回少年
轮回少年 2020-11-30 18:56

I have an HTML page with some textual spans marked up something like this:

...
p50
...


        
10条回答
  •  [愿得一人]
    2020-11-30 19:04

    I needed a similar solution, and I was looking into RaphaelJS JavaScript Library. For example you can draw a straight arrow from (x1,y1) to (x2,y2) with:

    Raphael.fn.arrow = function (x1, y1, x2, y2, size) {
      var angle = Math.atan2(x1-x2,y2-y1);
      angle = (angle / (2 * Math.PI)) * 360;
      var arrowPath = this.path(“M” + x2 + ” ” + y2 + ” L” + (x2 - size) + ” ” + (y2 - size) + ” L” + (x2 - size) + ” ” + (y2 + size) + ” L” + x2 + ” ” + y2 ).attr(“fill”,”black”).rotate((90+angle),x2,y2);
      var linePath = this.path(“M” + x1 + ” ” + y1 + ” L” + x2 + ” ” + y2);
      return [linePath,arrowPath];
    }
    

    I haven't figure out how to draw a curved arrow, but I'm sure it's possible.

提交回复
热议问题