Debian Codegraph @

bqplot/js/src/GeoScaleModel.ts

raw
1 /* Copyright 2015 Bloomberg Finance L.P.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 import * as d3 from 'd3';
17 // var d3 =Object.assign({}, require("d3-geo"));
18 import { ScaleModel } from './ScaleModel';
19
20 export class GeoScaleModel extends ScaleModel {
21 defaults() {
22 return {
23 ...ScaleModel.prototype.defaults(),
24 _model_name: 'GeoScaleModel',
25 _view_name: 'GeoScale',
26 };
27 }
28
29 compute_and_set_domain(data_array, id) {}
30
31 update_domain() {}
32
33 projection: d3.GeoProjection;
34 }
35
36 export class MercatorModel extends GeoScaleModel {
37 defaults() {
38 return {
39 ...GeoScaleModel.prototype.defaults(),
40 _model_name: 'MercatorModel',
41 _view_name: 'Mercator',
42 scale_factor: 190.0,
43 center: [0, 60],
44 rotate: [0, 0],
45 };
46 }
47
48 initialize(attributes, options) {
49 super.initialize(attributes, options);
50 this.on_some_change(
51 ['scale_factor', 'center', 'rotate'],
52 this.create_projection,
53 this
54 );
55 this.create_projection();
56 }
57
58 create_projection() {
59 this.projection = d3
60 .geoMercator()
61 .center(this.get('center'))
62 .scale(this.get('scale_factor'))
63 .rotate(this.get('rotate'));
64 this.attribute_changed();
65 }
66
67 attribute_changed() {
68 this.trigger('attribute_changed');
69 }
70 }
71
72 export class AlbersModel extends GeoScaleModel {
73 defaults() {
74 return {
75 ...GeoScaleModel.prototype.defaults(),
76 _model_name: 'AlbersModel',
77 _view_name: 'Albers',
78 scale_factor: 250.0,
79 /*rotate: [96, 0],*/
80 center: [0, 60],
81 parallels: [29.5, 45.5],
82 precision: 0.1,
83 };
84 }
85
86 initialize(attributes, options) {
87 super.initialize(attributes, options);
88 this.on_some_change(
89 ['rotate', 'center', 'parallels', 'scale_factor', 'precision'],
90 this.create_projection,
91 this
92 );
93 this.create_projection();
94 }
95
96 create_projection() {
97 this.projection = d3
98 .geoAlbers()
99 .rotate(this.get('rotate'))
100 .center(this.get('center'))
101 .parallels(this.get('parallels'))
102 .scale(this.get('scale_factor'))
103 .precision(this.get('precision'));
104 this.attribute_changed();
105 }
106
107 attribute_changed() {
108 this.trigger('attribute_changed');
109 }
110 }
111
112 export class AlbersUSAModel extends GeoScaleModel {
113 defaults() {
114 return {
115 ...GeoScaleModel.prototype.defaults(),
116 _model_name: 'AlbersUSAModel',
117 _view_name: 'AlbersUSA',
118 scale_factor: 1200,
119 translate: [600, 490], // center of the SVG viewbox (see Map.js)
120 };
121 }
122
123 initialize(attributes, options) {
124 super.initialize(attributes, options);
125 this.on_some_change(
126 ['scale_factor', 'translate'],
127 this.create_projection,
128 this
129 );
130 this.create_projection();
131 }
132
133 create_projection() {
134 this.projection = d3
135 .geoAlbersUsa()
136 .scale(this.get('scale_factor'))
137 .translate(this.get('translate'));
138 this.attribute_changed();
139 }
140
141 attribute_changed() {
142 this.trigger('attribute_changed');
143 }
144 }
145
146 export class EquiRectangularModel extends GeoScaleModel {
147 defaults() {
148 return {
149 ...GeoScaleModel.prototype.defaults(),
150 _model_name: 'EquiRectangularModel',
151 _view_name: 'EquiRectangular',
152 scale_factor: 145.0,
153 };
154 }
155
156 initialize(attributes, options) {
157 super.initialize(attributes, options);
158 this.on_some_change(
159 ['scale_factor', 'center'],
160 this.create_projection,
161 this
162 );
163 this.create_projection();
164 }
165
166 create_projection() {
167 this.projection = d3
168 .geoEquirectangular()
169 .center(this.get('center'))
170 .scale(this.get('scale_factor'));
171 this.attribute_changed();
172 }
173
174 attribute_changed() {
175 this.trigger('attribute_changed');
176 }
177 }
178
179 export class OrthographicModel extends GeoScaleModel {
180 defaults() {
181 return {
182 ...GeoScaleModel.prototype.defaults(),
183 _model_name: 'OrthographicModel',
184 _view_name: 'Orthographic',
185 scale_factor: 145.0,
186 center: [0, 60],
187 rotate: [0, 0],
188 clip_angle: 90.0,
189 precision: 0.1,
190 };
191 }
192
193 initialize(attributes, options) {
194 super.initialize(attributes, options);
195 this.on_some_change(
196 ['scale_factor', 'center', 'clip_angle', 'rotate', 'precision'],
197 this.create_projection,
198 this
199 );
200 this.create_projection();
201 }
202
203 create_projection() {
204 this.projection = d3
205 .geoOrthographic()
206 .center(this.get('center'))
207 .scale(this.get('scale_factor'))
208 .clipAngle(this.get('clip_angle'))
209 .rotate(this.get('rotate'))
210 .precision(this.get('precision'));
211 this.attribute_changed();
212 }
213
214 attribute_changed() {
215 this.trigger('attribute_changed');
216 }
217 }
218
219 export class GnomonicModel extends GeoScaleModel {
220 defaults() {
221 return {
222 ...GeoScaleModel.prototype.defaults(),
223 _model_name: 'GnomonicModel',
224 _view_name: 'Gnomonic',
225 scale_factor: 145.0,
226 center: [0, 60],
227 precision: 0.1,
228 clip_angle: 89.999,
229 };
230 }
231
232 initialize(attributes, options) {
233 super.initialize(attributes, options);
234 this.on_some_change(
235 ['scale_factor', 'precision', 'clip_angle'],
236 this.create_projection,
237 this
238 );
239 this.create_projection();
240 }
241
242 create_projection() {
243 this.projection = d3
244 .geoGnomonic()
245 .clipAngle(this.get('clip_angle'))
246 .scale(this.get('scale_factor'))
247 .precision(this.get('precision'));
248 this.attribute_changed();
249 }
250
251 attribute_changed() {
252 this.trigger('attribute_changed');
253 }
254 }
255
256 export class StereographicModel extends GeoScaleModel {
257 defaults() {
258 return {
259 ...GeoScaleModel.prototype.defaults(),
260 _model_name: 'StereographicModel',
261 _view_name: 'StereographicModel',
262 scale_factor: 245,
263 center: [0, 60],
264 precision: 0.1,
265 rotate: [96, 0],
266 clip_angle: 179.9999,
267 };
268 }
269
270 initialize(attributes, options) {
271 super.initialize(attributes, options);
272 this.on_some_change(
273 ['scale_factor', 'center', 'clip_angle', 'rotate', 'precision'],
274 this.create_projection,
275 this
276 );
277 this.create_projection();
278 }
279
280 create_projection() {
281 this.projection = d3
282 .geoStereographic()
283 .scale(this.get('scale_factor'))
284 .rotate(this.get('rotate'))
285 .clipAngle(this.get('clip_angle'))
286 .center(this.get('center'))
287 .precision(this.get('precision'));
288 this.attribute_changed();
289 }
290
291 attribute_changed() {
292 this.trigger('attribute_changed');
293 }
294 }