Skip to content

Commit d0dee28

Browse files
tanvirchahalroll
authored andcommitted
Responsive Design fixes (#332)
* Increased chart width on mobile * Updates to charts css * removed added widths * Reduced the paddings and added multiline support * Smaller labels and text wrap on titles * Updated x-tickcount for line charts * Updated x-tickcount for line charts
1 parent d0aceb3 commit d0dee28

File tree

6 files changed

+165
-34
lines changed

6 files changed

+165
-34
lines changed

ckanext/querytool/fanstatic/css/main.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ckanext/querytool/fanstatic/css/public-query-tool.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ckanext/querytool/fanstatic/css/public-story-tool.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ckanext/querytool/fanstatic/javascript/modules/viz-preview.js

Lines changed: 75 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,14 @@ ckan.module('querytool-viz-preview', function() {
178178
optionalFilter: optionalFilter,
179179
});
180180
options.title = {
181-
text: titleVal
181+
text: titleVal,
182+
position: "upper-left",
183+
padding: {
184+
left: 0,
185+
right: 0,
186+
bottom: 15,
187+
top:0
188+
}
182189
}
183190

184191
options.legend = {
@@ -252,14 +259,15 @@ ckan.module('querytool-viz-preview', function() {
252259
rotate: yrotate
253260
},
254261
padding: {
255-
top: parseInt(padding_top),
262+
top: 200,
256263
bottom: parseInt(padding_bottom)
257264
}
258265
},
259266
x: {
260267
tick: {
261268
rotate: x_text_rotate,
262-
multiline: x_text_multiline
269+
multiline: true,
270+
multilineMax: 2,
263271
}
264272
}
265273
}
@@ -338,37 +346,73 @@ ckan.module('querytool-viz-preview', function() {
338346
}
339347
}
340348

341-
options.axis = {
342-
y: {
343-
tick: {
344-
count: tick_count,
345-
format: function(value) {
346-
var dataf = this.sortFormatData(y_tick_format, value);
347-
return dataf;
348-
}.bind(this),
349-
rotate: yrotate
349+
//Tick count on x-axis for line charts
350+
if (this.options.chart_type === 'line') {
351+
options.axis = {
352+
y: {
353+
tick: {
354+
count: tick_count,
355+
format: function(value) {
356+
var dataf = this.sortFormatData(y_tick_format, value);
357+
return dataf;
358+
}.bind(this),
359+
rotate: yrotate
360+
},
361+
padding: {
362+
top: 200,
363+
bottom: parseInt(padding_bottom)
364+
},
365+
label: {
366+
text: y_label || measure_label || '',
367+
position: 'outer-middle',
368+
}
350369
},
351-
padding: {
352-
top: parseInt(padding_top),
353-
bottom: parseInt(padding_bottom)
370+
x: {
371+
type: 'category',
372+
categories: categories,
373+
tick: {
374+
count:5,
375+
rotate: x_text_rotate,
376+
multiline: true,
377+
multilineMax: 2
378+
}
354379
},
355-
label: {
356-
text: y_label || measure_label || '',
357-
position: 'outer-middle',
358-
}
359-
},
360-
x: {
361-
type: 'category',
362-
categories: categories,
363-
tick: {
364-
rotate: x_text_rotate,
365-
multiline: x_text_multiline,
366-
fit: true
367-
}
368-
},
369-
rotated: rotate,
370-
};
380+
rotated: rotate,
381+
};
382+
} else {
383+
//no Tick count on x-axis for bar
384+
options.axis = {
385+
y: {
386+
tick: {
387+
count: tick_count,
388+
format: function(value) {
389+
var dataf = this.sortFormatData(y_tick_format, value);
390+
return dataf;
391+
}.bind(this),
392+
rotate: yrotate
393+
},
394+
padding: {
395+
top: 200,
396+
bottom: parseInt(padding_bottom)
397+
},
398+
label: {
399+
text: y_label || measure_label || '',
400+
position: 'outer-middle',
401+
}
402+
},
403+
x: {
404+
type: 'category',
405+
categories: categories,
406+
tick: {
407+
rotate: x_text_rotate,
408+
multiline: true,
409+
multilineMax: 2
410+
}
411+
},
412+
rotated: rotate,
413+
};
371414

415+
}
372416
options.point = {
373417
r: 3,
374418
}

ckanext/querytool/fanstatic/javascript/public_query.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,5 +277,47 @@
277277
copyText.select();
278278
document.execCommand("Copy");
279279
});
280+
281+
280282
});
283+
284+
$(window).load(function(){
285+
//Only running on mobile phones
286+
if ($(window).width() <= 500) {
287+
setTimeout(function() { splitTitles(); }, 1000);
288+
}
289+
})
290+
291+
function splitTitles(){
292+
$(".c3-title").each(function(){
293+
//Fetching the HTML
294+
var text = $(this).html().split(" ");
295+
296+
//Getting word length
297+
var words = text.length;
298+
299+
var html = "";
300+
var y = 10;
301+
if(words>10){
302+
for(var i=1;i<=words;i++){
303+
//Splitting the string every 10 words and adding tspan
304+
if((i%10)==0) {
305+
html += "<tspan x=0 y="+y+">"+text.slice(i-10, i).join(" ") + "</tspan><tspan x=0 y="+(y+13)+">"+text.slice(i, i+10).join(" ") + "</tspan>";
306+
y = y+13;
307+
}
308+
}
309+
$(this).html(html);
310+
}
311+
312+
313+
314+
315+
console.log("words is: "+words)
316+
});
317+
318+
//Custom Function to split headers
319+
$(".c3-title").each(function(){
320+
321+
});
322+
}
281323
})($);

ckanext/querytool/fanstatic/less/inc/responsive.less

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,51 @@
195195
flex: auto;
196196
}
197197
}
198+
199+
.size-lg.chart {
200+
.item-content{
201+
height:500px !important;
202+
}
203+
}
204+
205+
/* Mobile updates to charts */
206+
.public-query {
207+
.item.chart {
208+
margin-right:0;
209+
padding-left:10px !important;
210+
padding-right:10px !important;
211+
}
212+
213+
.item {
214+
margin-left:0 !important;
215+
}
216+
217+
.item-content.c3 {
218+
min-height:460px;
219+
}
220+
221+
.c3-title {
222+
font-size:12px !important;
223+
}
224+
}
225+
226+
.public-query {
227+
.visualizations {
228+
padding-right:0px !important;
229+
}
230+
}
231+
232+
.c3-axis-y text
233+
{
234+
font-size: 10px;
235+
font-weight: 300;
236+
}
237+
238+
.c3-axis-x text
239+
{
240+
font-size: 10px;
241+
font-weight: 300;
242+
}
198243
}
199244

200245
/* Landscape phone to portrait tablet */

0 commit comments

Comments
 (0)