From 27aceb9b9e1a425e7be04f58cde2cbfa67d440af Mon Sep 17 00:00:00 2001 From: stacytalbot Date: Thu, 26 Mar 2020 16:29:18 +0000 Subject: [PATCH 01/11] Work on the new line chart --- .../stylesheets/components/_charts.scss | 21 +- app/controllers/marine_controller.rb | 222 +++++----- .../charts/chart-line/ChartLine.vue | 392 +++++++++--------- .../charts/chart-line/ChartLineDataset.vue | 69 +++ app/views/marine/index.html.erb | 13 +- app/views/marine/sections/_coverage.html.erb | 8 +- app/views/marine/sections/_ocean.html.erb | 10 +- 7 files changed, 421 insertions(+), 314 deletions(-) create mode 100644 app/javascript/components/charts/chart-line/ChartLineDataset.vue diff --git a/app/assets/stylesheets/components/_charts.scss b/app/assets/stylesheets/components/_charts.scss index e757101ea..5c7a4c6be 100644 --- a/app/assets/stylesheets/components/_charts.scss +++ b/app/assets/stylesheets/components/_charts.scss @@ -81,14 +81,23 @@ $chart-target-stroke-width: rem-calc(3); @import './charts/chart-dial'; @import './charts/chart-row-pa'; @import './charts/chart-row-target'; + + &__legend-item { + @include flex; + @include flex-v-center; + } - &__key { - background-color: $chart-aqua; - border-radius: 100%; - width: rem-calc(24); height: rem-calc(24); + &__legend-key { + background-color: $chart-aqua; + border-radius: 100%; + width: rem-calc(24); height: rem-calc(24); - display: block; - } + display: block; + } + + &__legend-text { + margin-left: rem-calc(6); + } } @import './charts/horizontal-bar-chart'; diff --git a/app/controllers/marine_controller.rb b/app/controllers/marine_controller.rb index 4648f008a..9b9b2673c 100644 --- a/app/controllers/marine_controller.rb +++ b/app/controllers/marine_controller.rb @@ -156,232 +156,232 @@ def growth @protectedAreasGrowth = [ { id: "Global", - dataset: [ + datapoints: [ { - year: 2000, - percent: 0.67 + x: 2000, + y: 0.67 }, { - year: 2001, - percent: 0.73 + x: 2001, + y: 0.73 }, { - year: 2002, - percent: 0.99 + x: 2002, + y: 0.99 }, { - year: 2003, - percent: 1.00 + x: 2003, + y: 1.00 }, { - year: 2004, - percent: 1.11 + x: 2004, + y: 1.11 }, { - year: 2005, - percent: 1.13 + x: 2005, + y: 1.13 }, { - year: 2006, - percent: 1.05 + x: 2006, + y: 1.05 }, { - year: 2007, - percent: 1.43 + x: 2007, + y: 1.43 }, { - year: 2008, - percent: 1.85 + x: 2008, + y: 1.85 }, { - year: 2009, - percent: 2.32 + x: 2009, + y: 2.32 }, { - year: 2010, - percent: 2.50 + x: 2010, + y: 2.50 }, { - year: 2011, - percent: 2.53 + x: 2011, + y: 2.53 }, { - year: 2012, - percent: 3.38 + x: 2012, + y: 3.38 }, { - year: 2013, - percent: 3.47 + x: 2013, + y: 3.47 }, { - year: 2014, - percent: 4.15 + x: 2014, + y: 4.15 }, { - year: 2015, - percent: 4.43 + x: 2015, + y: 4.43 }, { - year: 2016, - percent: 5.01 + x: 2016, + y: 5.01 }, { - year: 2017, - percent: 6.4 + x: 2017, + y: 6.4 } ] }, { id: "National", - dataset: [ + datapoints: [ { - year: 2000, - percent: 1.72 + x: 2000, + y: 1.72 }, { - year: 2001, - percent: 1.88 + x: 2001, + y: 1.88 }, { - year: 2002, - percent: 2.54 + x: 2002, + y: 2.54 }, { - year: 2003, - percent: 2.57 + x: 2003, + y: 2.57 }, { - year: 2004, - percent: 2.86 + x: 2004, + y: 2.86 }, { - year: 2005, - percent: 2.89 + x: 2005, + y: 2.89 }, { - year: 2006, - percent: 2.70 + x: 2006, + y: 2.70 }, { - year: 2007, - percent: 3.68 + x: 2007, + y: 3.68 }, { - year: 2008, - percent: 3.93 + x: 2008, + y: 3.93 }, { - year: 2009, - percent: 5.13 + x: 2009, + y: 5.13 }, { - year: 2010, - percent: 5.88 + x: 2010, + y: 5.88 }, { - year: 2011, - percent: 5.94 + x: 2011, + y: 5.94 }, { - year: 2012, - percent: 8.43 + x: 2012, + y: 8.43 }, { - year: 2013, - percent: 8.65 + x: 2013, + y: 8.65 }, { - year: 2014, - percent: 9.66 + x: 2014, + y: 9.66 }, { - year: 2015, - percent: 10.36 + x: 2015, + y: 10.36 }, { - year: 2016, - percent: 12.74 + x: 2016, + y: 12.74 }, { - year: 2017, - percent: 16.02 + x: 2017, + y: 16.02 } ] }, { id: "ABNJ", - dataset: [ + datapoints: [ { - year: 2000, - percent: 0.00 + x: 2000, + y: 0.00 }, { - year: 2001, - percent: 0.00 + x: 2001, + y: 0.00 }, { - year: 2002, - percent: 0.00 + x: 2002, + y: 0.00 }, { - year: 2003, - percent: 0.00 + x: 2003, + y: 0.00 }, { - year: 2004, - percent: 0.00 + x: 2004, + y: 0.00 }, { - year: 2005, - percent: 0.00 + x: 2005, + y: 0.00 }, { - year: 2006, - percent: 0.00 + x: 2006, + y: 0.00 }, { - year: 2007, - percent: 0.00 + x: 2007, + y: 0.00 }, { - year: 2008, - percent: 0.00 + x: 2008, + y: 0.00 }, { - year: 2009, - percent: 0.00 + x: 2009, + y: 0.00 }, { - year: 2010, - percent: 0.17 + x: 2010, + y: 0.17 }, { - year: 2011, - percent: 0.17 + x: 2011, + y: 0.17 }, { - year: 2012, - percent: 0.17 + x: 2012, + y: 0.17 }, { - year: 2013, - percent: 0.17 + x: 2013, + y: 0.17 }, { - year: 2014, - percent: 0.25 + x: 2014, + y: 0.25 }, { - year: 2015, - percent: 0.25 + x: 2015, + y: 0.25 }, { - year: 2016, - percent: 0.25 + x: 2016, + y: 0.25 }, { - year: 2017, - percent: 1.18 + x: 2017, + y: 1.18 } ] } diff --git a/app/javascript/components/charts/chart-line/ChartLine.vue b/app/javascript/components/charts/chart-line/ChartLine.vue index 7492716b6..41c8cd44e 100644 --- a/app/javascript/components/charts/chart-line/ChartLine.vue +++ b/app/javascript/components/charts/chart-line/ChartLine.vue @@ -1,231 +1,247 @@ \ No newline at end of file diff --git a/app/views/marine/index.html.erb b/app/views/marine/index.html.erb index 9a5e780c4..c2122ffae 100644 --- a/app/views/marine/index.html.erb +++ b/app/views/marine/index.html.erb @@ -23,4 +23,15 @@

--> -<%= render partial: "marine/sections/ocean" %> +<%= render partial: "marine/sections/ocean", locals: { + national: marine_stats('national_waters_percentage'), + national_coverage: marine_stats('national_waters_pa_coverage_percentage'), + high_seas: marine_stats('global_ocean_percentage'), + high_seas_coverage: marine_stats('high_seas_pa_coverage_percentage') +} %> + + +<%= render partial: "marine/sections/coverage", locals: { + cms_page: @cms_page, + +} %> \ No newline at end of file diff --git a/app/views/marine/sections/_coverage.html.erb b/app/views/marine/sections/_coverage.html.erb index afc701808..b0dccae87 100644 --- a/app/views/marine/sections/_coverage.html.erb +++ b/app/views/marine/sections/_coverage.html.erb @@ -1,9 +1,11 @@
-

<%= cms_fragment_render(:section_coverage_title, @cms_page) %>

-
<%= cms_fragment_render(:section_coverage_content, @cms_page) %>
+

<%= cms_fragment_render(:section_coverage_title, cms_page) %>

+
<%= cms_fragment_render(:section_coverage_content, cms_page) %>
- +
\ No newline at end of file diff --git a/app/views/marine/sections/_ocean.html.erb b/app/views/marine/sections/_ocean.html.erb index 9c184a99f..e487f40ce 100644 --- a/app/views/marine/sections/_ocean.html.erb +++ b/app/views/marine/sections/_ocean.html.erb @@ -4,13 +4,13 @@
<%= cms_fragment_render(:section_ocean_content, @cms_page) %>

National waters

- +

High seas

- -
- - % of Protected Area Coverage + +
+ + % of Protected Area Coverage
From 9f8a5e001cb2a1c400cb8a74f28b2956e1cd1a27 Mon Sep 17 00:00:00 2001 From: stacytalbot Date: Thu, 26 Mar 2020 16:49:29 +0000 Subject: [PATCH 02/11] Add legend to new line chart --- .../stylesheets/components/_charts.scss | 18 +- .../components/charts/_chart-legend.scss | 28 ++ app/controllers/marine_controller.rb | 270 ++++-------------- .../charts/chart-line/ChartLegend.vue | 61 ++++ .../charts/chart-line/ChartLine.vue | 28 +- 5 files changed, 166 insertions(+), 239 deletions(-) create mode 100644 app/assets/stylesheets/components/charts/_chart-legend.scss create mode 100644 app/javascript/components/charts/chart-line/ChartLegend.vue diff --git a/app/assets/stylesheets/components/_charts.scss b/app/assets/stylesheets/components/_charts.scss index 5c7a4c6be..583c6cb36 100644 --- a/app/assets/stylesheets/components/_charts.scss +++ b/app/assets/stylesheets/components/_charts.scss @@ -79,25 +79,9 @@ $chart-target-stroke-width: rem-calc(3); // charts //-------------------------------------------------- @import './charts/chart-dial'; + @import './charts/chart-legend'; @import './charts/chart-row-pa'; @import './charts/chart-row-target'; - - &__legend-item { - @include flex; - @include flex-v-center; - } - - &__legend-key { - background-color: $chart-aqua; - border-radius: 100%; - width: rem-calc(24); height: rem-calc(24); - - display: block; - } - - &__legend-text { - margin-left: rem-calc(6); - } } @import './charts/horizontal-bar-chart'; diff --git a/app/assets/stylesheets/components/charts/_chart-legend.scss b/app/assets/stylesheets/components/charts/_chart-legend.scss new file mode 100644 index 000000000..0358b8057 --- /dev/null +++ b/app/assets/stylesheets/components/charts/_chart-legend.scss @@ -0,0 +1,28 @@ +//-------------------------------------------------- +// classes +//-------------------------------------------------- + &--legend { + @include flex; + @include flex-wrap; + @include ul-unstyled; + margin: rem-calc(14 0); + } + + &__legend-item { + @include flex; + @include flex-v-center; + margin-right: rem-calc(14); + } + + &__legend-key { + @include flex-no-shrink; + background-color: $chart-aqua; + border-radius: 100%; + width: rem-calc(24); height: rem-calc(24); + + display: block; + } + + &__legend-text { + margin-left: rem-calc(6); + } \ No newline at end of file diff --git a/app/controllers/marine_controller.rb b/app/controllers/marine_controller.rb index 9b9b2673c..cba7872c5 100644 --- a/app/controllers/marine_controller.rb +++ b/app/controllers/marine_controller.rb @@ -157,232 +157,70 @@ def growth { id: "Global", datapoints: [ - { - x: 2000, - y: 0.67 - }, - { - x: 2001, - y: 0.73 - }, - { - x: 2002, - y: 0.99 - }, - { - x: 2003, - y: 1.00 - }, - { - x: 2004, - y: 1.11 - }, - { - x: 2005, - y: 1.13 - }, - { - x: 2006, - y: 1.05 - }, - { - x: 2007, - y: 1.43 - }, - { - x: 2008, - y: 1.85 - }, - { - x: 2009, - y: 2.32 - }, - { - x: 2010, - y: 2.50 - }, - { - x: 2011, - y: 2.53 - }, - { - x: 2012, - y: 3.38 - }, - { - x: 2013, - y: 3.47 - }, - { - x: 2014, - y: 4.15 - }, - { - x: 2015, - y: 4.43 - }, - { - x: 2016, - y: 5.01 - }, - { - x: 2017, - y: 6.4 - } + { x: 2000, y: 0.67 }, + { x: 2001, y: 0.73 }, + { x: 2002, y: 0.99 }, + { x: 2003, y: 1.00 }, + { x: 2004, y: 1.11 }, + { x: 2005, y: 1.13 }, + { x: 2006, y: 1.05 }, + { x: 2007, y: 1.43 }, + { x: 2008, y: 1.85 }, + { x: 2009, y: 2.32 }, + { x: 2010, y: 2.50 }, + { x: 2011, y: 2.53 }, + { x: 2012, y: 3.38 }, + { x: 2013, y: 3.47 }, + { x: 2014, y: 4.15 }, + { x: 2015, y: 4.43 }, + { x: 2016, y: 5.01 }, + { x: 2017, y: 6.4 } ] }, { id: "National", datapoints: [ - { - x: 2000, - y: 1.72 - }, - { - x: 2001, - y: 1.88 - }, - { - x: 2002, - y: 2.54 - }, - { - x: 2003, - y: 2.57 - }, - { - x: 2004, - y: 2.86 - }, - { - x: 2005, - y: 2.89 - }, - { - x: 2006, - y: 2.70 - }, - { - x: 2007, - y: 3.68 - }, - { - x: 2008, - y: 3.93 - }, - { - x: 2009, - y: 5.13 - }, - { - x: 2010, - y: 5.88 - }, - { - x: 2011, - y: 5.94 - }, - { - x: 2012, - y: 8.43 - }, - { - x: 2013, - y: 8.65 - }, - { - x: 2014, - y: 9.66 - }, - { - x: 2015, - y: 10.36 - }, - { - x: 2016, - y: 12.74 - }, - { - x: 2017, - y: 16.02 - } + { x: 2000, y: 1.72 }, + { x: 2001, y: 1.88 }, + { x: 2002, y: 2.54 }, + { x: 2003, y: 2.57 }, + { x: 2004, y: 2.86 }, + { x: 2005, y: 2.89 }, + { x: 2006, y: 2.70 }, + { x: 2007, y: 3.68 }, + { x: 2008, y: 3.93 }, + { x: 2009, y: 5.13 }, + { x: 2010, y: 5.88 }, + { x: 2011, y: 5.94 }, + { x: 2012, y: 8.43 }, + { x: 2013, y: 8.65 }, + { x: 2014, y: 9.66 }, + { x: 2015, y: 10.36 }, + { x: 2016, y: 12.74 }, + { x: 2017, y: 16.02 } ] }, { id: "ABNJ", datapoints: [ - { - x: 2000, - y: 0.00 - }, - { - x: 2001, - y: 0.00 - }, - { - x: 2002, - y: 0.00 - }, - { - x: 2003, - y: 0.00 - }, - { - x: 2004, - y: 0.00 - }, - { - x: 2005, - y: 0.00 - }, - { - x: 2006, - y: 0.00 - }, - { - x: 2007, - y: 0.00 - }, - { - x: 2008, - y: 0.00 - }, - { - x: 2009, - y: 0.00 - }, - { - x: 2010, - y: 0.17 - }, - { - x: 2011, - y: 0.17 - }, - { - x: 2012, - y: 0.17 - }, - { - x: 2013, - y: 0.17 - }, - { - x: 2014, - y: 0.25 - }, - { - x: 2015, - y: 0.25 - }, - { - x: 2016, - y: 0.25 - }, - { - x: 2017, - y: 1.18 - } + { x: 2000, y: 0.00 }, + { x: 2001, y: 0.00 }, + { x: 2002, y: 0.00 }, + { x: 2003, y: 0.00 }, + { x: 2004, y: 0.00 }, + { x: 2005, y: 0.00 }, + { x: 2006, y: 0.00 }, + { x: 2007, y: 0.00 }, + { x: 2008, y: 0.00 }, + { x: 2009, y: 0.00 }, + { x: 2010, y: 0.17 }, + { x: 2011, y: 0.17 }, + { x: 2012, y: 0.17 }, + { x: 2013, y: 0.17 }, + { x: 2014, y: 0.25 }, + { x: 2015, y: 0.25 }, + { x: 2016, y: 0.25 }, + { x: 2017, y: 1.18 } ] } ].to_json diff --git a/app/javascript/components/charts/chart-line/ChartLegend.vue b/app/javascript/components/charts/chart-line/ChartLegend.vue new file mode 100644 index 000000000..b8e01e5bd --- /dev/null +++ b/app/javascript/components/charts/chart-line/ChartLegend.vue @@ -0,0 +1,61 @@ + + + \ No newline at end of file diff --git a/app/javascript/components/charts/chart-line/ChartLine.vue b/app/javascript/components/charts/chart-line/ChartLine.vue index 41c8cd44e..6f0996722 100644 --- a/app/javascript/components/charts/chart-line/ChartLine.vue +++ b/app/javascript/components/charts/chart-line/ChartLine.vue @@ -66,7 +66,11 @@ - + @@ -75,7 +79,7 @@ import ChartLineTab from './ChartLineTab' // import ChartLineTargetX from './ChartLineTargetX' // import ChartLineTargetY from './ChartLineTargetY' - // import ChartLegend from './ChartLegend' + import ChartLegend from './ChartLegend' export default { name: 'chart-line', @@ -83,8 +87,8 @@ components: { // ChartLineTargetX, ChartLineTargetY, ChartLineDataset, - ChartLineTab - // ChartLegend + ChartLineTab, + ChartLegend }, props: { @@ -95,7 +99,10 @@ targets: Array, axis: Object, commitments: Array, - legend: Array + showLegend: { + default: true, + type: Boolean + } }, data () { @@ -139,8 +146,9 @@ text: '#000000' } ], + legend: [], legendColours: ['#207D94', '#6FD9F2', '#86BF37'], - targetColours: ['rgba(29, 125, 166, 0.4)', 'rgba(113, 163, 43, 0.4)'] + // targetColours: ['rgba(29, 125, 166, 0.4)', 'rgba(113, 163, 43, 0.4)'] } }, @@ -177,6 +185,14 @@ }, methods: { + getLegend (){ + const legend = this.lines.map((dataset) => { + return { title: dataset.id } + }) + + return legend + }, + getPath(dataset) { let path = '' From e56186f63d85fcfaca2867f1a9382819c4270728 Mon Sep 17 00:00:00 2001 From: stacytalbot Date: Fri, 27 Mar 2020 09:56:42 +0000 Subject: [PATCH 03/11] Add in temporary tooltip --- .../charts/chart-line/ChartLine.vue | 8 +- .../charts/chart-line/ChartLineDataset.vue | 16 ++-- .../charts/chart-line/ChartPopup.vue | 88 +++++++++++++++++++ 3 files changed, 104 insertions(+), 8 deletions(-) create mode 100644 app/javascript/components/charts/chart-line/ChartPopup.vue diff --git a/app/javascript/components/charts/chart-line/ChartLine.vue b/app/javascript/components/charts/chart-line/ChartLine.vue index 6f0996722..fb702fc91 100644 --- a/app/javascript/components/charts/chart-line/ChartLine.vue +++ b/app/javascript/components/charts/chart-line/ChartLine.vue @@ -113,7 +113,7 @@ paddingTop: 50 }, x: { - axisMarks: 6, + axisMarks: 8, chartPadding: 24, chartWidth: 890, max: 0, @@ -243,7 +243,11 @@ normaliseDataset (dataset) { console.log(dataset) const normalisedDataset = dataset.map((datapoint) => { - return { x: this.normaliseX(datapoint.x), y: this.normaliseY(datapoint.y) } + return { + value: datapoint.y + '%', + x: this.normaliseX(datapoint.x), + y: this.normaliseY(datapoint.y) + } }) console.log(normalisedDataset) return normalisedDataset diff --git a/app/javascript/components/charts/chart-line/ChartLineDataset.vue b/app/javascript/components/charts/chart-line/ChartLineDataset.vue index 7f89d998c..35f44c0f4 100644 --- a/app/javascript/components/charts/chart-line/ChartLineDataset.vue +++ b/app/javascript/components/charts/chart-line/ChartLineDataset.vue @@ -6,13 +6,13 @@ :stroke="colour.line" stroke-width="2" /> - - \ No newline at end of file From d1e6178078a36f8cc4336bfab332401a94c72cba Mon Sep 17 00:00:00 2001 From: stacytalbot Date: Fri, 27 Mar 2020 15:50:27 +0000 Subject: [PATCH 04/11] Add in correct toolip svg --- app/controllers/marine_controller.rb | 140 +++++++++--------- .../charts/chart-line/ChartPopup.vue | 29 ++-- 2 files changed, 86 insertions(+), 83 deletions(-) diff --git a/app/controllers/marine_controller.rb b/app/controllers/marine_controller.rb index cba7872c5..5b4bfb6e1 100644 --- a/app/controllers/marine_controller.rb +++ b/app/controllers/marine_controller.rb @@ -155,75 +155,81 @@ def marine_statistics def growth @protectedAreasGrowth = [ { - id: "Global", - datapoints: [ - { x: 2000, y: 0.67 }, - { x: 2001, y: 0.73 }, - { x: 2002, y: 0.99 }, - { x: 2003, y: 1.00 }, - { x: 2004, y: 1.11 }, - { x: 2005, y: 1.13 }, - { x: 2006, y: 1.05 }, - { x: 2007, y: 1.43 }, - { x: 2008, y: 1.85 }, - { x: 2009, y: 2.32 }, - { x: 2010, y: 2.50 }, - { x: 2011, y: 2.53 }, - { x: 2012, y: 3.38 }, - { x: 2013, y: 3.47 }, - { x: 2014, y: 4.15 }, - { x: 2015, y: 4.43 }, - { x: 2016, y: 5.01 }, - { x: 2017, y: 6.4 } - ] - }, - { - id: "National", - datapoints: [ - { x: 2000, y: 1.72 }, - { x: 2001, y: 1.88 }, - { x: 2002, y: 2.54 }, - { x: 2003, y: 2.57 }, - { x: 2004, y: 2.86 }, - { x: 2005, y: 2.89 }, - { x: 2006, y: 2.70 }, - { x: 2007, y: 3.68 }, - { x: 2008, y: 3.93 }, - { x: 2009, y: 5.13 }, - { x: 2010, y: 5.88 }, - { x: 2011, y: 5.94 }, - { x: 2012, y: 8.43 }, - { x: 2013, y: 8.65 }, - { x: 2014, y: 9.66 }, - { x: 2015, y: 10.36 }, - { x: 2016, y: 12.74 }, - { x: 2017, y: 16.02 } - ] - }, - { - id: "ABNJ", - datapoints: [ - { x: 2000, y: 0.00 }, - { x: 2001, y: 0.00 }, - { x: 2002, y: 0.00 }, - { x: 2003, y: 0.00 }, - { x: 2004, y: 0.00 }, - { x: 2005, y: 0.00 }, - { x: 2006, y: 0.00 }, - { x: 2007, y: 0.00 }, - { x: 2008, y: 0.00 }, - { x: 2009, y: 0.00 }, - { x: 2010, y: 0.17 }, - { x: 2011, y: 0.17 }, - { x: 2012, y: 0.17 }, - { x: 2013, y: 0.17 }, - { x: 2014, y: 0.25 }, - { x: 2015, y: 0.25 }, - { x: 2016, y: 0.25 }, - { x: 2017, y: 1.18 } - ] + id: 'a', + datapoints: [{x:0,y:0},{x:1,y:1},{x:2,y:2},{x:3,y:3},{x:4,y:4},{x:5,y:5},{x:6,y:6},{x:7,y:7}] } ].to_json + # @protectedAreasGrowth = [ + # { + # id: "Global", + # datapoints: [ + # { x: 2000, y: 0.67 }, + # { x: 2001, y: 0.73 }, + # { x: 2002, y: 0.99 }, + # { x: 2003, y: 1.00 }, + # { x: 2004, y: 1.11 }, + # { x: 2005, y: 1.13 }, + # { x: 2006, y: 1.05 }, + # { x: 2007, y: 1.43 }, + # { x: 2008, y: 1.85 }, + # { x: 2009, y: 2.32 }, + # { x: 2010, y: 2.50 }, + # { x: 2011, y: 2.53 }, + # { x: 2012, y: 3.38 }, + # { x: 2013, y: 3.47 }, + # { x: 2014, y: 4.15 }, + # { x: 2015, y: 4.43 }, + # { x: 2016, y: 5.01 }, + # { x: 2017, y: 6.4 } + # ] + # }, + # { + # id: "National", + # datapoints: [ + # { x: 2000, y: 1.72 }, + # { x: 2001, y: 1.88 }, + # { x: 2002, y: 2.54 }, + # { x: 2003, y: 2.57 }, + # { x: 2004, y: 2.86 }, + # { x: 2005, y: 2.89 }, + # { x: 2006, y: 2.70 }, + # { x: 2007, y: 3.68 }, + # { x: 2008, y: 3.93 }, + # { x: 2009, y: 5.13 }, + # { x: 2010, y: 5.88 }, + # { x: 2011, y: 5.94 }, + # { x: 2012, y: 8.43 }, + # { x: 2013, y: 8.65 }, + # { x: 2014, y: 9.66 }, + # { x: 2015, y: 10.36 }, + # { x: 2016, y: 12.74 }, + # { x: 2017, y: 16.02 } + # ] + # }, + # { + # id: "ABNJ", + # datapoints: [ + # { x: 2000, y: 0.00 }, + # { x: 2001, y: 0.00 }, + # { x: 2002, y: 0.00 }, + # { x: 2003, y: 0.00 }, + # { x: 2004, y: 0.00 }, + # { x: 2005, y: 0.00 }, + # { x: 2006, y: 0.00 }, + # { x: 2007, y: 0.00 }, + # { x: 2008, y: 0.00 }, + # { x: 2009, y: 0.00 }, + # { x: 2010, y: 0.17 }, + # { x: 2011, y: 0.17 }, + # { x: 2012, y: 0.17 }, + # { x: 2013, y: 0.17 }, + # { x: 2014, y: 0.25 }, + # { x: 2015, y: 0.25 }, + # { x: 2016, y: 0.25 }, + # { x: 2017, y: 1.18 } + # ] + # } + # ].to_json end def ecoregions diff --git a/app/javascript/components/charts/chart-line/ChartPopup.vue b/app/javascript/components/charts/chart-line/ChartPopup.vue index 5475de0ef..10c44c57f 100644 --- a/app/javascript/components/charts/chart-line/ChartPopup.vue +++ b/app/javascript/components/charts/chart-line/ChartPopup.vue @@ -3,34 +3,34 @@ - + {{ text }} @@ -43,16 +43,13 @@ export default { name: 'chart-popup', props: { - // showPopup: { - // type: Boolean - // }, colour: { required: true, type: String }, text: { required: true, - type: Number + type: String }, x: { required: true, From e7535cd58948cbc83518cc35186dea98d95dcae1 Mon Sep 17 00:00:00 2001 From: stacytalbot Date: Mon, 30 Mar 2020 16:01:33 +0100 Subject: [PATCH 05/11] Get teh axis making more sense --- app/controllers/marine_controller.rb | 146 +++++++++--------- .../charts/chart-line/ChartLine.vue | 24 ++- 2 files changed, 84 insertions(+), 86 deletions(-) diff --git a/app/controllers/marine_controller.rb b/app/controllers/marine_controller.rb index 5b4bfb6e1..eec001c71 100644 --- a/app/controllers/marine_controller.rb +++ b/app/controllers/marine_controller.rb @@ -153,83 +153,83 @@ def marine_statistics end def growth - @protectedAreasGrowth = [ - { - id: 'a', - datapoints: [{x:0,y:0},{x:1,y:1},{x:2,y:2},{x:3,y:3},{x:4,y:4},{x:5,y:5},{x:6,y:6},{x:7,y:7}] - } - ].to_json # @protectedAreasGrowth = [ # { - # id: "Global", - # datapoints: [ - # { x: 2000, y: 0.67 }, - # { x: 2001, y: 0.73 }, - # { x: 2002, y: 0.99 }, - # { x: 2003, y: 1.00 }, - # { x: 2004, y: 1.11 }, - # { x: 2005, y: 1.13 }, - # { x: 2006, y: 1.05 }, - # { x: 2007, y: 1.43 }, - # { x: 2008, y: 1.85 }, - # { x: 2009, y: 2.32 }, - # { x: 2010, y: 2.50 }, - # { x: 2011, y: 2.53 }, - # { x: 2012, y: 3.38 }, - # { x: 2013, y: 3.47 }, - # { x: 2014, y: 4.15 }, - # { x: 2015, y: 4.43 }, - # { x: 2016, y: 5.01 }, - # { x: 2017, y: 6.4 } - # ] - # }, - # { - # id: "National", - # datapoints: [ - # { x: 2000, y: 1.72 }, - # { x: 2001, y: 1.88 }, - # { x: 2002, y: 2.54 }, - # { x: 2003, y: 2.57 }, - # { x: 2004, y: 2.86 }, - # { x: 2005, y: 2.89 }, - # { x: 2006, y: 2.70 }, - # { x: 2007, y: 3.68 }, - # { x: 2008, y: 3.93 }, - # { x: 2009, y: 5.13 }, - # { x: 2010, y: 5.88 }, - # { x: 2011, y: 5.94 }, - # { x: 2012, y: 8.43 }, - # { x: 2013, y: 8.65 }, - # { x: 2014, y: 9.66 }, - # { x: 2015, y: 10.36 }, - # { x: 2016, y: 12.74 }, - # { x: 2017, y: 16.02 } - # ] - # }, - # { - # id: "ABNJ", - # datapoints: [ - # { x: 2000, y: 0.00 }, - # { x: 2001, y: 0.00 }, - # { x: 2002, y: 0.00 }, - # { x: 2003, y: 0.00 }, - # { x: 2004, y: 0.00 }, - # { x: 2005, y: 0.00 }, - # { x: 2006, y: 0.00 }, - # { x: 2007, y: 0.00 }, - # { x: 2008, y: 0.00 }, - # { x: 2009, y: 0.00 }, - # { x: 2010, y: 0.17 }, - # { x: 2011, y: 0.17 }, - # { x: 2012, y: 0.17 }, - # { x: 2013, y: 0.17 }, - # { x: 2014, y: 0.25 }, - # { x: 2015, y: 0.25 }, - # { x: 2016, y: 0.25 }, - # { x: 2017, y: 1.18 } - # ] + # id: 'a', + # datapoints: [{x:0,y:0},{x:1,y:1},{x:2,y:2},{x:3,y:3},{x:4,y:4},{x:5,y:5},{x:6,y:6},{x:7,y:7}] # } # ].to_json + @protectedAreasGrowth = [ + { + id: "Global", + datapoints: [ + { x: 2000, y: 0.67 }, + { x: 2001, y: 0.73 }, + { x: 2002, y: 0.99 }, + { x: 2003, y: 1.00 }, + { x: 2004, y: 1.11 }, + { x: 2005, y: 1.13 }, + { x: 2006, y: 1.05 }, + { x: 2007, y: 1.43 }, + { x: 2008, y: 1.85 }, + { x: 2009, y: 2.32 }, + { x: 2010, y: 2.50 }, + { x: 2011, y: 2.53 }, + { x: 2012, y: 3.38 }, + { x: 2013, y: 3.47 }, + { x: 2014, y: 4.15 }, + { x: 2015, y: 4.43 }, + { x: 2016, y: 5.01 }, + { x: 2017, y: 6.4 } + ] + }, + { + id: "National", + datapoints: [ + { x: 2000, y: 1.72 }, + { x: 2001, y: 1.88 }, + { x: 2002, y: 2.54 }, + { x: 2003, y: 2.57 }, + { x: 2004, y: 2.86 }, + { x: 2005, y: 2.89 }, + { x: 2006, y: 2.70 }, + { x: 2007, y: 3.68 }, + { x: 2008, y: 3.93 }, + { x: 2009, y: 5.13 }, + { x: 2010, y: 5.88 }, + { x: 2011, y: 5.94 }, + { x: 2012, y: 8.43 }, + { x: 2013, y: 8.65 }, + { x: 2014, y: 9.66 }, + { x: 2015, y: 10.36 }, + { x: 2016, y: 12.74 }, + { x: 2017, y: 16.02 } + ] + }, + { + id: "ABNJ", + datapoints: [ + { x: 2000, y: 0.00 }, + { x: 2001, y: 0.00 }, + { x: 2002, y: 0.00 }, + { x: 2003, y: 0.00 }, + { x: 2004, y: 0.00 }, + { x: 2005, y: 0.00 }, + { x: 2006, y: 0.00 }, + { x: 2007, y: 0.00 }, + { x: 2008, y: 0.00 }, + { x: 2009, y: 0.00 }, + { x: 2010, y: 0.17 }, + { x: 2011, y: 0.17 }, + { x: 2012, y: 0.17 }, + { x: 2013, y: 0.17 }, + { x: 2014, y: 0.25 }, + { x: 2015, y: 0.25 }, + { x: 2016, y: 0.25 }, + { x: 2017, y: 1.18 } + ] + } + ].to_json end def ecoregions diff --git a/app/javascript/components/charts/chart-line/ChartLine.vue b/app/javascript/components/charts/chart-line/ChartLine.vue index fb702fc91..aa252882d 100644 --- a/app/javascript/components/charts/chart-line/ChartLine.vue +++ b/app/javascript/components/charts/chart-line/ChartLine.vue @@ -93,7 +93,7 @@ props: { lines: { - type: Array, // [ { x: Number, y: Number } ] + type: Array, // [ id: String, datapoints: { x: Number, y: Number } ] required: true }, targets: Array, @@ -113,7 +113,6 @@ paddingTop: 50 }, x: { - axisMarks: 8, chartPadding: 24, chartWidth: 890, max: 0, @@ -123,7 +122,6 @@ precision: 1, }, y: { - axisMarks: 8, chartHeight: 500, chartPadding: 34, max: 0, @@ -180,10 +178,6 @@ this.y.maxNormalised = this.normaliseY(this.y.max) }, - mounted () { - - }, - methods: { getLegend (){ const legend = this.lines.map((dataset) => { @@ -213,13 +207,19 @@ }, getAxis (axis) { - let array = [], n = this[axis].min - const incrementor = (this[axis].max - this[axis].min)/ this[axis].axisMarks + const + totalDatapoints = this.lines[0].datapoints.length, + axisMarks = totalDatapoints % 2 == 0 ? (totalDatapoints + 1)/2 : totalDatapoints/2, + min = Math.floor(this[axis].min), + max = Math.ceil(this[axis].max), + incrementor = (max - min)/(axisMarks - 1) + + let array = [], n = min - while( n < this[axis].max + incrementor) { + while( n < (max + incrementor)) { array.push({ coord: this[`normalise${axis.toUpperCase()}`](n), - labelText: Math.ceil(n/this[axis].precision)*this[axis].precision + labelText: n }) n += incrementor @@ -241,7 +241,6 @@ }, normaliseDataset (dataset) { - console.log(dataset) const normalisedDataset = dataset.map((datapoint) => { return { value: datapoint.y + '%', @@ -249,7 +248,6 @@ y: this.normaliseY(datapoint.y) } }) - console.log(normalisedDataset) return normalisedDataset }, From e9b758c80122d5dc37f97098460375b2925e2692 Mon Sep 17 00:00:00 2001 From: stacytalbot Date: Wed, 1 Apr 2020 15:39:42 +0100 Subject: [PATCH 06/11] Finally fix axis --- .../charts/chart-line/ChartLine.vue | 123 +++++++----------- 1 file changed, 49 insertions(+), 74 deletions(-) diff --git a/app/javascript/components/charts/chart-line/ChartLine.vue b/app/javascript/components/charts/chart-line/ChartLine.vue index aa252882d..eb26c96c3 100644 --- a/app/javascript/components/charts/chart-line/ChartLine.vue +++ b/app/javascript/components/charts/chart-line/ChartLine.vue @@ -15,7 +15,7 @@ {{ t }} - {{ y.labelText }}% - {{ x.labelText }} - - + + - - @@ -77,15 +57,12 @@ \ No newline at end of file diff --git a/app/javascript/components/charts/chart-line/ChartPopup.vue b/app/javascript/components/charts/chart-line/ChartPopup.vue index a7871052e..b7283e14d 100644 --- a/app/javascript/components/charts/chart-line/ChartPopup.vue +++ b/app/javascript/components/charts/chart-line/ChartPopup.vue @@ -1,40 +1,29 @@ @@ -43,10 +32,6 @@ export default { name: 'chart-popup', props: { - colour: { - required: true, - type: String - }, text: { required: true, type: String @@ -68,9 +53,6 @@ export default { }, computed: { - coordX () { - return this.x - }, coordY () { return this.y - 10 }, From 536f754b1702322e44ee67300dee00a99bed86b4 Mon Sep 17 00:00:00 2001 From: stacytalbot Date: Wed, 1 Apr 2020 17:06:50 +0100 Subject: [PATCH 10/11] Put the rest of the page back --- .../stylesheets/components/_charts.scss | 2 +- .../components/charts/_chart-line.scss | 34 ++++ .../charts/_interactive-multiline.scss | 158 ------------------ .../charts/chart-line/ChartLine.vue | 3 - app/views/marine/index.html.erb | 47 +++++- app/views/marine/sections/_coverage.html.erb | 2 +- 6 files changed, 82 insertions(+), 164 deletions(-) create mode 100644 app/assets/stylesheets/components/charts/_chart-line.scss delete mode 100644 app/assets/stylesheets/components/charts/_interactive-multiline.scss diff --git a/app/assets/stylesheets/components/_charts.scss b/app/assets/stylesheets/components/_charts.scss index 583c6cb36..33e848789 100644 --- a/app/assets/stylesheets/components/_charts.scss +++ b/app/assets/stylesheets/components/_charts.scss @@ -80,11 +80,11 @@ $chart-target-stroke-width: rem-calc(3); //-------------------------------------------------- @import './charts/chart-dial'; @import './charts/chart-legend'; + @import './charts/chart-line'; @import './charts/chart-row-pa'; @import './charts/chart-row-target'; } @import './charts/horizontal-bar-chart'; -@import './charts/interactive-multiline'; @import './charts/interactive-treemap'; @import './charts/sunburst'; \ No newline at end of file diff --git a/app/assets/stylesheets/components/charts/_chart-line.scss b/app/assets/stylesheets/components/charts/_chart-line.scss new file mode 100644 index 000000000..385cfe862 --- /dev/null +++ b/app/assets/stylesheets/components/charts/_chart-line.scss @@ -0,0 +1,34 @@ +&--line { + .chart { + &__wrapper-ie11 { // do not remove - this is required to set the sizing for ie11 + @include breakpoint($small) { + padding-bottom: 54%; + width: 100%; + + position: relative; + } + } + + &__scrollable { + @include breakpoint-down($small) { + overflow-x: auto; + + display: flex; + } + } + + &__chart { + @include breakpoint-down($small) { min-width: 260%; } + } + + &__svg { + width: 100%; + + @include breakpoint($small) { + position: absolute; + top: 0; + left: 0; + } + } + } +} \ No newline at end of file diff --git a/app/assets/stylesheets/components/charts/_interactive-multiline.scss b/app/assets/stylesheets/components/charts/_interactive-multiline.scss deleted file mode 100644 index 333a679af..000000000 --- a/app/assets/stylesheets/components/charts/_interactive-multiline.scss +++ /dev/null @@ -1,158 +0,0 @@ -.v-interactive-multiline { - &__tabs { - border-bottom: solid rem-calc(1) $grey-xdark; - font-family: 'MuseoSans'; - font-weight: thin; - } - - &__tab-title { - background-color: $blue--marine-3; - border-right: solid rem-calc(1) $blue--marine-2; - border-left: solid rem-calc(1) $blue--marine-2; - cursor: pointer; - font-size: rem-calc(12); - padding: rem-calc(8 10 5 10); - text-transform: capitalize; - - display: inline-block; - position: relative; - - @include breakpoint($large){ font-size: rem-calc(16); } - - &.active { - background-color: transparent; - border: solid rem-calc(1) $grey-xdark; - border-bottom: 0; - - &:after { - background-color: $blue--marine-2; - content: ''; - width: 100%; height: rem-calc(1); - - position: absolute; - bottom: -1px; - left: 0; - } - } - } - - &__chart { - // hack to get the svg to scale in IE11 - width: 100%; - - position: relative; - // end hack - } - &__svg { - // hack to get the svg to scale in IE11 - display: block; - position: absolute; - top: 0; - left: 0; - // end hack - } - - &__axis { - .domain { stroke: $grey-xdark; } - - .tick { - line { stroke-width: 0; } - - text { - font-size: rem-calc(14); - fill: $blue--marine-5; - - @include breakpoint($large){ font-size: rem-calc(10); } - } - } - } - - &__gridlines { - .domain { stroke-width: 0; } - - .tick { - line { stroke: $grey; } - } - } - - &__target { - .domain { stroke-width: 0; } - - .tick { - line { - stroke: $white; - stroke-width: 2; - stroke-dasharray: 10px; - } - - text { - fill: $white; - font-size: rem-calc(14); - font-weight: bold; - - transform: translateY(6px); - - @include breakpoint($large){ font-size: rem-calc(10); } - } - } - } - - &__line { - stroke: $blue--marine-5; - stroke-linecap: round; - stroke-width: 3; - - stroke-dasharray: 1000; - stroke-dashoffset: 1000; - - @include breakpoint($medium){ stroke-width: 2; } - - @media screen\0 { - opacity: 0; //target IE11 - stroke-dashoffset: 0; //target IE11 - } - } - - &__line-active { - animation: dashOffsetNone 2s linear forwards 1; - - @media screen\0 { - animation: fullOpacity .1s linear forwards; //target IE11 - } - } - - &__datapoint { - cursor: pointer; - fill: white; - stroke: $blue--marine-5; - - transform-origin: 50%; - transform: scale(0); - - @media screen\0 { opacity: 0; } //target IE11 - - .v-interactive-multiline__datapoints-active & { - animation: fullScaleXY .2s linear forwards 1s; - - @media screen\0 { - animation: fullOpacity .1s linear forwards; //target IE11 - } - } - } - - &__tooltip-wrapper { - position: absolute; - } - - &__tooltip { - fill: white; - font-family: 'MuseoSans'; - font-size: rem-calc(18); - display: none; - text-anchor: middle; - } - - &__tooltip-active { - display: block; - } -} \ No newline at end of file diff --git a/app/javascript/components/charts/chart-line/ChartLine.vue b/app/javascript/components/charts/chart-line/ChartLine.vue index 6c8661b85..72147a99f 100644 --- a/app/javascript/components/charts/chart-line/ChartLine.vue +++ b/app/javascript/components/charts/chart-line/ChartLine.vue @@ -235,7 +235,6 @@ }, popupHide () { - console.log('here') this.popup.show = false this.popup.text = '' this.popup.x = 0 @@ -243,12 +242,10 @@ }, popupShow (datapoint) { - console.log('here') this.popup.show = true this.popup.text = datapoint.value this.popup.x = datapoint.x this.popup.y = datapoint.y - console.log('popup tex', this.popup.text) }, setAxisVariables () { diff --git a/app/views/marine/index.html.erb b/app/views/marine/index.html.erb index c2122ffae..bcbe4dd72 100644 --- a/app/views/marine/index.html.erb +++ b/app/views/marine/index.html.erb @@ -34,4 +34,49 @@ <%= render partial: "marine/sections/coverage", locals: { cms_page: @cms_page, -} %> \ No newline at end of file +} %> + + + +<%= render partial: "marine/sections/national" %> + +
+

<%= cms_fragment_render(:section_size_title, @cms_page) %>

+
<%= cms_fragment_render(:section_size_content, @cms_page) %>
+
+ +<%= render partial: "marine/sections/size_growth" %> + +<%= render partial: "marine/sections/coverage_growth" %> + +<%= render partial: "marine/sections/coverage_map" %> + +<%#= render partial: "partials/cards/sites", locals: { cards: @wdpa } %> + +<%= render "partials/carousels/themes" %> + +<%= render "partials/ctas/live-report" %> + +<%= content_for :twitter_card, "summary_large_image" %> +<%= content_for :social_title, "Explore the World's Marine Protected Areas" %> +<%= content_for :social_description, "Over 70% of the surface of Earth is ocean, comprised of highly diverse ecosystems, and providing a wide range of marine ecosystem services that support human society, health and the economy. This website presents the most recent official coverage statistics for marine protected areas, updated monthly from the World Database on Protected Areas." %> +<%= content_for :social_image, image_url('social-marine.png') %> +<%= content_for :social_image_alt, "A map of the world with highlighted areas that represent protected areas. The following statistics are shown: there are #{@marine_statistics['total_marine_protected_areas']} marine protected areas, #{@marine_statistics['total_ocean_pa_coverage_percentage']} of the ocean is covered by protected areas and the total area protected is 23,036,078kmĀ² These statistics are for 2017." %> + + +

Highlight some text to share via Twitter or Email.

+
+ + + +
+ + +<%= download_dropdown("marine", "general", [:csv, :shp, :pdf]) %> +
+ +
+<%= render partial: "marine/sections/footer" %> +
diff --git a/app/views/marine/sections/_coverage.html.erb b/app/views/marine/sections/_coverage.html.erb index b0dccae87..b871cc80d 100644 --- a/app/views/marine/sections/_coverage.html.erb +++ b/app/views/marine/sections/_coverage.html.erb @@ -1,4 +1,4 @@ -
+

<%= cms_fragment_render(:section_coverage_title, cms_page) %>

<%= cms_fragment_render(:section_coverage_content, cms_page) %>
From 06ba967e58cbbc0d95f09529c6a4241d49bb85f3 Mon Sep 17 00:00:00 2001 From: stacytalbot Date: Thu, 2 Apr 2020 10:31:02 +0100 Subject: [PATCH 11/11] Remove comments from controller --- app/controllers/marine_controller.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/controllers/marine_controller.rb b/app/controllers/marine_controller.rb index f140eb7f9..f30e193ce 100644 --- a/app/controllers/marine_controller.rb +++ b/app/controllers/marine_controller.rb @@ -153,12 +153,6 @@ def marine_statistics end def growth - # @protectedAreasGrowth = [ - # { - # id: 'a', - # datapoints: [{x:0,y:0},{x:1,y:1},{x:2,y:2},{x:3,y:3},{x:4,y:4},{x:5,y:5},{x:6,y:6},{x:7,y:7}] - # } - # ].to_json @protectedAreasGrowth = [ { id: "Global",