Skip to content

Commit 81a2bf8

Browse files
Merge pull request #110 from ViderumGlobal/add-axis-labeling
Add axis labeling
2 parents c9baf62 + 84f96ab commit 81a2bf8

File tree

5 files changed

+32
-5
lines changed

5 files changed

+32
-5
lines changed

ckanext/querytool/controllers/querytool.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ def edit_visualizations(self, querytool=None, data=None,
273273
visualization['show_legend'] = 'true'
274274
else:
275275
visualization['show_legend'] = 'false'
276+
if 'chart_field_labels_{}'.format(id) in data:
277+
visualization['show_labels'] = 'true'
278+
else:
279+
visualization['show_labels'] = 'false'
276280

277281
visualizations.append(visualization)
278282

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ ckan.module('querytool-viz-preview', function() {
8585
var y_tick_format = this.options.y_tick_format;
8686
var padding_top = this.options.padding_top;
8787
var padding_bottom = this.options.padding_bottom;
88+
var show_labels = this.options.show_labels;
89+
8890
var options = {
8991
bindto: this.el[0],
9092
color: {
@@ -214,7 +216,8 @@ ckan.module('querytool-viz-preview', function() {
214216
values.unshift(this.options.y_axis);
215217
options.data = {
216218
columns: [values],
217-
type: ctype
219+
type: ctype,
220+
labels: show_labels
218221
};
219222
options.axis = {
220223
y: {
@@ -261,7 +264,7 @@ ckan.module('querytool-viz-preview', function() {
261264
var chartTitleVal = chartTitle.val();
262265

263266
var legend = chartField.find('input[name*=chart_field_legend_]');
264-
var legendVal = legend.is(':checked')
267+
var legendVal = legend.is(':checked');
265268

266269
var xTextRotate = chartField.find('[name*=chart_field_x_text_rotate_]');
267270
var xTextRotateVal = xTextRotate.val();
@@ -280,6 +283,10 @@ ckan.module('querytool-viz-preview', function() {
280283

281284
var paddingBottom = chartField.find('input[name*=chart_field_padding_bottom_]');
282285
var paddingBottomVal = paddingBottom.val();
286+
287+
var dataLabels = chartField.find('input[name*=chart_field_labels_]');
288+
var dataLabelsVal = dataLabels.is(':checked');
289+
283290
// If the changed values from the dropdowns are from color, chart type or text rotate
284291
// then just update the chart without fetching new data. This leads
285292
// to a better UX.
@@ -296,6 +303,7 @@ ckan.module('querytool-viz-preview', function() {
296303
this.options.y_tick_format = yTickFormatVal;
297304
this.options.padding_top = paddingTopVal;
298305
this.options.padding_bottom = paddingBottomVal;
306+
this.options.show_labels = dataLabelsVal;
299307
this.createChart(this.fetched_data);
300308

301309
return;
@@ -313,6 +321,7 @@ ckan.module('querytool-viz-preview', function() {
313321
this.options.y_tick_format = yTickFormatVal;
314322
this.options.padding_top = paddingTopVal;
315323
this.options.padding_bottom = paddingBottomVal;
324+
this.options.show_labels = dataLabelsVal;
316325
var newSqlString = this.create_sql_string();
317326

318327
this.get_resource_datа(newSqlString);

ckanext/querytool/templates/ajax_snippets/chart_fields.html

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@
6060
</div>
6161

6262
{% if chart %}
63+
{% set show_labels = chart.show_labels %}
64+
{% endif %}
65+
<div class="control-group ">
66+
<label class="control-label" for="chart_field_labels_{{ n }}">{{ _('Show data labels') }}</label>
67+
<div class="controls ">
68+
<input id="chart_field_labels_{{ n }}" type="checkbox" name="chart_field_labels_{{ n }}" value="{{ show_labels }}"{% if show_labels=='false' %}{% else %}checked{% endif %}>
69+
</div>
70+
</div>
71+
72+
{% if chart %}
6373
{% set show_legend = chart.show_legend %}
6474
{% endif %}
6575
<div class="control-group ">
@@ -148,6 +158,7 @@
148158
{% set y_tick_format = chart.y_tick_format %}
149159
{% set padding_bottom = chart.padding_bottom %}
150160
{% set padding_top = chart.padding_top %}
161+
{% set show_labels = chart.show_labels %}
151162
{% endif %}
152163

153164
{% snippet 'ajax_snippets/visualization_item.html',
@@ -164,7 +175,8 @@
164175
tooltip_format = tooltip_format,
165176
y_tick_format = y_tick_format,
166177
padding_bottom = padding_bottom,
167-
padding_top = padding_top
178+
padding_top = padding_top,
179+
show_labels = show_labels
168180
%}
169181
</div>
170182
</div>

ckanext/querytool/templates/ajax_snippets/visualization_item.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
data-module-tooltip_format="{{ tooltip_format }}"
1313
data-module-y_tick_format="{{ y_tick_format }}"
1414
data-module-padding_top="{{ padding_top }}"
15-
data-module-padding_bottom="{{ padding_bottom }}">
15+
data-module-padding_bottom="{{ padding_bottom }}"
16+
data-module-show_labels="{{ show_labels }}">
1617
Loading...
1718
</div>

ckanext/querytool/templates/querytool/public/read.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ <h1>{{ querytool.title }}</h1>`
8282
tooltip_format = item.tooltip_format,
8383
y_tick_format = item.y_tick_format,
8484
padding_bottom = item.padding_bottom,
85-
padding_top = item.padding_top
85+
padding_top = item.padding_top,
86+
show_labels = item.show_labels
8687
%}
8788
</div>
8889
{% endfor %}

0 commit comments

Comments
 (0)