Skip to content

Commit 3118cd3

Browse files
committed
Cleanups + comments.
1 parent a63561d commit 3118cd3

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

d3-table-cards.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,53 @@ var cardsPerRow = 3;
77

88
var layoutInfo = {
99
table: {
10+
// ---- row position & size
11+
top: function(d){return 40+d.idx*29+'px'},
12+
left: 0,
1013
height: 28,
1114
width: 590,
15+
// ---- row border-radius
1216
radius: 0,
13-
top: function(d){return 40+d.idx*29+'px'},
14-
left: 0,
17+
// ---- table header
1518
headerOpacity: 1,
1619
headerLeft: 0,
20+
// ---- column 1
1721
c1Top: 5,
1822
c1Left: 8,
1923
c1FontSize: 16,
24+
// ---- column 2
2025
c2Top: 5,
2126
c2Left: 200,
2227
},
2328
card: {
29+
// ---- card position & size
30+
top: function(d){return Math.floor(d.idx/cardsPerRow)*90+'px'},
31+
left: function(d){return (d.idx%cardsPerRow)*200+'px'},
2432
height: 80,
2533
width: 188,
34+
// ---- card border-radius
2635
radius: '5px',
27-
top: function(d){return Math.floor(d.idx/cardsPerRow)*90+'px'},
28-
left: function(d){return (d.idx%cardsPerRow)*200+'px'},
36+
// ---- table header (hidden)
2937
headerOpacity: 0,
3038
headerLeft: -650,
39+
// ---- line 1
3140
c1Top: 10,
3241
c1Left: 10,
3342
c1FontSize: 18,
43+
// ---- line 2
3444
c2Top: 37,
3545
c2Left: 10,
3646
}
3747
};
3848

3949
function getLayoutInfo(style){
40-
var w = window.innerWidth -20;
41-
cardsPerRow = Math.floor(w/200);
50+
var width = window.innerWidth -20;
51+
cardsPerRow = Math.floor(width/200);
4252
return layoutInfo[style];
4353
}
4454

4555
function render(){
46-
var l=getLayoutInfo(curStyle);
56+
var l = getLayoutInfo(curStyle);
4757
var sel = d3.select('.holder').selectAll('.item')
4858
.data(data)
4959
.enter()
@@ -63,23 +73,22 @@ function redraw(style){
6373
.transition().duration(animTime));
6474
}
6575
function sort(key){
66-
var l=getLayoutInfo(curStyle);
67-
var data2 = data.sort(key=='chakra' ? function (a, b) {
76+
var l = getLayoutInfo(curStyle);
77+
data.sort(key=='chakra' ? function (a, b) {
6878
return (a.chakra+a.name).localeCompare(b.chakra+b.name);
6979
} : function (a, b) {
7080
return a.name.localeCompare(b.name);
7181
});
72-
data2.forEach(function(d,idx){
82+
data.forEach(function(d, idx){
7383
d.idx=idx;
7484
});
7585
layout(d3.select('.holder').selectAll('.item')
7686
.transition().duration(animTime));
7787
}
7888

7989
function layout(sel){
80-
var l=getLayoutInfo(curStyle);
81-
var t = d3.transition()
82-
.duration(animTime)
90+
var l = getLayoutInfo(curStyle),
91+
t = d3.transition().duration(animTime);
8392

8493
sel.style('left', l.left)
8594
.style('top', l.top)
@@ -102,6 +111,7 @@ function layout(sel){
102111
var totalHeight = 20+(curStyle==='card' ?
103112
Math.ceil(data.length/cardsPerRow)*90
104113
: 40+data.length*29);
114+
105115
d3.select('.holder').transition(t)
106116
.style('height', totalHeight);
107117
}

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<link href="d3-table-cards.css" rel="stylesheet">
88
<title>D3-Table-Cards</title>
99
<meta name="description" content="D3-Table-Cards: Table/Cards views using D3.js for animated transformations and transitions.">
10-
<meta name="keywords" content="d3 d3.js table card cards view javascript gemstones">
10+
<meta name="keywords" content="d3 d3v4 js table card cards view javascript gemstones">
1111
</head>
1212
<body onresize="redraw()">
1313

0 commit comments

Comments
 (0)