New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Activity chart #14
Changes from 2 commits
db88e95
69a01b6
da3fe2a
6ccb6e2
018b182
1747cad
af4c3fd
7613df8
3bdcfac
f37fe84
e4b408e
58995ce
8a8e155
50b04ca
410a22f
2f04302
ff9c404
fdad5bf
6082b13
5257e4a
349387b
cf43575
690c8dc
816a9b9
9c7163a
68ca7a4
2074174
785a759
f18bbc3
a59e687
3216b17
b726e20
027045b
1230a84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
on-response="handleResponse" | ||
debounce-duration="300"> | ||
</iron-ajax> | ||
<div style="display:none;">{{dataset}}</div> | ||
<div id="diagram"></div> | ||
</template> | ||
|
||
|
@@ -35,6 +36,15 @@ | |
/** URL of data to be plotted */ | ||
dataurl: { | ||
type: String, | ||
value: '', | ||
}, | ||
/** y values in JSON format (data to be displayed) */ | ||
dataset: { | ||
type: Array, | ||
}, | ||
/** x values in JSON format (labels for data) */ | ||
labels: { | ||
type: Array, | ||
}, | ||
/** Primary color of chart */ | ||
primarycolor: { | ||
|
@@ -72,27 +82,35 @@ | |
* @param {Object} data The data to be plotted | ||
*/ | ||
handleResponse: function (data) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe make that private? |
||
//var goodData = this._normalizeJSON(data.detail.response); | ||
if(this.dataurl != "") { | ||
var goodData = this._normalizeJSON(data.detail.response); | ||
this.dataset = goodData[0]["y"]; | ||
this.labels = goodData[0]["x"]; | ||
} | ||
this._plotDiagram(); | ||
}, | ||
|
||
_plotDiagram: function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please document |
||
console.log("Plotting..."); | ||
console.log(this.dataset); | ||
console.log(this.labels); | ||
var diagramDiv = this.$.diagram; | ||
var svgWidth = 500, | ||
svgHeight = 500; | ||
//values should range between 1, 100 | ||
var dataset = [1, 10, 20, 35, 47, 65, 87, 100, | ||
1, 10, 65, 20, 35, 47, 87, 100, | ||
1, 10, 20, 47, 65, 87, 35, 100, | ||
1, 10, 20, 100, 35, 47, 65, 87, | ||
1, 20, 35, 10, 47, 65, 87, 100, | ||
47, 65, 87, 1, 10, 20, 35, 100]; | ||
|
||
//so far, the appropriate color is calculated based on the value of the datum, there is no set of fixed colors | ||
var colorScale = d3.scaleLinear() | ||
.domain([1, 100]) | ||
.range(['#F5E8BB', '#930517']); | ||
svgHeight = 500; | ||
var dataset = this.dataset; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we move this line above |
||
var datasetMin = Math.min.apply(null, dataset); | ||
var datasetMax = Math.max.apply(null, dataset); | ||
|
||
//so far, the appropriate color is calculated based on the value of the datum, there is no set of fixed colors | ||
var colorScale = d3.scaleLinear() | ||
.domain([datasetMin, datasetMax]) | ||
.range(['#F5E8BB', '#930517']); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make that a parameter 😊 maybe |
||
|
||
var svg = d3.select('#diagram').append('svg') | ||
.attr('width', svgWidth) | ||
.attr('height', svgHeight); | ||
|
||
|
||
var squares = svg.selectAll('rect') | ||
.data(dataset) | ||
.enter().append('rect') | ||
|
@@ -109,15 +127,13 @@ | |
//using a group element 'label' with an appended text element and a rect element as background to display a label | ||
|
||
var polyElement = Polymer.dom(this).parentNode.parentNode.parentNode; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there maybe a better way to traverse the dom than There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sure there is; Jan made a remark about this earlier. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's discuss / investigate in the next team meeting |
||
|
||
var label = d3.select('svg').append('g') | ||
.attr('id', 'label-' + i); | ||
|
||
//append rect element first so that following text element is displayed above rect | ||
label.append('rect'); | ||
|
||
var labelText = label.append('text') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. like this approach |
||
.text(d + ' at ' + i) | ||
.text(d + ' at ' + polyElement.labels[i]) | ||
.style('font-size', '0.8em') | ||
.attr('fill', 'black'); | ||
//this split is necessary because the position is set relative to the size of the text element | ||
|
@@ -159,15 +175,15 @@ | |
|
||
_spaceSquareHor: function (d, i) { | ||
var polyElement = this; | ||
if (Polymer.dom(this).childNodes.length == 0) { | ||
if (Polymer.dom(this).node.nodeName != "ACTIVITYCHART-BASIC") { | ||
var polyElement = Polymer.dom(this).parentNode.parentNode.parentNode; | ||
} | ||
return polyElement.squareSpacing * (i % polyElement.squaresPerRow); | ||
}, | ||
|
||
_spaceSquareVert: function (d, i) { | ||
var polyElement = this; | ||
if (Polymer.dom(this).childNodes.length == 0) { | ||
if (Polymer.dom(this).node.nodeName != "ACTIVITYCHART-BASIC") { | ||
var polyElement = Polymer.dom(this).parentNode.parentNode.parentNode; | ||
} | ||
return polyElement.squareSpacing * (Math.floor(i / polyElement.squaresPerRow)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that bloody issue...
see #26