plotilla 0.2.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -11
- package/data/boundaries/world_countries.geojson +1 -1
- package/dist/colour/colour_scale.d.ts +55 -0
- package/dist/colour/colour_scale.js +80 -0
- package/dist/colour/palette.d.ts +176 -0
- package/dist/colour/palette.js +220 -0
- package/dist/fields/axis_fields.d.ts +56 -0
- package/dist/fields/axis_fields.js +46 -0
- package/dist/fields/colour_fields.d.ts +32 -0
- package/dist/fields/colour_fields.js +31 -0
- package/dist/fields/column_fields.d.ts +52 -0
- package/{src/fields/column_fields.ts → dist/fields/column_fields.js} +15 -29
- package/dist/fields/common_fields.d.ts +9 -0
- package/{src/fields/common_fields.ts → dist/fields/common_fields.js} +3 -6
- package/dist/fields/decide_plot_axes.d.ts +56 -0
- package/dist/fields/decide_plot_axes.js +71 -0
- package/dist/fields/marker_fields.d.ts +8 -0
- package/dist/fields/marker_fields.js +13 -0
- package/dist/fields/read_date_time.d.ts +85 -0
- package/dist/fields/read_date_time.js +199 -0
- package/dist/figure/check_axis_year_formats.d.ts +36 -0
- package/dist/figure/check_axis_year_formats.js +116 -0
- package/dist/figure/check_plot_category_limits.d.ts +128 -0
- package/dist/figure/check_plot_category_limits.js +284 -0
- package/dist/figure/plot_figure.d.ts +861 -0
- package/dist/figure/plot_figure.js +58 -0
- package/dist/figure/resolve_plot_figure.d.ts +28 -0
- package/dist/figure/resolve_plot_figure.js +41 -0
- package/dist/figure/validate_plot_figure.d.ts +50 -0
- package/dist/figure/validate_plot_figure.js +441 -0
- package/dist/map/assign_map_layer_hue_slots.d.ts +89 -0
- package/dist/map/assign_map_layer_hue_slots.js +146 -0
- package/dist/map/boundary_sets.d.ts +65 -0
- package/dist/map/boundary_sets.js +103 -0
- package/dist/map/build_world_outline_across_180.d.ts +21 -0
- package/dist/map/build_world_outline_across_180.js +23 -0
- package/dist/map/check_map_layers.d.ts +16 -0
- package/dist/map/check_map_layers.js +31 -0
- package/dist/map/fetch_region_outlines.d.ts +25 -0
- package/dist/map/fetch_region_outlines.js +39 -0
- package/dist/map/geojson.d.ts +150 -0
- package/dist/map/geojson.js +248 -0
- package/dist/map/join_region_rows.d.ts +40 -0
- package/dist/map/join_region_rows.js +45 -0
- package/dist/map/map_layers.d.ts +229 -0
- package/dist/map/map_layers.js +87 -0
- package/dist/model/find_panel_colour_scale.d.ts +25 -0
- package/dist/model/find_panel_colour_scale.js +27 -0
- package/dist/model/map_model.d.ts +30 -0
- package/dist/model/map_model.js +234 -0
- package/dist/model/panel_layout.d.ts +42 -0
- package/dist/model/panel_layout.js +154 -0
- package/dist/model/panel_model.d.ts +223 -0
- package/dist/model/panel_model.js +7 -0
- package/dist/model/plot_model.d.ts +28 -0
- package/dist/model/plot_model.js +431 -0
- package/dist/model/statistics.d.ts +83 -0
- package/dist/model/statistics.js +107 -0
- package/dist/plots/bar_plot.d.ts +46 -0
- package/dist/plots/bar_plot.js +30 -0
- package/dist/plots/box_plot.d.ts +30 -0
- package/dist/plots/box_plot.js +21 -0
- package/dist/plots/density_plot.d.ts +36 -0
- package/dist/plots/density_plot.js +23 -0
- package/dist/plots/heatmap_plot.d.ts +22 -0
- package/dist/plots/heatmap_plot.js +18 -0
- package/dist/plots/histogram_plot.d.ts +32 -0
- package/dist/plots/histogram_plot.js +24 -0
- package/dist/plots/line_plot.d.ts +44 -0
- package/dist/plots/line_plot.js +25 -0
- package/dist/plots/map_plot.d.ts +92 -0
- package/dist/plots/map_plot.js +35 -0
- package/dist/plots/pie_plot.d.ts +17 -0
- package/dist/plots/pie_plot.js +16 -0
- package/dist/plots/scatter_plot.d.ts +47 -0
- package/dist/plots/scatter_plot.js +27 -0
- package/dist/renderers/date_ticks.d.ts +37 -0
- package/dist/renderers/date_ticks.js +148 -0
- package/dist/renderers/echarts_map.d.ts +47 -0
- package/dist/renderers/echarts_map.js +492 -0
- package/dist/renderers/echarts_options.d.ts +30 -0
- package/dist/renderers/echarts_options.js +449 -0
- package/dist/renderers/echarts_pie_radius.d.ts +52 -0
- package/dist/renderers/echarts_pie_radius.js +158 -0
- package/dist/renderers/escape_html.d.ts +10 -0
- package/dist/renderers/escape_html.js +15 -0
- package/dist/renderers/line_colour_segments.d.ts +39 -0
- package/dist/renderers/line_colour_segments.js +41 -0
- package/dist/renderers/plotly_map.d.ts +48 -0
- package/dist/renderers/plotly_map.js +159 -0
- package/dist/renderers/plotly_options.d.ts +19 -0
- package/dist/renderers/plotly_options.js +345 -0
- package/dist/renderers/year_ticks.d.ts +27 -0
- package/dist/renderers/year_ticks.js +42 -0
- package/dist/table/check_column.d.ts +36 -0
- package/dist/table/check_column.js +46 -0
- package/dist/table/check_values_have_spread.d.ts +30 -0
- package/{src/table/check_values_have_spread.ts → dist/table/check_values_have_spread.js} +16 -17
- package/dist/table/compute_quantile.d.ts +16 -0
- package/dist/table/compute_quantile.js +23 -0
- package/dist/table/data_table.d.ts +59 -0
- package/dist/table/data_table.js +87 -0
- package/dist/table/density_bandwidth.d.ts +64 -0
- package/dist/table/density_bandwidth.js +88 -0
- package/dist/table/find_line_fit.d.ts +30 -0
- package/dist/table/find_line_fit.js +36 -0
- package/dist/table/get_number_range.d.ts +16 -0
- package/{src/table/get_number_range.ts → dist/table/get_number_range.js} +8 -8
- package/dist/table/group_rows.d.ts +40 -0
- package/dist/table/group_rows.js +67 -0
- package/dist/table/list_categories.d.ts +14 -0
- package/{src/table/list_categories.ts → dist/table/list_categories.js} +2 -3
- package/dist/table/read_number.d.ts +12 -0
- package/dist/table/read_number.js +14 -0
- package/package.json +30 -25
- package/src/colour/colour_scale.ts +0 -80
- package/src/colour/palette.ts +0 -220
- package/src/examples/example_figures.ts +0 -320
- package/src/fields/axis_fields.ts +0 -32
- package/src/fields/colour_fields.ts +0 -40
- package/src/fields/decide_plot_axes.ts +0 -77
- package/src/fields/marker_fields.ts +0 -16
- package/src/figure/plot_figure.ts +0 -67
- package/src/figure/resolve_plot_figure.ts +0 -47
- package/src/figure/validate_plot_figure.ts +0 -412
- package/src/map/boundary_sets.ts +0 -116
- package/src/map/check_map_layers.ts +0 -32
- package/src/map/fetch_region_outlines.ts +0 -48
- package/src/map/geojson.ts +0 -174
- package/src/map/map_layers.ts +0 -108
- package/src/model/check_axis_shows_years.ts +0 -58
- package/src/model/map_model.ts +0 -238
- package/src/model/panel_layout.ts +0 -171
- package/src/model/panel_model.ts +0 -85
- package/src/model/plot_model.ts +0 -347
- package/src/model/statistics.ts +0 -134
- package/src/plots/bar_plot.ts +0 -36
- package/src/plots/box_plot.ts +0 -26
- package/src/plots/density_plot.ts +0 -29
- package/src/plots/heatmap_plot.ts +0 -24
- package/src/plots/histogram_plot.ts +0 -29
- package/src/plots/line_plot.ts +0 -29
- package/src/plots/map_plot.ts +0 -46
- package/src/plots/pie_plot.ts +0 -23
- package/src/plots/scatter_plot.ts +0 -32
- package/src/renderers/echarts_map.ts +0 -194
- package/src/renderers/echarts_options.ts +0 -317
- package/src/renderers/plotly_map.ts +0 -170
- package/src/renderers/plotly_options.ts +0 -318
- package/src/table/check_column.ts +0 -34
- package/src/table/compute_quantile.ts +0 -23
- package/src/table/data_table.ts +0 -83
- package/src/table/density_bandwidth.ts +0 -94
- package/src/table/find_line_fit.ts +0 -44
- package/src/table/group_rows.ts +0 -71
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A map panel → an ECharts geo component and its series.
|
|
3
|
+
*
|
|
4
|
+
* ECharts draws maps over GeoJSON outlines, not street tiles: every regions
|
|
5
|
+
* layer's outlines, merged into one registered map under the panel's geo, or
|
|
6
|
+
* a world map (registered by the page) under points and lines. Drag and
|
|
7
|
+
* scroll to pan and zoom. ECharts has no globe; a globe map is drawn flat
|
|
8
|
+
* here, and the page says so (Plotly draws the globe).
|
|
9
|
+
*/
|
|
10
|
+
import { mapCollectionLongitudes, normaliseLongitude, placeLongitudeInBounds, placeLongitudeNear } from "../map/geojson.js";
|
|
11
|
+
import { getNumberRange } from "../table/get_number_range.js";
|
|
12
|
+
import { HEXADECIMAL, interpolateRampColour, MAP_INKS, PLOT_THEMES, pickSequentialColour } from "../colour/palette.js";
|
|
13
|
+
import { pickNoDataColour } from "../model/map_model.js";
|
|
14
|
+
import { escapeHtml } from "./escape_html.js";
|
|
15
|
+
/** The name the page registers the world outline under (see viewer_items.js). */
|
|
16
|
+
export const WORLD_MAP_NAME = "plotilla-world";
|
|
17
|
+
/** How much wider than the data the starting view is, as a fraction of its span. */
|
|
18
|
+
const BOUNDS_PADDING_FRACTION = 0.08;
|
|
19
|
+
const PERCENT = 100;
|
|
20
|
+
/** The whole world, which a map with nothing to fit starts on. */
|
|
21
|
+
const WHOLE_WORLD_BOUNDS = [-180, -90, 180, 90];
|
|
22
|
+
/** Degrees of longitude around the world. */
|
|
23
|
+
const WORLD_SPAN_DEGREES = 360;
|
|
24
|
+
/**
|
|
25
|
+
* The westernmost longitude the world outline a host registers has land at (buildWorldOutlineAcross180
|
|
26
|
+
* copies the world one turn east, not west). See pickViewTurns.
|
|
27
|
+
*/
|
|
28
|
+
const OUTLINE_WEST_LONGITUDE = -180;
|
|
29
|
+
/** The turns of the world the outline holds: the world and its copy a turn east (buildWorldOutlineAcross180). */
|
|
30
|
+
const OUTLINE_TURNS = 2;
|
|
31
|
+
/** The easternmost longitude the world outline a host registers has land at: 540. */
|
|
32
|
+
const OUTLINE_EAST_LONGITUDE = OUTLINE_WEST_LONGITUDE + OUTLINE_TURNS * WORLD_SPAN_DEGREES;
|
|
33
|
+
/** Each zoom level halves the span shown; ECharts' zoom is a plain scale factor. */
|
|
34
|
+
const ZOOM_LEVEL_SCALE = 2;
|
|
35
|
+
/** Pixels MapLibre, which Plotly's map draws with, gives the world's width at zoom 0 (its 512-pixel tiles). */
|
|
36
|
+
const MAPLIBRE_WORLD_PIXELS = 512;
|
|
37
|
+
/**
|
|
38
|
+
* How much ECharts shrinks a GeoJSON geo's height against its width (its default). A fitted view or the
|
|
39
|
+
* whole world keeps it wherever its box can be shaped to the panel within one turn and pole to pole, and
|
|
40
|
+
* is stretched only by what those limits leave (see shapeBoxToPanel); a caller's zoom replaces it (see
|
|
41
|
+
* buildGeoView).
|
|
42
|
+
*/
|
|
43
|
+
const GEO_ASPECT_SCALE = 0.75;
|
|
44
|
+
/**
|
|
45
|
+
* The northernmost latitude Web Mercator (MapLibre's, so Plotly's map's) draws, and the southernmost
|
|
46
|
+
* with its sign turned. A caller's centre is held inside it before its cosine shapes the view, which
|
|
47
|
+
* would reach 0 at a pole and flatten the map to nothing.
|
|
48
|
+
*/
|
|
49
|
+
const MERCATOR_LATITUDE_LIMIT = 85.0511;
|
|
50
|
+
const DEGREES_PER_HALF_TURN = 180;
|
|
51
|
+
/** Degrees of latitude from pole to pole: the most a view may show without passing a pole. */
|
|
52
|
+
const POLE_TO_POLE_DEGREES = 180;
|
|
53
|
+
/** The north pole's latitude, and the south pole's with its sign turned. */
|
|
54
|
+
const POLE_LATITUDE = POLE_TO_POLE_DEGREES / 2;
|
|
55
|
+
/** The latitude a view taller than pole to pole is centred on. */
|
|
56
|
+
const EQUATOR_LATITUDE = 0;
|
|
57
|
+
/** Value dimensions of a point or density datum: [drawn longitude, latitude, colour value or weight, longitude]. */
|
|
58
|
+
const LATITUDE_DIMENSION = 1;
|
|
59
|
+
const MEASURE_DIMENSION = 2;
|
|
60
|
+
const LONGITUDE_DIMENSION = 3;
|
|
61
|
+
/** A moved point's tooltip reads its real longitude, in the order an unmoved one shows its value. */
|
|
62
|
+
const MOVED_TOOLTIP_DIMENSIONS = [LONGITUDE_DIMENSION, LATITUDE_DIMENSION, MEASURE_DIMENSION];
|
|
63
|
+
function percent(fraction) {
|
|
64
|
+
return `${(fraction * PERCENT).toFixed(2)}%`;
|
|
65
|
+
}
|
|
66
|
+
/** The property each regions feature is named by: the id the model gives it ("<layer>:<feature>"), unique across layers. */
|
|
67
|
+
const REGION_NAME_PROPERTY = "plotilla_id";
|
|
68
|
+
/**
|
|
69
|
+
* The property each country of the world outline is named by, in both the boundary set and the world-atlas
|
|
70
|
+
* outline a host registers. ECharts groups a geo's regions by name, so the world named by a property its
|
|
71
|
+
* countries lack would be one region of 177 parts, all highlighted together on hover.
|
|
72
|
+
*/
|
|
73
|
+
const WORLD_NAME_PROPERTY = "name";
|
|
74
|
+
/** Registered regions maps are named this, then a hash of their outlines. */
|
|
75
|
+
const REGIONS_MAP_NAME_PREFIX = "plotilla-regions-";
|
|
76
|
+
/** 32-bit FNV-1a: small, fast, and spreads near-identical outlines apart. */
|
|
77
|
+
const FNV_OFFSET_BASIS = 0x811c9dc5;
|
|
78
|
+
const FNV_PRIME = 0x01000193;
|
|
79
|
+
/**
|
|
80
|
+
* Hash text to a short stable name part.
|
|
81
|
+
*
|
|
82
|
+
* @param text - The text, here a GeoJSON's JSON.
|
|
83
|
+
* @returns The 32-bit FNV-1a hash, in hexadecimal.
|
|
84
|
+
*/
|
|
85
|
+
function hashText(text) {
|
|
86
|
+
let hash = FNV_OFFSET_BASIS;
|
|
87
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
88
|
+
hash ^= text.charCodeAt(index);
|
|
89
|
+
hash = Math.imul(hash, FNV_PRIME);
|
|
90
|
+
}
|
|
91
|
+
return (hash >>> 0).toString(HEXADECIMAL);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Pick the bounds ECharts draws the map in. ECharts' plane ends where the
|
|
95
|
+
* outlines do, at ±180, so a map the model fits across the 180° line is drawn
|
|
96
|
+
* in its fitting bounds, longitudes west of them a turn east (past 180).
|
|
97
|
+
*
|
|
98
|
+
* @param map - The map.
|
|
99
|
+
* @returns The bounds to draw in, or null when there is nothing to fit.
|
|
100
|
+
*/
|
|
101
|
+
function pickDrawingBounds(map) {
|
|
102
|
+
const { bounds, fittingBounds } = map;
|
|
103
|
+
if (bounds === null || fittingBounds === null)
|
|
104
|
+
return bounds;
|
|
105
|
+
return fittingBounds.some((edge, index) => edge !== bounds[index]) ? fittingBounds : bounds;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Pick how many turns east the data is drawn, so it sits beside a caller's centre.
|
|
109
|
+
*
|
|
110
|
+
* A caller's centre is drawn at its own longitude, between -180 and 180, where the world outline has its
|
|
111
|
+
* land; the data moves to it, not it to the data (a map centred on Chukotka, 170, with towns in Canada
|
|
112
|
+
* draws the towns at about 246, not the centre at -190, where the outline has no land). Data is only ever
|
|
113
|
+
* moved east, as a wrapped fit moves it (see pickDrawingBounds): when the data sits more than half a turn
|
|
114
|
+
* east of the centre, buildGeoView moves the centre a turn east instead, so nothing is drawn west of -180.
|
|
115
|
+
* A fitted view (no caller centre) is not moved here; pickViewTurns moves a view past -180 afterwards.
|
|
116
|
+
*
|
|
117
|
+
* @param map - The map.
|
|
118
|
+
* @param options - The bounds the map is drawn in, before this move.
|
|
119
|
+
* @returns 1 to draw the data a turn east, else 0.
|
|
120
|
+
*/
|
|
121
|
+
function pickDataTurns(map, options) {
|
|
122
|
+
const drawn = options.drawingBounds;
|
|
123
|
+
if (!map.isCentreGiven || drawn === null)
|
|
124
|
+
return 0;
|
|
125
|
+
const middleLongitude = (drawn[0] + drawn[2]) / 2;
|
|
126
|
+
return normaliseLongitude(map.centre[0]) - middleLongitude > DEGREES_PER_HALF_TURN ? 1 : 0;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Hold a view's centre latitude so its north and south edges stay between the poles, as MapLibre (which
|
|
130
|
+
* Plotly's map draws with) holds its view inside Mercator's limits. A view taller than pole to pole has
|
|
131
|
+
* no such centre, so it is centred on the equator, showing as much past each pole.
|
|
132
|
+
*
|
|
133
|
+
* @param latitude - The centre latitude asked for.
|
|
134
|
+
* @param options - The latitude span the view shows, in degrees.
|
|
135
|
+
* @returns The centre latitude to draw at: the one asked for when the view already fits.
|
|
136
|
+
*/
|
|
137
|
+
function holdCentreLatitudeBetweenPoles(latitude, options) {
|
|
138
|
+
if (options.shownLatitudeSpan >= POLE_TO_POLE_DEGREES)
|
|
139
|
+
return EQUATOR_LATITUDE;
|
|
140
|
+
const limit = (POLE_TO_POLE_DEGREES - options.shownLatitudeSpan) / 2;
|
|
141
|
+
return Math.min(Math.max(latitude, -limit), limit);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Shape a view's box to its panel around its centre, so ECharts, which stretches the box to fill the
|
|
145
|
+
* panel (resizeGeo in echarts/lib/coord/geo/geoCreator.js ignores the box's aspect when the geo gives a
|
|
146
|
+
* width and a height, as here), draws it as near its own shape as the world allows: a degree across
|
|
147
|
+
* aspectScale times a degree down. Filling the panel, rather than shrinking the geo's rectangle to the
|
|
148
|
+
* box's shape, keeps the whole panel the area that pans and zooms it (ECharts' RoamController roams a geo
|
|
149
|
+
* only inside its rectangle).
|
|
150
|
+
*
|
|
151
|
+
* First the box is clipped to the world: to the poles, and its longitudes to one turn or the longitudes it
|
|
152
|
+
* must show, whichever is wider, so its padding alone never shows past a pole or land twice, and the clip
|
|
153
|
+
* grows with the data rather than stopping at one turn. Then it is shaped towards the panel: a box
|
|
154
|
+
* relatively narrower than the panel is widened, to at most one turn (or its own span, when that is wider);
|
|
155
|
+
* one relatively wider is made taller, to at most pole to pole. ECharts stretches only what those limits
|
|
156
|
+
* leave, so the drawn shape changes gradually as a box nears them, and the whole world, one turn by pole
|
|
157
|
+
* to pole, is returned as it is.
|
|
158
|
+
*
|
|
159
|
+
* The shaped box is built around the centre given, or, with none, around the clipped box's middle, and
|
|
160
|
+
* that centre's latitude is held between the poles (see holdCentreLatitudeBetweenPoles). Around the
|
|
161
|
+
* clipped box's middle, the shaped box holds the clipped box, which holds every longitude the box must
|
|
162
|
+
* show and every latitude it has between the poles, so shaping hides no data. Around a caller's centre it
|
|
163
|
+
* keeps the same size and only moves, so data far from that centre may start outside it, as on Plotly's map.
|
|
164
|
+
*
|
|
165
|
+
* @param box - The area the view must show: the data's padded box, or one turn by pole to pole.
|
|
166
|
+
* @param options - The longitudes the box must show without its padding, in degrees; the centre to build
|
|
167
|
+
* around, or null for the clipped box's middle; the view's aspect scale; and the panel's size in pixels.
|
|
168
|
+
* @returns The box ECharts fills the panel with, and the centre it is built around.
|
|
169
|
+
*/
|
|
170
|
+
function shapeBoxToPanel(box, options) {
|
|
171
|
+
const boxLongitudeSpan = box[2] - box[0];
|
|
172
|
+
const clippedLongitudeSpan = Math.min(boxLongitudeSpan, Math.max(WORLD_SPAN_DEGREES, options.ownLongitudeSpan));
|
|
173
|
+
const south = Math.max(box[1], -POLE_LATITUDE);
|
|
174
|
+
const north = Math.min(box[3], POLE_LATITUDE);
|
|
175
|
+
const clippedLatitudeSpan = north - south;
|
|
176
|
+
const panelAspect = options.panelPixels.width / options.panelPixels.height;
|
|
177
|
+
const widestLongitudeSpan = Math.max(WORLD_SPAN_DEGREES, clippedLongitudeSpan);
|
|
178
|
+
// Widened only when the clipped box is relatively narrower than the panel, then no wider than widestLongitudeSpan.
|
|
179
|
+
const longitudeSpan = Math.max(clippedLongitudeSpan, Math.min((clippedLatitudeSpan * panelAspect) / options.aspectScale, widestLongitudeSpan));
|
|
180
|
+
// Made taller only when the box is still relatively wider than the panel, which a widened box never is.
|
|
181
|
+
const latitudeSpan = Math.max(clippedLatitudeSpan, Math.min((longitudeSpan * options.aspectScale) / panelAspect, POLE_TO_POLE_DEGREES));
|
|
182
|
+
const asked = options.centre ?? [(box[0] + box[2]) / 2, (south + north) / 2];
|
|
183
|
+
const centre = [asked[0], holdCentreLatitudeBetweenPoles(asked[1], { shownLatitudeSpan: latitudeSpan })];
|
|
184
|
+
return {
|
|
185
|
+
box: [centre[0] - longitudeSpan / 2, centre[1] - latitudeSpan / 2, centre[0] + longitudeSpan / 2, centre[1] + latitudeSpan / 2],
|
|
186
|
+
centre,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Build the geo's starting view: the rectangle ECharts fits to the panel at
|
|
191
|
+
* its zoom 1, and the centre and zoom it starts at.
|
|
192
|
+
*
|
|
193
|
+
* A fitted map (no zoom from the caller) starts at zoom 1 on the drawn
|
|
194
|
+
* bounds with a margin, so it frames its data. Given a caller's centre, the
|
|
195
|
+
* same fitted box starts there instead, as Plotly's map keeps its fitted zoom
|
|
196
|
+
* and starts at the caller's centre: a centre is the caller's choice, so data
|
|
197
|
+
* far from it may start outside the view. A map with nothing to fit
|
|
198
|
+
* starts on the whole world, one turn of longitude by pole to pole. Each box
|
|
199
|
+
* is clipped to the world and shaped towards the panel, and ECharts stretches
|
|
200
|
+
* only what is left (see shapeBoxToPanel). A caller's zoom is absolute:
|
|
201
|
+
* zoom 1 is a rectangle that depends only on the panel's size, as wide in degrees as
|
|
202
|
+
* MapLibre (which Plotly's map draws with) shows at zoom 0 on that width, so
|
|
203
|
+
* the same centre and zoom show the same longitudes whatever the data, and
|
|
204
|
+
* the same as Plotly's. Its aspect scale is the cosine of the centre's
|
|
205
|
+
* latitude, so near the centre it shows the latitudes Mercator does. A single
|
|
206
|
+
* place, which has no area to fit, starts at its fitted zoom the same way.
|
|
207
|
+
* A centre the caller or the model gives is held so the view stays between
|
|
208
|
+
* the poles, as MapLibre's does (see holdCentreLatitudeBetweenPoles). Its
|
|
209
|
+
* longitude is placed on the copy of its meridian nearest the drawn data,
|
|
210
|
+
* which pickDataTurns has already brought beside it: its own longitude, or a
|
|
211
|
+
* turn east when the data is past 180.
|
|
212
|
+
*
|
|
213
|
+
* @param map - The map.
|
|
214
|
+
* @param options - The bounds the map is drawn in, and the panel's size in pixels.
|
|
215
|
+
* @returns The view: its rectangle, centre, zoom and aspect scale.
|
|
216
|
+
*/
|
|
217
|
+
function buildGeoView(map, options) {
|
|
218
|
+
const drawn = options.drawingBounds;
|
|
219
|
+
const hasArea = drawn !== null && (drawn[2] > drawn[0] || drawn[3] > drawn[1]);
|
|
220
|
+
const middle = drawn === null ? [0, 0] : [(drawn[0] + drawn[2]) / 2, (drawn[1] + drawn[3]) / 2];
|
|
221
|
+
// A fitted centre is the drawn area's middle, read here rather than from the model, so it is in the drawn frame.
|
|
222
|
+
const centre = hasArea && !map.isCentreGiven
|
|
223
|
+
? middle
|
|
224
|
+
: [placeLongitudeNear(map.centre[0], { reference: middle[0] }), map.centre[1]];
|
|
225
|
+
const view = (box, placing) => ({ box, ...placing });
|
|
226
|
+
if (!map.isZoomGiven && drawn !== null && hasArea) {
|
|
227
|
+
const pad = Math.max(drawn[2] - drawn[0], drawn[3] - drawn[1]) * BOUNDS_PADDING_FRACTION;
|
|
228
|
+
const padded = [drawn[0] - pad, drawn[1] - pad, drawn[2] + pad, drawn[3] + pad];
|
|
229
|
+
const shaped = shapeBoxToPanel(padded, {
|
|
230
|
+
ownLongitudeSpan: drawn[2] - drawn[0], centre: map.isCentreGiven ? centre : null, aspectScale: GEO_ASPECT_SCALE, panelPixels: options.panelPixels
|
|
231
|
+
});
|
|
232
|
+
return view(shaped.box, { centre: shaped.centre, zoom: 1, aspectScale: GEO_ASPECT_SCALE });
|
|
233
|
+
}
|
|
234
|
+
if (!map.isZoomGiven && drawn === null) {
|
|
235
|
+
// The whole world, exactly one turn around the caller's longitude, centred on the equator whatever latitude the
|
|
236
|
+
// caller or the model's default (north of the equator, for Plotly's Mercator) asks for.
|
|
237
|
+
const halfTurn = WORLD_SPAN_DEGREES / 2;
|
|
238
|
+
const world = [centre[0] - halfTurn, WHOLE_WORLD_BOUNDS[1], centre[0] + halfTurn, WHOLE_WORLD_BOUNDS[3]];
|
|
239
|
+
const shaped = shapeBoxToPanel(world, { ownLongitudeSpan: WORLD_SPAN_DEGREES, centre, aspectScale: GEO_ASPECT_SCALE, panelPixels: options.panelPixels });
|
|
240
|
+
return view(shaped.box, { centre: shaped.centre, zoom: 1, aspectScale: GEO_ASPECT_SCALE });
|
|
241
|
+
}
|
|
242
|
+
const { width, height } = options.panelPixels;
|
|
243
|
+
const longitudeSpan = (WORLD_SPAN_DEGREES * width) / MAPLIBRE_WORLD_PIXELS;
|
|
244
|
+
// ECharts draws latitude linearly; Mercator's degrees of latitude per pixel are its degrees of longitude
|
|
245
|
+
// per pixel times the cosine of the latitude. Shaping the view by the centre's cosine matches it there.
|
|
246
|
+
const latitude = Math.min(Math.max(centre[1], -MERCATOR_LATITUDE_LIMIT), MERCATOR_LATITUDE_LIMIT);
|
|
247
|
+
const aspectScale = Math.cos((latitude * Math.PI) / DEGREES_PER_HALF_TURN);
|
|
248
|
+
// As tall as makes the rectangle's drawn shape the panel's, so it fills the panel's width exactly.
|
|
249
|
+
const latitudeSpan = (longitudeSpan * aspectScale * height) / width;
|
|
250
|
+
const zoom = ZOOM_LEVEL_SCALE ** map.zoom;
|
|
251
|
+
// The view keeps the shape the asked-for latitude gives it and only moves, so a view that fits between
|
|
252
|
+
// the poles is unchanged, and one that does not is moved just far enough to fit.
|
|
253
|
+
const shownCentre = [centre[0], holdCentreLatitudeBetweenPoles(centre[1], { shownLatitudeSpan: latitudeSpan / zoom })];
|
|
254
|
+
const anchor = [
|
|
255
|
+
shownCentre[0] - longitudeSpan / 2, shownCentre[1] - latitudeSpan / 2, shownCentre[0] + longitudeSpan / 2, shownCentre[1] + latitudeSpan / 2,
|
|
256
|
+
];
|
|
257
|
+
return view(anchor, { centre: shownCentre, zoom, aspectScale });
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Measure the longitudes a view shows across its panel, from its west edge to its east edge.
|
|
261
|
+
*
|
|
262
|
+
* ECharts 6.1 stretches every view's rectangle to fill the panel (resizeGeo in
|
|
263
|
+
* echarts/lib/coord/geo/geoCreator.js), whether it was built in the panel's shape (a caller's view in
|
|
264
|
+
* buildGeoView, and a box shapeBoxToPanel could shape fully) or not (one it could shape only part way),
|
|
265
|
+
* and every such rectangle is centred on the view's centre, so the panel shows the rectangle's own longitude span, divided by the zoom, around the centre. A caller's span is MapLibre's: 360 × width / (512 × 2^zoom).
|
|
266
|
+
*
|
|
267
|
+
* @param view - The view.
|
|
268
|
+
* @returns The longitudes at the panel's west and east edges, in the view's frame.
|
|
269
|
+
*/
|
|
270
|
+
function measureShownLongitudes(view) {
|
|
271
|
+
const halfShownSpan = (view.box[2] - view.box[0]) / (2 * view.zoom);
|
|
272
|
+
return { west: view.centre[0] - halfShownSpan, east: view.centre[0] + halfShownSpan };
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Measure how many degrees of the longitudes a view shows lie outside the world outline's land.
|
|
276
|
+
*
|
|
277
|
+
* @param shown - The view's shown longitudes, from measureShownLongitudes.
|
|
278
|
+
* @returns The degrees west of OUTLINE_WEST_LONGITUDE plus those east of OUTLINE_EAST_LONGITUDE.
|
|
279
|
+
*/
|
|
280
|
+
function measureLongitudeOutsideOutline(shown) {
|
|
281
|
+
return Math.max(0, OUTLINE_WEST_LONGITUDE - shown.west) + Math.max(0, shown.east - OUTLINE_EAST_LONGITUDE);
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Pick how many more turns east a view and its data are drawn, so the view shows as little longitude
|
|
285
|
+
* outside the world outline's land (-180 to 540) as it can. A view past -180 on the west (a fit to data
|
|
286
|
+
* just east of the 180° line, padded, or a caller's centre near it) is drawn a turn east, inside the
|
|
287
|
+
* outline's copy, as Plotly's map shows the land there, unless that pushes more of it past 540 than it
|
|
288
|
+
* takes from west of -180 (a whole-world view centred on South-East Asia). With a tie, the view stays.
|
|
289
|
+
* The outline itself stays as a host registers it.
|
|
290
|
+
*
|
|
291
|
+
* @param view - The view, in the frame the data is drawn in so far.
|
|
292
|
+
* @returns 1 to draw the view and data a turn east, else 0.
|
|
293
|
+
*/
|
|
294
|
+
function pickViewTurns(view) {
|
|
295
|
+
const shown = measureShownLongitudes(view);
|
|
296
|
+
const outsideUnmoved = measureLongitudeOutsideOutline(shown);
|
|
297
|
+
const outsideMoved = measureLongitudeOutsideOutline({ west: shown.west + WORLD_SPAN_DEGREES, east: shown.east + WORLD_SPAN_DEGREES });
|
|
298
|
+
return outsideMoved < outsideUnmoved ? 1 : 0;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Move a view east by whole turns, keeping its shape.
|
|
302
|
+
*
|
|
303
|
+
* @param view - The view.
|
|
304
|
+
* @param options - The turns east.
|
|
305
|
+
* @returns The moved view.
|
|
306
|
+
*/
|
|
307
|
+
function moveViewEast(view, options) {
|
|
308
|
+
const offset = options.turns * WORLD_SPAN_DEGREES;
|
|
309
|
+
return { ...view, box: [view.box[0] + offset, view.box[1], view.box[2] + offset, view.box[3]], centre: [view.centre[0] + offset, view.centre[1]] };
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* ECharts reads a string tooltip formatter as a template, putting the series name, item name, value
|
|
313
|
+
* and percent in place of {a}, {b}, {c} and {d} (and a column in place of {@name}); braces written as
|
|
314
|
+
* entities are no template, and a page's HTML tooltip shows them as braces.
|
|
315
|
+
*/
|
|
316
|
+
const TEMPLATE_BRACE_ENTITIES = { "{": "{", "}": "}" };
|
|
317
|
+
const TEMPLATE_BRACE_PATTERN = /[{}]/g;
|
|
318
|
+
/**
|
|
319
|
+
* Escape text for an ECharts tooltip formatter, so a page shows it as written.
|
|
320
|
+
*
|
|
321
|
+
* @param text - The text, here a region's name and value.
|
|
322
|
+
* @returns The text with every HTML markup character and every template brace written as its entity.
|
|
323
|
+
*/
|
|
324
|
+
function escapeTooltipText(text) {
|
|
325
|
+
return escapeHtml(text).replace(TEMPLATE_BRACE_PATTERN, (brace) => TEMPLATE_BRACE_ENTITIES[brace] ?? brace);
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Build a map series' data item for a region.
|
|
329
|
+
*
|
|
330
|
+
* The item is named by the region's id, the name the geo gives the outline, so the two join. Its
|
|
331
|
+
* hover text is the region's label ("Annex: 31340", the name and the raw value, as Plotly shows it),
|
|
332
|
+
* given as the item's own tooltip text: the default tooltip would show the id and the value on the
|
|
333
|
+
* colour scale (a log, or a quantile's rank). A plain string, not a function, keeps the option JSON.
|
|
334
|
+
*
|
|
335
|
+
* @param region - A region of a regions layer.
|
|
336
|
+
* @returns The data item.
|
|
337
|
+
*/
|
|
338
|
+
function buildRegionItem(region) {
|
|
339
|
+
return {
|
|
340
|
+
name: region.id, value: region.value ?? undefined, tooltip: { formatter: escapeTooltipText(region.label) },
|
|
341
|
+
...(region.colour === null ? {} : { itemStyle: { areaColor: region.colour } }),
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Build a map panel's geo component and series for ECharts.
|
|
346
|
+
*
|
|
347
|
+
* @param panel - A panel with a map.
|
|
348
|
+
* @param options - Its index (for geo and series references), its rectangle, the figure's size in pixels, and the theme.
|
|
349
|
+
* @returns The parts to merge into the option.
|
|
350
|
+
*/
|
|
351
|
+
export function buildEChartsMap(panel, options) {
|
|
352
|
+
const map = panel.map;
|
|
353
|
+
const drawingBounds = pickDrawingBounds(map);
|
|
354
|
+
// Only fitting bounds past 180 move anything; plain ones hold every position where it is.
|
|
355
|
+
const wrappedBounds = drawingBounds !== null && drawingBounds !== map.bounds ? drawingBounds : null;
|
|
356
|
+
const centreTurns = pickDataTurns(map, { drawingBounds });
|
|
357
|
+
const panelPixels = { width: options.rectangle.width * options.size.width, height: options.rectangle.height * options.size.height };
|
|
358
|
+
const centredView = buildGeoView(map, {
|
|
359
|
+
drawingBounds: drawingBounds === null ? null
|
|
360
|
+
: [drawingBounds[0] + centreTurns * WORLD_SPAN_DEGREES, drawingBounds[1], drawingBounds[2] + centreTurns * WORLD_SPAN_DEGREES, drawingBounds[3]],
|
|
361
|
+
panelPixels,
|
|
362
|
+
});
|
|
363
|
+
const viewTurns = pickViewTurns(centredView);
|
|
364
|
+
const geoView = moveViewEast(centredView, { turns: viewTurns });
|
|
365
|
+
const dataTurns = centreTurns + viewTurns;
|
|
366
|
+
const turnOffset = dataTurns * WORLD_SPAN_DEGREES;
|
|
367
|
+
const isMoved = wrappedBounds !== null || dataTurns !== 0;
|
|
368
|
+
const placeLongitude = (longitude) => (wrappedBounds === null ? longitude : placeLongitudeInBounds(longitude, { bounds: wrappedBounds })) + turnOffset;
|
|
369
|
+
const placePosition = ([longitude, latitude]) => [placeLongitude(longitude), latitude];
|
|
370
|
+
const ink = PLOT_THEMES[options.theme];
|
|
371
|
+
const land = MAP_INKS[options.theme];
|
|
372
|
+
const scale = panel.colourScale;
|
|
373
|
+
// Every regions layer's outlines go in one registered map under one geo, so all layers share one view
|
|
374
|
+
// (ECharts keeps no two geos' pan and zoom together). Feature ids are unique across layers
|
|
375
|
+
// ("<layer>:<feature>"), so each layer's series names only its own regions.
|
|
376
|
+
const regionsLayers = map.layers.flatMap((layer) => (layer.kind === "regions" ? [layer] : []));
|
|
377
|
+
const mergedOutlines = regionsLayers.length === 0 ? null
|
|
378
|
+
: regionsLayers.length === 1 ? regionsLayers[0].geojson
|
|
379
|
+
: { type: "FeatureCollection", features: regionsLayers.flatMap((layer) => layer.geojson.features) };
|
|
380
|
+
const outlines = mergedOutlines === null || !isMoved ? mergedOutlines : mapCollectionLongitudes(mergedOutlines, { moveLongitude: placeLongitude });
|
|
381
|
+
// Named by content: a page registers maps globally, so two figures' outlines must never share a name.
|
|
382
|
+
const mapName = outlines === null ? WORLD_MAP_NAME : `${REGIONS_MAP_NAME_PREFIX}${hashText(JSON.stringify(outlines))}`;
|
|
383
|
+
const maps = outlines === null ? { [WORLD_MAP_NAME]: "world" } : { [mapName]: outlines };
|
|
384
|
+
// A layer's region with no data takes the no-data colour, as in Plotly; outlines in no layer keep the land colour.
|
|
385
|
+
const paintedRegions = regionsLayers.flatMap((layer) => layer.regions.map((region) => ({
|
|
386
|
+
name: region.id,
|
|
387
|
+
itemStyle: {
|
|
388
|
+
areaColor: region.colour ?? (region.value === null || scale === null ? pickNoDataColour(options.theme)
|
|
389
|
+
: interpolateRampColour(region.value, { minimum: scale.minimum, maximum: scale.maximum, colours: scale.colours })),
|
|
390
|
+
},
|
|
391
|
+
})));
|
|
392
|
+
const geo = {
|
|
393
|
+
map: mapName,
|
|
394
|
+
roam: true,
|
|
395
|
+
nameProperty: outlines === null ? WORLD_NAME_PROPERTY : REGION_NAME_PROPERTY,
|
|
396
|
+
left: percent(options.rectangle.left), top: percent(options.rectangle.top),
|
|
397
|
+
width: percent(options.rectangle.width), height: percent(options.rectangle.height),
|
|
398
|
+
boundingCoords: [[geoView.box[0], geoView.box[3]], [geoView.box[2], geoView.box[1]]],
|
|
399
|
+
center: geoView.centre, zoom: geoView.zoom, aspectScale: geoView.aspectScale,
|
|
400
|
+
itemStyle: { areaColor: land.land, borderColor: land.border, borderWidth: 0.6 },
|
|
401
|
+
emphasis: { label: { show: false }, itemStyle: { areaColor: land.land, borderColor: ink.textSecondary } },
|
|
402
|
+
select: { disabled: true },
|
|
403
|
+
label: { show: false },
|
|
404
|
+
// The geo paints every region, not the map series on it: it reads each region's style from here,
|
|
405
|
+
// and a series' data item colours are never read (ECharts' MapDraw). So every region's colour,
|
|
406
|
+
// by category, along the panel's scale, or for no data, is given here; the visualMap only draws the colour bar.
|
|
407
|
+
...(paintedRegions.length === 0 ? {} : { regions: paintedRegions }),
|
|
408
|
+
};
|
|
409
|
+
const series = [];
|
|
410
|
+
const scaledSeries = [];
|
|
411
|
+
const densitySeries = [];
|
|
412
|
+
const geoTarget = { geoIndex: options.geoIndex };
|
|
413
|
+
// A geo lets a visualMap repaint its regions only through the first map series on it, and then
|
|
414
|
+
// repaints every region, giving one missing from that series the series' default colour. So a
|
|
415
|
+
// regions layer coloured by category, when there is one, comes first: no visualMap reaches the
|
|
416
|
+
// geo, and every region keeps the colour set above. Alone, the scaled layer is first and its
|
|
417
|
+
// visualMap repaints each region in the same colour. Outlines draw in the registered map's order,
|
|
418
|
+
// so this reorders no shapes.
|
|
419
|
+
const isScaledRegions = (layer) => layer.kind === "regions" && layer.regions.some((region) => region.value !== null);
|
|
420
|
+
const layers = [
|
|
421
|
+
...map.layers.filter((layer) => layer.kind === "regions" && !isScaledRegions(layer)),
|
|
422
|
+
...map.layers.filter(isScaledRegions),
|
|
423
|
+
...map.layers.filter((layer) => layer.kind !== "regions"),
|
|
424
|
+
];
|
|
425
|
+
// The geo hands the hover of every region it draws to the first map series on it, and to no other
|
|
426
|
+
// (ECharts' MapDraw), so that series carries an item for every layer's region. Another layer's items
|
|
427
|
+
// there are only for their hover text: the geo's regions paint every region's colour.
|
|
428
|
+
const hostRegions = layers.flatMap((layer) => (layer.kind === "regions" ? layer.regions : []));
|
|
429
|
+
let isHostSeriesBuilt = false;
|
|
430
|
+
for (const layer of layers) {
|
|
431
|
+
if (layer.kind === "regions") {
|
|
432
|
+
if (isScaledRegions(layer))
|
|
433
|
+
scaledSeries.push(series.length);
|
|
434
|
+
const regions = isHostSeriesBuilt ? layer.regions : hostRegions;
|
|
435
|
+
isHostSeriesBuilt = true;
|
|
436
|
+
series.push({ type: "map", ...geoTarget, name: layer.name, data: regions.map(buildRegionItem) });
|
|
437
|
+
}
|
|
438
|
+
else if (layer.kind === "points") {
|
|
439
|
+
const hasLabels = layer.points.some((point) => point.label !== null);
|
|
440
|
+
if (layer.colour === null)
|
|
441
|
+
scaledSeries.push(series.length);
|
|
442
|
+
series.push({
|
|
443
|
+
type: "scatter", coordinateSystem: "geo", ...geoTarget, name: layer.name,
|
|
444
|
+
data: layer.points.map((point) => ({
|
|
445
|
+
name: point.label ?? "",
|
|
446
|
+
value: [placeLongitude(point.longitude), point.latitude, point.colourValue, ...(isMoved ? [point.longitude] : [])],
|
|
447
|
+
symbolSize: point.sizePixels,
|
|
448
|
+
})),
|
|
449
|
+
...(isMoved ? { encode: { tooltip: MOVED_TOOLTIP_DIMENSIONS } } : {}),
|
|
450
|
+
itemStyle: { borderColor: ink.surface, borderWidth: 1, ...(layer.colour === null ? {} : { color: layer.colour }) },
|
|
451
|
+
label: { show: hasLabels, formatter: "{b}", position: "right", color: ink.textPrimary },
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
else if (layer.kind === "density") {
|
|
455
|
+
// Nothing to draw, and ECharts cannot range a heat scale with no positive weight; the model tells the agent.
|
|
456
|
+
const maximumWeight = Math.max(0, getNumberRange(layer.points.map((point) => point.weight)).maximum);
|
|
457
|
+
if (maximumWeight <= 0)
|
|
458
|
+
continue;
|
|
459
|
+
densitySeries.push({ index: series.length, maximumWeight });
|
|
460
|
+
series.push({
|
|
461
|
+
type: "heatmap", coordinateSystem: "geo", ...geoTarget, name: layer.name,
|
|
462
|
+
data: layer.points.map((point) => [placeLongitude(point.longitude), point.latitude, point.weight, ...(isMoved ? [point.longitude] : [])]),
|
|
463
|
+
...(isMoved ? { encode: { tooltip: MOVED_TOOLTIP_DIMENSIONS } } : {}),
|
|
464
|
+
pointSize: 10, blurSize: 18,
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
else {
|
|
468
|
+
// Lines coloured by a number join the panel's colour legend; each keeps its own colour, from its value.
|
|
469
|
+
const isScaledLines = layer.colour === null && scale !== null;
|
|
470
|
+
if (isScaledLines)
|
|
471
|
+
scaledSeries.push(series.length);
|
|
472
|
+
series.push({
|
|
473
|
+
type: "lines", coordinateSystem: "geo", ...geoTarget, name: layer.name, polyline: true,
|
|
474
|
+
data: layer.lines.map((line) => ({
|
|
475
|
+
name: line.label ?? layer.name, coords: line.path.map(placePosition), ...(isScaledLines && line.colourValue !== null ? { value: line.colourValue } : {}),
|
|
476
|
+
// ECharts draws lines at half opacity by default, which would not match the legend's colours.
|
|
477
|
+
lineStyle: {
|
|
478
|
+
opacity: 1,
|
|
479
|
+
width: line.widthPixels,
|
|
480
|
+
color: layer.colour ?? (scale === null || line.colourValue === null
|
|
481
|
+
? ink.textSecondary
|
|
482
|
+
: pickSequentialColour((line.colourValue - scale.minimum) / (scale.maximum - scale.minimum || 1))),
|
|
483
|
+
},
|
|
484
|
+
})),
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
return {
|
|
489
|
+
geo, series, scaledSeries, densitySeries, maps,
|
|
490
|
+
notice: map.projection === "globe" ? "ECharts has no globe, so this map is flat. Switch to Plotly for the globe." : null,
|
|
491
|
+
};
|
|
492
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chart model → ECharts option object. Plain JSON (no functions), so it can
|
|
3
|
+
* be sent to the page as-is and passed to `chart.setOption`.
|
|
4
|
+
*/
|
|
5
|
+
import type { FigureModel } from "../model/panel_model.ts";
|
|
6
|
+
import { type FigureSize } from "../model/panel_layout.ts";
|
|
7
|
+
/**
|
|
8
|
+
* Keys the ECharts option carries for the page that draws it, beyond ECharts'
|
|
9
|
+
* own: the maps to register before drawing (name → GeoJSON, or "world" for
|
|
10
|
+
* the world outline the page loads), a notice for the person, and on an axis
|
|
11
|
+
* label, that its numbers are years to print in full or by two digits. The
|
|
12
|
+
* page acts on each and removes it before handing the option to ECharts.
|
|
13
|
+
*/
|
|
14
|
+
export declare const MAPS_OPTION_KEY = "plotillaMaps";
|
|
15
|
+
/** The option key holding a notice the page shows the person, then removes. */
|
|
16
|
+
export declare const NOTICE_OPTION_KEY = "plotillaNotice";
|
|
17
|
+
/** The axis-label key telling the page to print each number as it is, a year in full (1990, not 1,990), then removed. */
|
|
18
|
+
export declare const PLAIN_NUMBERS_LABEL_KEY = "plotillaPlainNumbers";
|
|
19
|
+
/** The axis-label key telling the page to print each number by its last two digits, a year (1990 as 90, 2005 as 05), then removed. */
|
|
20
|
+
export declare const TWO_DIGIT_YEARS_LABEL_KEY = "plotillaTwoDigitYears";
|
|
21
|
+
/**
|
|
22
|
+
* Build the ECharts option for a figure.
|
|
23
|
+
*
|
|
24
|
+
* @param model - The chart model.
|
|
25
|
+
* @param options - The size the host draws the figure at, in pixels; build again when it changes.
|
|
26
|
+
* @returns The option object.
|
|
27
|
+
*/
|
|
28
|
+
export declare function buildEChartsOption(model: FigureModel, options: {
|
|
29
|
+
size: FigureSize;
|
|
30
|
+
}): Record<string, unknown>;
|