Skip to content

Instantly share code, notes, and snippets.

@lavaliere
Last active November 19, 2016 23:11
Show Gist options
  • Save lavaliere/20d315e3bdd91c7041d44a42883bb5a2 to your computer and use it in GitHub Desktop.
Save lavaliere/20d315e3bdd91c7041d44a42883bb5a2 to your computer and use it in GitHub Desktop.
Jenkins plugin stats - aframe + d3 test
license: mit

Testing out aframe.io with d3.js.

This project visualizes the install counts of Jenkins CI plugins.

Since AFrame works with DOM elements, you can use d3's selection API to generate and modify 3D elements, as well as handle "mouse" events (including the VR friendly "fuse cursor") as if it was SVG.

Built with blockbuilder.org

forked from enjalot's block: aframe + d3 test

<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script src="https://aframe.io/releases/latest/aframe.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; background-color: white;}
</style>
</head>
<body>
<a-scene>
<!-- Camera with customized cursor -->
<a-camera position="0 1.8 0" cursor-visible="true" cursor-scale="2" cursor-color="#4CC3D9" cursor-offset="2" cursor-maxdistance="100" cursor-opacity="0.5" cursor-fuse="true"></a-camera>
<a-light color="#da47da" position="0 5 0" type="ambient"></a-light>
<a-entity camera look-controls wasd-controls></a-entity>
<a-entity light="type: point; color: #EEE; intensity: 0.5" position="0 3 0"></a-entity>
<!-- Sky -->
<a-sky color="#c8f8e0"></a-sky>
</a-scene>
<script>
//
var data = ["parameter-separator","1001"
"maven-invoker-plugin","1002"
"http-post","1023"
"avatar","1027"
"codedeploy","1028"
"dynamic-axis","1035"
"fitnesse","1038"
"rundeck","1058"
"perfpublisher","1061"
"jobcopy-builder","1062"
"project-build-times","1066"
"build-cause-run-condition","1066"
"pollscm","1067"
"files-found-trigger","1083"
"clang-scanbuild-plugin","1085"
"php","1088"
"matrix-reloaded","1089"
"crowd2","1091"
"configure-job-column-plugin","1097"
"description-column-plugin","1107"
"vs-code-metrics","1110"
"built-on-column","1121"
"promoted-builds-simple","1126"
"awseb-deployment-plugin","1130"
"google-play-android-publisher","1132"
"m2-repo-reaper","1134"
"teamconcert","1144"
"prereq-buildstep","1145"
"shared-workspace","1146"
"changelog-history","1147"
"lockable-resources","1159"
"kubernetes","1160"
"svnmerge","1167"
"nuget","1170"
"xshell","1179"
"gitbucket","1188"
"multi-slave-config-plugin","1194"
"gatling","1201"
"ownership","1204"
"artifact-promotion","1209"
"job-exporter","1222"
"bitbucket-approve","1226"
"test-stability","1228"
"summary_report","1230"
"stash-pullrequest-builder","1235"
"dropdown-viewstabbar-plugin","1237"
"changes-since-last-success","1246"
"custom-tools-plugin","1260"
"filesystem_scm","1263"
"JiraTestResultReporter","1269"
"unity3d-plugin","1275"
"maven-deployment-linker","1285"
"purge-job-history","1290"
"cloudbees-bitbucket-branch-source","1294"]
// we scale the height of our bars using d3's linear scale
var hscale = d3.scale.linear()
.domain([0, d3.max(data)])
.range([0, 3])
// we select the scene object just like an svg
var scene = d3.select("a-scene")
// we use d3's enter/update/exit pattern to draw and bind our dom elements
var bars = scene.selectAll("a-cube.bar").data(data)
bars.enter().append("a-cube").classed("bar", true)
// we set attributes on our cubes to determine how they are rendered
bars.attr({
position: function(d,i) {
// cubes are positioned by their center so we
// offset for their height
var y = 1 + hscale(d)/2;
// lets place the bars all around our camera
var radius = 5;
//var x = i - data.length/2;
var x = radius * Math.cos(i/data.length * 2 * Math.PI)
var z = radius * Math.sin(i/data.length * 2 * Math.PI)
return x + " " + y + " " + z
},
rotation: function(d,i) {
var x = 0;
var z = 0;
var y = -(i/data.length)*360;
return x + " " + y + " " + z
},
width: function(d) { return 0.5},
depth: function(d) { return 0.9},
height: function(d) { return hscale(d)},
opacity: function(d,i) { return 0.6 + (i/data.length) * 0.4},
//metalness: function(d,i) { return i/data.length}
})
.on("click", function(d,i) {
console.log("click", i,d)
})
.on("mouseenter", function(d,i) {
// this event gets fired continuously as long as the cursor
// is over the element. we only want trigger our animation the first time
if(this.hovering) return;
console.log("hover", i,d)
this.hovering = true;
d3.select(this).transition().duration(1000)
.attr({
metalness: 0.5,
width: 2
})
})
.on("mouseleave", function(d,i) {
console.log("leave",i,d)
this.hovering = false;
d3.select(this).transition()
.attr({
metalness: 0,
width: 0.5
})
})
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment