Skip to content

Commit

Permalink
add horizontal axis
Browse files Browse the repository at this point in the history
  • Loading branch information
JosuaKrause committed Nov 14, 2015
1 parent d013351 commit 8a50280
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
27 changes: 26 additions & 1 deletion index.html
Expand Up @@ -8,6 +8,22 @@
* {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

.axis {
shape-rendering: crispEdges;
}

.x.axis line {
stroke: lightgray;
}

.x.axis .minor {
stroke-opacity: .5;
}

.x.axis path {
display: none;
}

This comment has been minimized.

Copy link
@JosuaKrause

JosuaKrause Nov 16, 2015

Author Owner

We need to add some style information for the axis to look good.

</style>
</head>
<body onload="start()">
Expand All @@ -19,11 +35,12 @@
var w = 800;
var h = 600;
var radius = 2;
var textHeight = 20;

var content = d3.select("#divContent");
var svg = content.append("svg").attr({
"width": w,
"height": h
"height": h + textHeight

This comment has been minimized.

Copy link
@JosuaKrause

JosuaKrause Nov 16, 2015

Author Owner

Adding some scratch space for the axis labels.

}).style({
"border": "solid black 1px"
});
Expand Down Expand Up @@ -55,9 +72,17 @@
});

var xScale = d3.time.scale().domain([ d3.min(times), d3.max(times) ]).range([ 0, w ]).nice();
var xAxis = d3.svg.axis().scale(xScale).tickSize(-h).tickSubdivide(true);

This comment has been minimized.

Copy link
@JosuaKrause

JosuaKrause Nov 16, 2015

Author Owner

This creates an axis object.


var groupScale = d3.scale.category10().domain(Object.keys(groups));

var visAxis = svg.append("g").classed({
"x": true,
"axis": true
}).attr({
"transform": "translate(" + [ 0, h ] + ")"

This comment has been minimized.

Copy link
@JosuaKrause

JosuaKrause Nov 16, 2015

Author Owner

Translating the axis to the bottom of the SVG.

}).call(xAxis);

This comment has been minimized.

Copy link
@JosuaKrause

JosuaKrause Nov 16, 2015

Author Owner

This creates the actual axis geometry from the axis object.


var sel = svg.selectAll("circle.event").data(events);
sel.exit().remove();
sel.enter().append("circle").classed("event", true);
Expand Down
2 changes: 1 addition & 1 deletion outline.txt
Expand Up @@ -11,7 +11,7 @@
7. Position circles vertically by event type (X)
* Create a type scale (X)
* Order type scale by first occurrence (X)
8. Create horizontal axis
8. Create horizontal axis (X)
9. Add zooming and panning
10. Add mouse-over events to circles
* Grow circles upon mouse-over
Expand Down

0 comments on commit 8a50280

Please sign in to comment.