@amcharts/amcharts5 5.16.2 → 5.17.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.
Files changed (227) hide show
  1. package/.internal/charts/map/MapChartDefaultTheme.d.ts.map +1 -1
  2. package/.internal/charts/map/MapChartDefaultTheme.js +3 -0
  3. package/.internal/charts/map/MapChartDefaultTheme.js.map +1 -1
  4. package/.internal/charts/map/MapSankeyNodes.d.ts +155 -0
  5. package/.internal/charts/map/MapSankeyNodes.d.ts.map +1 -0
  6. package/.internal/charts/map/MapSankeyNodes.js +151 -0
  7. package/.internal/charts/map/MapSankeyNodes.js.map +1 -0
  8. package/.internal/charts/map/MapSankeySeries.d.ts +383 -0
  9. package/.internal/charts/map/MapSankeySeries.d.ts.map +1 -0
  10. package/.internal/charts/map/MapSankeySeries.js +794 -0
  11. package/.internal/charts/map/MapSankeySeries.js.map +1 -0
  12. package/.internal/core/Classes.d.ts +6 -0
  13. package/.internal/core/Classes.d.ts.map +1 -1
  14. package/.internal/core/Classes.js.map +1 -1
  15. package/.internal/core/Registry.js +1 -1
  16. package/.internal/core/Registry.js.map +1 -1
  17. package/.internal/core/util/Entity.d.ts.map +1 -1
  18. package/.internal/core/util/Entity.js +6 -0
  19. package/.internal/core/util/Entity.js.map +1 -1
  20. package/.internal/core/util/Math.d.ts +132 -49
  21. package/.internal/core/util/Math.d.ts.map +1 -1
  22. package/.internal/core/util/Math.js +151 -50
  23. package/.internal/core/util/Math.js.map +1 -1
  24. package/.internal/core/util/Object.d.ts +24 -1
  25. package/.internal/core/util/Object.d.ts.map +1 -1
  26. package/.internal/core/util/Object.js +24 -1
  27. package/.internal/core/util/Object.js.map +1 -1
  28. package/.internal/core/util/Utils.d.ts +69 -3
  29. package/.internal/core/util/Utils.d.ts.map +1 -1
  30. package/.internal/core/util/Utils.js +72 -18
  31. package/.internal/core/util/Utils.js.map +1 -1
  32. package/.internal/plugins/json/Classes-script.d.ts +6 -0
  33. package/.internal/plugins/json/Classes-script.d.ts.map +1 -1
  34. package/.internal/plugins/json/Classes-script.js +3 -0
  35. package/.internal/plugins/json/Classes-script.js.map +1 -1
  36. package/.internal/plugins/json/Classes.d.ts +6 -0
  37. package/.internal/plugins/json/Classes.d.ts.map +1 -1
  38. package/.internal/plugins/json/Classes.js +3 -0
  39. package/.internal/plugins/json/Classes.js.map +1 -1
  40. package/CHANGELOG.md +17 -8
  41. package/examples/javascript/flow-arc-horizontal/package.json +1 -1
  42. package/examples/javascript/flow-arc-vertical/package.json +1 -1
  43. package/examples/javascript/flow-chord/package.json +1 -1
  44. package/examples/javascript/flow-chord-directed/package.json +1 -1
  45. package/examples/javascript/flow-chord-non-ribbon/package.json +1 -1
  46. package/examples/javascript/flow-sankey/package.json +1 -1
  47. package/examples/javascript/gantt/package.json +1 -1
  48. package/examples/javascript/gantt-multilevel/package.json +1 -1
  49. package/examples/javascript/gantt-simple/package.json +1 -1
  50. package/examples/javascript/gauge/package.json +1 -1
  51. package/examples/javascript/gauge-bands/package.json +1 -1
  52. package/examples/javascript/hierarchy-force-directed/package.json +1 -1
  53. package/examples/javascript/hierarchy-pack/package.json +1 -1
  54. package/examples/javascript/hierarchy-partition/package.json +1 -1
  55. package/examples/javascript/hierarchy-sunburst/package.json +1 -1
  56. package/examples/javascript/hierarchy-tree/package.json +1 -1
  57. package/examples/javascript/hierarchy-treemap/package.json +1 -1
  58. package/examples/javascript/hierarchy-voronoi-treemap/package.json +1 -1
  59. package/examples/javascript/jest/package.json +1 -1
  60. package/examples/javascript/json-pie/package.json +1 -1
  61. package/examples/javascript/json-xy/package.json +1 -1
  62. package/examples/javascript/map-animating-along-lines/package.json +1 -1
  63. package/examples/javascript/map-clustered-points/package.json +1 -1
  64. package/examples/javascript/map-day-and-night/package.json +1 -1
  65. package/examples/javascript/map-globe-rotate-to-country/package.json +1 -1
  66. package/examples/javascript/map-globe-with-projected-circles/package.json +1 -1
  67. package/examples/javascript/map-sankey/README.md +6 -0
  68. package/examples/javascript/map-sankey/index.css +11 -0
  69. package/examples/javascript/map-sankey/index.html +13 -0
  70. package/examples/javascript/map-sankey/index.js +368 -0
  71. package/examples/javascript/map-sankey/package.json +17 -0
  72. package/examples/javascript/map-sankey/webpack.config.js +38 -0
  73. package/examples/javascript/map-sankey-waypoints/README.md +6 -0
  74. package/examples/javascript/map-sankey-waypoints/index.css +11 -0
  75. package/examples/javascript/map-sankey-waypoints/index.html +13 -0
  76. package/examples/javascript/map-sankey-waypoints/index.js +394 -0
  77. package/examples/javascript/map-sankey-waypoints/package.json +17 -0
  78. package/examples/javascript/map-sankey-waypoints/webpack.config.js +38 -0
  79. package/examples/javascript/map-with-bubbles/package.json +1 -1
  80. package/examples/javascript/map-zoom-to-country/package.json +1 -1
  81. package/examples/javascript/misc-40-charts/package.json +1 -1
  82. package/examples/javascript/misc-microchart-grid/package.json +1 -1
  83. package/examples/javascript/pie-chart/package.json +1 -1
  84. package/examples/javascript/pie-donut-chart/package.json +1 -1
  85. package/examples/javascript/pie-variable-radius/package.json +1 -1
  86. package/examples/javascript/radar-column-iwatch-style/package.json +1 -1
  87. package/examples/javascript/radar-heat-map/package.json +1 -1
  88. package/examples/javascript/radar-line/package.json +1 -1
  89. package/examples/javascript/radar-time-line/package.json +1 -1
  90. package/examples/javascript/sliced-funnel/package.json +1 -1
  91. package/examples/javascript/sliced-pictorial-stacked/package.json +1 -1
  92. package/examples/javascript/sliced-pyramid/package.json +1 -1
  93. package/examples/javascript/stock-chart/package.json +1 -1
  94. package/examples/javascript/stock-chart-comparing-stocks/package.json +1 -1
  95. package/examples/javascript/stock-chart-data-granularity/package.json +1 -1
  96. package/examples/javascript/stock-chart-data-grouping/package.json +1 -1
  97. package/examples/javascript/stock-chart-intraday/package.json +1 -1
  98. package/examples/javascript/stock-chart-live/package.json +1 -1
  99. package/examples/javascript/stock-chart-volume-separate-panel/package.json +1 -1
  100. package/examples/javascript/timeline-horizontal-serpentine-chart/package.json +1 -1
  101. package/examples/javascript/timeline-linear-process-diagram/package.json +1 -1
  102. package/examples/javascript/timeline-serpentine-chart/package.json +1 -1
  103. package/examples/javascript/timeline-spiral-chart/package.json +1 -1
  104. package/examples/javascript/venn-diagram/package.json +1 -1
  105. package/examples/javascript/wordcloud-with-data/package.json +1 -1
  106. package/examples/javascript/wordcloud-with-text/package.json +1 -1
  107. package/examples/javascript/xy-100-percent-stacked-column/package.json +1 -1
  108. package/examples/javascript/xy-animated-bullet-at-the-end-of-the-series/package.json +1 -1
  109. package/examples/javascript/xy-bubble/package.json +1 -1
  110. package/examples/javascript/xy-candlestick/package.json +1 -1
  111. package/examples/javascript/xy-clustered-column/package.json +1 -1
  112. package/examples/javascript/xy-column/package.json +1 -1
  113. package/examples/javascript/xy-comparing-series-google-analytics-style/package.json +1 -1
  114. package/examples/javascript/xy-data-grouping/package.json +1 -1
  115. package/examples/javascript/xy-draggable-range/package.json +1 -1
  116. package/examples/javascript/xy-drawing-series-with-mouse-or-touch/package.json +1 -1
  117. package/examples/javascript/xy-dumbbell plot/package.json +1 -1
  118. package/examples/javascript/xy-evenly-spaced-date-axis/package.json +1 -1
  119. package/examples/javascript/xy-line/package.json +1 -1
  120. package/examples/javascript/xy-line-highlight-on-legend-hover/package.json +1 -1
  121. package/examples/javascript/xy-live-data/package.json +1 -1
  122. package/examples/javascript/xy-multiple-synced-value-axes/package.json +1 -1
  123. package/examples/javascript/xy-ohlc/package.json +1 -1
  124. package/examples/javascript/xy-real-time-data-sorting/package.json +1 -1
  125. package/examples/javascript/xy-smoothed-line/package.json +1 -1
  126. package/examples/javascript/xy-stacked-and-clustered-column/package.json +1 -1
  127. package/examples/javascript/xy-stacked-column/package.json +1 -1
  128. package/examples/javascript/xy-stacked-step/package.json +1 -1
  129. package/examples/javascript/xy-stock/package.json +1 -1
  130. package/examples/javascript/xy-stock-comparing/package.json +1 -1
  131. package/examples/typescript/flow-arc-horizontal/package.json +1 -1
  132. package/examples/typescript/flow-arc-vertical/package.json +1 -1
  133. package/examples/typescript/flow-chord/package.json +1 -1
  134. package/examples/typescript/flow-chord-directed/package.json +1 -1
  135. package/examples/typescript/flow-chord-non-ribbon/package.json +1 -1
  136. package/examples/typescript/flow-sankey/package.json +1 -1
  137. package/examples/typescript/gantt/package.json +1 -1
  138. package/examples/typescript/gantt-multilevel/package.json +1 -1
  139. package/examples/typescript/gantt-simple/package.json +1 -1
  140. package/examples/typescript/gauge/package.json +1 -1
  141. package/examples/typescript/gauge-bands/package.json +1 -1
  142. package/examples/typescript/hierarchy-force-directed/package.json +1 -1
  143. package/examples/typescript/hierarchy-pack/package.json +1 -1
  144. package/examples/typescript/hierarchy-partition/package.json +1 -1
  145. package/examples/typescript/hierarchy-sunburst/package.json +1 -1
  146. package/examples/typescript/hierarchy-tree/package.json +1 -1
  147. package/examples/typescript/hierarchy-treemap/package.json +1 -1
  148. package/examples/typescript/hierarchy-voronoi-treemap/package.json +1 -1
  149. package/examples/typescript/jest/package.json +1 -1
  150. package/examples/typescript/json-pie/package.json +1 -1
  151. package/examples/typescript/json-xy/package.json +1 -1
  152. package/examples/typescript/map-animating-along-lines/package.json +1 -1
  153. package/examples/typescript/map-clustered-points/package.json +1 -1
  154. package/examples/typescript/map-day-and-night/package.json +1 -1
  155. package/examples/typescript/map-globe-rotate-to-country/package.json +1 -1
  156. package/examples/typescript/map-globe-with-projected-circles/package.json +1 -1
  157. package/examples/typescript/map-sankey/README.md +6 -0
  158. package/examples/typescript/map-sankey/index.css +11 -0
  159. package/examples/typescript/map-sankey/index.html +13 -0
  160. package/examples/typescript/map-sankey/index.ts +368 -0
  161. package/examples/typescript/map-sankey/package.json +19 -0
  162. package/examples/typescript/map-sankey/tsconfig.json +12 -0
  163. package/examples/typescript/map-sankey/webpack.config.js +45 -0
  164. package/examples/typescript/map-sankey-waypoints/README.md +6 -0
  165. package/examples/typescript/map-sankey-waypoints/index.css +11 -0
  166. package/examples/typescript/map-sankey-waypoints/index.html +13 -0
  167. package/examples/typescript/map-sankey-waypoints/index.ts +394 -0
  168. package/examples/typescript/map-sankey-waypoints/package.json +19 -0
  169. package/examples/typescript/map-sankey-waypoints/tsconfig.json +12 -0
  170. package/examples/typescript/map-sankey-waypoints/webpack.config.js +45 -0
  171. package/examples/typescript/map-with-bubbles/package.json +1 -1
  172. package/examples/typescript/map-zoom-to-country/package.json +1 -1
  173. package/examples/typescript/misc-40-charts/package.json +1 -1
  174. package/examples/typescript/misc-microchart-grid/package.json +1 -1
  175. package/examples/typescript/pie-chart/package.json +1 -1
  176. package/examples/typescript/pie-donut-chart/package.json +1 -1
  177. package/examples/typescript/pie-variable-radius/package.json +1 -1
  178. package/examples/typescript/radar-column-iwatch-style/package.json +1 -1
  179. package/examples/typescript/radar-heat-map/package.json +1 -1
  180. package/examples/typescript/radar-line/package.json +1 -1
  181. package/examples/typescript/radar-time-line/package.json +1 -1
  182. package/examples/typescript/sliced-funnel/package.json +1 -1
  183. package/examples/typescript/sliced-pictorial-stacked/package.json +1 -1
  184. package/examples/typescript/sliced-pyramid/package.json +1 -1
  185. package/examples/typescript/stock-chart/package.json +1 -1
  186. package/examples/typescript/stock-chart-comparing-stocks/package.json +1 -1
  187. package/examples/typescript/stock-chart-data-granularity/package.json +1 -1
  188. package/examples/typescript/stock-chart-data-grouping/package.json +1 -1
  189. package/examples/typescript/stock-chart-intraday/package.json +1 -1
  190. package/examples/typescript/stock-chart-live/package.json +1 -1
  191. package/examples/typescript/stock-chart-volume-separate-panel/package.json +1 -1
  192. package/examples/typescript/timeline-horizontal-serpentine-chart/package.json +1 -1
  193. package/examples/typescript/timeline-linear-process-diagram/package.json +1 -1
  194. package/examples/typescript/timeline-serpentine-chart/package.json +1 -1
  195. package/examples/typescript/timeline-spiral-chart/package.json +1 -1
  196. package/examples/typescript/venn-diagram/package.json +1 -1
  197. package/examples/typescript/wordcloud-with-data/package.json +1 -1
  198. package/examples/typescript/wordcloud-with-text/package.json +1 -1
  199. package/examples/typescript/xy-100-percent-stacked-column/package.json +1 -1
  200. package/examples/typescript/xy-animated-bullet-at-the-end-of-the-series/package.json +1 -1
  201. package/examples/typescript/xy-bubble/package.json +1 -1
  202. package/examples/typescript/xy-candlestick/package.json +1 -1
  203. package/examples/typescript/xy-clustered-column/package.json +1 -1
  204. package/examples/typescript/xy-column/package.json +1 -1
  205. package/examples/typescript/xy-comparing-series-google-analytics-style/package.json +1 -1
  206. package/examples/typescript/xy-data-grouping/package.json +1 -1
  207. package/examples/typescript/xy-draggable-range/package.json +1 -1
  208. package/examples/typescript/xy-drawing-series-with-mouse-or-touch/package.json +1 -1
  209. package/examples/typescript/xy-dumbbell plot/package.json +1 -1
  210. package/examples/typescript/xy-evenly-spaced-date-axis/package.json +1 -1
  211. package/examples/typescript/xy-line/package.json +1 -1
  212. package/examples/typescript/xy-line-highlight-on-legend-hover/package.json +1 -1
  213. package/examples/typescript/xy-live-data/package.json +1 -1
  214. package/examples/typescript/xy-multiple-synced-value-axes/package.json +1 -1
  215. package/examples/typescript/xy-ohlc/package.json +1 -1
  216. package/examples/typescript/xy-real-time-data-sorting/package.json +1 -1
  217. package/examples/typescript/xy-smoothed-line/package.json +1 -1
  218. package/examples/typescript/xy-stacked-and-clustered-column/package.json +1 -1
  219. package/examples/typescript/xy-stacked-column/package.json +1 -1
  220. package/examples/typescript/xy-stacked-step/package.json +1 -1
  221. package/examples/typescript/xy-stock/package.json +1 -1
  222. package/examples/typescript/xy-stock-comparing/package.json +1 -1
  223. package/map.d.ts +2 -0
  224. package/map.d.ts.map +1 -1
  225. package/map.js +2 -0
  226. package/map.js.map +1 -1
  227. package/package.json +1 -1
