Last active
August 29, 2015 14:13
-
-
Save panesofglass/60b1050d6362dee3c7fa to your computer and use it in GitHub Desktop.
d3.js - rendering a navigation tree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (global, Data, Nav, f) { | |
f(global, Data, Nav); | |
})(window, window.Data, window.Nav, | |
function app(global, data, Nav) { | |
"use strict"; | |
var nav = Nav("nav.nav"); | |
nav(data); | |
global.setTimeout(function () { | |
var newNavItem = { | |
name: 'test', | |
path: '/test' | |
}; | |
/* | |
data.push(newNavItem); | |
data.splice(1, 0, newNavItem); | |
nav(data); | |
*/ | |
}, 1000); | |
} | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (global, f) { | |
global.Data = f(); | |
})(window, function () { | |
return [ | |
{ | |
name: "home", | |
path: "/" | |
}, { | |
name: "reports", | |
children: [ | |
{ | |
name: "report 1", | |
path: "/reports/1" | |
}, { | |
name: "report 2", | |
path: "/reports/2" | |
} | |
] | |
} | |
]; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head lang="en"> | |
<meta charset="UTF-8"> | |
<title>D3 Experiments</title> | |
<link rel="stylesheet" type="text/css" href="style.css" /> | |
</head> | |
<body> | |
<nav class="nav"></nav> | |
<script src="d3.v3.js"></script> | |
<script src="nav.js"></script> | |
<script src="data.js"></script> | |
<script src="app.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.hide { | |
display: none; | |
} | |
.show { | |
display: block; | |
} | |
.nav li:hover ul.active, | |
.nav li:hover ul.hide { | |
display: block; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks to @TravisTheTechie for his help pairing on finding this solution.
Follow up goal: make this a component