├── .eslintrc.js
├── .gitignore
├── .prettierrc.js
├── LICENSE
├── README.md
├── package-lock.json
├── package.json
├── screenshot.png
├── src
├── components
│ ├── AboutThisApp
│ │ ├── index.tsx
│ │ └── style.scss
│ ├── App
│ │ ├── config.ts
│ │ ├── index.tsx
│ │ └── style.scss
│ ├── InfoPanel
│ │ ├── index.tsx
│ │ └── style.scss
│ ├── Map
│ │ ├── config.ts
│ │ ├── index.tsx
│ │ └── style.scss
│ ├── MobileHeader
│ │ ├── index.tsx
│ │ └── style.scss
│ ├── MonthlyTrendChart
│ │ ├── index.tsx
│ │ └── style.scss
│ ├── PolarToggleBtn
│ │ ├── MobileVersion.tsx
│ │ ├── ToggleBtn.tsx
│ │ ├── data.ts
│ │ ├── index.tsx
│ │ └── style.scss
│ ├── SeaIceExtByYearChart
│ │ ├── config.ts
│ │ ├── index.tsx
│ │ └── style.scss
│ ├── SidebarHeader
│ │ ├── index.tsx
│ │ └── style.scss
│ └── TimeControl
│ │ ├── SliderTicks.scss
│ │ ├── SliderTicks.tsx
│ │ ├── index.tsx
│ │ └── style.scss
├── index.template.html
├── index.tsx
├── services
│ └── sea-ice-extents
│ │ ├── config.ts
│ │ └── index.ts
├── style
│ ├── color.scss
│ ├── fancy-scrollbar.scss
│ └── index.scss
├── types.d.ts
└── types
│ └── calcite-web
│ └── index.d.ts
├── tsconfig.json
└── webpack.config.js
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | "extends": [
3 | 'plugin:react/recommended',
4 | 'plugin:@typescript-eslint/recommended',
5 | // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
6 | 'prettier/@typescript-eslint',
7 | // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
8 | 'plugin:prettier/recommended',
9 | ],
10 | "env": {
11 | "browser": true
12 | },
13 | "parser": "@typescript-eslint/parser",
14 | "parserOptions": {
15 | "ecmaVersion": 2017,
16 | "sourceType": "module"
17 | },
18 | "plugins": [
19 | "@typescript-eslint/eslint-plugin"
20 | ],
21 | "rules": {
22 | "@typescript-eslint/interface-name-prefix": "off",
23 | }
24 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Runtime data
9 | pids
10 | *.pid
11 | *.seed
12 | *.pid.lock
13 |
14 | # Directory for instrumented libs generated by jscoverage/JSCover
15 | lib-cov
16 |
17 | # Coverage directory used by tools like istanbul
18 | coverage
19 |
20 | # nyc test coverage
21 | .nyc_output
22 |
23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24 | .grunt
25 |
26 | # Bower dependency directory (https://bower.io/)
27 | bower_components
28 |
29 | # node-waf configuration
30 | .lock-wscript
31 |
32 | # Compiled binary addons (https://nodejs.org/api/addons.html)
33 | build/Release
34 |
35 | # Dependency directories
36 | node_modules/
37 | jspm_packages/
38 |
39 | # TypeScript v1 declaration files
40 | typings/
41 |
42 | # Optional npm cache directory
43 | .npm
44 |
45 | # Optional eslint cache
46 | .eslintcache
47 |
48 | # Optional REPL history
49 | .node_repl_history
50 |
51 | # Output of 'npm pack'
52 | *.tgz
53 |
54 | # Yarn Integrity file
55 | .yarn-integrity
56 |
57 | # dotenv environment variables file
58 | .env
59 |
60 | # next.js build output
61 | .next
62 |
63 | /dist
--------------------------------------------------------------------------------
/.prettierrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | semi: true,
3 | arrowParens: 'always',
4 | semi: true,
5 | trailingComma: 'es5',
6 | singleQuote: true,
7 | printWidth: 80,
8 | tabWidth: 2,
9 | };
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Sea Ice
2 | This app displays the monthly mean sea ice extent for the [Arctic](https://www.arcgis.com/home/item.html?id=d1fb8225058e4a0d96ead7b9a574a652) and [Antarctic](https://www.arcgis.com/home/item.html?id=e7f11116c0bc42fb8c7c4d1b1d70eceb) along with the historical median extent.
3 |
4 | [View it live](https://livingatlas.arcgis.com/sea-ice/)
5 |
6 | 
7 |
8 | ## Features
9 |
10 | This app displays the monthly mean sea ice extent for the Arctic and Antarctic along with the historical median extent. Additionally, graphs are used to visualize the minimum and maximum extent for each year (top), and the monthly time series for each year (bottom). Use the top graph to select specific years to display in the map.
11 |
12 | ## Instructions
13 |
14 | - Before we begin, make sure you have a fresh version of [Node.js](https://nodejs.org/en/) and NPM installed. The current Long Term Support (LTS) release is an ideal starting point.
15 |
16 | - To begin, clone this repository to your computer:
17 |
18 | ```sh
19 | https://github.com/vannizhang/sea-ice.git
20 | ```
21 |
22 | - From the project's root directory, install the required packages (dependencies):
23 |
24 | ```sh
25 | npm install
26 | ```
27 |
28 | - Now you can start the webpack dev server to test the app on your local machine:
29 |
30 | ```sh
31 | # it will start a server instance and begin listening for connections from localhost on port 8080
32 | npm run start
33 | ```
34 |
35 | - To build/deploye the app, you can simply run:
36 |
37 | ```sh
38 | # it will place all files needed for deployment into the /dist directory
39 | npm run build
40 | ```
41 |
42 | ## Resources
43 | - [ArcGIS API for JavaScript (version 4.21)](https://developers.arcgis.com/javascript/index.html)
44 | - [National Snow and Ice Data Center](https://nsidc.org/)
45 | - [ArcGIS Living Atlas of the World](https://livingatlas.arcgis.com/en/browse/#d=2&q=sea%20ice)
46 | - [D3.js](https://d3js.org/)
47 |
48 | ## Issues
49 |
50 | Find a bug or want to request a new feature? Please let us know by submitting an issue.
51 |
52 | ## Disclaimer
53 |
54 | This demo application is for illustrative purposes only and it is not maintained. There is no support available for deployment or development of the application.
55 |
56 | ## Contributing
57 |
58 | Esri welcomes contributions from anyone and everyone. Please see our [guidelines for contributing](https://github.com/esri/contributing).
59 |
60 | ## Licensing
61 | Copyright 2019 Esri
62 |
63 | Licensed under the Apache License, Version 2.0 (the "License");
64 | you may not use this file except in compliance with the License.
65 | You may obtain a copy of the License at
66 |
67 | http://www.apache.org/licenses/LICENSE-2.0
68 |
69 | Unless required by applicable law or agreed to in writing, software
70 | distributed under the License is distributed on an "AS IS" BASIS,
71 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
72 | See the License for the specific language governing permissions and
73 | limitations under the License.
74 |
75 | A copy of the license is available in the repository's [LICENSE](license) file.
76 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "sea-ice",
3 | "version": "1.0.0",
4 | "description": "Visualize Arctic and Antarctic sea ice",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1",
8 | "start": "webpack-dev-server --mode development --open",
9 | "dev": "webpack --mode development",
10 | "build": "webpack --mode production",
11 | "format": "prettier --write src/**/*.{ts,tsx,json}",
12 | "lint": "eslint src/**/*.{ts,tsx} --fix",
13 | "precommit": "npm run lint && npm run format"
14 | },
15 | "repository": {
16 | "type": "git",
17 | "url": "git+https://github.com/vannizhang/sea-ice.git"
18 | },
19 | "keywords": [],
20 | "author": "",
21 | "license": "ISC",
22 | "bugs": {
23 | "url": "https://github.com/vannizhang/sea-ice/issues"
24 | },
25 | "homepage": "https://github.com/vannizhang/sea-ice#readme",
26 | "devDependencies": {
27 | "@babel/polyfill": "^7.4.4",
28 | "@types/react": "^16.8.23",
29 | "@types/react-dom": "^16.8.5",
30 | "@typescript-eslint/eslint-plugin": "^2.7.0",
31 | "@typescript-eslint/parser": "^2.7.0",
32 | "clean-webpack-plugin": "^3.0.0",
33 | "css-loader": "^3.1.0",
34 | "eslint": "^6.6.0",
35 | "eslint-config-prettier": "^6.5.0",
36 | "eslint-plugin-prettier": "^3.1.1",
37 | "eslint-plugin-react": "^7.16.0",
38 | "file-loader": "^4.1.0",
39 | "html-loader": "^0.5.5",
40 | "html-webpack-plugin": "^3.2.0",
41 | "mini-css-extract-plugin": "^0.8.0",
42 | "node-sass": "^4.14.1",
43 | "optimize-css-assets-webpack-plugin": "^5.0.3",
44 | "prettier": "^1.19.1",
45 | "sass-loader": "^10.1.1",
46 | "source-map-loader": "^0.2.4",
47 | "style-loader": "^0.23.1",
48 | "terser-webpack-plugin": "^1.4.1",
49 | "ts-loader": "^6.0.4",
50 | "typescript": "^3.5.3",
51 | "uglifyjs-webpack-plugin": "^2.2.0",
52 | "url-loader": "^2.1.0",
53 | "webpack": "^4.38.0",
54 | "webpack-cli": "^3.3.6",
55 | "webpack-dev-server": "^3.7.2"
56 | },
57 | "dependencies": {
58 | "@esri/arcgis-rest-auth": "^2.0.0",
59 | "@esri/arcgis-rest-feature-layer": "^2.2.1",
60 | "@esri/arcgis-rest-request": "^2.2.1",
61 | "@types/arcgis-js-api": "^4.12.0",
62 | "@types/d3": "^5.7.2",
63 | "axios": "^0.19.0",
64 | "calcite-web": "github:Esri/calcite-web#v1.2.5",
65 | "d3": "^5.9.7",
66 | "es6-promise": "^4.2.8",
67 | "esri-loader": "^2.14.0",
68 | "helper-toolkit-ts": "^1.1.4",
69 | "isomorphic-fetch": "^2.2.1",
70 | "react": "^16.8.6",
71 | "react-dom": "^16.8.6"
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vannizhang/sea-ice/bcf240088edf3a551da7bc4862874d5c2f12d70d/screenshot.png
--------------------------------------------------------------------------------
/src/components/AboutThisApp/index.tsx:
--------------------------------------------------------------------------------
1 | import './style.scss';
2 | import * as React from 'react';
3 | import { modal as initCalciteModal } from 'calcite-web/dist/js/calcite-web.min.js';
4 |
5 | // interface IProps {}
6 | // interface IState {}
7 |
8 | export default class AboutThisApp extends React.PureComponent {
9 | // constructor(props: IProps) {
10 | // super(props);
11 | // }
12 |
13 | componentDidMount() {
14 | initCalciteModal();
15 | }
16 |
17 | render() {
18 | return (
19 |
23 |
28 |
33 |
40 |
41 |
42 |
43 |
44 |
About this App
45 |
46 |
47 | Areas of the ocean that have frozen are considered “sea ice,” and
48 | can vary from slushy, barely solid areas to sheets of ice that are
49 | meters thick. Since the late 1970s, satellites have been used to
50 | monitor both the extent and concentration of sea ice around the
51 | world, and the{' '}
52 |
58 | National Snow and Ice Data Center
59 | {' '}
60 | generates a sea ice extent analyses from this data. We have applied
61 | a smoothing algorithm to the original shapefiles accessed from
62 | NSIDC.
63 |
64 |
65 |
66 | This app displays the monthly mean sea ice extent for the{' '}
67 |
73 | Arctic
74 | {' '}
75 | and{' '}
76 |
82 | Antarctic
83 | {' '}
84 | along with the historical median extent. Additionally, graphs are
85 | used to visualize the minimum and maximum extent for each year
86 | (top), and the monthly time series for each year (bottom). Use the
87 | top graph to select specific years to display in the map.{' '}
88 |
89 |
90 |
91 | This app was designed by members of the{' '}
92 |
98 | ArcGIS Living Atlas of the World
99 | {' '}
100 | team.{' '}
101 |
102 |
103 |
104 | Close
105 |
106 |
107 |
108 | );
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/src/components/AboutThisApp/style.scss:
--------------------------------------------------------------------------------
1 | @import '../../style/color.scss';
2 |
3 | .about-this-app-modal{
4 | .modal-content {
5 | background: $themeColorAlpha85;
6 | color: #efefef;
7 | }
8 |
9 | }
--------------------------------------------------------------------------------
/src/components/App/config.ts:
--------------------------------------------------------------------------------
1 | export default {
2 | title: 'Sea Ice Aware',
3 | 'mobile-header-height': 60,
4 | };
5 |
--------------------------------------------------------------------------------
/src/components/App/index.tsx:
--------------------------------------------------------------------------------
1 | import './style.scss';
2 | import * as React from 'react';
3 |
4 | import Map from '../Map';
5 | import InfoPanel from '../InfoPanel';
6 | import TimeControl from '../TimeControl';
7 | import AboutThisApp from '../AboutThisApp';
8 | import SideBarHeader from '../SidebarHeader';
9 | import MobileHeader from '../MobileHeader';
10 | import AppConfig from './config';
11 |
12 | import {
13 | PolarRegion,
14 | IMinMaxSeaExtByYearData,
15 | ISeaIceExtByMonthData,
16 | IMedianSeaIceExtByMonth,
17 | IRecordDate,
18 | ISeaIceExtVal2MonthLookup,
19 | } from '../../types';
20 |
21 | import {
22 | queryMinMaxSeaIceExtByYear,
23 | querySeaIceExtByMonth,
24 | queryMedianSeaIceExtByMonth,
25 | queryRecordDates,
26 | prepareSeaIceExtByMonth,
27 | generateValue2MonthLookup,
28 | } from '../../services/sea-ice-extents';
29 |
30 | interface IProps {
31 | isMobile: boolean;
32 | }
33 |
34 | interface IState {
35 | polarRegion: PolarRegion;
36 | recordDates: Array;
37 | activeRecordDate: IRecordDate;
38 | seaIceExtByYearData: IMinMaxSeaExtByYearData;
39 | seaIceExtByMonthData: ISeaIceExtByMonthData;
40 | medianSeaIceExtByMonthData: IMedianSeaIceExtByMonth;
41 | seaIceExtVal2MonthLookup: ISeaIceExtVal2MonthLookup;
42 | isMobileInfoWindowVisible: boolean;
43 | }
44 |
45 | export default class App extends React.PureComponent {
46 | constructor(props: IProps) {
47 | super(props);
48 |
49 | this.state = {
50 | polarRegion: 'arctic',
51 | recordDates: [],
52 | activeRecordDate: null,
53 | seaIceExtByYearData: null,
54 | seaIceExtByMonthData: null,
55 | medianSeaIceExtByMonthData: null,
56 | seaIceExtVal2MonthLookup: null,
57 | isMobileInfoWindowVisible: false,
58 | };
59 |
60 | this.updatePolarRegion = this.updatePolarRegion.bind(this);
61 | this.timeControlOnValueChange = this.timeControlOnValueChange.bind(this);
62 | this.seaIceValOnSelect = this.seaIceValOnSelect.bind(this);
63 | this.toggleMobileInfoWindow = this.toggleMobileInfoWindow.bind(this);
64 | }
65 |
66 | updatePolarRegion(polarRegion: PolarRegion) {
67 | this.setState({
68 | polarRegion: polarRegion,
69 | });
70 | }
71 |
72 | updateActiveRecordDate(index = -1) {
73 | const { recordDates } = this.state;
74 |
75 | if (!recordDates.length) {
76 | return;
77 | }
78 |
79 | index = index === -1 ? recordDates.length - 1 : index;
80 |
81 | const activeRecordDate = recordDates[index];
82 |
83 | this.setState({
84 | activeRecordDate,
85 | });
86 | }
87 |
88 | setSeaIceExtByYearData(data: IMinMaxSeaExtByYearData) {
89 | this.setState({
90 | seaIceExtByYearData: data,
91 | });
92 | }
93 |
94 | setSeaIceExtByMonthData(
95 | data: ISeaIceExtByMonthData,
96 | medianData: IMedianSeaIceExtByMonth
97 | ) {
98 | this.setState({
99 | seaIceExtByMonthData: data,
100 | medianSeaIceExtByMonthData: medianData,
101 | });
102 | }
103 |
104 | setRecordDates(recordDates: Array) {
105 | this.setState(
106 | {
107 | recordDates,
108 | },
109 | () => {
110 | this.updateActiveRecordDate();
111 | }
112 | );
113 | }
114 |
115 | setSeaIceVal2MonthLookup(lookup: ISeaIceExtVal2MonthLookup) {
116 | this.setState({
117 | seaIceExtVal2MonthLookup: lookup,
118 | });
119 | }
120 |
121 | async loadAppData() {
122 | try {
123 | const seaIceExtByYear = await queryMinMaxSeaIceExtByYear();
124 |
125 | const seaIceExtByMonthFeatures = await querySeaIceExtByMonth();
126 |
127 | const seaIceExtByMonth: ISeaIceExtByMonthData = {
128 | antarctic: prepareSeaIceExtByMonth(seaIceExtByMonthFeatures.antarctic),
129 | arctic: prepareSeaIceExtByMonth(seaIceExtByMonthFeatures.arctic),
130 | };
131 |
132 | const medianSeaIceExtByMonth = await queryMedianSeaIceExtByMonth();
133 |
134 | const recordDates = await queryRecordDates();
135 |
136 | const seaIceVal2MonthLookup = generateValue2MonthLookup(
137 | seaIceExtByMonthFeatures
138 | );
139 |
140 | this.setSeaIceExtByYearData(seaIceExtByYear);
141 | // console.log(seaIceExtByYear);
142 |
143 | this.setSeaIceExtByMonthData(seaIceExtByMonth, medianSeaIceExtByMonth);
144 | // console.log(seaIceExtByMonthFeatures);
145 |
146 | this.setRecordDates(recordDates);
147 | // console.log(recordDates);
148 |
149 | this.setSeaIceVal2MonthLookup(seaIceVal2MonthLookup);
150 | // console.log(seaIceVal2MonthLookup);
151 | } catch (err) {
152 | console.error(err);
153 | }
154 | }
155 |
156 | timeControlOnValueChange(index: number) {
157 | this.updateActiveRecordDate(index);
158 | }
159 |
160 | seaIceValOnSelect(year: number, value: number) {
161 | const { seaIceExtByMonthData, recordDates, polarRegion } = this.state;
162 |
163 | // values for the selected year
164 | const values = seaIceExtByMonthData[polarRegion].filter((d) => {
165 | return d.year === year;
166 | })[0].values;
167 |
168 | const monthNum = values.indexOf(value) + 1;
169 |
170 | for (let i = 0, len = recordDates.length; i < len; i++) {
171 | const d = recordDates[i];
172 |
173 | if (d.year === year && d.month === monthNum) {
174 | this.updateActiveRecordDate(i);
175 | break;
176 | }
177 | }
178 | }
179 |
180 | toggleMobileInfoWindow() {
181 | const { isMobileInfoWindowVisible } = this.state;
182 | const newValue = !isMobileInfoWindowVisible;
183 |
184 | this.setState({
185 | isMobileInfoWindowVisible: newValue,
186 | });
187 | }
188 |
189 | componentDidMount() {
190 | this.loadAppData();
191 | }
192 |
193 | render() {
194 | const { isMobile } = this.props;
195 | const { isMobileInfoWindowVisible } = this.state;
196 | const mobileHeaderHeight = AppConfig['mobile-header-height'] || 50;
197 |
198 | const infoPanel = (
199 |
210 | );
211 |
212 | const timeControl = (
213 |
221 | );
222 |
223 | const desktopSidePanel = !isMobile ? (
224 |
225 |
226 | {timeControl}
227 | {infoPanel}
228 |
229 | ) : null;
230 |
231 | const mobileInfoPanel =
232 | isMobile && isMobileInfoWindowVisible ? (
233 | {infoPanel}
234 | ) : null;
235 |
236 | const mobileHeader = isMobile ? (
237 |
244 | ) : null;
245 |
246 | const mobileBottomPanel = isMobile ? (
247 | {timeControl}
248 | ) : null;
249 |
250 | return (
251 |
252 |
262 |
263 |
264 |
265 | {desktopSidePanel}
266 |
267 | {mobileHeader}
268 |
269 | {mobileInfoPanel}
270 |
271 | {mobileBottomPanel}
272 |
273 | );
274 | }
275 | }
276 |
--------------------------------------------------------------------------------
/src/components/App/style.scss:
--------------------------------------------------------------------------------
1 | @import '../../style/fancy-scrollbar.scss';
2 |
3 | .side-panel{
4 | position: absolute;
5 | top: 1rem;
6 | right: 1rem;
7 | bottom: 2rem;
8 | width: 500px;
9 | overflow-y: auto;
10 | }
11 |
12 | .mobile-view-bottom-panel{
13 | position: absolute;
14 | bottom: 5px;
15 | width: 100%;
16 | display: flex;
17 | justify-content: center;
18 | }
19 |
20 | .is-mobile {
21 | .esri-attribution{
22 | display: none;
23 | }
24 |
25 | .floating-panel{
26 | position: absolute;
27 | top: 65px;
28 | box-sizing: border-box;
29 | width: 100%;
30 | padding: 0 .25rem;
31 | bottom: 115px;
32 | overflow-y: auto;
33 | }
34 | }
35 |
36 |
--------------------------------------------------------------------------------
/src/components/InfoPanel/index.tsx:
--------------------------------------------------------------------------------
1 | import './style.scss';
2 | import * as React from 'react';
3 |
4 | import PolarToggleBtn from '../PolarToggleBtn';
5 | import SeaIceExtByYearChart from '../SeaIceExtByYearChart';
6 | import MonthlyTrendChart from '../MonthlyTrendChart';
7 |
8 | // import { queryMinMaxSeaIceExtByYear, querySeaIceExtByMonth, queryMedianSeaIceExtByMonth } from '../../services/sea-ice-extents'
9 | import {
10 | PolarRegion,
11 | IMinMaxSeaExtByYearData,
12 | ISeaIceExtByMonthData,
13 | IMedianSeaIceExtByMonth,
14 | ISeaIceExtVal2MonthLookup,
15 | IRecordDate,
16 | } from '../../types';
17 |
18 | interface IProps {
19 | polarRegion: PolarRegion;
20 | polarRegionOnChange: (value: string) => void;
21 | activeRecordDate: IRecordDate;
22 | seaIceExtByYearData: IMinMaxSeaExtByYearData;
23 | seaIceExtByMonthData: ISeaIceExtByMonthData;
24 | medianSeaIceExtByMonthData: IMedianSeaIceExtByMonth;
25 | seaIceExtVal2MonthLookup: ISeaIceExtVal2MonthLookup;
26 | seaIceValOnSelect: (year: number, value: number) => void;
27 | isMobile?: boolean;
28 | }
29 |
30 | interface IState {
31 | // year value returned by the mouse hover on sea ice ext by year bar chart
32 | yearOnHover: number;
33 | }
34 |
35 | export default class InfoPanel extends React.PureComponent {
36 | constructor(props: IProps) {
37 | super(props);
38 |
39 | this.state = {
40 | yearOnHover: undefined,
41 | };
42 |
43 | this.seaIceExtByYearChartOnHover = this.seaIceExtByYearChartOnHover.bind(
44 | this
45 | );
46 | }
47 |
48 | // componentDidMount(){
49 | // }
50 |
51 | seaIceExtByYearChartOnHover(year: number) {
52 | // console.log(year);
53 | this.setState({
54 | yearOnHover: year,
55 | });
56 | }
57 |
58 | render() {
59 | const { isMobile } = this.props;
60 | const { yearOnHover } = this.state;
61 |
62 | const toggleBtn = !isMobile ? (
63 |
69 | ) : null;
70 |
71 | return (
72 |
73 | {toggleBtn}
74 |
75 |
76 |
83 |
84 |
85 |
86 |
92 |
93 |
94 | {/*
*/}
100 |
101 | );
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/src/components/InfoPanel/style.scss:
--------------------------------------------------------------------------------
1 | @import '../../style/color.scss';
2 |
3 | #infoPanelDiv {
4 | // position: absolute;
5 | // top: 1rem;
6 | // right: 1rem;
7 | padding: 1rem 1.5rem;
8 | box-sizing: border-box;
9 | // width: 400px;
10 | // min-height: 200px;
11 | background-color: $themeColorAlpha95;
12 | box-shadow: 0 0 2px 2px rgba(0,0,0,0.1);
13 | // margin-bottom: 150px;
14 | // max-height: calc(100% - 2.5rem);
15 | // overflow-y: auto;
16 | }
17 |
18 | .is-mobile {
19 | #infoPanelDiv {
20 | padding: 1rem .5rem;
21 | }
22 | }
--------------------------------------------------------------------------------
/src/components/Map/config.ts:
--------------------------------------------------------------------------------
1 | import {
2 | antarctic,
3 | arctic,
4 | antarcticMedianSeaIceExt,
5 | arcticMedianSeaIceExt,
6 | } from '../../services/sea-ice-extents/config';
7 |
8 | const MapConfig = {
9 | 'container-id': 'mapViewDiv',
10 | 'web-map-id': {
11 | antarctic: '8bb127da2b0a4d1290d83072cbc8548b', //'9abb66054ee94c5c9e066dde3bf8aef8',
12 | arctic: 'beec7fd80cb24356a5f05407976c6696',
13 | },
14 | 'map-scale-4-mobile-view': 56000000,
15 | 'sea-ice-ext-feature-service': {
16 | url: {
17 | antarctic: antarctic.url,
18 | arctic: arctic.url,
19 | },
20 | fields: {
21 | date: 'Rec_Date',
22 | year: 'Rec_Year',
23 | month: 'Rec_Month',
24 | },
25 | style: {
26 | fillColor: 'rgba(89,255,252,.3)',
27 | outlineColor: 'rgba(89,255,252,1)',
28 | },
29 | },
30 | 'median-sea-ice-ext-feature-service': {
31 | url: {
32 | antarctic: antarcticMedianSeaIceExt.url,
33 | arctic: arcticMedianSeaIceExt.url,
34 | },
35 | fields: {
36 | date: 'Rec_Date',
37 | year: 'Rec_Year',
38 | month: 'Rec_Month',
39 | },
40 | style: {
41 | fillColor: 'rgba(0,0,0,0)',
42 | outlineColor: '#fff766',
43 | },
44 | },
45 | };
46 |
47 | export { MapConfig };
48 |
--------------------------------------------------------------------------------
/src/components/Map/index.tsx:
--------------------------------------------------------------------------------
1 | import './style.scss';
2 |
3 | import * as React from 'react';
4 | import { loadCss, loadModules } from 'esri-loader';
5 |
6 | import { MapConfig } from './config';
7 |
8 | import { PolarRegion, IRecordDate } from '../../types';
9 | import IMapView from 'esri/views/MapView';
10 | import IWebMap from 'esri/WebMap';
11 | import IFeatureLayer from 'esri/layers/FeatureLayer';
12 | import ISimpleRenderer from 'esri/renderers/SimpleRenderer';
13 | import ISimpleFillSymbol from 'esri/symbols/SimpleFillSymbol';
14 | import ISimpleLineSymbol from 'esri/symbols/SimpleLineSymbol';
15 |
16 | interface IProps {
17 | polarRegion: PolarRegion;
18 | activeRecordDate: IRecordDate;
19 | padding?: {
20 | top?: number;
21 | bottom?: number;
22 | left?: number;
23 | right?: number;
24 | };
25 | isMobile?: boolean;
26 | }
27 |
28 | // interface IState {}
29 |
30 | export default class Map extends React.PureComponent {
31 | private mapView: IMapView;
32 | private readonly LayerIdSeaIceExt = 'seaIceExt';
33 | private readonly LayerIdMedianSeaIceExt = 'medianSeaIceExt';
34 | private delay: NodeJS.Timeout;
35 |
36 | constructor(props: IProps) {
37 | super(props);
38 |
39 | // this.state = {};
40 |
41 | loadCss();
42 | }
43 |
44 | async initMap() {
45 | const { padding, isMobile } = this.props;
46 |
47 | try {
48 | type Modules = [typeof IMapView];
49 |
50 | const [MapView] = await (loadModules(['esri/views/MapView']) as Promise<
51 | Modules
52 | >);
53 |
54 | const webmap = await this.getWebMap();
55 |
56 | const view = new MapView({
57 | container: MapConfig['container-id'],
58 | map: webmap,
59 | padding,
60 | // overwrite the scale if using a mobile device
61 | scale: isMobile ? MapConfig['map-scale-4-mobile-view'] : undefined,
62 | });
63 |
64 | view.when(() => {
65 | this.mapViewOnReadyHandler(view);
66 | });
67 | } catch (err) {
68 | console.error(err);
69 | }
70 | }
71 |
72 | async toggleWebMap() {
73 | try {
74 | if (this.mapView) {
75 | this.mapView.map = await this.getWebMap();
76 | }
77 | } catch (err) {
78 | console.error(err);
79 | }
80 | }
81 |
82 | async getWebMap() {
83 | try {
84 | type Modules = [typeof IWebMap];
85 |
86 | const [WebMap] = await (loadModules(['esri/WebMap']) as Promise);
87 |
88 | const seaIceExtLayers = await this.getSeaIceExtLayers();
89 |
90 | const webmap = new WebMap({
91 | portalItem: {
92 | id: MapConfig['web-map-id'][this.props.polarRegion],
93 | },
94 | layers: [...seaIceExtLayers],
95 | });
96 |
97 | return webmap;
98 | } catch (err) {
99 | console.error(err);
100 | return null;
101 | }
102 | }
103 |
104 | async getSeaIceExtLayers() {
105 | try {
106 | type Modules = [
107 | typeof IFeatureLayer,
108 | typeof ISimpleRenderer,
109 | typeof ISimpleFillSymbol,
110 | typeof ISimpleLineSymbol
111 | ];
112 |
113 | const [
114 | FeatureLayer,
115 | SimpleRenderer,
116 | SimpleFillSymbol,
117 | SimpleLineSymbol,
118 | ] = await (loadModules([
119 | 'esri/layers/FeatureLayer',
120 | 'esri/renderers/SimpleRenderer',
121 | 'esri/symbols/SimpleFillSymbol',
122 | 'esri/symbols/SimpleLineSymbol',
123 | ]) as Promise);
124 |
125 | const defExp = this.getDefExpForSeaIceExtLayer();
126 | // console.log(defExp);
127 |
128 | const rendererSeaIceExt = new SimpleRenderer({
129 | symbol: new SimpleFillSymbol({
130 | color: MapConfig['sea-ice-ext-feature-service'].style.fillColor,
131 | outline: {
132 | // autocasts as new SimpleLineSymbol()
133 | width: 1,
134 | color: MapConfig['sea-ice-ext-feature-service'].style.outlineColor,
135 | },
136 | }),
137 | });
138 |
139 | const seaIceExtLayer = new FeatureLayer({
140 | id: this.LayerIdSeaIceExt,
141 | url:
142 | MapConfig['sea-ice-ext-feature-service'].url[this.props.polarRegion],
143 | definitionExpression: defExp,
144 | visible: true,
145 | renderer: rendererSeaIceExt,
146 | });
147 |
148 | const rendererMedianSeaIceExt = new SimpleRenderer({
149 | symbol: new SimpleLineSymbol({
150 | color:
151 | MapConfig['median-sea-ice-ext-feature-service'].style.outlineColor,
152 | width: 1,
153 | style: 'dash',
154 | }),
155 | });
156 |
157 | const medianSeaIceExtLayer = new FeatureLayer({
158 | id: this.LayerIdMedianSeaIceExt,
159 | url:
160 | MapConfig['median-sea-ice-ext-feature-service'].url[
161 | this.props.polarRegion
162 | ],
163 | definitionExpression: defExp,
164 | visible: true,
165 | renderer: rendererMedianSeaIceExt,
166 | });
167 |
168 | return [medianSeaIceExtLayer, seaIceExtLayer];
169 | } catch (err) {
170 | console.error(err);
171 | return [];
172 | }
173 | }
174 |
175 | updateDefExp4SeaIceExtLayers() {
176 | if (!this.mapView) {
177 | return;
178 | }
179 |
180 | const seaIceExtLayer = this.mapView.map.findLayerById(
181 | this.LayerIdSeaIceExt
182 | ) as IFeatureLayer;
183 | const medianSeaIceExtLayer = this.mapView.map.findLayerById(
184 | this.LayerIdMedianSeaIceExt
185 | ) as IFeatureLayer;
186 |
187 | if (seaIceExtLayer && medianSeaIceExtLayer) {
188 | const defExp = this.getDefExpForSeaIceExtLayer();
189 |
190 | [seaIceExtLayer, medianSeaIceExtLayer].forEach((layer) => {
191 | layer.definitionExpression = defExp;
192 | });
193 | }
194 | }
195 |
196 | activeRecordDateOnChangeHandler() {
197 | clearTimeout(this.delay);
198 |
199 | this.delay = setTimeout(() => {
200 | this.updateDefExp4SeaIceExtLayers();
201 | }, 500);
202 | }
203 |
204 | getDefExpForSeaIceExtLayer() {
205 | const { activeRecordDate } = this.props;
206 |
207 | const year = activeRecordDate ? activeRecordDate.year : 0;
208 | const month = activeRecordDate ? activeRecordDate.month : 0;
209 |
210 | return `${MapConfig['median-sea-ice-ext-feature-service'].fields.year} = ${year} AND ${MapConfig['median-sea-ice-ext-feature-service'].fields.month} = ${month}`;
211 | }
212 |
213 | mapViewOnReadyHandler(mapView: IMapView) {
214 | this.mapView = mapView;
215 |
216 | // the activeRecordDate data might not be ready at the time when map view get initialized,
217 | // therefore need to call this method to make sure the sea ice ext layer will be displayed on the map once it's ready
218 | this.updateDefExp4SeaIceExtLayers();
219 | }
220 |
221 | componentDidUpdate(prevProps: IProps) {
222 | if (this.props.polarRegion !== prevProps.polarRegion) {
223 | this.toggleWebMap();
224 | }
225 |
226 | if (this.props.activeRecordDate !== prevProps.activeRecordDate) {
227 | // this.updateDefExp4SeaIceExtLayers();
228 | this.activeRecordDateOnChangeHandler();
229 | }
230 | }
231 |
232 | componentDidMount() {
233 | this.initMap();
234 | }
235 |
236 | render() {
237 | return
;
238 | }
239 | }
240 |
--------------------------------------------------------------------------------
/src/components/Map/style.scss:
--------------------------------------------------------------------------------
1 | html,
2 | body {
3 | padding: 0;
4 | margin: 0;
5 | height: 100%;
6 | width: 100%;
7 | }
8 |
9 | #mapViewDiv{
10 | position: absolute;
11 | top: 0;
12 | bottom: 0;
13 | left: 0;
14 | right: 0;
15 | margin: 0;
16 | padding: 0;
17 | background-color: black;
18 |
19 | .esri-attribution {
20 | display: none;
21 | }
22 | }
--------------------------------------------------------------------------------
/src/components/MobileHeader/index.tsx:
--------------------------------------------------------------------------------
1 | import './style.scss';
2 | import * as React from 'react';
3 |
4 | import PolarToggleBtn from '../PolarToggleBtn/MobileVersion';
5 | import { PolarRegion } from '../../types';
6 |
7 | interface IProps {
8 | height?: number;
9 | title: string;
10 | polarRegion: PolarRegion;
11 | toggleChartOnClick: () => void;
12 | polarRegionOnChange: (value: string) => void;
13 | }
14 | // interface IState {}
15 |
16 | export default class MobileHeader extends React.PureComponent {
17 | constructor(props: IProps) {
18 | super(props);
19 | }
20 |
21 | render() {
22 | const {
23 | height,
24 | title,
25 | toggleChartOnClick,
26 | polarRegion,
27 | polarRegionOnChange,
28 | } = this.props;
29 |
30 | return (
31 |
37 |
38 | {title}
39 |
40 |
41 |
42 |
48 |
49 |
53 |
59 |
60 |
61 |
62 |
63 |
64 |
70 |
71 |
72 |
73 |
74 |
75 | );
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/components/MobileHeader/style.scss:
--------------------------------------------------------------------------------
1 | @import '../../style/color.scss';
2 |
3 | .mobile-header {
4 | position: absolute;
5 | top: 0;
6 |
7 | display: flex;
8 | justify-content: flex-start;
9 | align-content: flex-start;
10 | align-items: center;
11 |
12 | // height: 50px;
13 | box-sizing: border-box;
14 | width: 100%;
15 | padding: 0 1rem;
16 |
17 | background: $themeColorAlpha95;
18 | box-shadow: 0 0 2px 2px rgba(0,0,0,0.1);
19 |
20 | .app-title{
21 | flex-grow: 1;
22 | flex-shrink: 0;
23 | flex-basis: 50px;
24 | }
25 |
26 | .nav-btns {
27 | display: flex;
28 | }
29 |
30 | .nav-btn {
31 | display: flex;
32 | align-items: center;
33 |
34 | svg {
35 | fill: #fff;
36 | stroke: #fff;
37 | }
38 | }
39 |
40 | .breadcrumbs{
41 |
42 | .crumb {
43 | color: rgba(255,255,255,.8);
44 | }
45 |
46 | .crumb.is-active {
47 | color: rgba(255,255,255,.95);
48 | }
49 | }
50 | }
--------------------------------------------------------------------------------
/src/components/MonthlyTrendChart/index.tsx:
--------------------------------------------------------------------------------
1 | import './style.scss';
2 |
3 | import * as React from 'react';
4 | import * as d3 from 'd3';
5 |
6 | import {
7 | PolarRegion,
8 | ISeaIceExtByMonthData,
9 | IMedianSeaIceExtByMonth,
10 | } from '../../types';
11 |
12 | interface IProps {
13 | data: ISeaIceExtByMonthData;
14 | medianData: IMedianSeaIceExtByMonth;
15 | polarRegion: PolarRegion;
16 | yearOnHover: number;
17 | }
18 |
19 | interface IState {
20 | svg: any;
21 | height: number;
22 | width: number;
23 | xScale: d3.ScaleLinear;
24 | yScale: d3.ScaleLinear;
25 | chartData: Array>;
26 | medianData: Array;
27 | years: Array;
28 | }
29 |
30 | export default class SeaIceExtByYearChart extends React.PureComponent<
31 | IProps,
32 | IState
33 | > {
34 | private containerRef = React.createRef();
35 | private trendLineClassName = 'monthly-trend-line';
36 |
37 | constructor(props: IProps) {
38 | super(props);
39 |
40 | this.state = {
41 | svg: null,
42 | height: 0,
43 | width: 0,
44 | xScale: null,
45 | yScale: null,
46 | chartData: [],
47 | medianData: [],
48 | years: [],
49 | };
50 | }
51 |
52 | setSvg(svg: any) {
53 | this.setState({
54 | svg: svg,
55 | });
56 | }
57 |
58 | setScales(x: any, y: any) {
59 | this.setState({
60 | xScale: x,
61 | yScale: y,
62 | });
63 | }
64 |
65 | setHeightWidth(height: number, width: number) {
66 | this.setState({
67 | height: height,
68 | width: width,
69 | });
70 | }
71 |
72 | setChartData() {
73 | const data = this.props.data[this.props.polarRegion].filter((d, i) => {
74 | // only include data for years with full 12 month of data
75 | // except the for the last item, which is the current year
76 | return (
77 | d.values.length === 12 ||
78 | i === this.props.data[this.props.polarRegion].length - 1
79 | );
80 | });
81 | // .filter(d=>d.values.length === 12);
82 |
83 | const chartData = data.map((d) => {
84 | const values = d.values.filter((n) => n);
85 | return values;
86 | });
87 |
88 | const medianData = this.props.medianData[this.props.polarRegion];
89 |
90 | const years = data.map((d) => d.year);
91 |
92 | this.setState(
93 | {
94 | chartData,
95 | medianData,
96 | years,
97 | },
98 | () => {
99 | this.drawChart();
100 | }
101 | );
102 | }
103 |
104 | initSvg() {
105 | const container = this.containerRef.current;
106 | const margin = { top: 15, right: 10, bottom: 25, left: 25 };
107 |
108 | const width = container.offsetWidth - margin.left - margin.right;
109 | const height = container.offsetHeight - margin.top - margin.bottom;
110 | this.setHeightWidth(height, width);
111 |
112 | const xScale = d3
113 | .scaleLinear()
114 | .range([0, width])
115 | .domain([0, 11]); // 12 month on x scale
116 |
117 | const yScale = d3.scaleLinear().range([height, 0]);
118 |
119 | this.setScales(xScale, yScale);
120 |
121 | const svg = d3
122 | .select(container)
123 | .append('svg')
124 | .attr('width', width + margin.left + margin.right)
125 | .attr('height', height + margin.top + margin.bottom)
126 | .attr('class', 'sea-ice-monthly-trend-chart')
127 | .append('g')
128 | .attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
129 |
130 | this.setSvg(svg);
131 | }
132 |
133 | drawChart() {
134 | // this.updateDomainForXScale();
135 | this.updateDomainForYScale();
136 | this.drawXLabels();
137 | this.drawYLabels();
138 | this.drawLines();
139 | }
140 |
141 | // updateDomainForXScale = ()=>{
142 | // const { xScale } = this.state;
143 | // }
144 |
145 | updateDomainForYScale = () => {
146 | const { yScale, chartData } = this.state;
147 |
148 | const minVals = chartData.map((d) => d3.min(d));
149 | const minVal = Math.floor(d3.min(minVals));
150 |
151 | const maxVals = chartData.map((d) => d3.max(d));
152 | const maxVal = Math.ceil(d3.max(maxVals));
153 |
154 | // console.log(chartData, minVal, maxVal);
155 |
156 | yScale.domain([minVal, maxVal]);
157 | };
158 |
159 | drawXLabels() {
160 | const { svg, height, xScale } = this.state;
161 |
162 | const labels = [
163 | 'Jan',
164 | 'Feb',
165 | 'Mar',
166 | 'Apr',
167 | 'May',
168 | 'Jun',
169 | 'Jul',
170 | 'Aug',
171 | 'Sep',
172 | 'Oct',
173 | 'Nov',
174 | 'Dec',
175 | ];
176 |
177 | const xAxis = d3.axisBottom(xScale).tickFormat((d, i) => {
178 | return labels[i];
179 | });
180 |
181 | const xAxisLabel = svg.selectAll('.x.axis');
182 |
183 | if (!xAxisLabel.size()) {
184 | svg
185 | .append('g')
186 | .attr('class', 'x axis')
187 | .attr('transform', 'translate(0,' + height + ')')
188 | .call(xAxis);
189 | } else {
190 | xAxisLabel.attr('transform', 'translate(0,' + height + ')').call(xAxis);
191 | }
192 | }
193 |
194 | drawYLabels() {
195 | const { svg, yScale } = this.state;
196 |
197 | const yAxis = d3.axisLeft(yScale).ticks(5);
198 |
199 | const yAxisLabel = svg.selectAll('.y.axis');
200 |
201 | if (!yAxisLabel.size()) {
202 | svg
203 | .append('g')
204 | .attr('class', 'y axis')
205 | .call(yAxis);
206 | } else {
207 | yAxisLabel.call(yAxis);
208 | }
209 | }
210 |
211 | drawLines() {
212 | const { svg, xScale, yScale, chartData, medianData } = this.state;
213 |
214 | const lineGroupClassName = 'monthly-trend-lines';
215 | const medianLineClassName = 'median-monthly-trend-line';
216 |
217 | const existingLineGroups = svg.selectAll('.' + lineGroupClassName);
218 | const existingMedianLine = svg.selectAll('.' + medianLineClassName);
219 |
220 | if (existingLineGroups) {
221 | existingLineGroups.remove().exit();
222 | }
223 |
224 | if (existingMedianLine) {
225 | existingMedianLine.remove().exit();
226 | }
227 |
228 | const valueline = d3
229 | .line()
230 | .curve(d3.curveCardinal)
231 | .x((d) => {
232 | return xScale(d[0]);
233 | })
234 | .y((d) => {
235 | return yScale(d[1]);
236 | });
237 |
238 | const lines = svg
239 | .append('g')
240 | .attr('class', 'monthly-trend-lines')
241 | .selectAll('.monthly-trend-line-group')
242 | .data(chartData)
243 | .enter()
244 | .append('g')
245 | .attr('class', 'monthly-trend-line-group')
246 | .append('path')
247 | // .attr('class', 'monthly-trend-line')
248 | .attr('class', (d: any, idx: number) => {
249 | const modifierClass = [this.trendLineClassName];
250 |
251 | if (idx === chartData.length - 1) {
252 | modifierClass.push('is-current-year');
253 | }
254 |
255 | return modifierClass.join(' ');
256 | })
257 | .attr('data-index', (d: any, idx: number) => idx)
258 | .attr('d', (lineData: any) => {
259 | const data = lineData.map((value: number, index: number) => {
260 | return [+index, +value];
261 | });
262 | return valueline(data);
263 | });
264 | // .on('mouseover', (d:any, i:number)=>{
265 | // console.log(i);
266 | // })
267 |
268 | const medianLine = svg
269 | .append('path')
270 | .data([medianData])
271 | .attr('class', medianLineClassName)
272 | .style('stroke-dasharray', '6, 6')
273 | .attr('d', (d: any) => {
274 | const data = d.map((value: number, index: number) => {
275 | return [+index, +value];
276 | });
277 | return valueline(data);
278 | });
279 | }
280 |
281 | highlightYearOnHover() {
282 | const { yearOnHover } = this.props;
283 | const { years } = this.state;
284 |
285 | const yearOnHoverIndex = years.indexOf(yearOnHover);
286 |
287 | d3.selectAll('.' + this.trendLineClassName).classed('is-active', false);
288 |
289 | if (yearOnHoverIndex !== -1) {
290 | const lineToHighlight = d3.select(
291 | `.${this.trendLineClassName}[data-index='${yearOnHoverIndex}']`
292 | );
293 | lineToHighlight.classed('is-active', true);
294 | }
295 | }
296 |
297 | getInfoDiv() {
298 | const { yearOnHover } = this.props;
299 |
300 | const titleStr = 'Monthly Change';
301 |
302 | const title = yearOnHover ? (
303 |
304 |
305 | {yearOnHover} {titleStr}
306 |
307 |
308 | ) : (
309 |
310 | {titleStr}
311 |
312 | );
313 |
314 | return (
315 |
316 | {title}
317 |
318 | current year
319 | monthly median
320 |
321 |
322 | );
323 | }
324 |
325 | componentDidUpdate(prevProps: IProps, prevState: IState) {
326 | if (!this.state.svg) {
327 | this.initSvg();
328 | }
329 |
330 | if (this.props.data) {
331 | if (
332 | this.props.data !== prevProps.data ||
333 | this.props.polarRegion !== prevProps.polarRegion
334 | ) {
335 | this.setChartData();
336 | }
337 |
338 | if (this.props.yearOnHover !== prevProps.yearOnHover) {
339 | this.highlightYearOnHover();
340 | }
341 | }
342 | }
343 |
344 | componentDidMount() {
345 | if (!this.state.svg && this.props.data) {
346 | this.initSvg();
347 | this.setChartData();
348 | }
349 | }
350 |
351 | render() {
352 | const InfoDiv = this.getInfoDiv();
353 |
354 | return (
355 |
356 | {InfoDiv}
357 |
364 |
365 | );
366 | }
367 | }
368 |
--------------------------------------------------------------------------------
/src/components/MonthlyTrendChart/style.scss:
--------------------------------------------------------------------------------
1 | @import '../../style/color.scss';
2 |
3 | .sea-ice-monthly-trend-chart-wrap {
4 | .info-window {
5 | padding: 0 1rem;
6 | display: flex;
7 | color: rgba(255,255,255,.75);
8 |
9 | div {
10 | flex-grow: 1;
11 | flex-shrink: 0;
12 | }
13 |
14 | .sea-ice-ext-color {
15 | color: $secIceExtColorAlpha5
16 | }
17 |
18 | .sea-ice-ext-color.is-bright {
19 | color: $secIceExtColor
20 | }
21 |
22 | .median-sea-ice-ext-color {
23 | color: $medianSecIceExtColor;
24 | opacity: .9;
25 | }
26 | }
27 |
28 |
29 | }
30 |
31 | .sea-ice-monthly-trend-chart{
32 |
33 | .monthly-trend-line {
34 | fill: none;
35 | stroke: $secIceExtColorAlpha15;
36 | stroke-width: .8px;
37 | }
38 |
39 | .monthly-trend-line.is-active {
40 | fill: none;
41 | stroke: $secIceExtColor;
42 | stroke-width: 2px;
43 | }
44 |
45 | .is-current-year{
46 | fill: none;
47 | stroke: rgba(255,255,255,.75);
48 | stroke-width: 1.5px;
49 | }
50 |
51 | .median-monthly-trend-line{
52 | fill: none;
53 | stroke: $medianSecIceExtColor;
54 | stroke-width: 1.5px;
55 | }
56 |
57 | .axis {
58 | text {
59 | fill: rgba(255,255,255,.5);
60 | }
61 |
62 | line {
63 | stroke: rgba(255,255,255,.4);
64 | }
65 |
66 | path {
67 | stroke: rgba(255,255,255,.4);
68 | }
69 |
70 | }
71 | }
--------------------------------------------------------------------------------
/src/components/PolarToggleBtn/MobileVersion.tsx:
--------------------------------------------------------------------------------
1 | import './style.scss';
2 | import * as React from 'react';
3 |
4 | import { PolarRegion } from '../../types';
5 |
6 | interface IProps {
7 | activePolarRegion: PolarRegion;
8 | onClick: (value: string) => void;
9 | }
10 | // interface IState {}
11 |
12 | import data from './data';
13 |
14 | export default class PolarToggleBtns extends React.PureComponent {
15 | constructor(props: IProps) {
16 | super(props);
17 | }
18 |
19 | render() {
20 | const btns = data.map((d, i) => {
21 | const modifierClasses = ['crumb'];
22 |
23 | if (d.value === this.props.activePolarRegion) {
24 | modifierClasses.push('is-active');
25 | }
26 |
27 | return (
28 |
33 | {d.shortLabel}
34 |
35 | );
36 | });
37 |
38 | return {btns} ;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/components/PolarToggleBtn/ToggleBtn.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react';
2 |
3 | interface IProps {
4 | label: string;
5 | value: string;
6 | isActive: boolean;
7 | onClick: (value: string) => void;
8 | }
9 |
10 | // interface IState {}
11 |
12 | export default class PolarToggleBtn extends React.PureComponent {
13 | constructor(props: IProps) {
14 | super(props);
15 |
16 | this.onClickHandler = this.onClickHandler.bind(this);
17 | }
18 |
19 | onClickHandler() {
20 | this.props.onClick(this.props.value);
21 | }
22 |
23 | render() {
24 | const isActive = this.props.isActive ? 'is-active' : '';
25 |
26 | return (
27 |
31 | {this.props.label}
32 |
33 | );
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/components/PolarToggleBtn/data.ts:
--------------------------------------------------------------------------------
1 | import { PolarRegion } from '../../types';
2 |
3 | interface IData {
4 | label: string;
5 | shortLabel: string;
6 | value: PolarRegion;
7 | }
8 |
9 | const data: Array = [
10 | {
11 | label: 'Arctic Sea Ice',
12 | shortLabel: 'Arctic',
13 | value: 'arctic',
14 | },
15 | {
16 | label: 'Antarctic Sea Ice',
17 | shortLabel: 'Antarctic',
18 | value: 'antarctic',
19 | },
20 | ];
21 |
22 | export default data;
23 |
--------------------------------------------------------------------------------
/src/components/PolarToggleBtn/index.tsx:
--------------------------------------------------------------------------------
1 | import './style.scss';
2 | import * as React from 'react';
3 | import ToggleBtn from './ToggleBtn';
4 |
5 | import { PolarRegion } from '../../types';
6 |
7 | interface IProps {
8 | activePolarRegion: PolarRegion;
9 | onClick: (value: string) => void;
10 | }
11 | // interface IState {}
12 |
13 | import data from './data';
14 |
15 | export default class PolarToggleBtns extends React.PureComponent {
16 | constructor(props: IProps) {
17 | super(props);
18 | }
19 |
20 | render() {
21 | const btns = data.map((d, i) => {
22 | return (
23 |
30 | );
31 | });
32 |
33 | return {btns}
;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/components/PolarToggleBtn/style.scss:
--------------------------------------------------------------------------------
1 | @import '../../style/color.scss';
2 |
3 | .polar-toggle-btns{
4 | display: flex;
5 | padding-bottom: .25rem;
6 | }
7 |
8 | .polar-toggle-btn {
9 | flex-grow: 1;
10 | flex-shrink: 0;
11 | color: rgba(255,255,255,.5);
12 | cursor: pointer;
13 | border-bottom: 2px solid rgba(255,255,255, .2);
14 | padding-bottom: .5rem;
15 | }
16 |
17 | .polar-toggle-btn.is-active {
18 | color: rgba(255,255,255, .9);
19 | border-bottom: 2px solid $secIceExtColorAlpha75;
20 | }
21 |
22 | // .polar-toggle-btn:nth-child(1){
23 | // margin-right: 1rem;
24 | // }
--------------------------------------------------------------------------------
/src/components/SeaIceExtByYearChart/config.ts:
--------------------------------------------------------------------------------
1 | export default {
2 | color: {
3 | minVal: 'rgba(89,255,252,.6)',
4 | maxVal: 'rgba(89,255,252,.4)',
5 | },
6 | };
7 |
--------------------------------------------------------------------------------
/src/components/SeaIceExtByYearChart/index.tsx:
--------------------------------------------------------------------------------
1 | import './style.scss';
2 |
3 | import * as React from 'react';
4 | import * as d3 from 'd3';
5 |
6 | import {
7 | IMinMaxSeaExtByYearData,
8 | PolarRegion,
9 | ISeaIceExtVal2MonthLookup,
10 | } from '../../types';
11 | // import config from './config';
12 | import { dateFns } from 'helper-toolkit-ts';
13 |
14 | interface IDataOnHover {
15 | year: number;
16 | max: number;
17 | min: number;
18 | value: number;
19 | }
20 |
21 | interface IProps {
22 | data: IMinMaxSeaExtByYearData;
23 | seaIceExtVal2MonthLookup: ISeaIceExtVal2MonthLookup;
24 | polarRegion: PolarRegion;
25 | onHover: (year?: number) => void;
26 | onClick: (year: number, value: number) => void;
27 | }
28 |
29 | interface IState {
30 | svg: any;
31 | height: number;
32 | width: number;
33 | xScale0: d3.ScaleBand;
34 | xScale1: d3.ScaleBand;
35 | yScale: d3.ScaleLinear;
36 | chartData: Array>;
37 | years: Array;
38 | dataOnHover: IDataOnHover;
39 | }
40 |
41 | const margin = { top: 15, right: 10, bottom: 25, left: 25 };
42 |
43 | export default class SeaIceExtByYearChart extends React.PureComponent<
44 | IProps,
45 | IState
46 | > {
47 | private containerRef = React.createRef();
48 | private tooltipRef = React.createRef();
49 |
50 | constructor(props: IProps) {
51 | super(props);
52 |
53 | this.state = {
54 | svg: null,
55 | height: 0,
56 | width: 0,
57 | xScale0: null,
58 | xScale1: null,
59 | yScale: null,
60 | chartData: [],
61 | years: null,
62 | dataOnHover: null,
63 | };
64 | }
65 |
66 | setChartData() {
67 | const data = this.props.data[this.props.polarRegion];
68 |
69 | const minValues = data.map((d) => {
70 | return d.min;
71 | });
72 |
73 | const maxValues = data.map((d) => {
74 | return d.max;
75 | });
76 |
77 | const years = data.map((d) => {
78 | return d.year;
79 | });
80 |
81 | this.setState(
82 | {
83 | chartData: [maxValues, minValues],
84 | years: years,
85 | },
86 | () => {
87 | this.drawChart();
88 | }
89 | );
90 | }
91 |
92 | setSvg(svg: any) {
93 | this.setState({
94 | svg: svg,
95 | });
96 | }
97 |
98 | setScales(x0: any, x1: any, y: any) {
99 | this.setState({
100 | xScale0: x0,
101 | xScale1: x1,
102 | yScale: y,
103 | });
104 | }
105 |
106 | setHeightWidth(height: number, width: number) {
107 | this.setState({
108 | height: height,
109 | width: width,
110 | });
111 | }
112 |
113 | initSvg() {
114 | const container = this.containerRef.current;
115 |
116 | const width = container.offsetWidth - margin.left - margin.right;
117 | const height = container.offsetHeight - margin.top - margin.bottom;
118 | this.setHeightWidth(height, width);
119 |
120 | const xScale0 = d3.scaleBand();
121 | const xScale1 = d3.scaleBand();
122 | const yScale = d3.scaleLinear().range([height, 0]);
123 | this.setScales(xScale0, xScale1, yScale);
124 |
125 | const svg = d3
126 | .select(container)
127 | .append('svg')
128 | .attr('width', width + margin.left + margin.right)
129 | .attr('height', height + margin.top + margin.bottom)
130 | .attr('class', 'sea-ice-ext-by-year-chart')
131 | .append('g')
132 | .attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
133 |
134 | this.setSvg(svg);
135 | }
136 |
137 | drawChart() {
138 | this.updateDomainForXScale();
139 | this.updateDomainForYScale();
140 | this.drawXLabels();
141 | this.drawYLabels();
142 | this.drawBars();
143 | }
144 |
145 | updateDomainForXScale = () => {
146 | const xDomain0 = d3.range(this.state.chartData[0].length);
147 | this.state.xScale0.domain(xDomain0).range([0, this.state.width]);
148 |
149 | const xDomain1 = d3.range(this.state.chartData.length);
150 | // this.state.xScale1.domain(xDomain1).range([0, this.state.xScale0.bandwidth()*.6]);
151 | this.state.xScale1
152 | .domain(xDomain1)
153 | .range([0, this.state.xScale0.bandwidth() * 1.1]);
154 | };
155 |
156 | updateDomainForYScale = () => {
157 | const maxValues = this.state.chartData[0];
158 | const yScaleMax = d3.max(maxValues);
159 | this.state.yScale.domain([0, yScaleMax]);
160 | };
161 |
162 | drawXLabels() {
163 | const { svg, xScale0, years } = this.state;
164 |
165 | // show the ticks on xAxis for every 4 years
166 | const tickValues = xScale0.domain().filter((d) => {
167 | return !(years[d] % 4);
168 | });
169 |
170 | const xAxis = d3
171 | .axisBottom(xScale0)
172 | .tickValues(tickValues)
173 | .tickFormat((d) => {
174 | return years[d].toString();
175 | });
176 |
177 | const xAxisLabel = svg.selectAll('.x.axis');
178 |
179 | if (!xAxisLabel.size()) {
180 | svg
181 | .append('g')
182 | .attr('class', 'x axis')
183 | .attr('transform', 'translate(0,' + this.state.height + ')')
184 | .call(xAxis);
185 | } else {
186 | xAxisLabel
187 | .attr('transform', 'translate(0,' + this.state.height + ')')
188 | .call(xAxis);
189 | }
190 | }
191 |
192 | drawYLabels() {
193 | const { svg, yScale } = this.state;
194 | // const yAxis = this.state.yAxis;
195 | const yAxis = d3.axisLeft(yScale).ticks(5);
196 |
197 | const yAxisLabel = svg.selectAll('.y.axis');
198 |
199 | if (!yAxisLabel.size()) {
200 | svg
201 | .append('g')
202 | .attr('class', 'y axis')
203 | .call(yAxis);
204 | } else {
205 | yAxisLabel.call(yAxis);
206 | }
207 | }
208 |
209 | drawBars() {
210 | const {
211 | svg,
212 | xScale0,
213 | xScale1,
214 | yScale,
215 | width,
216 | height,
217 | chartData,
218 | } = this.state;
219 |
220 | const barGroupClassName = 'sea-ice-ext-by-year-bar-group';
221 | const backgroundRectClassName = 'invisible-background-rect';
222 |
223 | const barGroups = svg.selectAll('.' + barGroupClassName);
224 | const invisibleBackgroundRect = svg.selectAll(
225 | '.' + backgroundRectClassName
226 | );
227 |
228 | if (barGroups) {
229 | barGroups.remove().exit();
230 | }
231 |
232 | // need to add an invisible rect with same size of the container to detect when the mouse is out of the chart area
233 | // the content in the chart info window will only be reset when mouse is out of this rect
234 | if (!invisibleBackgroundRect.size()) {
235 | svg
236 | .append('rect')
237 | .attr('class', backgroundRectClassName)
238 | .attr('width', width + 40)
239 | .attr('height', height + 80)
240 | .attr('transform', (d: any, i: number) => {
241 | return 'translate(-30, -60)';
242 | })
243 | .style('opacity', 0)
244 | .on('mouseout', () => {
245 | this.onHoverHandler();
246 | });
247 | }
248 |
249 | svg
250 | .append('g')
251 | .attr('class', barGroupClassName)
252 | .selectAll('g')
253 | .data(chartData)
254 | .enter()
255 | .append('g')
256 | // .style("fill", (d:any, i:number)=>{
257 | // return i === 0 ? config.color.maxVal : config.color.minVal
258 | // })
259 | .attr('class', (d: any, i: number) => {
260 | return i === 0 ? 'max-val-bars' : 'min-val-bars';
261 | })
262 | .attr('transform', (d: any, i: number) => {
263 | return 'translate(' + 0 + ',0)';
264 | })
265 | // .attr("transform", (d:any, i:number)=>{
266 | // return "translate(" + xScale1(i) + ",0)";
267 | // })
268 | .selectAll('rect')
269 | .data((d: any) => {
270 | return d;
271 | })
272 | .enter()
273 | .append('rect')
274 | .attr('class', 'bar-rect')
275 | .attr('data-index', (d: any, idx: number) => idx)
276 | .attr('width', xScale1.bandwidth())
277 | .attr('height', (d: number) => {
278 | return height - yScale(d);
279 | })
280 | .attr('x', (d: any, i: number) => {
281 | return xScale0(i);
282 | })
283 | .attr('y', (d: number) => {
284 | return yScale(d);
285 | })
286 | .style('opacity', 0.8)
287 | .on('mouseover', (d: any, i: number) => {
288 | // console.log(d);
289 | // onHover(years[i]);
290 | this.onHoverHandler(i, d);
291 | })
292 | .on('mouseout', (d: any, i: number) => {
293 | // onHover(undefined);
294 | // this.onHoverHandler()
295 | })
296 | .on('click', (d: number, i: number) => {
297 | // console.log(d, i);
298 | this.onClickHandler(d, i);
299 | });
300 | }
301 |
302 | toggleHoverEffect(index?: number) {
303 | const barRectClassName = 'bar-rect';
304 |
305 | if (typeof index === 'number') {
306 | d3.selectAll('.' + barRectClassName).style('opacity', 0.35);
307 |
308 | const barsToHighlight = d3.selectAll(
309 | `.${barRectClassName}[data-index='${index}']`
310 | );
311 | barsToHighlight.style('opacity', 0.8);
312 | } else {
313 | d3.selectAll('.' + barRectClassName).style('opacity', 0.8);
314 | }
315 | }
316 |
317 | onClickHandler(value: number, index: number) {
318 | const { onClick } = this.props;
319 | const { years } = this.state;
320 | const year = years[index];
321 |
322 | onClick(year, value);
323 | }
324 |
325 | onHoverHandler(index?: number, value?: number) {
326 | const { onHover } = this.props;
327 | const { chartData, years } = this.state;
328 |
329 | const year = years[index];
330 | const max = chartData[0][index];
331 | const min = chartData[1][index];
332 | // console.log(year, max, min);
333 |
334 | const dataOnHover =
335 | year && max && min
336 | ? ({
337 | year,
338 | max,
339 | min,
340 | value,
341 | } as IDataOnHover)
342 | : undefined;
343 |
344 | this.setState(
345 | {
346 | dataOnHover,
347 | },
348 | () => {
349 | onHover(year);
350 | }
351 | );
352 |
353 | this.toggleHoverEffect(index);
354 | }
355 |
356 | getInfoDiv() {
357 | const { dataOnHover } = this.state;
358 |
359 | if (!dataOnHover) {
360 | return (
361 |
362 |
363 |
364 | Annual Sea Ice Extent in million km2
365 |
366 |
367 |
368 | Max Extent
369 | Min Extent
370 |
371 |
372 | );
373 | }
374 |
375 | return (
376 |
377 |
378 |
379 | {dataOnHover.year} Sea Ice Extent in million km
380 | 2
381 |
382 |
383 |
384 |
385 |
386 | Max: {dataOnHover.max}
387 |
388 | Min: {dataOnHover.min}
389 |
390 |
391 | );
392 | }
393 |
394 | getTooltipContent() {
395 | const { seaIceExtVal2MonthLookup, polarRegion } = this.props;
396 | const { dataOnHover } = this.state;
397 |
398 | if (!dataOnHover) {
399 | return null;
400 | }
401 |
402 | const minOrMaxClass =
403 | +dataOnHover.value === +dataOnHover.min ? 'min-value' : 'max-value';
404 | const yearOnHover = dataOnHover.year.toString();
405 | const valOnHover = dataOnHover.value.toString();
406 | const monthIdxOnHover =
407 | seaIceExtVal2MonthLookup[polarRegion][yearOnHover][valOnHover];
408 | const monthOnHover = dateFns.getMonthName(monthIdxOnHover - 1);
409 |
410 | const tooltipContent = dataOnHover ? (
411 |
412 | {`${yearOnHover} ${monthOnHover}`}
415 |
416 | Click to view on map
417 |
418 | ) : null;
419 |
420 | return tooltipContent;
421 | }
422 |
423 | getTooltipPosition() {
424 | const { dataOnHover, xScale0, yScale, years } = this.state;
425 |
426 | if (!dataOnHover) {
427 | return {
428 | top: 0,
429 | left: 0,
430 | };
431 | }
432 |
433 | const yearIndexOnHover = years.indexOf(dataOnHover.year);
434 | const valOnHover = dataOnHover.value;
435 |
436 | const xPos = xScale0(yearIndexOnHover);
437 | const yPos = yScale(valOnHover);
438 | const topPos = dataOnHover.min === dataOnHover.value ? yPos - 25 : yPos;
439 |
440 | const leftPos =
441 | yearIndexOnHover <= years.length / 2
442 | ? xPos + margin.left + 12
443 | : xPos - 120;
444 |
445 | return {
446 | top: topPos,
447 | left: leftPos,
448 | };
449 | }
450 |
451 | componentDidMount() {
452 | if (!this.state.svg && this.props.data) {
453 | this.initSvg();
454 | this.setChartData();
455 | }
456 | }
457 |
458 | componentDidUpdate(prevProps: IProps, prevState: IState) {
459 | if (!this.state.svg) {
460 | this.initSvg();
461 | }
462 |
463 | if (
464 | this.props.data !== prevProps.data ||
465 | this.props.polarRegion !== prevProps.polarRegion
466 | ) {
467 | if (this.props.data) {
468 | this.setChartData();
469 | }
470 | }
471 | }
472 |
473 | render() {
474 | const InfoDiv = this.getInfoDiv();
475 | const tooltipContent = this.getTooltipContent();
476 | const tooltipPos = this.getTooltipPosition();
477 |
478 | return (
479 |
480 | {InfoDiv}
481 |
482 |
491 | {tooltipContent}
492 |
493 |
494 |
501 |
502 | );
503 | }
504 | }
505 |
--------------------------------------------------------------------------------
/src/components/SeaIceExtByYearChart/style.scss:
--------------------------------------------------------------------------------
1 | $maxValColor: rgba(89,255,252,.45);
2 | $minValColor: rgba(89,255,252,.65);
3 | $maxValColor4Text: rgba(89,255,252,.65);
4 | $minValColor4Text: rgba(89,255,252,.85);
5 |
6 | .sea-ice-ext-by-year-chart-wrap{
7 | width: 100%;
8 | // height: 250px;
9 | // background: rgba(0,0,0,.1);
10 |
11 | position: relative;
12 |
13 | .info-window {
14 | padding: 0 1rem;
15 | display: flex;
16 | color: rgba(255,255,255,.75);
17 |
18 | div {
19 | flex-grow: 1;
20 | flex-shrink: 0;
21 | }
22 | }
23 |
24 | .sea-ice-ext-by-year-bar-group {
25 | cursor: pointer;
26 | }
27 |
28 | .min-val-bars {
29 | fill: $minValColor;
30 | }
31 |
32 | .max-val-bars{
33 | fill: $maxValColor;
34 | }
35 |
36 | .min-value {
37 | color: $minValColor4Text;
38 | }
39 |
40 | .max-value {
41 | color: $maxValColor4Text;
42 | }
43 |
44 | .axis {
45 | text {
46 | fill: rgba(255,255,255,.5);
47 | }
48 |
49 | line {
50 | stroke: rgba(255,255,255,.4);
51 | }
52 |
53 | path {
54 | stroke: rgba(255,255,255,.4);
55 | }
56 |
57 | }
58 |
59 | .chart-tooltip-wrap{
60 | pointer-events: none;
61 |
62 | .tooltip-content{
63 | padding: .5rem;
64 | background: rgba(0,0,0,.6);
65 | color: rgba(255,255,255,.75);
66 | pointer-events: none;
67 | }
68 | }
69 | }
--------------------------------------------------------------------------------
/src/components/SidebarHeader/index.tsx:
--------------------------------------------------------------------------------
1 | import './style.scss';
2 | import * as React from 'react';
3 |
4 | interface IProps {
5 | title: string;
6 | }
7 | // interface IState {}
8 |
9 | export default class SideBarHeader extends React.PureComponent {
10 | constructor(props: IProps) {
11 | super(props);
12 | }
13 |
14 | render() {
15 | return (
16 |
17 |
18 | Sea Ice Aware
19 |
20 |
24 |
25 | About this app
26 |
27 |
28 | );
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/components/SidebarHeader/style.scss:
--------------------------------------------------------------------------------
1 | @import '../../style/color.scss';
2 |
3 | .sidebar-header {
4 | display: flex;
5 | align-items: center;
6 | background: $themeColorAlpha95;
7 | padding: 1rem 1.5rem;
8 |
9 | div {
10 | flex-grow: 1;
11 | flex-shrink: 0;
12 |
13 | display: flex;
14 | align-items: center;
15 | }
16 |
17 | .about-app-btn {
18 | justify-content:flex-end;
19 | cursor: pointer;
20 | color: rgba(255,255,255,.8);
21 | }
22 | }
--------------------------------------------------------------------------------
/src/components/TimeControl/SliderTicks.scss:
--------------------------------------------------------------------------------
1 | .slider-ticks-wrap{
2 | width: 100%;
3 | // height: 20px;
4 |
5 | .slider-ticks-group {
6 | position: relative;
7 | display: flex;
8 | // width: 100%;
9 |
10 | .tick {
11 | height: 3px;
12 | width: 1px;
13 | background: rgba(255,255,255,.3);
14 | }
15 | }
16 |
17 | .slider-labels-group{
18 | // display: flex;
19 | position: relative;
20 | width: 100%;
21 | // height: 10px;
22 | // background: rgba(255,255,255,.1);
23 | font-size: .65rem;
24 | color:rgba(255,255,255,.8);
25 | margin-top: .3rem;
26 |
27 | .tick-label{
28 | position: absolute;
29 | top: 0;
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/src/components/TimeControl/SliderTicks.tsx:
--------------------------------------------------------------------------------
1 | import './SliderTicks.scss';
2 | import * as React from 'react';
3 |
4 | import { IRecordDate } from '../../types';
5 |
6 | interface IProps {
7 | recordDates: Array;
8 | }
9 | // interface IState {}
10 |
11 | export default class TimeControl extends React.PureComponent {
12 | private containerRef = React.createRef();
13 |
14 | constructor(props: IProps) {
15 | super(props);
16 | }
17 |
18 | getTicks(): JSX.Element {
19 | const { recordDates } = this.props;
20 | const uniqueYear = Array.from(new Set(recordDates.map((d) => d.year)));
21 |
22 | const container = this.containerRef.current;
23 | const containerWidth = container ? container.clientWidth : 0;
24 | const gapWidth = uniqueYear.length
25 | ? (containerWidth - uniqueYear.length - 5) / (uniqueYear.length - 1)
26 | : 0;
27 |
28 | const ticks = uniqueYear.map((d, i) => {
29 | const xFromLeft = i * gapWidth;
30 |
31 | const style = {
32 | transform: `translate(${xFromLeft}px)`,
33 | };
34 |
35 | return (
36 |
42 | );
43 | });
44 |
45 | const labels = uniqueYear
46 | .filter((d, i) => {
47 | return i >= 2 && !(d % 10);
48 | })
49 | .map((year, i) => {
50 | const posByYear = uniqueYear.indexOf(year);
51 |
52 | const xFromLeftByYear = (posByYear / uniqueYear.length) * 100;
53 |
54 | const style = {
55 | position: 'absolute' as 'absolute',
56 | top: 0,
57 | left: xFromLeftByYear + '%',
58 | transform: `translate(-50%)`,
59 | };
60 |
61 | return (
62 |
68 | {year}
69 |
70 | );
71 | });
72 |
73 | return (
74 |
75 |
{ticks}
76 |
{labels}
77 |
78 | );
79 | }
80 |
81 | render() {
82 | const ticks = this.getTicks();
83 |
84 | return {ticks}
;
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/components/TimeControl/index.tsx:
--------------------------------------------------------------------------------
1 | import './style.scss';
2 | import * as React from 'react';
3 |
4 | import { dateFns } from 'helper-toolkit-ts';
5 |
6 | import {
7 | PolarRegion,
8 | ISeaIceExtByMonthData,
9 | IRecordDate,
10 | IMedianSeaIceExtByMonth,
11 | } from '../../types';
12 |
13 | import SliderTicks from './SliderTicks';
14 |
15 | interface IProps {
16 | polarRegion: PolarRegion;
17 | recordDates: Array;
18 | activeRecordDate: IRecordDate;
19 | seaIceExtByMonthData: ISeaIceExtByMonthData;
20 | medianSeaIceExtByMonthData: IMedianSeaIceExtByMonth;
21 | onValueChange: (index: number) => void;
22 | }
23 |
24 | interface IState {
25 | value: number;
26 | seaIceExtAreaValues: {
27 | [key in PolarRegion]: number[];
28 | };
29 | isPlaying: boolean;
30 | }
31 |
32 | export default class TimeControl extends React.PureComponent {
33 | private playInterval: NodeJS.Timeout;
34 |
35 | constructor(props: IProps) {
36 | super(props);
37 |
38 | this.state = {
39 | value: 0,
40 | // save sea ext area values in memory so it's easier to retrive
41 | seaIceExtAreaValues: {
42 | antarctic: [],
43 | arctic: [],
44 | },
45 | isPlaying: false,
46 | };
47 |
48 | this.onChangeHandler = this.onChangeHandler.bind(this);
49 | this.goNext = this.goNext.bind(this);
50 | this.goPrev = this.goPrev.bind(this);
51 | this.togglePlay = this.togglePlay.bind(this);
52 | }
53 |
54 | updateValue(newVal = 0) {
55 | const { onValueChange } = this.props;
56 |
57 | this.setState(
58 | {
59 | value: newVal,
60 | },
61 | () => {
62 | onValueChange(newVal);
63 | }
64 | );
65 | }
66 |
67 | goNext() {
68 | const { recordDates } = this.props;
69 | const { value } = this.state;
70 |
71 | const newVal = value + 1 <= recordDates.length - 1 ? value + 1 : 0;
72 | this.updateValue(newVal);
73 | }
74 |
75 | goPrev() {
76 | const { recordDates } = this.props;
77 | const { value } = this.state;
78 |
79 | const newVal = value - 1 >= 0 ? value - 1 : recordDates.length - 1;
80 | this.updateValue(newVal);
81 | }
82 |
83 | togglePlay() {
84 | const { isPlaying } = this.state;
85 |
86 | const newVal = !isPlaying;
87 |
88 | this.setState(
89 | {
90 | isPlaying: newVal,
91 | },
92 | () => {
93 | if (newVal) {
94 | this.play();
95 | } else {
96 | this.pause();
97 | }
98 | }
99 | );
100 | }
101 |
102 | play() {
103 | this.playInterval = setInterval(() => {
104 | this.goNext();
105 | }, 3000);
106 | }
107 |
108 | pause() {
109 | clearInterval(this.playInterval);
110 | }
111 |
112 | updateSeaIceExtAreaValues() {
113 | let antarcticValues: Array = [];
114 | let arcticValues: Array = [];
115 |
116 | this.props.seaIceExtByMonthData['antarctic'].forEach((d) => {
117 | antarcticValues = antarcticValues.concat(d.values);
118 | });
119 |
120 | this.props.seaIceExtByMonthData['arctic'].forEach((d) => {
121 | arcticValues = arcticValues.concat(d.values);
122 | });
123 |
124 | const seaIceExtAreaValues = {
125 | antarctic: antarcticValues,
126 | arctic: arcticValues,
127 | };
128 |
129 | this.setState({
130 | seaIceExtAreaValues,
131 | });
132 | }
133 |
134 | onChangeHandler(event: React.FormEvent) {
135 | const newVal = +event.currentTarget.value || 0;
136 | // console.log(newVal);
137 | this.updateValue(newVal);
138 | }
139 |
140 | getLabelForActiveDate() {
141 | const { activeRecordDate } = this.props;
142 | const activeDate = activeRecordDate; //recordDates.length ? recordDates[this.state.value] : null;
143 | const monthIdx = activeDate ? activeDate.month - 1 : undefined;
144 | const monthName = dateFns.getMonthName(monthIdx, true);
145 | return activeDate ? `${monthName} ${activeDate.year}` : '';
146 | }
147 |
148 | getSeaIceExtArea() {
149 | const {
150 | polarRegion,
151 | medianSeaIceExtByMonthData,
152 | activeRecordDate,
153 | } = this.props;
154 | const { seaIceExtAreaValues, value } = this.state;
155 |
156 | const medianVal = activeRecordDate
157 | ? medianSeaIceExtByMonthData[polarRegion][activeRecordDate.month - 1]
158 | : 0;
159 | const values = seaIceExtAreaValues[polarRegion];
160 |
161 | return {
162 | area: values[value] || 0,
163 | median: medianVal,
164 | };
165 | }
166 |
167 | getSeaIceExtInfo() {
168 | const { recordDates } = this.props;
169 |
170 | if (!recordDates.length) {
171 | return Loading...
;
172 | }
173 |
174 | const activeRecordDateLabel = this.getLabelForActiveDate();
175 | const areaForActiveRecordDate = this.getSeaIceExtArea();
176 |
177 | const areaDiff =
178 | areaForActiveRecordDate.area - areaForActiveRecordDate.median;
179 | const areaDiffInPct = (
180 | (Math.abs(areaDiff) / areaForActiveRecordDate.median) *
181 | 100
182 | ).toFixed(1);
183 | const areaDiffDesc =
184 | areaDiff > 0 ? (
185 |
186 | {areaDiffInPct}% above median
187 |
188 | ) : (
189 |
190 | {areaDiffInPct}% below median
191 |
192 | );
193 |
194 | return (
195 |
196 | {activeRecordDateLabel}
197 |
198 | {areaForActiveRecordDate.area} million km2
199 |
200 |
201 | {areaDiffInPct !== '0.0' ? areaDiffDesc : 'same as median'}
202 |
203 |
204 | );
205 | }
206 |
207 | componentDidUpdate(prevProps: IProps) {
208 | // if(this.props.recordDates !== prevProps.recordDates){
209 | // this.updateValue(this.props.recordDates.length - 1);
210 | // }
211 |
212 | if (this.props.activeRecordDate !== prevProps.activeRecordDate) {
213 | const index = this.props.recordDates.indexOf(this.props.activeRecordDate);
214 | // console.log(index);
215 | this.updateValue(index);
216 | }
217 |
218 | if (this.props.seaIceExtByMonthData !== prevProps.seaIceExtByMonthData) {
219 | this.updateSeaIceExtAreaValues();
220 | }
221 | }
222 |
223 | render() {
224 | const { recordDates } = this.props;
225 | const { isPlaying } = this.state;
226 |
227 | const maxVal = recordDates.length - 1;
228 |
229 | const infoWindow = this.getSeaIceExtInfo();
230 |
231 | return (
232 |
233 |
234 |
235 | {isPlaying ? (
236 |
242 |
243 |
244 | ) : (
245 |
251 |
252 |
253 | )}
254 |
255 |
256 | {infoWindow}
257 |
258 |
259 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
287 |
288 |
298 |
299 |
300 | );
301 | }
302 | }
303 |
--------------------------------------------------------------------------------
/src/components/TimeControl/style.scss:
--------------------------------------------------------------------------------
1 | @import '../../style/color.scss';
2 | $height: 100px;
3 | $textColor: rgba(255,255,255,.9);
4 | $textColorLighter: rgba(255,255,255,.7);
5 | $iconColor: rgba(255,255,255,.5);
6 | $isAboveColor: #59fffc;
7 | $isBelowColor: #ff824d;
8 |
9 | #time-control-container{
10 | // position: absolute;
11 | // left: 0;
12 | // right: 0;
13 | // bottom: 20px;
14 |
15 | display: flex;
16 | justify-content: center;
17 | pointer-events: none;
18 | }
19 |
20 | .time-control {
21 | cursor: default;
22 | display: flex;
23 | flex-direction: row;
24 | align-items: flex-start;
25 | justify-content: flex-start;
26 | overflow: hidden;
27 | height: $height;
28 | // box-shadow: 0 0 2px 2px rgba(0,0,0,0.1);
29 | color: $textColor;
30 | background: $themeColorAlpha95;
31 | pointer-events: all;
32 | width: 100%;
33 | border-top: 1px solid rgba(255,255,255,.2);
34 | border-bottom: 1px solid rgba(255,255,255,.2);
35 |
36 | .widget-btn {
37 | font-size: 14px;
38 | color: #6e6e6e;
39 | height: $height;
40 | padding: 0;
41 | margin: 0;
42 | overflow: hidden;
43 | cursor: pointer;
44 | text-align: center;
45 | display: flex;
46 | flex-flow: row nowrap;
47 | justify-content: center;
48 | align-items: center;
49 | transition: background-color 125ms ease-in-out;
50 | }
51 |
52 | .widget-btn:hover{
53 | background: rgba(0,0,0,.1);
54 | }
55 |
56 | .play-btn{
57 | flex: none;
58 | width: 45px;
59 | border-right: 1px solid rgba(110,110,110,0.3);
60 | }
61 |
62 | .previous-btn{
63 | flex: none;
64 | width: 32px;
65 | padding-left: .25rem;
66 | border-left: 1px solid rgba(110,110,110,0.3);
67 | }
68 |
69 | .next-btn{
70 | flex: none;
71 | width: 32px;
72 | padding-right: .25rem;
73 | }
74 |
75 | .info-window{
76 | height: $height;
77 | min-width: 160px;
78 | flex: none;
79 | font-weight: 400;
80 | padding: 0 1rem;
81 | margin: 0;
82 | overflow: hidden;
83 | text-align: center;
84 | display: flex;
85 | flex-flow: column nowrap;
86 | justify-content: center;
87 | align-items: flex-start;
88 | border-right: 1px solid rgba(110,110,110,0.3);
89 | line-height: 12px;
90 | box-sizing: border-box;
91 | }
92 |
93 | .time-slider{
94 | height: $height;
95 | // width: 193px;
96 |
97 | display: flex;
98 | flex-flow: column nowrap;
99 | justify-content: center;
100 | align-items: center;
101 | box-sizing: border-box;
102 |
103 | flex-grow: 1;
104 | flex-shrink: 0;
105 | // flex-basis: 100px;
106 |
107 | .calcite-slider{
108 |
109 | width: 100%;
110 |
111 | label {
112 | margin: 0;
113 | }
114 | }
115 |
116 | // .slider-ticks-wrap{
117 | // }
118 | }
119 |
120 | svg {
121 | stroke: $iconColor;
122 | fill: $iconColor;
123 | }
124 |
125 | .lighter-text {
126 | color: $textColorLighter
127 | }
128 |
129 | .is-above {
130 | color: $isAboveColor;
131 | }
132 |
133 | .is-below {
134 | color: $isBelowColor;
135 | }
136 | }
137 |
138 | .is-mobile {
139 |
140 | .time-control {
141 | .play-btn{
142 | width: 35px;
143 | }
144 |
145 | .previous-btn{
146 | width: 26px;
147 | }
148 |
149 | .next-btn{
150 | width: 26px;
151 | }
152 | }
153 | }
--------------------------------------------------------------------------------
/src/index.template.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | Sea Ice Aware
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/index.tsx:
--------------------------------------------------------------------------------
1 | import './style/index.scss';
2 | import '@babel/polyfill';
3 |
4 | // required by ArcGIS REST JS
5 | import 'isomorphic-fetch';
6 | import 'es6-promise';
7 |
8 | import * as React from 'react';
9 | import * as ReactDOM from 'react-dom';
10 |
11 | import App from './components/App';
12 | import { miscFns } from 'helper-toolkit-ts';
13 |
14 | import {
15 | setDefaultOptions
16 | } from 'esri-loader'
17 |
18 | setDefaultOptions({
19 | version: '4.21'
20 | })
21 |
22 | const initApp = () => {
23 | const isMobileDevice = miscFns.isMobileDevice();
24 | const isNarrowScreen = window.outerWidth < 860 ? true : false;
25 | const isMobileView = isMobileDevice || isNarrowScreen;
26 |
27 | ReactDOM.render(
28 | ,
29 | document.getElementById('appRootDiv')
30 | );
31 | };
32 |
33 | initApp();
34 |
--------------------------------------------------------------------------------
/src/services/sea-ice-extents/config.ts:
--------------------------------------------------------------------------------
1 | const antarctic = {
2 | url:
3 | 'https://services9.arcgis.com/RHVPKKiFTONKtxq3/arcgis/rest/services/seaice_extent_S_v1/FeatureServer/0',
4 | fields: {
5 | date: 'Rec_Date',
6 | year: 'Rec_Year',
7 | month: 'Rec_Month',
8 | area: 'Rec_Area',
9 | extent: 'Rec_Extent',
10 | },
11 | };
12 |
13 | const arctic = {
14 | url:
15 | 'https://services9.arcgis.com/RHVPKKiFTONKtxq3/arcgis/rest/services/seaice_extent_N_v1/FeatureServer/0',
16 | fields: {
17 | date: 'Rec_Date',
18 | year: 'Rec_Year',
19 | month: 'Rec_Month',
20 | area: 'Rec_Area',
21 | extent: 'Rec_Extent',
22 | },
23 | };
24 |
25 | const antarcticMedianSeaIceExt = {
26 | url:
27 | 'https://services9.arcgis.com/RHVPKKiFTONKtxq3/arcgis/rest/services/Median_Sea_Ice_Extent_for_the_Antarctic/FeatureServer/0',
28 | fields: {
29 | date: 'Rec_Date',
30 | year: 'Rec_Year',
31 | month: 'Rec_Month',
32 | area: 'Area',
33 | extent: 'ExtentSI',
34 | },
35 | };
36 |
37 | const arcticMedianSeaIceExt = {
38 | url:
39 | 'https://services9.arcgis.com/RHVPKKiFTONKtxq3/arcgis/rest/services/Median_Sea_Ice_Extent_for_the_Arctic/FeatureServer/0',
40 | fields: {
41 | date: 'Rec_Date',
42 | year: 'Rec_Year',
43 | month: 'Rec_Month',
44 | area: 'Area',
45 | extent: 'ExtentSI',
46 | },
47 | };
48 |
49 | export { antarctic, arctic, antarcticMedianSeaIceExt, arcticMedianSeaIceExt };
50 |
--------------------------------------------------------------------------------
/src/services/sea-ice-extents/index.ts:
--------------------------------------------------------------------------------
1 | import {
2 | queryFeatures,
3 | IQueryFeaturesResponse,
4 | IStatisticDefinition,
5 | IFeature,
6 | } from '@esri/arcgis-rest-feature-layer';
7 |
8 | import {
9 | antarctic as antarcticConfig,
10 | arctic as arcticConfig,
11 | antarcticMedianSeaIceExt as antarcticMedianSeaIceExtConfig,
12 | arcticMedianSeaIceExt as arcticMedianSeaIceExtConfig,
13 | } from './config';
14 |
15 | import {
16 | IMinMaxSeaExtByYearData,
17 | IMinMaxSeaExtByYearDataItem,
18 | IFeaturesSeaIceExtByMonth,
19 | ISeaIceExtByMonthDataItem,
20 | IMedianSeaIceExtByMonth,
21 | IRecordDate,
22 | ISeaIceExtByMonthQueryResponse,
23 | ISeaIceExtVal2MonthLookup,
24 | ISeaIceExtVal2MonthLookupItem,
25 | } from '../../types';
26 |
27 | const queryMinMaxSeaIceExtByYear = async (): Promise => {
28 | const outStatisticFieldNameMinExt = 'Min_Rec_Area';
29 | const outStatisticFieldNameMaxExt = 'Max_Rec_Area';
30 | const outStatisticFieldNameCountMonth = 'Count_Month';
31 |
32 | const outStatisticsMinExt: IStatisticDefinition = {
33 | statisticType: 'min',
34 | onStatisticField: antarcticConfig.fields.extent,
35 | outStatisticFieldName: outStatisticFieldNameMinExt,
36 | };
37 |
38 | const outStatisticsMaxExt: IStatisticDefinition = {
39 | statisticType: 'max',
40 | onStatisticField: antarcticConfig.fields.extent,
41 | outStatisticFieldName: outStatisticFieldNameMaxExt,
42 | };
43 |
44 | const outStatisticsCountMonth: IStatisticDefinition = {
45 | statisticType: 'count',
46 | onStatisticField: antarcticConfig.fields.month,
47 | outStatisticFieldName: outStatisticFieldNameCountMonth,
48 | };
49 |
50 | const queryResForAntarctic = (await queryFeatures({
51 | url: antarcticConfig.url,
52 | where: '1=1',
53 | outFields: '*',
54 | groupByFieldsForStatistics: antarcticConfig.fields.year,
55 | orderByFields: antarcticConfig.fields.year,
56 | outStatistics: [
57 | outStatisticsMinExt,
58 | outStatisticsMaxExt,
59 | outStatisticsCountMonth,
60 | ],
61 | })) as IQueryFeaturesResponse;
62 |
63 | const queryResForArctic = (await queryFeatures({
64 | url: arcticConfig.url,
65 | where: '1=1',
66 | outFields: '*',
67 | groupByFieldsForStatistics: arcticConfig.fields.year,
68 | orderByFields: arcticConfig.fields.year,
69 | outStatistics: [
70 | outStatisticsMinExt,
71 | outStatisticsMaxExt,
72 | outStatisticsCountMonth,
73 | ],
74 | })) as IQueryFeaturesResponse;
75 |
76 | const outputDataAntarctic: Array = queryResForAntarctic.features
77 | .filter((d: IFeature) => {
78 | // technically should only keep years with full 12 month of data, but the satellite was broken in later 1987 and early 1988,
79 | // so we only have 11 month of data for those two years...
80 | return d.attributes[outStatisticFieldNameCountMonth] >= 11;
81 | })
82 | .map((d: IFeature) => {
83 | return {
84 | min: d.attributes[outStatisticFieldNameMinExt],
85 | max: d.attributes[outStatisticFieldNameMaxExt],
86 | year: d.attributes[antarcticConfig.fields.year],
87 | };
88 | });
89 |
90 | const outputDataArctic: Array = queryResForArctic.features
91 | .filter((d: IFeature) => {
92 | return d.attributes[outStatisticFieldNameCountMonth] >= 11;
93 | })
94 | .map((d: IFeature) => {
95 | return {
96 | min: d.attributes[outStatisticFieldNameMinExt],
97 | max: d.attributes[outStatisticFieldNameMaxExt],
98 | year: d.attributes[arcticConfig.fields.year],
99 | };
100 | });
101 |
102 | // console.log(queryResForAntarctic, queryResForArctic)
103 |
104 | return {
105 | antarctic: outputDataAntarctic,
106 | arctic: outputDataArctic,
107 | };
108 | };
109 |
110 | const querySeaIceExtByMonth = async (): Promise => {
111 | const queryResForAntarctic = (await queryFeatures({
112 | url: antarcticConfig.url,
113 | where: '1=1',
114 | outFields: [
115 | antarcticConfig.fields.year,
116 | antarcticConfig.fields.month,
117 | antarcticConfig.fields.extent,
118 | ],
119 | orderByFields: `${antarcticConfig.fields.year},${antarcticConfig.fields.month}`,
120 | returnGeometry: false,
121 | })) as IQueryFeaturesResponse;
122 |
123 | const queryResForArctic = (await queryFeatures({
124 | url: arcticConfig.url,
125 | where: '1=1',
126 | outFields: [
127 | arcticConfig.fields.year,
128 | arcticConfig.fields.month,
129 | arcticConfig.fields.extent,
130 | ],
131 | orderByFields: `${arcticConfig.fields.year},${arcticConfig.fields.month}`,
132 | returnGeometry: false,
133 | })) as IQueryFeaturesResponse;
134 |
135 | const featuresForAntarctic: Array = queryResForAntarctic.features.map(
136 | (d: IFeature) => {
137 | return {
138 | year: d.attributes[antarcticConfig.fields.year],
139 | month: d.attributes[antarcticConfig.fields.month],
140 | value: d.attributes[antarcticConfig.fields.extent],
141 | };
142 | }
143 | );
144 |
145 | const featuresForArctic: Array = queryResForArctic.features.map(
146 | (d: IFeature) => {
147 | return {
148 | year: d.attributes[arcticConfig.fields.year],
149 | month: d.attributes[arcticConfig.fields.month],
150 | value: d.attributes[arcticConfig.fields.extent],
151 | };
152 | }
153 | );
154 |
155 | return {
156 | antarctic: featuresForAntarctic,
157 | arctic: featuresForArctic,
158 | };
159 | };
160 |
161 | const prepareSeaIceExtByMonth = (
162 | features: Array
163 | ): Array => {
164 | const dataByYear: { [key: number]: number[] } = {};
165 |
166 | features.forEach((feature: IFeaturesSeaIceExtByMonth) => {
167 | const year = feature.year;
168 | const value = feature.value;
169 |
170 | if (!dataByYear[year]) {
171 | dataByYear[year] = [value];
172 | } else {
173 | dataByYear[year].push(value);
174 | }
175 | });
176 |
177 | const outputData = Object.keys(dataByYear).map((key) => {
178 | const year = +key;
179 |
180 | const values = dataByYear[year];
181 |
182 | return {
183 | year,
184 | values,
185 | };
186 | });
187 |
188 | return outputData;
189 | };
190 |
191 | const queryMedianSeaIceExtByMonth = async (): Promise => {
192 | const queryResForAntarctic = (await queryFeatures({
193 | url: antarcticMedianSeaIceExtConfig.url,
194 | // the monthly median extent data are the same for each year, so only need to query one year of data
195 | where: `${antarcticMedianSeaIceExtConfig.fields.year} = 1980`,
196 | outFields: [
197 | antarcticMedianSeaIceExtConfig.fields.month,
198 | antarcticMedianSeaIceExtConfig.fields.extent,
199 | ],
200 | returnGeometry: false,
201 | orderByFields: antarcticMedianSeaIceExtConfig.fields.month,
202 | })) as IQueryFeaturesResponse;
203 |
204 | const queryResForArctic = (await queryFeatures({
205 | url: arcticMedianSeaIceExtConfig.url,
206 | where: `${arcticConfig.fields.year} = 1980`,
207 | outFields: [
208 | arcticMedianSeaIceExtConfig.fields.month,
209 | arcticMedianSeaIceExtConfig.fields.extent,
210 | ],
211 | returnGeometry: false,
212 | orderByFields: arcticMedianSeaIceExtConfig.fields.month,
213 | })) as IQueryFeaturesResponse;
214 |
215 | const featuresForAntarctic: Array = queryResForAntarctic.features.map(
216 | (d: IFeature) => {
217 | return d.attributes[antarcticMedianSeaIceExtConfig.fields.extent];
218 | }
219 | );
220 |
221 | const featuresForArctic: Array = queryResForArctic.features.map(
222 | (d: IFeature) => {
223 | return d.attributes[arcticMedianSeaIceExtConfig.fields.extent];
224 | }
225 | );
226 |
227 | return {
228 | antarctic: featuresForAntarctic,
229 | arctic: featuresForArctic,
230 | };
231 |
232 | // console.log(featuresForAntarctic, featuresForArctic);
233 | };
234 |
235 | const queryRecordDates = async () => {
236 | const queryResForAntarctic = (await queryFeatures({
237 | url: antarcticConfig.url,
238 | where: '1=1',
239 | outFields: [
240 | antarcticConfig.fields.year,
241 | antarcticConfig.fields.month,
242 | antarcticConfig.fields.date,
243 | ],
244 | returnGeometry: false,
245 | returnDistinctValues: true,
246 | })) as IQueryFeaturesResponse;
247 |
248 | const recordDates: Array = queryResForAntarctic.features.map(
249 | (d: IFeature) => {
250 | return {
251 | year: d.attributes[antarcticConfig.fields.year],
252 | month: d.attributes[antarcticConfig.fields.month],
253 | date: d.attributes[antarcticConfig.fields.date],
254 | };
255 | }
256 | );
257 |
258 | return recordDates;
259 | };
260 |
261 | const generateValue2MonthLookup = (
262 | data: ISeaIceExtByMonthQueryResponse
263 | ): ISeaIceExtVal2MonthLookup => {
264 | const antarcticData = data.antarctic;
265 | const arcticData = data.arctic;
266 |
267 | const antarcticLookupTable: ISeaIceExtVal2MonthLookupItem = {};
268 | const arcticLookupTable: ISeaIceExtVal2MonthLookupItem = {};
269 |
270 | antarcticData.forEach((d: IFeaturesSeaIceExtByMonth) => {
271 | const { year, month, value } = d;
272 |
273 | const yearInStr = year.toString();
274 | const valueInStr = value.toString();
275 |
276 | if (!antarcticLookupTable[yearInStr]) {
277 | antarcticLookupTable[yearInStr] = {};
278 | }
279 |
280 | antarcticLookupTable[yearInStr][valueInStr] = month;
281 | });
282 |
283 | arcticData.forEach((d: IFeaturesSeaIceExtByMonth) => {
284 | const { year, month, value } = d;
285 |
286 | if (!arcticLookupTable[year]) {
287 | arcticLookupTable[year] = {};
288 | }
289 |
290 | arcticLookupTable[year][value] = month;
291 | });
292 |
293 | return {
294 | antarctic: antarcticLookupTable,
295 | arctic: arcticLookupTable,
296 | };
297 | };
298 |
299 | export {
300 | queryMinMaxSeaIceExtByYear,
301 | querySeaIceExtByMonth,
302 | queryMedianSeaIceExtByMonth,
303 | queryRecordDates,
304 | prepareSeaIceExtByMonth,
305 | generateValue2MonthLookup,
306 | };
307 |
--------------------------------------------------------------------------------
/src/style/color.scss:
--------------------------------------------------------------------------------
1 | $themeColor: rgba(0,48,77,1);
2 | $themeColorAlpha95: rgba(0,48,77,.95);
3 | $themeColorAlpha85: rgba(0,48,77,.85);
4 | $themeColorAlpha5: rgba(0,48,77,.5);
5 | $themeColorAlpha3: rgba(0,48,77,.3);
6 | $themeColorAlpha1: rgba(0,48,77,.1);
7 |
8 | $secIceExtColor: rgba(89,255,252,1);
9 | $secIceExtColorAlpha75: rgba(89,255,252,.75);
10 | $secIceExtColorAlpha5: rgba(89,255,252,.5);
11 | $secIceExtColorAlpha15: rgba(89,255,252,.15);
12 | $medianSecIceExtColor: #fff766;
--------------------------------------------------------------------------------
/src/style/fancy-scrollbar.scss:
--------------------------------------------------------------------------------
1 | @import './color.scss';
2 |
3 | .fancy-scrollbar::-webkit-scrollbar {
4 | width: 5px;
5 | }
6 |
7 | .fancy-scrollbar::-webkit-scrollbar-track {
8 | background: $themeColor;
9 | }
10 |
11 | .fancy-scrollbar::-webkit-scrollbar-thumb {
12 | background: rgba(255,255,255,.3);
13 | }
14 |
15 | .fancy-scrollbar::-webkit-scrollbar-thumb:hover {
16 | background: rgba(255,255,255,.5);
17 | }
--------------------------------------------------------------------------------
/src/style/index.scss:
--------------------------------------------------------------------------------
1 | @import '~calcite-web/dist/css/calcite-web.min.css';
--------------------------------------------------------------------------------
/src/types.d.ts:
--------------------------------------------------------------------------------
1 | type PolarRegion = 'arctic' | 'antarctic';
2 |
3 | interface IMinMaxSeaExtByYearDataItem {
4 | min: number;
5 | max: number;
6 | year: number;
7 | }
8 |
9 | interface IMinMaxSeaExtByYearData {
10 | arctic: Array;
11 | antarctic: Array;
12 | }
13 |
14 | interface IFeaturesSeaIceExtByMonth {
15 | year: number;
16 | month: number;
17 | value: number;
18 | }
19 |
20 | interface ISeaIceExtByMonthQueryResponse {
21 | arctic: Array;
22 | antarctic: Array;
23 | }
24 |
25 | interface ISeaIceExtByMonthDataItem {
26 | year: number;
27 | values: number[];
28 | }
29 |
30 | interface ISeaIceExtByMonthData {
31 | arctic: Array;
32 | antarctic: Array;
33 | }
34 |
35 | interface IMedianSeaIceExtByMonth {
36 | arctic: Array;
37 | antarctic: Array;
38 | }
39 |
40 | interface IRecordDate {
41 | year: number;
42 | month: number;
43 | date: number;
44 | }
45 |
46 | interface ISeaIceExtVal2MonthLookupItem {
47 | [key: string]: {
48 | [value: string]: number;
49 | };
50 | }
51 |
52 | interface ISeaIceExtVal2MonthLookup {
53 | arctic: ISeaIceExtVal2MonthLookupItem;
54 | antarctic: ISeaIceExtVal2MonthLookupItem;
55 | }
56 |
57 | export {
58 | PolarRegion,
59 | IMinMaxSeaExtByYearData,
60 | IMinMaxSeaExtByYearDataItem,
61 | IFeaturesSeaIceExtByMonth,
62 | ISeaIceExtByMonthData,
63 | ISeaIceExtByMonthDataItem,
64 | IMedianSeaIceExtByMonth,
65 | IRecordDate,
66 | ISeaIceExtByMonthQueryResponse,
67 | ISeaIceExtVal2MonthLookupItem,
68 | ISeaIceExtVal2MonthLookup,
69 | };
70 |
--------------------------------------------------------------------------------
/src/types/calcite-web/index.d.ts:
--------------------------------------------------------------------------------
1 | declare module 'calcite-web/dist/js/calcite-web.min.js';
2 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "allowSyntheticDefaultImports": true,
4 | "allowJs": false,
5 | "jsx": "react",
6 | "module": "commonjs",
7 | "noImplicitAny": true,
8 | "outDir": "./build/",
9 | "preserveConstEnums": true,
10 | "removeComments": true,
11 | "sourceMap": true,
12 | "target": "es5",
13 | "resolveJsonModule": true,
14 | "typeRoots": [ "./types", "./node_modules/@types"]
15 | },
16 | "exclude": ["node_modules", "typings"],
17 | "include": [
18 | "./src/**/**/*"
19 | ]
20 | }
--------------------------------------------------------------------------------
/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const HtmlWebpackPlugin = require("html-webpack-plugin");
3 | const MiniCssExtractPlugin = require("mini-css-extract-plugin");
4 | const TerserPlugin = require('terser-webpack-plugin');
5 | const OptimizeCSSAssets = require('optimize-css-assets-webpack-plugin');
6 | const { CleanWebpackPlugin } = require('clean-webpack-plugin');
7 |
8 | module.exports = (env, options)=> {
9 |
10 | const devMode = options.mode === 'development' ? true : false;
11 |
12 | return {
13 | entry: path.resolve(__dirname, './src/index.tsx'),
14 | output: {
15 | path: path.resolve(__dirname, './dist'),
16 | filename: '[name].[contenthash].js',
17 | chunkFilename: '[name].[contenthash].js',
18 | },
19 | devtool: 'source-map',
20 | resolve: {
21 | extensions: ['.js', '.jsx', '.json', '.ts', '.tsx']
22 | },
23 | module: {
24 | rules: [
25 | {
26 | test: /\.(ts|tsx)$/,
27 | loader: 'ts-loader'
28 | },
29 | {
30 | test: /\.s?[ac]ss$/,
31 | use: [
32 | devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
33 | {
34 | loader: "css-loader", options: {
35 | sourceMap: true
36 | }
37 | }, {
38 | loader: "sass-loader", options: {
39 | sourceMap: true
40 | }
41 | }
42 | ]
43 | },
44 | { test: /\.woff$/, loader: "url-loader?limit=10000&mimetype=application/font-woff" },
45 | { test: /\.ttf$/, loader: "url-loader?limit=10000&mimetype=application/octet-stream" },
46 | { test: /\.eot$/, loader: "file-loader" },
47 | {
48 | test: /\.svg$/,
49 | loader: "url-loader",
50 | options: {
51 | limit: 10000,
52 | fallback: {
53 | loader: "file-loader"
54 | }
55 | }
56 | },
57 | {
58 | test: /\.(png|jpg|gif)$/,
59 | loader: "url-loader",
60 | options: {
61 | limit: 10000,
62 | fallback: {
63 | loader: "file-loader"
64 | }
65 | }
66 | }
67 | ]
68 | },
69 | plugins: [
70 | new MiniCssExtractPlugin({
71 | // Options similar to the same options in webpackOptions.output
72 | // both options are optional
73 | filename: devMode ? '[name].css' : '[name].[contenthash].css',
74 | chunkFilename: devMode ? '[name].css' : '[name].[contenthash].css',
75 | }),
76 | new HtmlWebpackPlugin({
77 | template: './src/index.template.html',
78 | filename: 'index.html',
79 | minify: {
80 | html5 : true,
81 | collapseWhitespace : true,
82 | minifyCSS : true,
83 | minifyJS : true,
84 | minifyURLs : false,
85 | removeComments : true,
86 | removeEmptyAttributes : true,
87 | removeOptionalTags : true,
88 | removeRedundantAttributes : true,
89 | removeScriptTypeAttributes : true,
90 | removeStyleLinkTypeAttributese : true,
91 | useShortDoctype : true
92 | }
93 | }),
94 | new CleanWebpackPlugin()
95 | ],
96 | optimization: {
97 | splitChunks: {
98 | cacheGroups: {
99 | default: false,
100 | vendors: false,
101 | // vendor chunk
102 | vendor: {
103 | // sync + async chunks
104 | chunks: 'all',
105 | name: 'vendor',
106 | // import file path containing node_modules
107 | test: /node_modules/
108 | }
109 | }
110 | },
111 | minimizer: [
112 | new TerserPlugin({
113 | extractComments: true,
114 | terserOptions: {
115 | compress: {
116 | drop_console: true,
117 | }
118 | }
119 | }),
120 | new OptimizeCSSAssets({}),
121 | ],
122 | },
123 | }
124 |
125 | };
--------------------------------------------------------------------------------