src/widgets/Arrow.js
author ymh <ymh.work@gmail.com>
Thu, 17 Oct 2024 00:58:24 +0200
changeset 1073 687133dc13cf
parent 1072 ac1eacb3aa33
permissions -rw-r--r--
Add VideojsPlayer for handling youtube and vimeo
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
     1
import Raphael from "raphael";
876
03967b6ada7c ArrowWidget, AnnotationWidget
veltr
parents:
diff changeset
     2
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
     3
// Arrow
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
     4
const Arrow = function (ns) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
     5
  return class extends ns.Widgets.Widget {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
     6
    constructor(player, config) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
     7
      super(player, config);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
     8
      this.current_pilot_widget = this.pilot_widget;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
     9
    }
876
03967b6ada7c ArrowWidget, AnnotationWidget
veltr
parents:
diff changeset
    10
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    11
    static defaults = {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    12
      arrow_height: 12,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    13
      arrow_width: 20,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    14
      base_height: 0,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    15
      base_curve: 0,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    16
      fill_url: ns.widgetsDir + "/img/pinstripe.png",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    17
      fill_color: "#ffffff", //Gradients can be used, e.g. "90-#000-#fff" for vertical white-to-black
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    18
      stroke_color: "#b7b7b7",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    19
      stroke_width: 1.5,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    20
      animation_speed: 20,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    21
    };
876
03967b6ada7c ArrowWidget, AnnotationWidget
veltr
parents:
diff changeset
    22
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    23
    draw() {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    24
      this.height = this.arrow_height + this.base_height;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    25
      this.$.addClass("Ldt-Arrow").css({
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    26
        height: 1 + this.height + "px",
965
eadb7290c325 Improvements in widget communication
veltr
parents: 957
diff changeset
    27
        "margin-top": "1px",
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    28
        overflow: "hidden",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    29
      });
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    30
      this.paper = new Raphael(this.container, this.width, 1 + this.height);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    31
      window.myArrow = this;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    32
      this.svgArrow = this.paper.path(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    33
        "M0," + this.height + "L" + this.width + "," + this.height
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    34
      );
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    35
      this.svgArrow.attr({
880
4c7b33bf2795 Started work on CreateAnnotation and Mediafragment
veltr
parents: 876
diff changeset
    36
        stroke: this.stroke_color,
4c7b33bf2795 Started work on CreateAnnotation and Mediafragment
veltr
parents: 876
diff changeset
    37
        "stroke-width": this.stroke_width,
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    38
        fill: this.fill_url ? "url(" + this.fill_url + ")" : this.fill_color,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    39
      });
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    40
      this.moveToX(0);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    41
    }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    42
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    43
    drawAt(_x) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    44
      _x = Math.max(0, Math.min(_x, this.width));
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    45
      var _d =
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    46
        "M0," +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    47
        this.height +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    48
        "L0," +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    49
        Math.min(this.height, this.arrow_height + this.base_curve) +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    50
        "Q0," +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    51
        this.arrow_height +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    52
        " " +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    53
        Math.max(0, Math.min(this.base_curve, _x - this.arrow_width / 2)) +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    54
        "," +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    55
        this.arrow_height +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    56
        "L" +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    57
        Math.max(0, _x - this.arrow_width / 2) +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    58
        "," +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    59
        this.arrow_height +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    60
        "L" +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    61
        Math.max(0, _x - this.arrow_width / 2) +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    62
        "," +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    63
        Math.min(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    64
          this.arrow_height,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    65
          (2 * this.arrow_height * _x) / this.arrow_width
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    66
        ) +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    67
        "L" +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    68
        _x +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    69
        ",0" +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    70
        "L" +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    71
        Math.min(this.width, _x + this.arrow_width / 2) +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    72
        "," +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    73
        Math.min(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    74
          this.arrow_height,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    75
          (2 * this.arrow_height * (this.width - _x)) / this.arrow_width
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    76
        ) +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    77
        "L" +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    78
        Math.min(this.width, _x + this.arrow_width / 2) +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    79
        "," +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    80
        this.arrow_height +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    81
        "L" +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    82
        Math.min(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    83
          this.width,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    84
          Math.max(this.width - this.base_curve, _x + this.arrow_width / 2)
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    85
        ) +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    86
        "," +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    87
        this.arrow_height +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    88
        "Q" +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    89
        this.width +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    90
        "," +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    91
        this.arrow_height +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    92
        " " +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    93
        this.width +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    94
        "," +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    95
        Math.min(this.height, this.arrow_height + this.base_curve) +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    96
        "L" +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    97
        this.width +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    98
        "," +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
    99
        this.height;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   100
      this.svgArrow.attr({
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   101
        path: _d,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   102
      });
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   103
    }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   104
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   105
    moveToX(_x) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   106
      this.targetX = Math.max(0, Math.min(_x, this.width));
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   107
      if (typeof this.animInterval === "undefined") {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   108
        this.animInterval = window.setInterval(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   109
          this.functionWrapper("increment"),
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   110
          40
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   111
        );
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   112
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   113
      this.increment();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   114
    }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   115
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   116
    moveToTime(_t) {
1073
687133dc13cf Add VideojsPlayer for handling youtube and vimeo
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   117
      if (this.media) {
687133dc13cf Add VideojsPlayer for handling youtube and vimeo
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   118
        this.moveToX((this.width * _t) / this.media.duration);
687133dc13cf Add VideojsPlayer for handling youtube and vimeo
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   119
      }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   120
    }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   121
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   122
    increment() {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   123
      if (typeof this.currentX === "undefined") {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   124
        this.currentX = this.targetX;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   125
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   126
      if (this.currentX < this.targetX) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   127
        this.currentX = Math.min(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   128
          this.targetX,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   129
          this.currentX + this.animation_speed
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   130
        );
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   131
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   132
      if (this.currentX > this.targetX) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   133
        this.currentX = Math.max(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   134
          this.targetX,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   135
          this.currentX - this.animation_speed
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   136
        );
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   137
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   138
      if (this.currentX === this.targetX) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   139
        window.clearInterval(this.animInterval);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   140
        this.animInterval = undefined;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   141
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   142
      this.drawAt(this.currentX);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   143
    }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   144
  };
1013
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 965
diff changeset
   145
};
876
03967b6ada7c ArrowWidget, AnnotationWidget
veltr
parents:
diff changeset
   146
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1021
diff changeset
   147
export { Arrow };