Skip to content

Commit

Permalink
Add axis to history graphs (#1529)
Browse files Browse the repository at this point in the history
* Update topology to latest

* Add axis to history graphs

* Offset by 1px
  • Loading branch information
corradio authored Jul 30, 2018
1 parent 8ac91b6 commit bfbc754
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
23 changes: 12 additions & 11 deletions web/src/components/areagraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ function AreaGraph(selector, modeColor, modeOrder) {
var that = this;

this.rootElement = d3.select(selector);

// Create axis
this.xAxisElement = this.rootElement.append('g')
.attr('class', 'x axis')
.style('pointer-events', 'none');
this.yAxisElement = this.rootElement.append('g')
.attr('class', 'y axis')
.style('pointer-events', 'none');

this.graphElement = this.rootElement.append('g');
this.interactionRect = this.graphElement.append('rect')
.style('cursor', 'pointer')
Expand All @@ -26,21 +35,14 @@ function AreaGraph(selector, modeColor, modeOrder) {
.style('display', 'none')
.style('pointer-events', 'none')
.style('shape-rendering', 'crispEdges')

this.markerElement = this.rootElement.append('circle')
.style('pointer-events', 'none')
.style('display', 'none')
.attr('r', 6)
.style('stroke', 'black')
.style('stroke-width', 1.5);

// Create axis
this.xAxisElement = this.rootElement.append('g')
.attr('class', 'x axis')
.style('pointer-events', 'none');
this.yAxisElement = this.rootElement.append('g')
.attr('class', 'y axis')
.style('pointer-events', 'none');

// Create scales
this.x = d3.scaleTime();
this.y = d3.scaleLinear();
Expand Down Expand Up @@ -308,15 +310,14 @@ AreaGraph.prototype.render = function() {
.ticks(5)
.tickFormat(function(d) { return moment(d).format('LT'); });
this.xAxisElement
// Need to remove 1px in order to see the 1px line
.attr('transform', `translate(0 ${height - X_AXIS_HEIGHT})`)
.attr('transform', `translate(-1 ${height - X_AXIS_HEIGHT - 1})`)
.call(xAxis);

// y axis
var yAxis = d3.axisRight(y)
.ticks(5);
this.yAxisElement
.attr('transform', `translate(${width - Y_AXIS_WIDTH} 0)`)
.attr('transform', `translate(${width - Y_AXIS_WIDTH - 1} -1)`)
.call(yAxis);

return this;
Expand Down
22 changes: 11 additions & 11 deletions web/src/components/linegraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ var moment = require('moment');

function LineGraph(selector, xAccessor, yAccessor, definedAccessor) {
this.rootElement = d3.select(selector);

// Create axis
this.xAxisElement = this.rootElement.append('g')
.attr('class', 'x axis')
.style('pointer-events', 'none');
this.yAxisElement = this.rootElement.append('g')
.attr('class', 'y axis')
.style('pointer-events', 'none');

this.graphElement = this.rootElement.append('g');
this.interactionRect = this.graphElement.append('rect')
.style('cursor', 'pointer')
Expand All @@ -39,14 +48,6 @@ function LineGraph(selector, xAccessor, yAccessor, definedAccessor) {
this.definedAccessor = definedAccessor;
this._gradient = true;

// Create axis
this.xAxisElement = this.rootElement.append('g')
.attr('class', 'x axis')
.style('pointer-events', 'none');
this.yAxisElement = this.rootElement.append('g')
.attr('class', 'y axis')
.style('pointer-events', 'none');

// Create scales
var x, y;
this.x = x = d3.scaleTime();
Expand Down Expand Up @@ -250,15 +251,14 @@ LineGraph.prototype.render = function () {
.ticks(5)
.tickFormat(function(d) { return moment(d).format('LT'); });
this.xAxisElement
// Need to remove 1px in order to see the 1px line
.attr('transform', `translate(0 ${height - X_AXIS_HEIGHT})`) // Need to use transform attribute (and not css property) due to lack of IE support: https://aheadcreative.co.uk/articles/svg-transitions-not-working-ie11/
.attr('transform', `translate(-1 ${height - X_AXIS_HEIGHT - 1})`) // Need to use transform attribute (and not css property) due to lack of IE support: https://aheadcreative.co.uk/articles/svg-transitions-not-working-ie11/
.call(xAxis);

// y axis
var yAxis = d3.axisRight(y)
.ticks(5);
this.yAxisElement
.attr('transform', `translate(${width - Y_AXIS_WIDTH} 0)`)
.attr('transform', `translate(${width - Y_AXIS_WIDTH - 1} -1)`)
.call(yAxis);

return this;
Expand Down
10 changes: 4 additions & 6 deletions web/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,8 @@ body {
color: black;
}
.left-panel .axis .tick line {
opacity: 0.3;
shape-rendering: crispEdges;
stroke: gray;
shape-rendering: auto;
stroke: lightgray;
stroke-width: 1;
}
.left-panel .axis .tick text {
Expand All @@ -391,9 +390,8 @@ body {
}
.left-panel .axis path.domain {
fill: none;
opacity: 0.3;
shape-rendering: crispEdges;
stroke: transparent;
shape-rendering: auto;
stroke: lightgray;
}
.left-panel-toolbar,
.left-panel-zone-details-toolbar {
Expand Down

0 comments on commit bfbc754

Please sign in to comment.