From 5635fcbc3a3f54cc3ff3cc1b955d545ad8009915 Mon Sep 17 00:00:00 2001 From: 545zhou <545zhou@gmail.com> Date: Tue, 6 Dec 2016 21:06:49 -0500 Subject: [PATCH 1/6] created new plotly donut chart --- client/app/components/donut-chart-plotly.js | 90 +++++++++++++++++++ client/app/components/generic-chart.js | 15 +++- client/app/routes/dashboards/dashboard.js | 4 +- .../components/donut-chart-plotly.hbs | 2 + client/bower.json | 3 +- client/ember-cli-build.js | 1 + service/dashboard/migrations/0001_initial.py | 31 +++++++ service/service/settings/local.py | 6 +- service/widget/migrations/0001_initial.py | 29 ++++++ 9 files changed, 174 insertions(+), 7 deletions(-) create mode 100644 client/app/components/donut-chart-plotly.js create mode 100644 client/app/templates/components/donut-chart-plotly.hbs create mode 100644 service/dashboard/migrations/0001_initial.py create mode 100644 service/widget/migrations/0001_initial.py diff --git a/client/app/components/donut-chart-plotly.js b/client/app/components/donut-chart-plotly.js new file mode 100644 index 000000000..159c67e70 --- /dev/null +++ b/client/app/components/donut-chart-plotly.js @@ -0,0 +1,90 @@ +/* global Plotly */ +import Ember from 'ember'; + +export default Ember.Component.extend({ + classNames: ['chart'], + + sourcesList: Ember.computed('data', function() { + return this.get('data').map(({ key, doc_count }) => [key, doc_count]); + }), + + dataChanged: Ember.observer('aggregations', function() { + this.updateDonut(); + }), + + data: [], + + sizeChanged: Ember.observer('resizedSignal', function() { + this.updateDonut(); + }), + + updateDonut() { + this.set('data', this.get('aggregations.sources.buckets')); + let columns = this.get('sourcesList'); + let title = 'Published in...'; + let donut = this.get('donut'); + if (donut) { + donut.load({ + columns, + unload: true + }); + donut.resize({ + height: this.get('height')*150-20, + width: this.get('width')*150 + }); + } else { + this.initDonut(title, columns); + } + }, + + initDonut(title, columns) { + let element = this.$(`.donut`).get(0); + // let donut = c3.generate({ + // bindto: element, + // data: { + // columns, + // type: 'donut' + // }, + // legend: { show: false }, + // donut: { + // title, + // label: { + // show: false + // } + // }, + // size: { height: this.get('height')*150-20 } + // }); + // this.set('donut', donut); + let labels = this.get('sourcesList').map(function(value,index) { return value[0]; }); + let values = this.get('sourcesList').map(function(value,index) { return value[1]; }); + var data = [{ + values: values, + labels: labels, + hoverinfo: 'label+percent', + hole: .6, + type: 'pie', + direction : 'clockwise', + outsidetextfont:{color:'#FFFFFF'}, + }]; + + var layout = { + annotations:[{ + font: { + size: 12 + }, + showarrow: false, + text: 'Published in...', + x: 0.5, + y: 0.5, + }], + showlegend: false, + }; + + this.set('chart', Plotly.newPlot(element, data, layout)); + }, + + didRender() { + this.updateDonut(); + }, + +}); diff --git a/client/app/components/generic-chart.js b/client/app/components/generic-chart.js index d6f6ff5e1..33882bbce 100644 --- a/client/app/components/generic-chart.js +++ b/client/app/components/generic-chart.js @@ -1,4 +1,5 @@ /* global c3 */ +/* global Plotly */ import Ember from 'ember'; export default Ember.Component.extend({ @@ -15,7 +16,7 @@ export default Ember.Component.extend({ sizeChanged: Ember.observer('resizedSignal', function() { if (this.get('resizedSignal') == false) return; this.updateChart(); - this.set('resizedSignal', false); + this.set('resizedSignal', false); //debugger; }), @@ -127,7 +128,19 @@ export default Ember.Component.extend({ chart_options['data']['columns'] = columns; chart_options[chart_type]['title'] = title; + + var data = [{ + values: [19, 26, 55], + labels: ['Residential', 'Non-Residential', 'Utility'], + type: 'pie' + }]; + + var layout = { + height: 400, + width: 500 + }; this.set('chart', c3.generate(chart_options)); + // this.set('chart', Plotly.newPlot(this.element, data, layout)); }, diff --git a/client/app/routes/dashboards/dashboard.js b/client/app/routes/dashboards/dashboard.js index ce5a76ceb..e3c7f3087 100644 --- a/client/app/routes/dashboards/dashboard.js +++ b/client/app/routes/dashboards/dashboard.js @@ -11,8 +11,8 @@ export default Ember.Route.extend({ widgets: [ {chartType: 'topContributors', widgetType: 'top-contributors', name: 'Top Contributors'}, {chartType: 'timeseries', widgetType: 'generic-chart', name:'timeser'}, - {chartType: 'donut', widgetType: 'generic-chart', name: 'don1'}, - {chartType: 'donut', widgetType: 'generic-chart', name: 'don2'} + {chartType: 'donut', widgetType: 'donut-chart', name: 'don1'}, + {chartType: 'donut', widgetType: 'donut-chart-plotly', name: 'don2'} ] }, user: { diff --git a/client/app/templates/components/donut-chart-plotly.hbs b/client/app/templates/components/donut-chart-plotly.hbs new file mode 100644 index 000000000..dc250f8cb --- /dev/null +++ b/client/app/templates/components/donut-chart-plotly.hbs @@ -0,0 +1,2 @@ +
+{{yield}} diff --git a/client/bower.json b/client/bower.json index cfe53bc6e..6293d0869 100644 --- a/client/bower.json +++ b/client/bower.json @@ -14,6 +14,7 @@ "packery": "^2.1.1", "font-awesome": "^4.7.0", "toastr": "^2.1.3", - "freewall": "^1.0.6" + "freewall": "^1.0.6", + "plotlyjs": "plotly#^1.18.1" } } diff --git a/client/ember-cli-build.js b/client/ember-cli-build.js index 89f82456b..548e29e4f 100644 --- a/client/ember-cli-build.js +++ b/client/ember-cli-build.js @@ -26,6 +26,7 @@ module.exports = function(defaults) { app.import('bower_components/d3/d3.js'); app.import('bower_components/c3/c3.js'); + app.import('bower_components/plotlyjs/plotly.js'); app.import('bower_components/freewall/freewall.js'); app.import('bower_components/packery/dist/packery.pkgd.min.js'); app.import('bower_components/draggabilly/dist/draggabilly.pkgd.min.js') diff --git a/service/dashboard/migrations/0001_initial.py b/service/dashboard/migrations/0001_initial.py new file mode 100644 index 000000000..58bde90ea --- /dev/null +++ b/service/dashboard/migrations/0001_initial.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2016-12-05 20:36 +from __future__ import unicode_literals + +from django.conf import settings +import django.contrib.postgres.fields.jsonb +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('widget', '0001_initial'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Dashboard', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(default='Unnamed Dashboard', max_length=64)), + ('settings', django.contrib.postgres.fields.jsonb.JSONField(blank=True, null=True)), + ('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ('widgets', models.ManyToManyField(related_name='containing_dashboards', to='widget.Widget')), + ], + ), + ] diff --git a/service/service/settings/local.py b/service/service/settings/local.py index 4a06dfd9a..4a35b1547 100644 --- a/service/service/settings/local.py +++ b/service/service/settings/local.py @@ -1,9 +1,9 @@ DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': 'public', - 'USER': 'admin', - 'PASSWORD': 'itsover9000', + 'NAME': 'share', + 'USER': 'taozhou', + 'PASSWORD': '', 'HOST': '127.0.0.1', 'PORT': '5432', } diff --git a/service/widget/migrations/0001_initial.py b/service/widget/migrations/0001_initial.py new file mode 100644 index 000000000..8c3230592 --- /dev/null +++ b/service/widget/migrations/0001_initial.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2016-12-05 20:36 +from __future__ import unicode_literals + +import django.contrib.postgres.fields.jsonb +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Widget', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(default='Unnamed Widget', max_length=32)), + ('author', models.TextField(max_length=20, null=True)), + ('width', models.IntegerField(default=2)), + ('height', models.IntegerField(default=2)), + ('query', django.contrib.postgres.fields.jsonb.JSONField(blank=True, null=True)), + ('settings', django.contrib.postgres.fields.jsonb.JSONField(blank=True, null=True)), + ], + ), + ] From 75afee9c6731862954a2316a7371a2905d17a10e Mon Sep 17 00:00:00 2001 From: 545zhou <545zhou@gmail.com> Date: Wed, 7 Dec 2016 09:00:18 -0500 Subject: [PATCH 2/6] deleted unnecessary --- client/app/components/generic-chart.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/client/app/components/generic-chart.js b/client/app/components/generic-chart.js index 33882bbce..cfc3aafd3 100644 --- a/client/app/components/generic-chart.js +++ b/client/app/components/generic-chart.js @@ -129,18 +129,7 @@ export default Ember.Component.extend({ chart_options['data']['columns'] = columns; chart_options[chart_type]['title'] = title; - var data = [{ - values: [19, 26, 55], - labels: ['Residential', 'Non-Residential', 'Utility'], - type: 'pie' - }]; - - var layout = { - height: 400, - width: 500 - }; this.set('chart', c3.generate(chart_options)); - // this.set('chart', Plotly.newPlot(this.element, data, layout)); }, From cad7492c88565d59c7d2d2cc4f11037b7850134d Mon Sep 17 00:00:00 2001 From: Tao Zhou <545zhou@gmail.com> Date: Wed, 7 Dec 2016 09:02:51 -0500 Subject: [PATCH 3/6] Delete local.py --- service/service/settings/local.py | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 service/service/settings/local.py diff --git a/service/service/settings/local.py b/service/service/settings/local.py deleted file mode 100644 index 4a35b1547..000000000 --- a/service/service/settings/local.py +++ /dev/null @@ -1,10 +0,0 @@ -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': 'share', - 'USER': 'taozhou', - 'PASSWORD': '', - 'HOST': '127.0.0.1', - 'PORT': '5432', - } -} From 83f451ec1dc11f6dcb00acdc336057afd92637bd Mon Sep 17 00:00:00 2001 From: 545zhou <545zhou@gmail.com> Date: Mon, 12 Dec 2016 10:07:23 -0500 Subject: [PATCH 4/6] init barchart plotly --- client/app/components/bar-chart-plotly.js | 0 client/app/templates/components/bar-chart-plotly.hbs | 2 ++ 2 files changed, 2 insertions(+) create mode 100644 client/app/components/bar-chart-plotly.js create mode 100644 client/app/templates/components/bar-chart-plotly.hbs diff --git a/client/app/components/bar-chart-plotly.js b/client/app/components/bar-chart-plotly.js new file mode 100644 index 000000000..e69de29bb diff --git a/client/app/templates/components/bar-chart-plotly.hbs b/client/app/templates/components/bar-chart-plotly.hbs new file mode 100644 index 000000000..64315d8a3 --- /dev/null +++ b/client/app/templates/components/bar-chart-plotly.hbs @@ -0,0 +1,2 @@ +
+{{yield}} From 86ee384a9799293843537f79eaaa21d85d3fef64 Mon Sep 17 00:00:00 2001 From: 545zhou <545zhou@gmail.com> Date: Mon, 19 Dec 2016 14:27:03 -0500 Subject: [PATCH 5/6] deleted unnecessary --- client/app/components/bar-chart-plotly.js | 0 client/app/components/donut-chart-plotly.js | 90 --------------------- 2 files changed, 90 deletions(-) delete mode 100644 client/app/components/bar-chart-plotly.js delete mode 100644 client/app/components/donut-chart-plotly.js diff --git a/client/app/components/bar-chart-plotly.js b/client/app/components/bar-chart-plotly.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/client/app/components/donut-chart-plotly.js b/client/app/components/donut-chart-plotly.js deleted file mode 100644 index 159c67e70..000000000 --- a/client/app/components/donut-chart-plotly.js +++ /dev/null @@ -1,90 +0,0 @@ -/* global Plotly */ -import Ember from 'ember'; - -export default Ember.Component.extend({ - classNames: ['chart'], - - sourcesList: Ember.computed('data', function() { - return this.get('data').map(({ key, doc_count }) => [key, doc_count]); - }), - - dataChanged: Ember.observer('aggregations', function() { - this.updateDonut(); - }), - - data: [], - - sizeChanged: Ember.observer('resizedSignal', function() { - this.updateDonut(); - }), - - updateDonut() { - this.set('data', this.get('aggregations.sources.buckets')); - let columns = this.get('sourcesList'); - let title = 'Published in...'; - let donut = this.get('donut'); - if (donut) { - donut.load({ - columns, - unload: true - }); - donut.resize({ - height: this.get('height')*150-20, - width: this.get('width')*150 - }); - } else { - this.initDonut(title, columns); - } - }, - - initDonut(title, columns) { - let element = this.$(`.donut`).get(0); - // let donut = c3.generate({ - // bindto: element, - // data: { - // columns, - // type: 'donut' - // }, - // legend: { show: false }, - // donut: { - // title, - // label: { - // show: false - // } - // }, - // size: { height: this.get('height')*150-20 } - // }); - // this.set('donut', donut); - let labels = this.get('sourcesList').map(function(value,index) { return value[0]; }); - let values = this.get('sourcesList').map(function(value,index) { return value[1]; }); - var data = [{ - values: values, - labels: labels, - hoverinfo: 'label+percent', - hole: .6, - type: 'pie', - direction : 'clockwise', - outsidetextfont:{color:'#FFFFFF'}, - }]; - - var layout = { - annotations:[{ - font: { - size: 12 - }, - showarrow: false, - text: 'Published in...', - x: 0.5, - y: 0.5, - }], - showlegend: false, - }; - - this.set('chart', Plotly.newPlot(element, data, layout)); - }, - - didRender() { - this.updateDonut(); - }, - -}); From 1f2369b6ca70c8c85e4b8d463f2162253e5da1aa Mon Sep 17 00:00:00 2001 From: 545zhou <545zhou@gmail.com> Date: Thu, 22 Dec 2016 10:19:27 -0500 Subject: [PATCH 6/6] plotly graph can now adaptive to window size --- client/app/components/bar-chart.js | 82 ------- client/app/components/donut-chart.js | 64 ------ .../app/components/plotly-chart/component.js | 7 +- client/app/components/timeseries-chart.js | 209 ------------------ 4 files changed, 6 insertions(+), 356 deletions(-) delete mode 100644 client/app/components/bar-chart.js delete mode 100644 client/app/components/donut-chart.js delete mode 100644 client/app/components/timeseries-chart.js diff --git a/client/app/components/bar-chart.js b/client/app/components/bar-chart.js deleted file mode 100644 index 93c33b62c..000000000 --- a/client/app/components/bar-chart.js +++ /dev/null @@ -1,82 +0,0 @@ -/* global c3 */ -import Ember from 'ember'; - -export default Ember.Component.extend({ - - classNames: ['chart'], - - sourcesList: Ember.computed('data', function() { - return this.get('data').map(({ key, doc_count }) => [key, doc_count]).slice(0, 10); - }), - - dataChanged: Ember.observer('aggregations', function() { - this.updateBar(); - }), - - sizeChanged: Ember.observer('resizedSignal', function() { - this.updateBar(); - }), - - updateBar() { - this.set('data', this.get('aggregations.contributors.buckets')); - let columns = this.get('sourcesList'); // jscs:ignore - let title = 'Top 10 Contributors: '; - let bar = this.get('bar'); - if (bar) { - bar.load({ - columns, - unload: true - }); - bar.resize({ - height: this.get('height')*150-20, - width: this.get('width')*150 - }); - } else { - this.initBar(title, columns); - } - }, - - initBar(title, columns) { - let element = this.$(`.bar`).get(0); - let bar = c3.generate({ - bindto: element, - data: { - columns, - type: 'bar', - onclick: (d) => { - let url = 'https://share.osf.io/discover?q=' + d.name; - window.open(url, '_blank'); - } - }, - axis: { - x: { - tick: { - format: function() { - return 'Top 10 Contributors'; - } - } - }, - y: { - label: 'Number of Publications' - }, - }, - tooltip: { - grouped: false, // Default true - }, - legend: { show: false }, - bar: { - title, - label: { - show: false - } - }, - size: { height: this.get('height')*150-20 } - }); - this.set('bar', bar); - }, - - didRender() { - this.updateBar(); - }, - -}); diff --git a/client/app/components/donut-chart.js b/client/app/components/donut-chart.js deleted file mode 100644 index 3c1e2c10b..000000000 --- a/client/app/components/donut-chart.js +++ /dev/null @@ -1,64 +0,0 @@ -/* global c3 */ -import Ember from 'ember'; - -export default Ember.Component.extend({ - classNames: ['chart'], - - sourcesList: Ember.computed('data', function() { - return this.get('data').map(({ key, doc_count }) => [key, doc_count]); - }), - - dataChanged: Ember.observer('aggregations', function() { - this.updateDonut(); - }), - - data: [], - - sizeChanged: Ember.observer('resizedSignal', function() { - this.updateDonut(); - }), - - updateDonut() { - this.set('data', this.get('aggregations.sources.buckets')); - let columns = this.get('sourcesList'); - let title = 'Published in...'; - let donut = this.get('donut'); - if (donut) { - donut.load({ - columns, - unload: true - }); - donut.resize({ - height: this.get('height')*150-20, - width: this.get('width')*150 - }); - } else { - this.initDonut(title, columns); - } - }, - - initDonut(title, columns) { - let element = this.$(`.donut`).get(0); - let donut = c3.generate({ - bindto: element, - data: { - columns, - type: 'donut' - }, - legend: { show: false }, - donut: { - title, - label: { - show: false - } - }, - size: { height: this.get('height')*150-20 } - }); - this.set('donut', donut); - }, - - didRender() { - this.updateDonut(); - }, - -}); diff --git a/client/app/components/plotly-chart/component.js b/client/app/components/plotly-chart/component.js index df62fcdab..aa4e9f4c2 100644 --- a/client/app/components/plotly-chart/component.js +++ b/client/app/components/plotly-chart/component.js @@ -13,6 +13,7 @@ export default Ember.Component.extend({ data: [], sizeChanged: Ember.observer('resizedSignal', function() { + console.log("get resizedSignal"); if (this.get('resizedSignal') === false) return; this.updateChart(); this.set('resizedSignal', false); @@ -94,8 +95,8 @@ export default Ember.Component.extend({ text: '', }], paper_bgcolor : 'rgba(0,0,0,0)', - autosize: true, height: 320, + // autosize: true, margin:{l: 25, r: 20, t: 20, b: 20, pad: 0}, showlegend: false, }; @@ -176,6 +177,10 @@ export default Ember.Component.extend({ } Plotly.newPlot(this.element, data, layout, {displayModeBar: false}); + var graph = this.element; + window.addEventListener("resize", function(){ + Plotly.Plots.resize(graph); + }); }, didRender() { diff --git a/client/app/components/timeseries-chart.js b/client/app/components/timeseries-chart.js deleted file mode 100644 index 38f7e5eed..000000000 --- a/client/app/components/timeseries-chart.js +++ /dev/null @@ -1,209 +0,0 @@ -/* global c3 */ -import Ember from 'ember'; - -export default Ember.Component.extend({ - - classNames: ['chart'], - - // Define boolean variables that specify which subsets (if any) of abstractcreativeworks we're specifically looking at - tPub: false, // Publication - tPre: false, // Preprint - tCre: false, // Creativework - tPro: false, // Project - - timeseriesList: Ember.computed('data', function() { // Format our timeseries data - let data = this.get('data'); - return [ - ['x'].concat(data.map((datum) => {return datum.key_as_string})), - ['Articles'].concat(data.map((datum) => {return datum.doc_count})), - ]; - }), - - data: [], - - dataChanged: Ember.observer('data', function() { // Initiate a chart update if the TS data changes - this.updateTS(); - }), - - sizeChanged: Ember.observer('resizedSignal', function() { - this.updateTS(); - }), - - updateTS() { // Update our TS chart when data/subsets change - this.set('data', this.get('aggregations.articles_over_time.buckets')); - let columns = this.get('timeseriesList'); - let title = ''; - let interval = this.get('interval'); - let ts = this.get('ts'); - if (ts) { - ts.load({ - columns, - unload: true - }); - ts.resize({ - height: this.get('height')*150-20, - width: this.get('width')*150 - }); - } else { - this.initTS(title, columns, interval); - } - }, - - pushTS(xCol) { // Add a specific subset of abstractcreativeworks to the TS chart - let ts = this.get('ts'); - ts.load({ - columns: [xCol] - }); - }, - - popTS(xCol) { // Remove a specific subset of abstractcreativeworks from the TS chart - let ts = this.get('ts'); - ts.unload([xCol]); - }, - - initTS(title, columns, interval) { // Draw the TS chart the first time its rendered - let element = this.$(`.ts`).get(0); - let ts = c3.generate({ - bindto: element, - data: { - x: 'x', - columns: columns, - types: { - x: 'area-spline', - Articles: 'area' - } - }, - axis: { - x: { - type: 'timeseries', - tick: { - culling: { - max: 10 - }, - rotate: 90, - format: '%d-%m-%Y' // Format the tick labels on our chart - } - } - }, - zoom: { - enabled: true - }, - tooltip: { // Format the tooltips on our chart - format: { // We want to return a nice-looking tooltip whose content is determined by (or at least consistent with) sour TS intervals - title: function (d) { - return d.toString().substring(4,15); // This isn't perfect, but it's at least more verbose than before - } - } - }, - point: { - show: false, - }, - size: { height: this.get('height')*150-20 } - }); - this.set('ts', ts); - }, - - init() { // Init should be used ONLY for setting component proprties. When we want to work on the component DOM element, we use didInsertElement hook - this._super(...arguments); - }, - - didRender() { // When this component has been inserted into the DOM - this.updateTS(); - }, - - // If the user wants to isolate preprints: - tPreChanged: Ember.observer('tPre', function() { - let otherSubsets = (this.get('tPub') || this.get('tCre') || this.get('tPro')); // check if we already are displaying article subsets on the chart - if(this.get('tPre')) { // if the user checked the box - this.filterTS('preprint',otherSubsets); - } - else { // if the user unchecked the box - if(!otherSubsets) { // if this is the only data on the chart right now and we're removing it - let data = this.get('timeseriesList'); // reload the original chart - this.updateTS(data); - } - else { - this.popTS('preprint'); - } - } - }), - - // If the user wants to isolate publications: - tPubChanged: Ember.observer('tPub', function() { - let otherSubsets = (this.get('tPre') || this.get('tCre') || this.get('tPro')); - if(this.get('tPub')) { // if the user checked the box - this.filterTS('publication',otherSubsets); - } - else { // if the user unchecked the box - if(!otherSubsets) { - let data = this.get('timeseriesList'); - this.updateTS(data); - } - else { - this.popTS('publication'); - } - } - }), - - // If the user wants to isolate creativeworks: - tCreChanged: Ember.observer('tCre', function() { - let otherSubsets = (this.get('tPre') || this.get('tPub') || this.get('tPro')); - if(this.get('tCre')) { // if the user checked the box - this.filterTS('creativework',otherSubsets); - } - else { // if the user unchecked the box - if(!otherSubsets) { - let data = this.get('timeseriesList'); - this.updateTS(data); - } - else { - this.popTS('creativework'); - } - } - }), - - // If the user wants to isolate projects: - tProChanged: Ember.observer('tPro', function() { - let otherSubsets = (this.get('tPre') || this.get('tPub') || this.get('tCre')); - if(this.get('tPro')) { // if the user checked the box - this.filterTS('project',otherSubsets); - } - else { // if the user unchecked the box - if(!otherSubsets) { - let data = this.get('timeseriesList'); - this.updateTS(data); - } - else { - this.popTS('project'); - } - } - }), - - // Isolate specific subsets of abstractcreativeworks - filterTS(typeString,o) { - let d = this.get('aggregations.articles_over_time.buckets'); - let firstRow = ['x']; - let secondRow = [typeString]; - d.forEach(function(entry) { - firstRow.push(entry.key_as_string); - let hasPubBucket = false; - entry.arttype.buckets.forEach(function(b) { - if(b.key === typeString) { - hasPubBucket = true; - secondRow.push(b.doc_count); - } - }); - if(!hasPubBucket) { - secondRow.push(0); - } - }); - if(o) { - this.pushTS(secondRow); - } - else { - let data = [firstRow, secondRow]; - this.updateTS(data); - } - } - -});