-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathgraphic.js
More file actions
85 lines (72 loc) · 2 KB
/
Copy pathgraphic.js
File metadata and controls
85 lines (72 loc) · 2 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
// Global vars
var pymChild = null;
var isMobile = false;
/*
* Initialize the graphic.
*/
var onWindowLoaded = function() {
pymChild = new pym.Child({
renderCallback: render
});
pymChild.onMessage('on-screen', function(bucket) {
ANALYTICS.trackEvent('on-screen', bucket);
});
pymChild.onMessage('scroll-depth', function(data) {
data = JSON.parse(data);
ANALYTICS.trackEvent('scroll-depth', data.percent, data.seconds);
});
}
/*
* Render the graphic.
*/
var render = function(containerWidth) {
if (!containerWidth) {
containerWidth = DEFAULT_WIDTH;
}
if (containerWidth <= MOBILE_THRESHOLD) {
isMobile = true;
} else {
isMobile = false;
}
// Render the chart!
// renderGraphic({
// container: '#graphic',
// width: containerWidth,
// data: []
// });
// Update iframe
if (pymChild) {
pymChild.sendHeight();
}
}
/*
* Render a graphic.
*/
var renderGraphic = function(config) {
var aspectWidth = 4;
var aspectHeight = 3;
var margins = {
top: 0,
right: 15,
bottom: 20,
left: 15
};
// Calculate actual chart dimensions
var chartWidth = config['width'] - margins['left'] - margins['right'];
var chartHeight = Math.ceil((config['width'] * aspectHeight) / aspectWidth) - margins['top'] - margins['bottom'];
// Clear existing graphic (for redraw)
var containerElement = d3.select(config['container']);
containerElement.html('');
// Create container
var chartElement = containerElement.append('svg')
.attr('width', chartWidth + margins['left'] + margins['right'])
.attr('height', chartHeight + margins['top'] + margins['bottom'])
.append('g')
.attr('transform', 'translate(' + margins['left'] + ',' + margins['top'] + ')');
// Draw here!
}
/*
* Initially load the graphic
* (NB: Use window.load to ensure all images have loaded)
*/
window.onload = onWindowLoaded;