@@ -0,0 +1,368 @@
1
+ import * as am5 from "@amcharts/amcharts5";
2
+ import * as am5map from "@amcharts/amcharts5/map";
3
+ import am5geodata_worldLow from "@amcharts/amcharts5-geodata/worldLow";
4
+ import am5themes_Animated from "@amcharts/amcharts5/themes/Animated";
5
+
6
+
7
+ // Create root element
8
+ // https://www.amcharts.com/docs/v5/getting-started/#Root_element
9
+ const root = am5.Root.new("chartdiv");
10
+
11
+
12
+ // Set themes
13
+ // https://www.amcharts.com/docs/v5/concepts/themes/
14
+ const coffeeTheme = am5.Theme.new(root);
15
+ coffeeTheme.rule("InterfaceColors").setAll({
16
+ primaryButton: am5.color(0x8b5e3c),
17
+ primaryButtonHover: am5.color(0x5c3a1e),
18
+ primaryButtonDown: am5.color(0x3c1e0e),
19
+ primaryButtonActive: am5.color(0xc4956a),
20
+ primaryButtonText: am5.color(0xf5ece0),
21
+ secondaryButton: am5.color(0xe8d5b7),
22
+ secondaryButtonHover: am5.color(0xd4c4a8),
23
+ secondaryButtonDown: am5.color(0xc4956a),
24
+ secondaryButtonText: am5.color(0x3c1e0e),
25
+ background: am5.color(0xe8d5b7),
26
+ text: am5.color(0x3c1e0e)
27
+ });
28
+
29
+ root.setThemes([am5themes_Animated.new(root), coffeeTheme]);
30
+
31
+
32
+ // Grainy paper background
33
+ root.container.set("background", am5.Rectangle.new(root, {
34
+ fill: am5.color(0xf0e6d6),
35
+ fillPattern: am5.GrainPattern.new(root, {
36
+ density: 0.4,
37
+ maxOpacity: 0.07,
38
+ colors: [am5.color(0x000000)]
39
+ })
40
+ }));
41
+
42
+
43
+ // Coffee palette
44
+ const espresso = am5.color(0x3c1e0e);
45
+ const darkRoast = am5.color(0x5c3a1e);
46
+ const mediumRoast = am5.color(0x8b5e3c);
47
+ const lightRoast = am5.color(0xc4956a);
48
+ const crema = am5.color(0xe8d5b7);
49
+ const cream = am5.color(0xf5ece0);
50
+
51
+
52
+ // Create the map chart
53
+ // https://www.amcharts.com/docs/v5/charts/map-chart/
54
+ const chart = root.container.children.push(am5map.MapChart.new(root, {
55
+ panX: "rotateX",
56
+ panY: "rotateY",
57
+ projection: am5map.geoOrthographic(),
58
+ rotationX: -15,
59
+ rotationY: -20,
60
+ minZoomLevel: 0.5,
61
+ zoomLevel: 0.9
62
+ }));
63
+
64
+
65
+ // Create series for background fill
66
+ // https://www.amcharts.com/docs/v5/charts/map-chart/map-polygon-series/#Background_polygon
67
+ const bgSeries = chart.series.push(am5map.MapPolygonSeries.new(root, {}));
68
+ bgSeries.mapPolygons.template.setAll({
69
+ fill: am5.color(0xede4d4),
70
+ fillOpacity: 1,
71
+ strokeOpacity: 0
72
+ });
73
+ bgSeries.data.push({ geometry: am5map.getGeoRectangle(90, 180, -90, -180) });
74
+
75
+
76
+ // Create graticule series
77
+ // https://www.amcharts.com/docs/v5/charts/map-chart/graticule-series/
78
+ const graticuleSeries = chart.series.push(am5map.GraticuleSeries.new(root, {}));
79
+ graticuleSeries.mapLines.template.setAll({
80
+ stroke: mediumRoast,
81
+ strokeOpacity: 0.15,
82
+ strokeWidth: 0.5
83
+ });
84
+
85
+
86
+ // Create main polygon series for countries
87
+ // https://www.amcharts.com/docs/v5/charts/map-chart/map-polygon-series/
88
+ const polygonSeries = chart.series.push(am5map.MapPolygonSeries.new(root, {
89
+ geoJSON: am5geodata_worldLow
90
+ }));
91
+ polygonSeries.mapPolygons.template.setAll({
92
+ fill: cream,
93
+ stroke: lightRoast,
94
+ strokeWidth: 0.5,
95
+ strokeOpacity: 0.5
96
+ });
97
+
98
+ // Highlight producer, hub, and consumer countries
99
+ const producerIds = ["BR", "VN", "CO", "ET", "ID", "HN"];
100
+ const hubIds = ["DE", "BE", "IT", "US"];
101
+ const consumerIds = ["FR", "PL", "SE", "RU", "GB", "NL", "GR", "AT", "CA", "JP"];
102
+
103
+ polygonSeries.events.on("datavalidated", () => {
104
+ am5.array.each(polygonSeries.dataItems, (di) => {
105
+ const id = di.get("id");
106
+ if (id && producerIds.includes(id)) {
107
+ di.get("mapPolygon").setAll({ fill: am5.color(0x8fae7e) });
108
+ } else if (id && hubIds.includes(id)) {
109
+ di.get("mapPolygon").setAll({ fill: am5.color(0xc4a878) });
110
+ } else if (id && consumerIds.includes(id)) {
111
+ di.get("mapPolygon").setAll({ fill: am5.color(0xddc8a0) });
112
+ }
113
+ });
114
+ });
115
+
116
+
117
+ // Create Map Sankey series
118
+ // https://www.amcharts.com/docs/v5/charts/map-chart/map-sankey-series/
119
+ const sankeySeries = chart.series.push(am5map.MapSankeySeries.new(root, {
120
+ polygonSeries: polygonSeries,
121
+ maxWidth: 2,
122
+ controlPointDistance: 0.4,
123
+ resolution: 60,
124
+ nodePadding: 0.3
125
+ }));
126
+
127
+ sankeySeries.mapPolygons.template.setAll({
128
+ fill: mediumRoast,
129
+ fillOpacity: 0.65,
130
+ strokeOpacity: 0,
131
+ tooltipText: "{sourceNode.name} > {targetNode.name}\n{value}k tonnes"
132
+ });
133
+
134
+ sankeySeries.nodes.mapPolygons.template.setAll({
135
+ fill: espresso,
136
+ stroke: crema,
137
+ strokeWidth: 1.5,
138
+ fillOpacity: 0.95,
139
+ strokeOpacity: 1,
140
+ tooltipText: "{name}\n{sum}k tonnes"
141
+ });
142
+
143
+
144
+ // Add animated coffee bean bullets
145
+ sankeySeries.bullets.push(() => {
146
+ return am5.Bullet.new(root, {
147
+ locationX: 0,
148
+ autoRotate: true,
149
+ sprite: am5.Graphics.new(root, {
150
+ svgPath: "M-4,-2.5 C-4,-5 -1.5,-6.5 1,-6.5 C3.5,-6.5 5,-4.5 5,-2 C5,1 3,3.5 0.5,5 C-0.5,5.7 -1.5,5.7 -2.5,5 C-5,3.5 -6,1 -4,-2.5 Z M-1,-5 C-1,-1 -1,2 -0.5,4.5",
151
+ fill: espresso,
152
+ stroke: darkRoast,
153
+ strokeWidth: 0.5,
154
+ centerX: am5.p50,
155
+ centerY: am5.p50,
156
+ scale: 0.35,
157
+ visible: false
158
+ })
159
+ });
160
+ });
161
+
162
+ // Set data after polygonSeries loads (sourceId/targetId need centroid lookup)
163
+ // Producers > Processing Hubs > Consumer Markets
164
+ polygonSeries.events.once("datavalidated", () => {
165
+ sankeySeries.data.setAll([
166
+ // Producers > Hubs
167
+ { sourceId: "BR", targetId: "DE", value: 350 },
168
+ { sourceId: "BR", targetId: "US", value: 450 },
169
+ { sourceId: "BR", targetId: "IT", value: 200 },
170
+ { sourceId: "VN", targetId: "DE", value: 200 },
171
+ { sourceId: "VN", targetId: "BE", value: 150 },
172
+ { sourceId: "CO", targetId: "US", value: 250 },
173
+ { sourceId: "CO", targetId: "DE", value: 80 },
174
+ { sourceId: "ET", targetId: "DE", value: 60 },
175
+ { sourceId: "ET", targetId: "BE", value: 40 },
176
+ { sourceId: "ID", targetId: "US", value: 80 },
177
+ { sourceId: "HN", targetId: "DE", value: 60 },
178
+ { sourceId: "HN", targetId: "BE", value: 40 },
179
+
180
+ // Hubs > Consumer Markets
181
+ { sourceId: "DE", targetId: "FR", value: 150 },
182
+ { sourceId: "DE", targetId: "PL", value: 100 },
183
+ { sourceId: "DE", targetId: "SE", value: 80 },
184
+ { sourceId: "DE", targetId: "RU", value: 120 },
185
+ { sourceId: "BE", targetId: "GB", value: 100 },
186
+ { sourceId: "BE", targetId: "NL", value: 80 },
187
+ { sourceId: "IT", targetId: "GR", value: 50 },
188
+ { sourceId: "IT", targetId: "AT", value: 40 },
189
+ { sourceId: "US", targetId: "CA", value: 120 },
190
+ { sourceId: "US", targetId: "JP", value: 80 }
191
+ ]);
192
+ });
193
+
194
+
195
+ // Set country names on auto-created nodes and animate bullets
196
+ const countryNames = {
197
+ BR: "Brazil", VN: "Vietnam", CO: "Colombia", ET: "Ethiopia",
198
+ ID: "Indonesia", HN: "Honduras", DE: "Germany", BE: "Belgium",
199
+ IT: "Italy", US: "United States", FR: "France", PL: "Poland",
200
+ SE: "Sweden", RU: "Russia", GB: "United Kingdom", NL: "Netherlands",
201
+ GR: "Greece", AT: "Austria", CA: "Canada", JP: "Japan"
202
+ };
203
+
204
+ sankeySeries.events.on("datavalidated", () => {
205
+ am5.array.each(sankeySeries.nodes.dataItems, (di) => {
206
+ const id = di.get("id");
207
+ if (id && countryNames[id]) {
208
+ di.set("name", countryNames[id]);
209
+ }
210
+ });
211
+
212
+ // Defer bullet animation to next frame — bullets are not yet
213
+ // instantiated when datavalidated fires inside polygonSeries handler
214
+ setTimeout(() => {
215
+ am5.array.each(sankeySeries.dataItems, (dataItem) => {
216
+ const bullets = dataItem.bullets;
217
+ if (bullets) {
218
+ am5.array.each(bullets, (bullet) => {
219
+ var randomDur = 3000 + Math.random() * 3000;
220
+ var delay = Math.random() * randomDur;
221
+ setTimeout(() => {
222
+ const sprite = bullet.get("sprite");
223
+ if (sprite) sprite.set("visible", true);
224
+ bullet.animate({
225
+ key: "locationX",
226
+ from: 0,
227
+ to: 1,
228
+ duration: randomDur,
229
+ easing: am5.ease.linear,
230
+ loops: Infinity
231
+ });
232
+ }, delay);
233
+ });
234
+ }
235
+ });
236
+ }, 100);
237
+ });
238
+
239
+
240
+ // Add title and subtitle
241
+ const titleCont = chart.children.push(am5.Container.new(root, {
242
+ layout: root.verticalLayout,
243
+ x: am5.p50,
244
+ centerX: am5.p50,
245
+ y: am5.p100,
246
+ centerY: am5.p100,
247
+ position: "absolute",
248
+ paddingBottom: 16
249
+ }));
250
+
251
+ titleCont.children.push(am5.Label.new(root, {
252
+ text: "Global Coffee Supply Chain",
253
+ fontSize: 18,
254
+ fontWeight: "600",
255
+ fill: espresso,
256
+ x: am5.p50,
257
+ centerX: am5.p50
258
+ }));
259
+
260
+ titleCont.children.push(am5.Label.new(root, {
261
+ text: "(Thousands of tonnes)",
262
+ fontSize: 11,
263
+ fill: mediumRoast,
264
+ x: am5.p50,
265
+ centerX: am5.p50
266
+ }));
267
+
268
+
269
+ // Add Globe / Map projection toggle
270
+ const switchCont = chart.children.push(am5.Container.new(root, {
271
+ layout: root.horizontalLayout,
272
+ x: 20,
273
+ y: 40
274
+ }));
275
+
276
+ switchCont.children.push(am5.Label.new(root, {
277
+ centerY: am5.p50,
278
+ text: "Globe",
279
+ fill: espresso,
280
+ fontSize: 13
281
+ }));
282
+
283
+ const switchButton = switchCont.children.push(am5.Button.new(root, {
284
+ themeTags: ["switch"],
285
+ centerY: am5.p50,
286
+ icon: am5.Circle.new(root, {
287
+ themeTags: ["icon"]
288
+ })
289
+ }));
290
+
291
+ const easing = am5.ease.inOut(am5.ease.cubic);
292
+ const duration = 1500;
293
+ const fadeDuration = 300;
294
+
295
+ function zoomToGlobe() {
296
+ chart.set("projection", am5map.geoOrthographic());
297
+ chart.set("panX", "rotateX");
298
+ chart.set("panY", "rotateY");
299
+ chart.animate({ key: "rotationX", to: -15, duration, easing });
300
+ chart.animate({ key: "rotationY", to: -20, duration, easing });
301
+ bgSeries.mapPolygons.template.set("fillOpacity", 1);
302
+ chart.set("minZoomLevel", 0.9);
303
+ chart.animate({ key: "zoomLevel", to: 0.9, duration, easing });
304
+ }
305
+
306
+ function zoomToMap() {
307
+ chart.set("projection", am5map.geoMercator());
308
+ chart.set("panX", "translateX");
309
+ chart.set("panY", "translateY");
310
+ chart.animate({ key: "rotationX", to: 0, duration, easing });
311
+ chart.animate({ key: "rotationY", to: 0, duration, easing });
312
+ bgSeries.mapPolygons.template.set("fillOpacity", 0);
313
+ chart.set("minZoomLevel", 1);
314
+ chart.animate({ key: "zoomLevel", to: 1.7, duration, easing });
315
+ }
316
+
317
+ switchButton.on("active", () => {
318
+ chart.goHome(duration);
319
+ // Fade out before projection switch
320
+ setTimeout(() => {
321
+ chart.seriesContainer.animate({ key: "opacity", to: 0, duration: fadeDuration });
322
+ }, duration - fadeDuration);
323
+ setTimeout(() => {
324
+ if (switchButton.get("active")) {
325
+ zoomToMap();
326
+ } else {
327
+ zoomToGlobe();
328
+ }
329
+ // Fade in after projection switch
330
+ chart.seriesContainer.animate({ key: "opacity", to: 1, duration: fadeDuration });
331
+ }, duration);
332
+ });
333
+
334
+ switchCont.children.push(am5.Label.new(root, {
335
+ centerY: am5.p50,
336
+ text: "Map",
337
+ fill: espresso,
338
+ fontSize: 13
339
+ }));
340
+
341
+
342
+ // Add zoom controls
343
+ // https://www.amcharts.com/docs/v5/charts/map-chart/map-zoom/
344
+ const zoomControl = chart.set("zoomControl", am5map.ZoomControl.new(root, {}));
345
+ zoomControl.homeButton.set("visible", true);
346
+
347
+
348
+ // Auto-rotate globe until user interaction
349
+ let rotationAnimation = chart.animate({
350
+ key: "rotationX",
351
+ from: -15,
352
+ to: -15 + 360,
353
+ duration: 120000,
354
+ loops: Infinity,
355
+ easing: am5.ease.linear
356
+ });
357
+
358
+ chart.chartContainer.events.on("pointerdown", () => {
359
+ if (rotationAnimation) {
360
+ rotationAnimation.stop();
361
+ rotationAnimation = null;
362
+ }
363
+ });
364
+
365
+
366
+ // Make stuff animate on load
367
+ // https://www.amcharts.com/docs/v5/concepts/animations/#Initial_animation
368
+ chart.appear(1000, 100);
@@ -0,0 +1,17 @@
1
+ {
2
+ "private": true,
3
+ "name": "amcharts5-example-map-sankey",
4
+ "version": "0.1.0",
5
+ "devDependencies": {
6
+ "@amcharts/amcharts5": "^5.17.0",
7
+ "@amcharts/amcharts5-geodata": "^5.1.5",
8
+ "source-map-loader": "^4.0.1",
9
+ "webpack": "^5.1.3",
10
+ "webpack-cli": "^5.1.1",
11
+ "webpack-dev-server": "^4.15.0"
12
+ },
13
+ "scripts": {
14
+ "build": "webpack",
15
+ "start": "webpack serve --mode development"
16
+ }
17
+ }
@@ -0,0 +1,38 @@
1
+ var $path = require("path");
2
+
3
+ module.exports = {
4
+ mode: "production",
5
+
6
+ devtool: "source-map",
7
+
8
+ stats: "errors-warnings",
9
+
10
+ target: ["web", "es5"],
11
+
12
+ entry: {
13
+ index: "./index.js",
14
+ },
15
+
16
+ devServer: {
17
+ publicPath: "/dist/",
18
+ liveReload: true,
19
+ overlay: true,
20
+ noInfo: true,
21
+ open: true
22
+ },
23
+
24
+ output: {
25
+ path: $path.join(__dirname, "dist"),
26
+ publicPath: "dist/",
27
+ filename: "[name].js",
28
+ chunkFilename: "[name].js"
29
+ },
30
+
31
+ module: {
32
+ rules: [{
33
+ test: /.js$/,
34
+ use: ["source-map-loader"],
35
+ enforce: "pre"
36
+ }]
37
+ }
38
+ };
@@ -0,0 +1,6 @@
1
+ Steps to use
2
+ ============
3
+
4
+ 1. Run `yarn`
5
+
6
+ 2. Run `yarn start` for development, or `yarn build` for production
@@ -0,0 +1,11 @@
1
+ body {
2
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
3
+ padding: 0;
4
+ margin: 0;
5
+ background-color: #ffffff;
6
+ }
7
+
8
+ #chartdiv {
9
+ width: 100%;
10
+ height: 80vh;
11
+ }
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <title>amCharts 5 Example - map-sankey-waypoints</title>
6
+ <link rel="stylesheet" href="index.css" />
7
+ </head>
8
+ <body>
9
+ <style>body { margin: 0; padding: 0; background: #0a0e12; overflow: hidden; }</style>
10
+ <div id="chartdiv" style="width: 100%; height: 100vh; background: #0a0e12;"></div>
11
+ <script src="dist/index.js"></script>
12
+ </body>
13
+ </html>