forked from sleamer/colorchart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
267 lines (222 loc) · 8.77 KB
/
index.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="description" content="Examining the relationships between colors, pigments, and brands.">
<title>Paint Color Wheel</title>
<link rel="stylesheet" type="text/css" href="css/colorstyle.css">
<script src="http://d3js.org/d3.v3.js" charset="utf-8"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js" charset="utf-8"></script>
</head>
<body>
<h1>Paint Company Color Wheel</h1>
<form name="companyFilterForm"><!-- indexed in DOM at form[0] -->
Select a Company:
<select id="company">
<option value="Golden">Golden Acrylic</option>
<option value="Liquitex">Liquitex Acrylic</option>
</select>
<input type="button" value="Pick" onClick="companyPicker()">
</form>
<div id="vis"><!-- SAL: Visualization is inserted into this section -->
<div id="welcomeBox"><p>Welcome to this visualization of color company offerings. I used Munsell scales from Golden and Liquitex to map their measurements to the closest approximation in an munsell to rgb chart. </p>
<img src="images/Munsell_color_sphere.png" height="300">
<h3>References</h3>
<p>Built with <a href="http://d3js.org">D3.js</a>.
Sunburst zooming based on an <a href="http://bl.ocks.org/mbostock/4348373">example</a> by <a href="http://bost.ocks.org/mike">Mike Bostock</a>.</p>
<p>Golden Acrylic <a href="http://www.goldenpaint.com">Munsell Notation</a></p>
<p>Liquitex Acrylic <a href="http://www.liquitex.com/">Munsell Notation</a></p>
</div><!-- id="welcomeBox" -->
</div><!-- id="vis" -->
<!--
<h2>Colors</h2>
<p>
<ul>
<li><a href="chromium_oxide_green.html">Chromium Oxide Green</a></li>
<li><a href="raw_umber.html">Raw Umber</a></li>
</ul>
</p>
-->
<script>
function companyPicker() {
var companyName = document.getElementById('company').value;
d3.select("svg").remove();/*SAL: Remove the prior color wheel*/
var width = 840,
height = width,
radius = width / 2,
// Change to xScale and yScale
x = d3.scale.linear().range([0, 2 * Math.PI]),
y = d3.scale.pow().exponent(1.3).domain([0, 1]).range([0, radius]),
padding = 20, /*This changes the padding from the center ring*/
duration = 1000; /* the duration of the circle transitions 1000*/
var div = d3.select("#vis");
div.select("#welcomeBox").remove(); /*Take the default text out of the div after loading*/
div.select("p#intro").remove();/*SAL: Take out the text for new selections*/
div.insert("p")
.attr("id", "intro")
.text(companyName + " Paint Selection -- Click Color Name For Specifics, otherwise click Color wedge to dig deeper"); /*Might be able to hijack this to show the paint contents*/
var vis = div.append("svg")
.attr("width", width + padding * 2)
.attr("height", height + padding * 2)
.append("g")
.attr("transform", "translate(" + [radius + padding, radius + padding] + ")");
var partition = d3.layout.partition()
.sort(null)
.value(function(d) {
return 5.8 - d.depth; });
var arc = d3.svg.arc()
.startAngle(function(d) {
return Math.max(0, Math.min(2 * Math.PI, x(d.x))); })
.endAngle(function(d) { return Math.max(0, Math.min(2 * Math.PI, x(d.x + d.dx))); })
.innerRadius(function(d) { return Math.max(0, d.y ? y(d.y) : d.y); })
.outerRadius(function(d) { return Math.max(0, y(d.y + d.dy)); });
d3.json("data/colors.json", function(error, json) {
var json = json.filter(function(d){
return traverse(d)
})
nodes = partition.nodes({children: json});
var path = vis.selectAll("path").data(nodes);
path.enter()/*.filter(function(d){
})*/
.append("path")
.attr("id", function(d, i) {
return "path-" + i; })
.attr("d", arc)
.attr("fill-rule", "evenodd")
.style("fill", colour)
.on("click", click);
var text = vis.selectAll("text").data(nodes);
var textEnter = text.enter().append("text")
.style("fill-opacity", 1)
.style("fill", function(d) {
return brightness(d3.rgb(colour(d))) < 125 ? "#eee" : "#000";
})
.attr("text-anchor", function(d) {
return x(d.x + d.dx / 2) > Math.PI ? "end" : "start";
})
.attr("dy", ".2em")
.attr("transform", function(d) {
var multiline = (d.name || "").split(" ").length > 1,
angle = x(d.x + d.dx / 2) * 180 / Math.PI - 90,
rotate = angle + (multiline ? -.5 : 0);
return "rotate(" + rotate + ")translate(" + (y(d.y) + padding) + ")rotate(" + (angle > 90 ? -180 : 0) + ")";
})
.on("click", pigPageLink) /*SAL: Hijack this click event go to pigpage in Json -- should be dynamically generated later based on colorname*/
.on("mouseenter", colorWheelHighlight)
.on("mouseleave", colorWheelDefault);
textEnter.append("tspan")
.attr("x", 0)
.text(function(d) { return d.depth ? d.name: ""; });
/* textEnter.append("tspan")
.attr("x", 0)
.attr("dy", "1em")
.text(function(d) { return d.depth ? d.name.split(" ")[1] || "" : ""; });*/
function colorWheelHighlight(d){
d3.select(this).style("fill", "red");
/* d3.select(this).style("stroke-width", .5);
d3.select(this).style("stroke" , "black");*/
};
function colorWheelDefault(d){
d3.select(this).style("stroke-width", "none");
d3.select(this).style("stroke" , "none");
d3.select(this).style("fill-opacity", 1);
d3.select(this).style("fill", function(d) {
return brightness(d3.rgb(colour(d))) < 125 ? "#eee" : "#000";
});
};
function pigPageLink(d){
var pigPage = d.pigpage;
console.log(pigPage);
/*window.location = ; SAL: incase new windows get annoying*/
window.open(pigPage);
};
function click(d) {
path.transition()
.duration(duration)
.attrTween("d", arcTween(d));
// Somewhat of a hack as we rely on arcTween updating the scales.
text.style("visibility", function(e) {
return isParentOf(d, e) ? null : d3.select(this).style("visibility");
})
.transition()
.duration(duration)
.attrTween("text-anchor", function(d) {
return function() {
return x(d.x + d.dx / 2) > Math.PI ? "end" : "start";
};
})
.attrTween("transform", function(d) {
var multiline = (d.name || "").split(" ").length > 1;
return function() {
var angle = x(d.x + d.dx / 2) * 180 / Math.PI - 90,
rotate = angle + (multiline ? -.5 : 0);
return "rotate(" + rotate + ")translate(" + (y(d.y) + padding) + ")rotate(" + (angle > 90 ? -180 : 0) + ")";
};
})
.style("fill-opacity", function(e) { return isParentOf(d, e) ? 1 : 1e-6; })
.each("end", function(e) {
d3.select(this).style("visibility", isParentOf(d, e) ? null : "hidden");
});
}
});
function isParentOf(p, c) {
if (p === c) return true;
if (p.children) {
return p.children.some(function(d) {
return isParentOf(d, c);
});
}
return false;
}
function colour(d, i) {
/* if (d.children) {*/
return d.hex || "#000000";//*#fff*//*colour
// There is a maximum of two children!
/* var colours = d.children.map(colour),
a = d3.hsl(colours[0]),
b = d3.hsl(colours[1]);
// L*a*b* might be better here...
return d3.hsl((a.h + b.h) / 2, a.s * 1.2, a.l / 1.2);*/
/* }*/
}
// Interpolate the scales!
function arcTween(d) {
var my = maxY(d),
xd = d3.interpolate(x.domain(), [d.x, d.x + d.dx]),
yd = d3.interpolate(y.domain(), [d.y, my]),
yr = d3.interpolate(y.range(), [d.y ? 20 : 0, radius]);
return function(d) {
return function(t) { x.domain(xd(t)); y.domain(yd(t)).range(yr(t)); return arc(d); };
};
}
function maxY(d) {
return d.children ? Math.max.apply(Math, d.children.map(maxY)) : d.y + d.dy;
}
// http://www.w3.org/WAI/ER/WD-AERT/#color-contrast
function brightness(rgb) {
return rgb.r * .299 + rgb.g * .587 + rgb.b * .114;
}
function traverse(node) {
if (node.children) {
children = node.children.filter(function(child) {
if( (child.children) && (child.children.length > 0) ) {
traverse(child)
}
else {
if (child.company == companyName) {
/*console.log(child);*/
return child;}
}
});
results = node
node.children = children
return node
};
}
}
</script>
<script>
if (top != self) top.location.replace(location);
</script>
</body>
</html>