Skip to content

Commit

Permalink
chart is now working, still hard coded data
Browse files Browse the repository at this point in the history
maybe we have an js expert who can find a cleaner approach to solve the "this" problem.
  • Loading branch information
MaximilianV committed Jan 8, 2017
1 parent 69a01b6 commit da3fe2a
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions activitychart-basic.html
Expand Up @@ -62,6 +62,7 @@
value: 20,
},
},

ready: function() {
this.$.ajaxCaller.generateRequest();
},
Expand All @@ -73,7 +74,6 @@
handleResponse: function (data) {
//var goodData = this._normalizeJSON(data.detail.response);
var diagramDiv = this.$.diagram;
alert(this.squareSpacing);
var svgWidth = 500,
svgHeight = 500;
//values should range between 1, 100
Expand Down Expand Up @@ -106,18 +106,19 @@
},

_showLabel: function (d, i) {
var polyElement = Polymer.dom(this).parentNode.parentNode.parentNode;

This comment has been minimized.

Copy link
@janrenz

janrenz Jan 9, 2017

Contributor

is there any smarter way to do this, by classname or identifier maybe? Could also ask Franz

This comment has been minimized.

Copy link
@JakobEdding

JakobEdding Jan 30, 2017

Contributor

Solved in 5257e4a by binding 'this' to _showLabel and other methods when they're called (this seems to be one of the "best" solutions looking at: Polymer/polymer#2095).

d3.select('svg').append('rect')
.attr('x', this._spaceSquareHor(d, i) - 3)
.attr('y', this._spaceSquareVert(d, i) - 14)
.attr('x', polyElement._spaceSquareHor(d, i) - 3)
.attr('y', polyElement._spaceSquareVert(d, i) - 14)
.attr('id', 'label-bg-' + i)
.attr('fill', 'white')
.attr('width', 60)
.attr('height', 15);

d3.select('svg').append('text')
.text(d + ' at ' + i)
.attr('x', this._spaceSquareHor(d, i))
.attr('y', this._spaceSquareVert(d, i) - 3)
.attr('x', polyElement._spaceSquareHor(d, i))
.attr('y', polyElement._spaceSquareVert(d, i) - 3)
.attr('id', 'label-' + i)
.style('font-size', '0.8em')
.attr('fill', 'black');
Expand All @@ -129,11 +130,19 @@
},

_spaceSquareHor: function (d, i) {
return this.squareSpacing * (i % this.squaresPerRow);
var polyElement = this;
if (Polymer.dom(this).childNodes.length == 0) {
var polyElement = Polymer.dom(this).parentNode.parentNode.parentNode;
}
return polyElement.squareSpacing * (i % polyElement.squaresPerRow);
},

_spaceSquareVert: function (d, i) {
return this.squareSpacing * (Math.floor(i / this.squaresPerRow));
var polyElement = this;
if (Polymer.dom(this).childNodes.length == 0) {
var polyElement = Polymer.dom(this).parentNode.parentNode.parentNode;
}
return polyElement.squareSpacing * (Math.floor(i / polyElement.squaresPerRow));
},
/**
* Normalizes the data supplied by the API to work with Plotly
Expand Down

0 comments on commit da3fe2a

Please sign in to comment.