Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add awards over time chart to awards dash #113

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
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
46 changes: 28 additions & 18 deletions client/app/components/c3-chart/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ export default Ember.Component.extend({
if (this.get('name') === "Awards") {
this.processData(this.get('aggregations.funders.buckets'));
}
if (this.get('name') === "Awards Over Time") {
this.processData(this.get('aggregations.awards_over_time.buckets'));
}
},

processData: async function(data) {
Expand All @@ -102,7 +105,7 @@ export default Ember.Component.extend({
)
);
}
if (this.get('name') === "Awards") {
if (this.get('name') === "Awards" || this.get('name') === 'Awards Over Time') {
data = data.map(function(datum) {
datum._source = {
id: datum.key,
Expand All @@ -126,11 +129,8 @@ export default Ember.Component.extend({
}),

updateChart: async function() {

var self = this;

let chart_type = this.get('chartType');

let chart_options = {
bindto: this.$(this.element).find('.renderChart')[0],
data: {
Expand All @@ -149,7 +149,7 @@ export default Ember.Component.extend({
},
};

if (chart_type == 'donut') {
if (chart_type === 'donut') {
var title = '';

var _data = this.get('data');
Expand Down Expand Up @@ -274,19 +274,27 @@ export default Ember.Component.extend({
chart_options['point'] = {show: false};

} else if (chart_type === 'timeseries') {


let x_axis = this.get('data.aggregations.all_over_time.buckets').map((datum) => { return datum.key_as_string; });
var columns = this.get('data.aggregations.sorted_by_type.buckets').map((bucket) => {
return [bucket.key].concat(bucket['type_over_time'].buckets.reduce((ret, bucket) => {
ret[x_axis.indexOf(bucket.key_as_string)] = linearToLog10(bucket.doc_count);
return ret;
}, (new Array(x_axis.length)).fill(0)));
});
columns.unshift(['x'].concat(x_axis));
columns.unshift(['All Events'].concat(this.get('data.aggregations.all_over_time.buckets').map((bucket) => {
if (this.get('name') === 'Awards Over Time') {
let x_axis = this.get('data').map((datum) => datum.key_as_string);
var columns = [];
columns.unshift(['x'].concat(x_axis));
columns.unshift(['Awards'].concat(this.get('data').map((bucket) => {
return bucket.doc_count;
})));
} else {
let x_axis = this.get('data.aggregations.all_over_time.buckets').map((datum) => { return datum.key_as_string; });
var columns = this.get('data.aggregations.sorted_by_type.buckets').map((bucket) => {
return [bucket.key].concat(bucket['type_over_time'].buckets.reduce((ret, bucket) => {
ret[x_axis.indexOf(bucket.key_as_string)] = linearToLog10(bucket.doc_count);
return ret;
}, (new Array(x_axis.length)).fill(0)));
});
columns.unshift(['x'].concat(x_axis));
columns.unshift(['All Events'].concat(this.get('data.aggregations.all_over_time.buckets').map((bucket) => {
return linearToLog10(bucket.doc_count);
})));

}
let data_x = 'x';
chart_options['axis'] = {
x: {
Expand All @@ -302,9 +310,11 @@ export default Ember.Component.extend({
y: {
min: 1,
tick: {
format: log10ToLinear
culling: {
max: 10
}
},
label: 'Number of Items (Log Scale)'
label: 'Number of Items'
}
};
let data_types = columns.reduce((r, c, i, a) => {
Expand Down
60 changes: 59 additions & 1 deletion client/app/routes/dashboards/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,65 @@ export default Ember.Route.extend({
}
],
facetDash: "awards"
}
},
{
chartType: 'timeseries',
widgetType: 'c3-chart',
name: 'Awards Over Time',
width: 12,
facetDash: "awards",
post_body: {
"aggregations": {
"awards_over_time": {
"date_histogram": {
"field": "lists.funders.awards.date",
"interval": "1M",
"format": "yyyy-MM-dd"
},
"aggregations": {
"awards": {
"sum": {
"script": {
"lang": "expression",
"inline": "doc['lists.funders.awards.amount'].sum()"
}
}
}
}
}
}
},
postBodyParams: [
{
parameterPath: ["query", "bool", "minimum_should_match"],
parameterName: "shouldMatch",
defaultValue: 1
},
{
parameterPath: ["query", "bool", "should"],
defaultValue: (()=>{ return transition.queryParams.all ? ucsd_query : undefined; })()
},
{
parameterPath: ["query", "bool", "filter", 0, "term", "sources"],
parameterName: "sources"
},
{
parameterPath: ["query", "bool", "must", 1, "range", "date", "gte"],
parameterName: "min_date",
defaultValue: gte
},
{
parameterPath: ["query", "bool", "must", 1, "range", "date", "lte"],
parameterName: "max_date",
defaultValue: lte
},
{
parameterPath: ["query", "bool", "must", 1, "range", "date", "format"],
parameterName: "date_range_format",
defaultValue: "yyyy-MM-dd||yyyy"
}
]
}
]
},
institution2: {
Expand Down