Skip to content

Commit a2d6617

Browse files
ioandrdrjova
authored andcommitted
responsive behavior: initial version
Update the SVG holding the graph on window resize event. * Adds responsive behavior to the graphs. (closes #8) * Appends all circles as the upper layer of the graph. (closes #27) Signed-off by Ioannis Androulidakis <[email protected]>
1 parent 83075ec commit a2d6617

File tree

12 files changed

+324
-272
lines changed

12 files changed

+324
-272
lines changed

.eslintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# TODO: Check for a fix
1414
"jsx-a11y/href-no-hash": "off",
1515
"jsx-a11y/anchor-is-valid": ["warn", { "aspects": ["invalidHref"] }],
16-
"no-use-before-define": ["error", { "functions": false, "classes": true }]
16+
"no-use-before-define": ["error", { "functions": false, "classes": true }],
17+
"class-methods-use-this": "off"
1718
}
1819
}

examples/bar/config.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@
2424
// Export configuration object
2525
const config = {};
2626
config.pageviewsVideosPerCountry = {
27-
width: 1000,
28-
height: 450,
2927
margin: {
30-
top: 30,
31-
right: 80,
32-
bottom: 80,
33-
left: 80
28+
top: 50,
29+
right: 60,
30+
bottom: 70,
31+
left: 60
3432
},
3533
graph: {
3634
type: 'bar'
@@ -97,6 +95,11 @@ config.pageviewsVideosPerCountry = {
9795
legend: {
9896
visible: false,
9997
position: 'side'
98+
},
99+
resize: {
100+
enabled: true,
101+
breakPointX: 500,
102+
breakPointY: 350
100103
}
101104
};
102105

examples/bar/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<title>Bar Chart</title>
2828
</head>
2929
<body>
30+
<div class='pageviews_country' style='width: 100vw; height:80vh;'></div>
3031
<script src="../dist/bar.bundle.js"></script>
3132
</body>
3233
</html>

examples/bar/index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ import config from './config';
2626
import dataCDS from '../data/data';
2727
import { BarGraph } from '../../src/index';
2828

29-
// BarGraph 1
3029
const cfg1 = config.pageviewsVideosPerCountry;
3130
const data1 = dataCDS.pageviewsVideosPerCountry;
3231
const data1Update = dataCDS.pageviewsVideosPerCountryUpdate;
33-
const class1 = 'pageviews';
32+
const class1 = 'pageviews_country';
3433
const g1 = new BarGraph(cfg1, data1, class1);
34+
35+
// BarGraph 1
3536
g1.render();
3637
setTimeout(() => g1.update(data1Update), 3000);

examples/line/config.js

+34-111
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,21 @@
2424
// Export configuration object
2525
const config = {};
2626
config.downloadVideosInterval1day = {
27-
width: 1000,
28-
height: 450,
2927
margin: {
30-
top: 30,
31-
right: 80,
32-
bottom: 80,
33-
left: 80
28+
top: 50,
29+
right: 60,
30+
bottom: 70,
31+
left: 60
3432
},
3533
graph: {
3634
type: 'line',
3735
options: {
3836
curveType: 'curveLinear',
39-
fillArea: true
37+
fillArea: true,
38+
circles: {
39+
visible: true,
40+
radius: 5.5
41+
}
4042
}
4143
},
4244
axis: {
@@ -49,15 +51,15 @@ config.downloadVideosInterval1day = {
4951
options: {
5052
label: {
5153
value: 'Date',
52-
visible: false
54+
visible: true
5355
},
5456
line: {
5557
visible: false
5658
},
5759
ticks: {
5860
number: 5,
5961
format: '',
60-
visible: true
62+
visible: false
6163
},
6264
tickLabels: {
6365
visible: true,
@@ -75,18 +77,19 @@ config.downloadVideosInterval1day = {
7577
options: {
7678
label: {
7779
value: 'Downloads',
78-
visible: false
80+
visible: true
7981
},
8082
line: {
8183
visible: false
8284
},
8385
ticks: {
8486
number: 5,
8587
format: '',
86-
visible: true
88+
visible: false
8789
},
8890
tickLabels: {
89-
visible: true
91+
visible: true,
92+
rotated: false
9093
},
9194
gridlines: false
9295
}
@@ -98,115 +101,33 @@ config.downloadVideosInterval1day = {
98101
visible: true,
99102
position: 'side'
100103
},
101-
circles: {
102-
visible: true,
103-
radius: 5.5
104-
},
105104
title: {
106105
visible: true,
107106
value: 'Video Downloads per day'
108-
}
109-
};
110-
111-
config.pageviewsVideosInterval1day = {
112-
width: 1000,
113-
height: 450,
114-
margin: {
115-
top: 30,
116-
right: 30,
117-
bottom: 60,
118-
left: 85
119-
},
120-
graph: {
121-
type: 'line',
122-
options: {
123-
curveType: 'curveMonotoneX',
124-
fillArea: true
125-
}
126-
},
127-
axis: {
128-
x: {
129-
mapTo: 'time',
130-
scale: {
131-
type: 'scaleTime',
132-
format: '%d-%b-%y'
133-
},
134-
options: {
135-
label: {
136-
value: 'Date',
137-
visible: false
138-
},
139-
line: {
140-
visible: false
141-
},
142-
ticks: {
143-
number: 5,
144-
format: '',
145-
visible: false
146-
},
147-
tickLabels: {
148-
visible: true,
149-
rotated: true
150-
},
151-
gridlines: true
152-
}
153-
},
154-
y: {
155-
mapTo: 'count',
156-
scale: {
157-
type: 'scaleLinear',
158-
format: ''
159-
},
160-
options: {
161-
label: {
162-
value: 'Pageviews',
163-
visible: false
164-
},
165-
line: {
166-
visible: false
167-
},
168-
ticks: {
169-
number: 5,
170-
format: '',
171-
visible: false
172-
},
173-
tickLabels: {
174-
visible: true
175-
},
176-
gridlines: true
177-
}
178-
}
179-
},
180-
colorScale: 'schemeCategory10',
181-
tooltip: false,
182-
legend: {
183-
visible: true,
184-
position: 'side'
185-
},
186-
circles: {
187-
visible: true,
188-
radius: 5.5
189107
},
190-
title: {
191-
visible: true,
192-
value: 'Pageviews per day'
108+
resize: {
109+
enabled: true,
110+
breakPointX: 500,
111+
breakPointY: 350
193112
}
194113
};
195114

196115
config.pageviewsVideosInterval1month = {
197-
width: 1000,
198-
height: 450,
199116
margin: {
200-
top: 30,
201-
right: 30,
202-
bottom: 60,
203-
left: 85
117+
top: 50,
118+
right: 60,
119+
bottom: 70,
120+
left: 60
204121
},
205122
graph: {
206123
type: 'line',
207124
options: {
208125
curveType: 'curveMonotoneX',
209-
fillArea: true
126+
fillArea: true,
127+
circles: {
128+
visible: true,
129+
radius: 5.5
130+
}
210131
}
211132
},
212133
axis: {
@@ -256,7 +177,8 @@ config.pageviewsVideosInterval1month = {
256177
visible: false
257178
},
258179
tickLabels: {
259-
visible: true
180+
visible: true,
181+
rotated: false
260182
},
261183
gridlines: true
262184
}
@@ -272,9 +194,10 @@ config.pageviewsVideosInterval1month = {
272194
visible: true,
273195
position: 'bottom'
274196
},
275-
circles: {
276-
visible: true,
277-
radius: 5.5
197+
resize: {
198+
enabled: true,
199+
breakPointX: 500,
200+
breakPointY: 350
278201
}
279202
};
280203

examples/line/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<title>Line Chart</title>
2828
</head>
2929
<body>
30-
<div class='pageviews_month'></div>
30+
<div class='pageviews_month' style='width: 100vw; height:80vh;'></div>
3131
<script src="../dist/line.bundle.js"></script>
3232
</body>
3333
</html>

examples/line/index.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,19 @@ import config from './config';
2626
import dataCDS from '../data/data';
2727
import { LineGraph } from '../../src/index';
2828

29-
// LineGraph 1
3029
const cfg1 = config.pageviewsVideosInterval1month;
3130
const data1 = dataCDS.pageviewsVideosInterval1month;
3231
const data1Update = dataCDS.pageviewsVideosInterval1monthUpdate;
3332
const class1 = 'pageviews_month';
33+
// const cfg2 = config.downloadVideosInterval1day;
34+
// const data2 = dataCDS.downloadVideosInterval1day;
35+
// const class2 = 'downloads_day';
36+
37+
// LineGraph 1
3438
const g1 = new LineGraph(cfg1, data1, class1);
3539
g1.render();
3640
setTimeout(() => g1.update(data1Update), 3000);
3741

3842
// LineGraph 2
39-
const cfg2 = config.downloadVideosInterval1day;
40-
const data2 = dataCDS.downloadVideosInterval1day;
41-
const class2 = 'downloads_day';
42-
const g2 = new LineGraph(cfg2, data2, class2);
43-
g2.render();
43+
// const g2 = new LineGraph(cfg2, data2, class2);
44+
// g2.render();

examples/line/styles.scss

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ $white: #fff;
4141
.igj-focus {
4242
circle {
4343
fill: none;
44-
stroke-opacity: .75;
44+
stroke-opacity: .85;
4545
stroke-width: 7px;
4646
}
4747
transition: transform 150ms;
4848
}
4949

5050
svg {
51-
margin: 30px;
51+
margin: 12px;
5252
pointer-events: all;
5353
}
5454

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
"eslint-plugin-jsx-a11y": "^6.0.2",
3030
"eslint-plugin-react": "^7.1.0",
3131
"istanbul": "^0.4.5",
32-
"jasmine": "^2.6.0",
33-
"jasmine-core": "^2.6.4",
32+
"jasmine": "^2.7.0",
33+
"jasmine-core": "^2.7.0",
3434
"jsdoc": "^3.5.3",
3535
"karma": "^1.7.0",
3636
"karma-coverage": "^1.1.1",
@@ -45,6 +45,7 @@
4545
},
4646
"dependencies": {
4747
"d3": "^4.10.0",
48+
"d3-extended": "^1.2.10",
4849
"d3-svg-legend": "^2.24.1",
4950
"d3-tip": "^0.7.1",
5051
"lodash": "^4.17.4"

0 commit comments

Comments
 (0)