Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions ckanext/basiccharts/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def update_config(self, config):
def info(self):
schema = {
'y_axis': [not_empty],
'show_legends': [ignore_missing]
'show_legends': [ignore_missing],
'count_rows': [ignore_missing]
}

if self.GROUP_BY_IS_REQUIRED:
Expand All @@ -49,6 +50,7 @@ def setup_template_variables(self, context, data_dict):
resource = data_dict['resource']
resource_view = data_dict['resource_view']
resource_view['show_legends'] = bool(resource_view.get('show_legends'))
resource_view['count_rows'] = bool(resource_view.get('count_rows'))

fields = _get_fields_without_id(resource)

Expand Down Expand Up @@ -194,7 +196,7 @@ def _fields_as_string(self, resource_view):
def _view_data(resource_view):
data = {
'resource_id': resource_view['resource_id'],
'limit': int(resource_view.get('limit', 100))
'limit': 50000
}

filters = resource_view.get('filters', {})
Expand Down
50 changes: 38 additions & 12 deletions ckanext/basiccharts/theme/public/basiccharts.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ this.ckan.views.basiccharts = this.ckan.views.basiccharts || {};
hits.reverse();
}
}

data = prepareDataForPlot(fields, hits, config.xaxis, config.yaxis, params);

if (fields[params.x_axis]){
for (let key = 0; key < data.length; key++) {
config['xaxis']['ticks'].push([key, data[key]['label']]);
}
}
$.plot(elementId, data, config);
});
}
Expand All @@ -49,7 +52,7 @@ this.ckan.views.basiccharts = this.ckan.views.basiccharts || {};
var query = {
filters: [],
sort: [],
size: 1000
size: 50000
};

if (params.filters) {
Expand Down Expand Up @@ -115,6 +118,7 @@ this.ckan.views.basiccharts = this.ckan.views.basiccharts || {};
text: {
mode: "categories",
tickColor: "rgba(0, 0, 0, 0)",
ticks: [],
tickFormatter: function (value, axis) {
return value;
}
Expand All @@ -124,7 +128,7 @@ this.ckan.views.basiccharts = this.ckan.views.basiccharts || {};
};

config = {
yaxis: axisConfigByType[yAxisType],
yaxis: 'numeric',
colors: ['#e41a1c', '#377eb8', '#4daf4a',
'#984ea3', '#ff7f00', '#ffff33',
'#a65628', '#f781bf', '#999999']
Expand All @@ -137,7 +141,7 @@ this.ckan.views.basiccharts = this.ckan.views.basiccharts || {};
show: true,
label: {
show: true,
threshold: 0.05
threshold: 0.5
}
}
},
Expand All @@ -149,7 +153,7 @@ this.ckan.views.basiccharts = this.ckan.views.basiccharts || {};
},
tooltip: true,
tooltipOpts: {
content: "%p.0%, %s"
content: "%s: %p.0% (%y.0)"
}
});
} else {
Expand All @@ -163,7 +167,7 @@ this.ckan.views.basiccharts = this.ckan.views.basiccharts || {};
},
tooltip: true,
tooltipOpts: {
content: "%s | "+params.x_axis+": %x | "+params.y_axis+": %y",
content: "%s: %y.0",
xDateFormat: "%d/%m/%Y",
yDateFormat: "%d/%m/%Y"
}
Expand All @@ -173,7 +177,6 @@ this.ckan.views.basiccharts = this.ckan.views.basiccharts || {};
if (xAxisType) {
config.xaxis = axisConfigByType[xAxisType];
}

return config;
}

Expand All @@ -197,11 +200,34 @@ this.ckan.views.basiccharts = this.ckan.views.basiccharts || {};
if (x === null) {
return;
}
result[group_by] = result[group_by] || [];
result[group_by].push([xParsed, yParsed]);
if (params['count_rows']){
if (result[group_by]){
result[group_by][0][1] = result[group_by][0][1] + 1;
}else{
result[group_by] = result[group_by] || [];
result[group_by].push([xParsed, 1]);
}
}else if (typeof yParsed == 'number') {
if (typeof yParsed == 'number'){
result[group_by] = result[group_by] || [];
if (result[group_by].length > 0){
result[group_by][0][1] = result[group_by][0][1] + yParsed;
}else{
result[group_by].push([xParsed, yParsed]);
}
}
}else{
result[group_by] = result[group_by] || [];
result[group_by].push([xParsed, yParsed]);
}
} else {
result[group_by] = result[group_by] || 0;
result[group_by] = result[group_by] + yParsed;
if (params['count_rows'] || typeof yParsed == 'string'){
result[group_by] = result[group_by] || 0;
result[group_by] = result[group_by] + 1;
}else{
result[group_by] = result[group_by] || 0;
result[group_by] = result[group_by] + yParsed;
}
}
});
return result;
Expand Down
5 changes: 5 additions & 0 deletions ckanext/basiccharts/theme/templates/barchart_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@
form.checkbox('horizontal', label=_('Horizontal'),
value=True, checked=resource_view['horizontal'])
}}

{{
form.checkbox('count_rows', label=_("Count Rows"),
value=True, checked=resource_view['count_rows'])
}}
{% endblock %}
5 changes: 5 additions & 0 deletions ckanext/basiccharts/theme/templates/linechart_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@
form.checkbox('show_legends', label=_("Show groups' legend"),
value=True, checked=resource_view['show_legends'])
}}

{{
form.checkbox('count_rows', label=_("Count Rows"),
value=True, checked=resource_view['count_rows'])
}}
{% endblock %}
6 changes: 6 additions & 0 deletions ckanext/basiccharts/theme/templates/piechart_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@
form.checkbox('show_legends', label=_("Show groups' legend"),
value=True, checked=resource_view['show_legends'])
}}

{{
form.checkbox('count_rows', label=_("Count Rows"),
value=True, checked=resource_view['count_rows'])
}}

{% endblock %}