@amcharts/amcharts5-mcp 1.9.3 → 1.9.4

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.
@@ -0,0 +1,348 @@
1
+ ---
2
+ title: "CPU and Memory Timeline"
3
+ source: "https://www.amcharts.com/demos/cpu-and-memory-timeline/"
4
+ category: "line-area"
5
+ scraped: "2026-10-25"
6
+ ---
7
+
8
+ A 10-second recording of a web page, like the overview strip of the browser's performance tools: how busy the processor was and with what, and below it the memory the page's JavaScript held, sawing down at each garbage collection. Long tasks are marked in red.
9
+
10
+ One clock, several measures: Stacking axes on one time line keeps measures with different units apart but in step: here the processor's load in percent and the memory in megabytes, so a burst of script lines up with the memory it allocated, and a garbage collection with the drop it caused. The cursor runs through both panels, and the legend reads off every value at that moment.
11
+
12
+ Good for:
13
+ - Performance and monitoring data
14
+ - Several measures of one process over time
15
+ - Matching causes and effects on one time line
16
+
17
+ Think twice when:
18
+ - Measures with no common time: separate charts
19
+ - Many panels: a dashboard of small charts reads better
20
+
21
+ Prompt: Create a performance timeline like the overview of Chrome DevTools' performance panel, with generated data: a 10-second recording sampled every 20 ms. Top panel (60%): CPU use stacked by category as filled areas, 0 to 100% (Loading, Scripting, Rendering, Painting in theme colors, System in faint gray). Bottom panel: the JavaScript heap in MB as a line with a light fill, sawing down at each garbage collection, with a dot at each collection (larger for a major one). Both panels share the time axis in seconds (stacked y axes, each with an upright title). Mark long tasks (the processor busy at 95% or more for over 50 ms, whatever with) as faint red bands across the plot. Add a legend that shows each value at the cursor, a cursor that zooms on drag, and a scrollbar under the plot. On phones hide the legend. Use the amCharts 5 library with its Responsive theme.
22
+
23
+ ## JavaScript
24
+
25
+ ```javascript
26
+ // Create root element
27
+ // https://docs.amcharts.com/v5/getting-started/#root-element
28
+ var root = am5.Root.new("chartdiv");
29
+
30
+ // Set themes
31
+ // https://docs.amcharts.com/v5/concepts/themes/
32
+ var responsive = am5themes_Responsive.new(root); // kept in a variable: a rule of its own is added below
33
+ root.setThemes([
34
+ am5themes_Animated.new(root),
35
+ responsive
36
+ ]);
37
+
38
+
39
+ // ── Sample data: a 10-second recording of a web page, every 20 ms, like the overview of the browser's performance
40
+ // tools: how busy the processor was and with what, and how much memory the page's JavaScript held. The page loads,
41
+ // rests, answers a click with a long burst of script, is scrolled for three seconds and fetches more data ──
42
+
43
+ // A seeded random number generator (mulberry32): the same recording on every visit
44
+ function makeRandom(seed) {
45
+ return function() {
46
+ seed = seed + 0x6D2B79F5 | 0;
47
+ var t = Math.imul(seed ^ seed >>> 15, 1 | seed);
48
+ t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
49
+ return ((t ^ t >>> 14) >>> 0) / 4294967296;
50
+ };
51
+ }
52
+ var random = makeRandom(1020);
53
+
54
+ var data = [];
55
+ var heap = 6; // MB of JavaScript memory in use
56
+ var sinceGC = 0; // MB allocated since the last garbage collection
57
+ for (var i = 0; i <= 500; i++) {
58
+ var t = i * 0.02; // seconds
59
+ var r = random();
60
+ var loading = 0, scripting = 2 * r, rendering = 0, painting = 0;
61
+ if (t < 1.2) { // the page loads: parsing and its scripts
62
+ loading = 30 + 10 * r;
63
+ scripting = 65 + 15 * random(); // with the parsing, the processor is flat out: one long task
64
+ rendering = t > 0.9 ? 10 * random() : 0;
65
+ } else if (t >= 2.5 && t < 3.4) { // a click: a long burst of script, then the new content is laid out and painted
66
+ scripting = t < 2.9 ? 88 + 8 * r : 15 + 25 * r;
67
+ rendering = t >= 2.9 && t < 3.15 ? 45 + 20 * random() : 3 * random();
68
+ painting = t >= 3.15 && t < 3.3 ? 30 + 15 * random() : 0;
69
+ } else if (t >= 4 && t < 7) { // scrolling: style, layout and paint every frame, a little script
70
+ rendering = 18 + 12 * Math.sin(t * 9) * r + 6 * random();
71
+ painting = 12 + 14 * random();
72
+ scripting = 4 + 8 * random();
73
+ } else if (t >= 7.6 && t < 8.3) { // more data arrives and is shown
74
+ loading = t < 7.75 ? 12 * r : 0;
75
+ scripting = 40 + 30 * random();
76
+ rendering = t > 8 ? 25 * random() : 5 * random();
77
+ }
78
+ var system = 3 + 4 * random(); // the browser's own housekeeping
79
+ // the processor can't be more than 100% busy: a sample that adds up to more is scaled down
80
+ var total = loading + scripting + rendering + painting + system;
81
+ if (total > 99) {
82
+ var k = 99 / total;
83
+ loading *= k; scripting *= k; rendering *= k; painting *= k; system *= k;
84
+ }
85
+
86
+ // memory: script allocates as it runs; a minor collection frees most of what was allocated since the last one;
87
+ // the scrolling leaves a little behind each time, so the heap creeps up until a major collection at 7.3 s
88
+ var allocated = (scripting * 0.0045 + rendering * 0.0015) * (0.6 + 0.8 * random());
89
+ heap += allocated;
90
+ sinceGC += allocated;
91
+ var gc = "";
92
+ if (Math.abs(t - 7.3) < 0.01) {
93
+ heap = 6 + (heap - 6) * 0.3; // it frees what the minor ones left behind
94
+ sinceGC = 0;
95
+ gc = "Major GC";
96
+ } else if (sinceGC > 2.2) {
97
+ heap -= sinceGC * (t >= 4 && t < 7 ? 0.8 : 0.92);
98
+ sinceGC = 0;
99
+ gc = "Minor GC";
100
+ }
101
+
102
+ data.push({
103
+ time: Math.round(t * 1000) / 1000,
104
+ loading: Math.round(loading), scripting: Math.round(scripting), rendering: Math.round(rendering),
105
+ painting: Math.round(painting), system: Math.round(system),
106
+ heap: Math.round(heap * 10) / 10,
107
+ gc: gc
108
+ });
109
+ }
110
+
111
+
112
+ // Create chart
113
+ // https://docs.amcharts.com/v5/charts/xy-chart/
114
+ var chart = root.container.children.push(am5xy.XYChart.new(root, {
115
+ panX: false,
116
+ panY: false,
117
+ wheelX: "panX", // a sideways wheel pans...
118
+ wheelY: "zoomX", // ...the wheel zooms in on the time
119
+ layout: root.verticalLayout
120
+ }));
121
+
122
+ // The two panels, CPU above memory, share the time axis: the y axes are stacked
123
+ // https://docs.amcharts.com/v5/charts/xy-chart/axes/ (see "Stacked axes")
124
+ chart.leftAxesContainer.set("layout", root.verticalLayout);
125
+
126
+ // Add legend: with the cursor on the chart, it shows each series' value at that moment
127
+ // https://docs.amcharts.com/v5/charts/xy-chart/legend-xy-series/
128
+ var legend = chart.children.unshift(am5.Legend.new(root, {
129
+ centerX: am5.p50,
130
+ x: am5.p50,
131
+ marginBottom: 10
132
+ }));
133
+
134
+ // Create axes
135
+ // https://docs.amcharts.com/v5/charts/xy-chart/axes/
136
+ var xRenderer = am5xy.AxisRendererX.new(root, { minGridDistance: 60 });
137
+ xRenderer.grid.template.set("strokeOpacity", 0.06);
138
+ var xAxis = chart.xAxes.push(am5xy.ValueAxis.new(root, {
139
+ min: 0,
140
+ max: 10,
141
+ strictMinMax: true,
142
+ numberFormat: "#.#' s'",
143
+ renderer: xRenderer
144
+ }));
145
+
146
+ // The axis' name, upright beside its labels
147
+ function axisTitle(axis, text) {
148
+ axis.children.unshift(am5.Label.new(root, {
149
+ text: text,
150
+ rotation: -90,
151
+ y: am5.p50,
152
+ centerX: am5.p50,
153
+ fontWeight: "500"
154
+ }));
155
+ }
156
+
157
+ // CPU: how busy the main thread was, 0 to 100%, the top 60% of the plot
158
+ var cpuAxis = chart.yAxes.push(am5xy.ValueAxis.new(root, {
159
+ min: 0,
160
+ max: 100,
161
+ strictMinMax: true,
162
+ numberFormat: "#'%'",
163
+ height: am5.percent(60),
164
+ renderer: am5xy.AxisRendererY.new(root, { minGridDistance: 30 })
165
+ }));
166
+ axisTitle(cpuAxis, "CPU");
167
+
168
+ // Memory: the JavaScript heap, in MB, the rest of the plot
169
+ var heapAxis = chart.yAxes.push(am5xy.ValueAxis.new(root, {
170
+ min: 0,
171
+ numberFormat: "#' MB'",
172
+ height: am5.percent(40),
173
+ marginTop: 16, // a gap between the panels
174
+ renderer: am5xy.AxisRendererY.new(root, { minGridDistance: 30 })
175
+ }));
176
+ axisTitle(heapAxis, "JS heap");
177
+
178
+ // Create series
179
+ // https://docs.amcharts.com/v5/charts/xy-chart/series/
180
+ // The CPU's work by category, stacked: together they are how busy it was. The theme's colors, the browser's own work
181
+ // in a faint gray
182
+ var gray = root.interfaceColors.get("alternativeBackground");
183
+ [["Loading", "loading"], ["Scripting", "scripting"], ["Rendering", "rendering"], ["Painting", "painting"], ["System", "system"]].forEach(function(category) {
184
+ var settings = {
185
+ name: category[0],
186
+ xAxis: xAxis,
187
+ yAxis: cpuAxis,
188
+ valueXField: "time",
189
+ valueYField: category[1],
190
+ stacked: true,
191
+ legendValueText: "{valueY}%" // the value at the cursor, in the legend
192
+ };
193
+ if (category[0] === "System") {
194
+ settings.stroke = gray;
195
+ settings.fill = gray;
196
+ }
197
+ var series = chart.series.push(am5xy.LineSeries.new(root, settings));
198
+ // a thin line along each area's top, in its own color: it closes the hairline gaps between the stacked fills
199
+ series.strokes.template.setAll({
200
+ strokeWidth: 1,
201
+ strokeOpacity: category[0] === "System" ? 0.3 : 0.9 // the faint gray area's line as faint
202
+ });
203
+ series.fills.template.setAll({
204
+ visible: true,
205
+ fillOpacity: category[0] === "System" ? 0.3 : 0.8
206
+ });
207
+ series.data.setAll(data);
208
+ legend.data.push(series);
209
+ });
210
+
211
+ // The JavaScript heap: a line that saws up as the page allocates and down at each garbage collection
212
+ var heapSeries = chart.series.push(am5xy.LineSeries.new(root, {
213
+ name: "JS heap",
214
+ xAxis: xAxis,
215
+ yAxis: heapAxis,
216
+ valueXField: "time",
217
+ valueYField: "heap",
218
+ legendValueText: "{valueY} MB",
219
+ tooltip: am5.Tooltip.new(root, {
220
+ labelText: "{valueY} MB"
221
+ })
222
+ }));
223
+ heapSeries.strokes.template.set("strokeWidth", 2);
224
+ heapSeries.fills.template.setAll({ visible: true, fillOpacity: 0.12 });
225
+ heapSeries.data.setAll(data);
226
+ legend.data.push(heapSeries);
227
+
228
+ // The garbage collections: a series of their own on the heap's panel, with no line, only a dot at each (larger for
229
+ // a major one), so the legend can show and hide them
230
+ var gcSeries = chart.series.push(am5xy.LineSeries.new(root, {
231
+ name: "Garbage collection",
232
+ xAxis: xAxis,
233
+ yAxis: heapAxis,
234
+ valueXField: "time",
235
+ valueYField: "heap",
236
+ stroke: heapSeries.get("stroke"), // the heap's color
237
+ fill: heapSeries.get("fill")
238
+ }));
239
+ gcSeries.strokes.template.set("visible", false); // no line between the dots
240
+ gcSeries.bullets.push(function(root, series) {
241
+ return am5.Bullet.new(root, {
242
+ sprite: am5.Circle.new(root, {
243
+ fill: series.get("fill"),
244
+ stroke: root.interfaceColors.get("background"),
245
+ strokeWidth: 1.5,
246
+ tooltipText: "[bold]{gc}[/]\n{valueX.formatNumber('#.00')} s",
247
+ templateField: "dotSettings" // its size (no radius here: a setting made here would win over the data's)
248
+ })
249
+ });
250
+ });
251
+ gcSeries.data.setAll(data.filter(function(point) { return point.gc; }).map(function(point) {
252
+ return {
253
+ time: point.time,
254
+ heap: point.heap,
255
+ gc: point.gc,
256
+ dotSettings: { radius: point.gc === "Major GC" ? 6 : 3 }
257
+ };
258
+ }));
259
+ legend.data.push(gcSeries);
260
+
261
+ // On a narrow chart (a phone) the legend would take most of the height: it is hidden there. The rule is
262
+ // undone on a wider chart
263
+ responsive.addRule({
264
+ relevant: am5themes_Responsive.widthM, // the chart is 600px wide or less
265
+ applying: function() {
266
+ legend.set("forceHidden", true);
267
+ },
268
+ removing: function() {
269
+ legend.set("forceHidden", false);
270
+ }
271
+ });
272
+
273
+ // Long tasks: where the processor was busy (95% or more, whatever with) for more than 50 ms in a row, the page could
274
+ // not answer the user. A faint red band across both panels
275
+ // https://docs.amcharts.com/v5/charts/xy-chart/axes/axis-ranges/
276
+ // the busy stretches: one sample (20 ms) a little under the line doesn't end a stretch, as no task could run in it
277
+ var runs = [];
278
+ data.forEach(function(point) {
279
+ var busy = point.loading + point.scripting + point.rendering + point.painting + point.system >= 95;
280
+ var last = runs[runs.length - 1];
281
+ if (busy) {
282
+ if (last && point.time - last.end <= 0.041) {
283
+ last.end = point.time; // goes on, or picks up again after one quiet sample
284
+ } else {
285
+ runs.push({ start: point.time, end: point.time });
286
+ }
287
+ }
288
+ });
289
+ runs.filter(function(run) { return run.end - run.start > 0.05; }).forEach(function(run) {
290
+ var range = xAxis.createAxisRange(xAxis.makeDataItem({ value: run.start, endValue: run.end + 0.02 }));
291
+ range.get("axisFill").setAll({
292
+ visible: true,
293
+ fill: root.interfaceColors.get("negative"),
294
+ fillOpacity: 0.1
295
+ });
296
+ range.get("label").setAll({
297
+ text: "Long task",
298
+ inside: true,
299
+ fill: root.interfaceColors.get("negative"),
300
+ fontSize: "0.75em",
301
+ location: 0.5, // over the middle of the band...
302
+ centerY: am5.p100, // ...at the bottom of the plot
303
+ dy: -4
304
+ });
305
+ });
306
+
307
+ // Add cursor: a line through both panels; the legend reads off the values where it is
308
+ // https://docs.amcharts.com/v5/charts/xy-chart/cursor/
309
+ var cursor = chart.set("cursor", am5xy.XYCursor.new(root, {
310
+ behavior: "zoomX", // drag across to zoom in
311
+ xAxis: xAxis
312
+ }));
313
+ cursor.lineY.set("visible", false);
314
+
315
+ // Add scrollbar under the plot
316
+ // https://docs.amcharts.com/v5/charts/xy-chart/scrollbars/
317
+ chart.set("scrollbarX", am5.Scrollbar.new(root, {
318
+ orientation: "horizontal",
319
+ opposite: true
320
+ }));
321
+
322
+ // Make stuff animate on load
323
+ // https://docs.amcharts.com/v5/concepts/animations/
324
+ chart.appear(1000, 100);
325
+ ```
326
+
327
+ ## HTML
328
+
329
+ ```html
330
+ <div id="chartdiv"></div>
331
+ ```
332
+
333
+ ## CSS
334
+
335
+ ```css
336
+ #chartdiv {
337
+ width: 100%;
338
+ height: 500px;
339
+ font-size: 0.875rem;
340
+ }
341
+ ```
342
+
343
+ ## Required resources
344
+
345
+ - https://cdn.amcharts.com/lib/5/index.js
346
+ - https://cdn.amcharts.com/lib/5/xy.js
347
+ - https://cdn.amcharts.com/lib/5/themes/Animated.js
348
+ - https://cdn.amcharts.com/lib/5/themes/Responsive.js
@@ -0,0 +1,209 @@
1
+ ---
2
+ title: "Jupiter and Its Moons"
3
+ source: "https://www.amcharts.com/demos/jupiter-and-its-moons/"
4
+ category: "maps"
5
+ scraped: "2026-10-25"
6
+ ---
7
+
8
+ Jupiter as a globe wearing Cassini's map of its clouds, spinning a Jupiter day in 30 seconds, with its four largest moons going round at their real relative speeds: Io in under two days, Callisto in over sixteen.
9
+
10
+ More than maps of the Earth: A map chart wears any whole-planet picture in the usual equirectangular layout, and since 5.21.0 places points by height too: here the moons float above Jupiter on raised orbits and pass behind it. Turning the map turns the planet; each moon moves on the map at its own speed less the planet's, so on screen it goes round as fast as it really does. The picture is Cassini's map of December 2000: Jupiter's clouds move, so it shows them as they were then.
11
+
12
+ Good for:
13
+ - Space and science pages
14
+ - Anything that orbits: moons, satellites, stations
15
+ - An eye-catching opener
16
+
17
+ Think twice when:
18
+ - Exact distances: the moons' distances are squeezed to fit
19
+ - Today's weather on Jupiter: the picture is from 2000
20
+
21
+ Prompt: Create Jupiter as a map chart in globe projection wearing the amCharts CDN's picture of Jupiter (https://cdn.amcharts.com/lib/5/geodata/images/jupiter2048.jpg), as a time-lapse: the map turns once a Jupiter day in 30 seconds. Add Io, Europa, Ganymede and Callisto as map points raised onto barely visible solid orbits (dashes would spin with the turning map) round the equator, their distances squeezed with a logarithm so Callisto fits, each sized by the square root of its radius and colored like the moon, going round at its real relative speed (its longitude on the turning map moves at its speed less the planet's). View it from 12 degrees above the equator on a dark background; a drag up or down tilts it. Tooltips: each moon's diameter, real distance and period. Credit the picture to NASA/JPL/Space Science Institute. Use the amCharts 5 library with its Responsive theme.
22
+
23
+ ## JavaScript
24
+
25
+ ```javascript
26
+ // Create root element
27
+ // https://docs.amcharts.com/v5/getting-started/#root-element
28
+ var root = am5.Root.new("chartdiv");
29
+
30
+ // Set themes
31
+ // https://docs.amcharts.com/v5/concepts/themes/
32
+ root.setThemes([
33
+ am5themes_Animated.new(root),
34
+ am5themes_Responsive.new(root)
35
+ ]);
36
+
37
+ // The buttons (the zoom control) in a dark slate that suits the night sky, instead of the default blue
38
+ root.interfaceColors.setAll({
39
+ primaryButton: am5.color(0x2a3042),
40
+ primaryButtonHover: am5.color(0x3a4259),
41
+ primaryButtonDown: am5.color(0x485170),
42
+ primaryButtonActive: am5.color(0x485170),
43
+ primaryButtonStroke: am5.color(0x4a5370),
44
+ primaryButtonText: am5.color(0xe6e8f0),
45
+ primaryButtonDisabled: am5.color(0x1c2030), // the minus button, zoomed out as far as it goes
46
+ primaryButtonTextDisabled: am5.color(0x5c6278)
47
+ });
48
+
49
+ // Jupiter as a map: the planet is a globe wearing a picture of its clouds, and its four largest moons are map points
50
+ // raised above it, so the planet hides them when they pass behind. Heights are in meters of the map's globe, which is
51
+ // the Earth's size: a moon twice Jupiter's radius from its center is one globe radius up
52
+ var GLOBE = 6371008.8; // the map globe's radius, meters
53
+ var JUPITER = 71492; // Jupiter's radius at the equator, km
54
+
55
+ // A time-lapse: a Jupiter day (9.9 hours) in 30 seconds, and the moons as fast as they really are, at that scale
56
+ var DAY_HOURS = 9.925;
57
+ var DAY = 30000; // milliseconds
58
+ var HOUR = DAY / DAY_HOURS; // milliseconds for an hour
59
+
60
+ // Create the map chart: Jupiter seen from a little above its equator. The map turns once a Jupiter day, so the
61
+ // clouds go round; a drag up or down tilts it (a sideways drag would stop the spin, so it does nothing)
62
+ // https://docs.amcharts.com/v5/charts/map-chart/
63
+ var chart = root.container.children.push(am5map.MapChart.new(root, {
64
+ projection: am5map.geoOrthographic(), // a globe
65
+ panX: "none", // the planet turns by itself
66
+ panY: "rotateY", // an up or down drag tilts it
67
+ rotationY: -12, // the moons' orbits open a little toward the camera
68
+ rotationZ: -3, // Jupiter's axis leans 3° on its orbit
69
+ homeZoomLevel: 0.45, // zoomed out far enough for the moons around the planet...
70
+ minZoomLevel: 0.45, // zooming out stops there: any further and the moons are specks
71
+ zoomLevel: 0.45,
72
+ autoHome: true, // ...from the start
73
+ animations: [
74
+ // a full turn a Jupiter day, eastward as Jupiter spins; loops: 0 repeats it for ever
75
+ { key: "rotationX", from: 0, to: 360, duration: DAY, loops: 0 }
76
+ ]
77
+ }));
78
+
79
+ // Add the picture of Jupiter, a map of its whole cloud top redrawn to fit the globe as it turns: Cassini's map from
80
+ // its flyby in December 2000, read from the amCharts CDN. The clouds move, so it shows them as they were then
81
+ // https://docs.amcharts.com/v5/charts/map-chart/map-raster-series/
82
+ chart.series.push(am5map.MapRasterSeries.new(root, {
83
+ src: "https://cdn.amcharts.com/lib/5/geodata/images/jupiter2048.jpg"
84
+ }));
85
+
86
+
87
+ // ── The moons ──
88
+
89
+ // The four Galilean moons: distance from Jupiter's center (km), orbital period (hours), radius (km), color, and
90
+ // where each starts. On the map they are closer in than in life (distances squeezed with a logarithm), so Callisto,
91
+ // 26 Jupiter radii out, still fits; the tooltips have the real numbers
92
+ var MOONS = [
93
+ { name: "Io", distance: 421700, period: 42.46, radius: 1821.6, color: 0xe6cf6e, start: 40 },
94
+ { name: "Europa", distance: 671034, period: 85.23, radius: 1560.8, color: 0xece4d4, start: 160 },
95
+ { name: "Ganymede", distance: 1070412, period: 171.71, radius: 2634.1, color: 0xb6a68e, start: -70 },
96
+ { name: "Callisto", distance: 1882709, period: 400.54, radius: 2410.3, color: 0x8d7f6b, start: -150 }
97
+ ];
98
+ function shown(km) { return 1 + 0.65 * Math.log(km / JUPITER); } // in Jupiter radii, on the map
99
+ function height(km) { return (shown(km) - 1) * GLOBE; } // as a height above the map's globe
100
+
101
+ // A circle round the equator at a moon's height: longitude, latitude and height
102
+ function orbit(km) {
103
+ var coordinates = [];
104
+ for (var longitude = -180; longitude <= 180; longitude += 5) {
105
+ coordinates.push([longitude, 0, height(km)]);
106
+ }
107
+ return { type: "LineString", coordinates: coordinates };
108
+ }
109
+
110
+ // Create line series for the orbits: faint circles at the moons' heights. They are drawn on the map, which turns
111
+ // once a Jupiter day, so they are solid: dashes would spin round with the planet, far faster than the moons
112
+ // https://docs.amcharts.com/v5/charts/map-chart/map-line-series/
113
+ var orbitSeries = chart.series.push(am5map.MapLineSeries.new(root, {}));
114
+ orbitSeries.mapLines.template.setAll({
115
+ stroke: am5.color(0xffffff),
116
+ strokeOpacity: 0.06, // barely there: Jupiter has no rings, so its moons' paths stay a hint
117
+ altitude: 0, // each point of a line carries its own height (the third number of its coordinates)
118
+ interactive: false // the orbits take no pointer: the moons have the tooltips
119
+ });
120
+ orbitSeries.data.setAll(MOONS.map(function(moon) {
121
+ return { geometry: orbit(moon.distance) };
122
+ }));
123
+
124
+ // Create point series for the moons, raised to their orbits (altitudeField)
125
+ // https://docs.amcharts.com/v5/charts/map-chart/map-point-series/
126
+ var moonSeries = chart.series.push(am5map.MapPointSeries.new(root, {
127
+ latitudeField: "latitude",
128
+ longitudeField: "longitude",
129
+ altitudeField: "altitude"
130
+ }));
131
+ moonSeries.bullets.push(function() {
132
+ var circle = am5.Circle.new(root, {
133
+ // no radius or fill here: a setting made here would win over the size and color each moon's data gives
134
+ tooltipText: "[bold]{name}[/]\n{across} km across\n{km} km from Jupiter's center\nOnce round in {days} days",
135
+ tooltipY: 0, // the tooltip points at the top of the moon, not its middle
136
+ templateField: "circleSettings"
137
+ });
138
+ // pointed at, the moon grows a little
139
+ // https://docs.amcharts.com/v5/concepts/settings/states/
140
+ circle.states.create("hover", { scale: 1.4 });
141
+ return am5.Bullet.new(root, { sprite: circle });
142
+ });
143
+ moonSeries.data.setAll(MOONS.map(function(moon) {
144
+ // The map itself turns once a Jupiter day, and a moon's longitude is on the map: to go round at its own speed on
145
+ // screen, it moves on the map at its speed less the planet's. Every moon is slower than the spin, so its longitude
146
+ // runs backward, a full turn in this many hours
147
+ var lap = 1 / (1 / DAY_HOURS - 1 / moon.period);
148
+ return {
149
+ name: moon.name,
150
+ across: Math.round(moon.radius * 2).toLocaleString("en-US"),
151
+ km: moon.distance.toLocaleString("en-US"),
152
+ days: (moon.period / 24).toFixed(1),
153
+ longitude: moon.start,
154
+ latitude: 0,
155
+ altitude: height(moon.distance),
156
+ circleSettings: {
157
+ radius: 8 * Math.sqrt(moon.radius / 2634.1), // by the square root of the moon's size: Ganymede 8px
158
+ fill: am5.color(moon.color),
159
+ animations: [{ target: "dataItem", key: "longitude", from: moon.start, to: moon.start - 360, duration: Math.round(lap * HOUR), loops: 0 }]
160
+ }
161
+ };
162
+ }));
163
+
164
+ // Add zoom control: plus, minus and home buttons, at the bottom left
165
+ // https://docs.amcharts.com/v5/charts/map-chart/map-pan-zoom/#zoom-control
166
+ var zoomControl = chart.set("zoomControl", am5map.ZoomControl.new(root, {
167
+ x: 0, // at the chart's left edge...
168
+ centerX: 0,
169
+ dx: 10 // ...10px in
170
+ }));
171
+ zoomControl.homeButton.set("visible", true); // the home button is hidden by default
172
+
173
+ // Add image credit, at the bottom right
174
+ chart.children.push(am5.Label.new(root, {
175
+ text: "Imagery: NASA/JPL/Space Science Institute",
176
+ fontSize: 11, // small print
177
+ fill: am5.color(0xffffff), // white, over the dark background
178
+ fillOpacity: 0.6, // a little see-through
179
+ x: am5.p100, // at the chart's right edge...
180
+ centerX: am5.p100, // ...lined up by the label's own right side
181
+ y: am5.p100, // and at the bottom
182
+ centerY: am5.p100,
183
+ dx: -10, // 10px in from the edges
184
+ dy: -10
185
+ }));
186
+ ```
187
+
188
+ ## HTML
189
+
190
+ ```html
191
+ <div id="chartdiv"></div>
192
+ ```
193
+
194
+ ## CSS
195
+
196
+ ```css
197
+ #chartdiv {
198
+ width: 100%;
199
+ height: 500px;
200
+ font-size: 0.875rem;
201
+ }
202
+ ```
203
+
204
+ ## Required resources
205
+
206
+ - https://cdn.amcharts.com/lib/5/index.js
207
+ - https://cdn.amcharts.com/lib/5/map.js
208
+ - https://cdn.amcharts.com/lib/5/themes/Animated.js
209
+ - https://cdn.amcharts.com/lib/5/themes/Responsive.js