Skip to content

Commit 42091e4

Browse files
Merge pull request #111 from ViderumGlobal/add-y-label
Add y label
2 parents 81a2bf8 + b7a389a commit 42091e4

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

ckanext/querytool/controllers/querytool.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ def edit_visualizations(self, querytool=None, data=None,
269269
data['chart_field_padding_bottom_{}'.format(id)]
270270
visualization['padding_top'] = \
271271
data['chart_field_padding_top_{}'.format(id)]
272+
visualization['y_label'] = \
273+
data['chart_field_y_label_{}'.format(id)]
272274
if 'chart_field_legend_{}'.format(id) in data:
273275
visualization['show_legend'] = 'true'
274276
else:

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ ckan.module('querytool-viz-preview', function() {
8686
var padding_top = this.options.padding_top;
8787
var padding_bottom = this.options.padding_bottom;
8888
var show_labels = this.options.show_labels;
89-
89+
var y_label = this.options.y_label;
9090
var options = {
9191
bindto: this.el[0],
9292
color: {
@@ -228,7 +228,8 @@ ckan.module('querytool-viz-preview', function() {
228228
padding: {
229229
top: padding_top,
230230
bottom: padding_bottom
231-
}
231+
},
232+
label: y_label
232233
},
233234
x: {
234235
type: 'category',
@@ -287,6 +288,9 @@ ckan.module('querytool-viz-preview', function() {
287288
var dataLabels = chartField.find('input[name*=chart_field_labels_]');
288289
var dataLabelsVal = dataLabels.is(':checked');
289290

291+
var yLabbel = chartField.find('input[name*=chart_field_y_label_]');
292+
var yLabbelVal = yLabbel.val();
293+
290294
// If the changed values from the dropdowns are from color, chart type or text rotate
291295
// then just update the chart without fetching new data. This leads
292296
// to a better UX.
@@ -304,6 +308,7 @@ ckan.module('querytool-viz-preview', function() {
304308
this.options.padding_top = paddingTopVal;
305309
this.options.padding_bottom = paddingBottomVal;
306310
this.options.show_labels = dataLabelsVal;
311+
this.options.y_label = yLabbelVal;
307312
this.createChart(this.fetched_data);
308313

309314
return;
@@ -322,6 +327,7 @@ ckan.module('querytool-viz-preview', function() {
322327
this.options.padding_top = paddingTopVal;
323328
this.options.padding_bottom = paddingBottomVal;
324329
this.options.show_labels = dataLabelsVal;
330+
this.options.y_label = yLabbelVal;
325331
var newSqlString = this.create_sql_string();
326332

327333
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
@@ -113,6 +113,16 @@
113113
</div>
114114
</div>
115115

116+
{% if chart %}
117+
{% set y_label = chart.y_label %}
118+
{% endif %}
119+
<div class="control-group ">
120+
<label class="control-label" for="chart_field_y_label_{{ n }}">{{ _('Y axis label') }}</label>
121+
<div class="controls ">
122+
<input id="chart_field_y_label_{{ n }}" type="text" name="chart_field_y_label_{{ n }}" value="{{ y_label }}">
123+
</div>
124+
</div>
125+
116126

117127
{% if chart %}
118128
{% set ptop = chart.padding_top %}
@@ -159,6 +169,7 @@
159169
{% set padding_bottom = chart.padding_bottom %}
160170
{% set padding_top = chart.padding_top %}
161171
{% set show_labels = chart.show_labels %}
172+
{% set y_label = chart.y_label %}
162173
{% endif %}
163174

164175
{% snippet 'ajax_snippets/visualization_item.html',
@@ -176,7 +187,8 @@
176187
y_tick_format = y_tick_format,
177188
padding_bottom = padding_bottom,
178189
padding_top = padding_top,
179-
show_labels = show_labels
190+
show_labels = show_labels,
191+
y_label = y_label
180192
%}
181193
</div>
182194
</div>

ckanext/querytool/templates/ajax_snippets/visualization_item.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
data-module-y_tick_format="{{ y_tick_format }}"
1414
data-module-padding_top="{{ padding_top }}"
1515
data-module-padding_bottom="{{ padding_bottom }}"
16-
data-module-show_labels="{{ show_labels }}">
16+
data-module-show_labels="{{ show_labels }}"
17+
data-module-y_label="{{ y_label }}">
1718
Loading...
1819
</div>

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

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

0 commit comments

Comments
 (0)