forked from susielu/d3-legend
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.html
154 lines (133 loc) · 3.79 KB
/
example.html
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<!DOCTYPE html>
<meta charset="utf-8" />
<style>
body {
margin: 0;
overflow: hidden;
}
svg {
font: 10px sans-serif;
}
.caption {
font-weight: bold;
}
.key path {
display: none;
}
.key line {
stroke: #000;
shape-rendering: crispEdges;
}
</style>
<body>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="../d3-legend.min.js"></script>
<script>
var width = 960,
height = 500,
formatPercent = d3.format(".0%"),
formatNumber = d3.format(".0f")
var svg = d3
.select("body")
.append("svg")
.attr("width", width)
.attr("height", height)
// var g = svg
// .append("g")
// .attr("class", "key")
// .attr(
// "transform",
// "translate(" + (width - 240) / 2 + "," + height / 2 + ")"
// )
// // var linear = d3
// // .scaleLinear()
// // .domain([0, 10])
// // .range(["rgb(46, 73, 123)", "rgb(71, 187, 94)"])
// // var linear = d3
// // .scaleTime()
// // .domain([new Date(2000, 0, 1), new Date(2000, 0, 2)])
// // .range(["rgb(46, 73, 123)", "rgb(71, 187, 94)"])
// // svg
// // .append("g")
// // .attr("class", "legendLinear")
// // .attr("transform", "translate(20,20)")
// // var legendLinear = d3
// // .legendColor()
// // .shapeWidth(30)
// // .orient("horizontal")
// // // .labelFormat(d3.timeFormat("%B"))
// // .scale(linear)
// // console.log(d3.timeFormat("%B"), d3.timeFormat("%B")(new Date()))
// // console.log(d3.formatSpecifier(d3.timeFormat("%B")))
// // svg.select(".legendLinear").call(legendLinear)
// var ordinal = d3
// .scaleOrdinal()
// .domain(["a"])
// .range(["rgb(153, 107, 195)"])
// svg
// .append("g")
// .attr("class", "legendOrdinal")
// .attr("transform", "translate(20,20)")
// var legendOrdinal = d3
// .legendColor()
// //d3 symbol creates a path-string, for example
// //"M0,-8.059274488676564L9.306048591020996,
// //8.059274488676564 -9.306048591020996,8.059274488676564Z"
// .shape(
// "path",
// d3
// .symbol()
// .type(d3.symbolTriangle)
// .size(150)()
// )
// .shapePadding(10)
// //use cellFilter to hide the "e" cell
// .cellFilter(function(d) {
// return d.label !== "e"
// })
// .scale(ordinal)
// svg.select(".legendOrdinal").call(legendOrdinal)
var colorLegendG__3 = d3
.select("svg")
.append("g")
.attr("class", "color-legend")
.attr("transform", "translate(40, 160)")
var colorScale__3 = d3.scaleOrdinal(d3.schemeCategory10).domain([0, 9])
var colorLegend__3 = d3
.legendColor()
.scale(colorScale__3)
.shapePadding(3)
.shapeWidth(10)
.shapeHeight(10)
.labelOffset(4)
.on("cellclick", function(d, e) {
// Determine if current line is visible
console.log(d, e)
var active = d.active ? false : true,
newOpacity = active ? 0 : 1
// Hide or show the elements based on the ID
d3.select("#tag" + d.key.replace(/\s+/g, ""))
.transition()
.duration(100)
.style("opacity", newOpacity)
// Update whether or not the elements are active
d.active = active
})
// var nested__3 = d3
// .nest()
// .key(function(d) {
// return d.lineColumn__3
// })
// .entries(data.data)
// Loop through each symbol / key
// nested__3.forEach(function(d, i) {
// //UUSI
// colorScale__3.domain(
// nested__3.map(function(d) {
// return d.key
// })
// )
colorLegendG__3.call(colorLegend__3)
// })
</script>
</body>