Skip to content

Commit 9dad92e

Browse files
committed
Layout improvements + ES6 updates + added package.json.
1 parent ea5e5a9 commit 9dad92e

File tree

7 files changed

+87
-40
lines changed

7 files changed

+87
-40
lines changed

LICENSE.md LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 Olivier Giulieri
3+
Copyright (c) 2020 Olivier Giulieri
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

css/pages.css

+26-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
/* html pages ------------------------------ */
2+
html,
3+
body{
4+
margin: 0;
5+
padding: 0;
6+
}
27
body{
38
color: black;
49
background-color: white;
510
background-image: url("bg.gif");
611
}
712
.header{
813
position: relative;
9-
margin: 20px;
14+
margin: 10px;
1015
padding: 20px;
1116
border: solid 1px silver;
1217
background-color: #ffffff;
13-
min-width: 550px;
14-
max-width: 804px;
18+
width: 760px;
19+
height: 55px;
20+
}
21+
svg {
22+
user-select: none;
1523
}
1624
h1{
1725
font-size: 18px;
@@ -20,11 +28,24 @@ h1{
2028

2129
.github{
2230
position:absolute;
23-
top:20px;
24-
right:20px;
31+
top: 18px;
32+
right: 16px;
2533
text-align: right;
2634
}
2735
.github > a{
2836
color: #0099cc;
2937
text-decoration: none;
38+
}
39+
#graph {
40+
background-color: white;
41+
border: solid 1px silver;
42+
border-radius: 5px;
43+
margin: 0 10px;
44+
}
45+
footer{
46+
margin: 20px;
47+
color: grey;
48+
}
49+
footer > a {
50+
color: grey;
3051
}

index.html

+10-6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
<html>
33
<head>
44
<title>d3-dual-range-slider</title>
5-
<meta name="description" content="SVG slider with d3.js">
6-
<meta name="keywords" content="d3 d3.js dual slider widget component">
5+
<meta name="viewport" content="width=device-width,initial-scale=1">
6+
<meta name="description" content="SVG range slider for d3.js">
7+
<meta name="keywords" content="d3 d3.js dual range slider svg component widget">
78

89
<link rel="icon" type="image/png" href="favicon.png" />
910
<meta charset="utf-8">
@@ -44,14 +45,17 @@
4445
<div class="header">
4546
<div class="slider-holder"></div>
4647
<div class="github">
47-
d3-dual-range-slider<br/><br/>
48-
<a href="https://github.com/evoluteur/d3-dual-range-slider" target="github">
49-
<svg height="24" class="octicon octicon-mark-github" viewBox="0 0 16 16" version="1.1" width="24" aria-hidden="true"><path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path></svg>
50-
</a></div>
48+
<a href="https://github.com/evoluteur/d3-dual-range-slider">d3-dual-range-slider</a><br/><br/>
49+
<iframe src="https://ghbtns.com/github-btn.html?user=evoluteur&repo=d3-dual-range-slider&type=star&count=true&size=small" frameborder="0" scrolling="0" width="100px" height="30px"></iframe>
50+
</div>
5151
</div>
5252

5353
<svg id="graph" width="800" height="600"></svg>
5454

55+
<footer>
56+
&#169; 2020 <a href="https://evoluteur.github.io/">Olivier Giulieri</a>
57+
</footer>
58+
5559
</body>
5660

5761
</html>

js/data.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ function getData(minGroup, maxGroup){
1414
nodesH[n.id]=true;
1515
}
1616
});
17-
links=fullData.links.filter(function(l){
18-
return nodesH[l.source] && nodesH[l.target];
19-
})
17+
links=fullData.links.filter(l => nodesH[l.source] && nodesH[l.target])
2018
data = {
2119
nodes: nodes,
2220
links: links

js/graph.js

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11

22
function graph(color){
3-
4-
var svg = d3.select("#graph"),
3+
const svg = d3.select("#graph"),
54
width = +svg.attr("width"),
65
height = +svg.attr("height");
76

8-
var simulation = d3.forceSimulation()
9-
.force("link", d3.forceLink().id(function(d) { return d.id; }))
7+
const simulation = d3.forceSimulation()
8+
.force("link", d3.forceLink().id(d => d.id))
109
.force("charge", d3.forceManyBody())
1110
.force("center", d3.forceCenter(width / 2, height / 2))
11+
.force('collision', d3.forceCollide().radius(10))
1212
.on("tick", ticked);
1313

14-
var link = svg.append("g")
14+
let link = svg.append("g")
1515
.attr("class", "links")
1616
.selectAll("line");
1717

18-
var node = svg.append("g")
18+
let node = svg.append("g")
1919
.attr("class", "nodes")
2020
.selectAll("circle");
2121

22-
var t = d3.transition()
23-
.duration(750)
24-
.ease(d3.easeLinear);
22+
const t = d3.transition()
23+
.duration(750);
2524

2625
function restart(data){
2726

2827
// Apply the general update pattern to the nodes.
29-
node = node.data(data.nodes, function(d) { return d.id;});
30-
node.exit().remove();
28+
node = node.data(data.nodes, d => d.id);
29+
node.exit().transition(t)
30+
.style("opacity", 0).remove();
3131
var newNode = node.enter().append("circle")
32-
.attr("r", 7)
32+
.attr("r", 10)
3333
.style("opacity", 0)
34-
.attr("fill", function(d) { return color(d.group); })
34+
.attr("fill", d => color(d.group))
3535
.call(d3.drag()
3636
.on("start", dragstarted)
3737
.on("drag", dragged)
@@ -43,12 +43,12 @@ function graph(color){
4343
node = newNode.merge(node);
4444

4545
newNode.append("title")
46-
.text(function(d) { return d.id+' ('+d.group+')'; });
46+
.text(d => d.id+' ('+d.group+')');
4747

4848
// Apply the general update pattern to the links.
49-
link = link.data(data.links, function(d) { return d.source.id + "-" + d.target.id; });
49+
link = link.data(data.links, d => d.source.id + "-" + d.target.id);
5050
link.exit().remove();
51-
link = link.enter().append("line").attr("stroke-width", function(d) { return Math.sqrt(d.value); }).merge(link);
51+
link = link.enter().append("line").attr("stroke-width", d => Math.sqrt(d.value)).merge(link);
5252

5353
// Update and restart the simulation.
5454
simulation.nodes(data.nodes);
@@ -59,14 +59,14 @@ function graph(color){
5959

6060
function ticked() {
6161
link
62-
.attr("x1", function(d) { return d.source.x; })
63-
.attr("y1", function(d) { return d.source.y; })
64-
.attr("x2", function(d) { return d.target.x; })
65-
.attr("y2", function(d) { return d.target.y; });
62+
.attr("x1", d => d.source.x)
63+
.attr("y1", d => d.source.y)
64+
.attr("x2", d => d.target.x)
65+
.attr("y2", d => d.target.y);
6666

6767
node
68-
.attr("cx", function(d) { return d.x; })
69-
.attr("cy", function(d) { return d.y; });
68+
.attr("cx", d => d.x)
69+
.attr("cy", d => d.y);
7070
}
7171

7272
function dragstarted(d) {

js/slider.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ slider.insert("g", ".track-overlay")
3838
.attr("x", x)
3939
.attr("text-anchor", "middle")
4040
.style("font-weight", "bold")
41-
.style("fill", function(x){return color(x);})
42-
.text(function(d) { return d; });
41+
.style("fill", x => color(x))
42+
.text(d => d);
4343

4444
var handle = slider.selectAll("rect")
4545
.data([0, 1])
4646
.enter().append("rect", ".track-overlay")
4747
.attr("class", "handle")
4848
.attr("y", -8)
49-
.attr("x", function(d) { return x(sliderVals[d]); })
49+
.attr("x", d => x(sliderVals[d]))
5050
.attr("rx", 3)
5151
.attr("height", 16)
5252
.attr("width", 20)

package.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "d3-dual-range-slider",
3+
"version": "0.0.2",
4+
"description": "SVG component for dual-range-slider built with D3.js.",
5+
"author": "Olivier Giulieri (https://evoluteur.github.io/)",
6+
"copyright": "(c) 2020 Olivier Giulieri",
7+
"repository": {
8+
"type": "git",
9+
"url": "https://github.com/evoluteur/d3-dual-range-slider.git"
10+
},
11+
"license": "MIT",
12+
"homepage": "https://evoluteur.github.io/d3-dual-range-slider/",
13+
"bugs": "https://github.com/evoluteur/d3-dual-range-slider/issues",
14+
"keywords": [
15+
"d3",
16+
"slider",
17+
"range",
18+
"range-slider",
19+
"svg",
20+
"svg-component",
21+
"component",
22+
"javascript"
23+
]
24+
}

0 commit comments

Comments
 (0)