This repository was archived by the owner on Feb 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
68 lines (53 loc) · 1.9 KB
/
Copy pathindex.js
File metadata and controls
68 lines (53 loc) · 1.9 KB
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
import * as d3 from "d3" // You could refine this to certain modules only
// Your plugin's closure
export default function() {
"use strict";
// A private variable
var color = "#328a60"
// A private method
var update = function() {}
// Plugin implementation operating on the provided selection,
// usually an SVG object.
function pluginImpl(selection) {
selection.each(function(data) {
// Next lines are just simple demo code, i.e., this boilerplate
// would append rectangles to the selection with the dimensions
// determined by the data provided.
// Replace the below code with your own initialization
// implementation ...
var s = d3.select(this)
s.selectAll(".rect")
.data(data).enter()
.append("rect")
.attr("class", "rect")
.attr("width", function(d) {
return d["width"]
})
.attr("height", function(d) {
return d["height"]
})
// We have reached the update-function...
update = function(first) {
first = first || false
first // just to trick the linter.
// add updatable part of charts here. The example sets
// the rectangles to the provided color.
s.selectAll(".rect")
.attr("fill", color)
}
update(true)
})
}
// A getter/setter best-practise method for private variables
pluginImpl.color = function(value) {
if (!arguments.length) return color
color = value;
return pluginImpl;
}
// A method to invoke the private update method
pluginImpl.update = function() {
update()
return pluginImpl
}
return pluginImpl;
}