-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathrhumbs.js
99 lines (89 loc) · 3.04 KB
/
rhumbs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { getangle } from "../helpers/getangle.js";
// rhumbs
export function rhumbs(selection, width, height, clipid, options = {}) {
let visibility = options.visibility ? options.visibility : "visible";
let nb = options.nb != undefined ? options.nb : 16;
let position =
options.position != undefined
? options.position
: [width / 4, height - height / 4];
let stroke = options.stroke ? options.stroke : "#394a70";
let strokeWidth = options.strokeWidth != undefined ? options.strokeWidth : 1;
let strokeOpacity =
options.strokeOpacity != undefined ? options.strokeOpacity : 0.3;
let strokeDasharray = options.strokeDasharray
? options.strokeDasharray
: [3, 2];
let angles = getangle(nb);
let size = Math.max(width, height);
selection
.append("g")
.attr("class", options.id)
.attr("data-layer", JSON.stringify({ _type: "rhumbs" }))
.attr("fill", "none")
.attr("visibility", visibility)
.attr("stroke", stroke)
.attr("stroke-opacity", strokeOpacity)
.attr("stroke-width", strokeWidth)
.attr("stroke-dasharray", strokeDasharray)
.attr("clip-path", clipid == null ? `none` : `url(#clip_${clipid})`)
.selectAll("polyline")
.data(angles)
.join("polyline")
.attr("points", function (d, i) {
let x2 = position[0] + Math.cos(d) * size;
let y2 = position[1] + Math.sin(d) * size;
return position[0] + "," + position[1] + " " + x2 + "," + y2;
});
// Update function
// selection.node().update = update;
// function update({
// id = null,
// attr = null,
// value = null,
// duration = 0,
// delay = 0,
// } = {}) {
// selection
// .select(`g.${id}`)
// .transition()
// .delay(delay)
// .duration(duration)
// .attr(getattr(attr), value)
// .style(getattr(attr), value);
// let node = selection.select(`g.${id}`);
// if (attr == "nb") {
// let node = selection.select(`g.${id}`);
// let pos = node.selectAll("polyline").nodes()[0].animatedPoints[0];
// selection
// .select(`g.${id}`)
// .selectAll("polyline")
// .data(getangle(value))
// .join("polyline")
// .transition()
// .delay(delay)
// .duration(duration)
// .attr("points", function (d, i) {
// let x2 = pos.x + Math.cos(d) * size;
// let y2 = pos.y + Math.sin(d) * size;
// return pos.x + "," + pos.y + " " + x2 + "," + y2;
// });
// }
// if (attr == "position") {
// let node = selection.select(`g.${id}`);
// selection
// .select(`g.${id}`)
// .selectAll("polyline")
// .data(getangle(node.selectAll("polyline").size()))
// .join("polyline")
// .transition()
// .delay(delay)
// .duration(duration)
// .attr("points", function (d, i) {
// let x2 = value[0] + Math.cos(d) * size;
// let y2 = value[1] + Math.sin(d) * size;
// return value[0] + "," + value[1] + " " + x2 + "," + y2;
// });
// }
// }
}