-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot-y-axis.html
73 lines (63 loc) · 1.59 KB
/
plot-y-axis.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<link rel="import" href="../polymer/polymer.html">
<dom-module id="plot-y-axis">
<template>
<style>
:host {
display: block;
width: 100%;
height: 100%;
position: absolute;
top: 0;
bottom: 0;
}
#y_axis {
width: 100%;
height: 100%;
display: block;
background-color: transparent !important;
z-index: 1;
}
</style>
<div id="y_axis"></div>
<content></content>
</template>
<script>
Polymer({
is: 'plot-y-axis',
properties: {
ymin: {
type: Number,
value: -1
},
ymax: {
type: Number,
value: 1
},
displayAxis: {
type: Boolean,
value: true
}
},
computeXMin: function(){
return this.root.host.parentNode.xmin;
},
computeXMax: function(){
return this.root.host.parentNode.xmax;
},
attached: function(){
let w = Polymer.dom(this.root).node.host.offsetWidth;
let h = Polymer.dom(this.root).node.host.offsetHeight;
var y_scale = d3.scaleLinear()
.domain([this.ymin, this.ymax])
.range([this.root.host.parentNode.height, 0]);
var svg = d3.select(this.$.y_axis)
.append("svg")
.attr("width", w)
.attr("height", h)
.append("g")
.attr("transform", "translate(25, 15)") // Just in line with plots
.call(d3.axisLeft(y_scale)); // Just add the damn scale
}
});
</script>
</dom-module>