order-details.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. $(function () {
  2. 'use strict';
  3. am4core.ready(function() {
  4. // Themes begin
  5. am4core.useTheme(am4themes_animated);
  6. // Themes end
  7. // Create map instance
  8. var chart = am4core.create("chartdiv2", am4maps.MapChart);
  9. chart.geodata = am4geodata_worldLow;
  10. chart.projection = new am4maps.projections.Miller();
  11. chart.homeZoomLevel = 2.5;
  12. chart.homeGeoPoint = {
  13. latitude: 38,
  14. longitude: -60
  15. };
  16. // Create map polygon series
  17. var polygonSeries = chart.series.push(new am4maps.MapPolygonSeries());
  18. polygonSeries.useGeodata = true;
  19. polygonSeries.mapPolygons.template.fill = chart.colors.getIndex(0).lighten(0.5);
  20. polygonSeries.mapPolygons.template.nonScalingStroke = true;
  21. polygonSeries.exclude = ["AQ"];
  22. // Add line bullets
  23. var cities = chart.series.push(new am4maps.MapImageSeries());
  24. cities.mapImages.template.nonScaling = true;
  25. var city = cities.mapImages.template.createChild(am4core.Circle);
  26. city.radius = 6;
  27. city.fill = chart.colors.getIndex(0).brighten(-0.2);
  28. city.strokeWidth = 2;
  29. city.stroke = am4core.color("#fff");
  30. function addCity(coords, title) {
  31. var city = cities.mapImages.create();
  32. city.latitude = coords.latitude;
  33. city.longitude = coords.longitude;
  34. city.tooltipText = title;
  35. return city;
  36. }
  37. var paris = addCity({ "latitude": 48.8567, "longitude": 2.3510 }, "Paris");
  38. var toronto = addCity({ "latitude": 43.8163, "longitude": -79.4287 }, "Toronto");
  39. var la = addCity({ "latitude": 34.3, "longitude": -118.15 }, "Los Angeles");
  40. var havana = addCity({ "latitude": 23, "longitude": -82 }, "Havana");
  41. // Add lines
  42. var lineSeries = chart.series.push(new am4maps.MapArcSeries());
  43. lineSeries.mapLines.template.line.strokeWidth = 2;
  44. lineSeries.mapLines.template.line.strokeOpacity = 0.5;
  45. lineSeries.mapLines.template.line.stroke = city.fill;
  46. lineSeries.mapLines.template.line.nonScalingStroke = true;
  47. lineSeries.mapLines.template.line.strokeDasharray = "1,1";
  48. lineSeries.zIndex = 10;
  49. var shadowLineSeries = chart.series.push(new am4maps.MapLineSeries());
  50. shadowLineSeries.mapLines.template.line.strokeOpacity = 0;
  51. shadowLineSeries.mapLines.template.line.nonScalingStroke = true;
  52. shadowLineSeries.mapLines.template.shortestDistance = false;
  53. shadowLineSeries.zIndex = 5;
  54. function addLine(from, to) {
  55. var line = lineSeries.mapLines.create();
  56. line.imagesToConnect = [from, to];
  57. line.line.controlPointDistance = -0.3;
  58. var shadowLine = shadowLineSeries.mapLines.create();
  59. shadowLine.imagesToConnect = [from, to];
  60. return line;
  61. }
  62. addLine(paris, toronto);
  63. addLine(toronto, la);
  64. addLine(la, havana);
  65. // Add plane
  66. var plane = lineSeries.mapLines.getIndex(0).lineObjects.create();
  67. plane.position = 0;
  68. plane.width = 48;
  69. plane.height = 48;
  70. plane.adapter.add("scale", function(scale, target) {
  71. return 0.5 * (1 - (Math.abs(0.5 - target.position)));
  72. })
  73. var planeImage = plane.createChild(am4core.Sprite);
  74. planeImage.scale = 0.08;
  75. planeImage.horizontalCenter = "middle";
  76. planeImage.verticalCenter = "middle";
  77. planeImage.path = "m2,106h28l24,30h72l-44,-133h35l80,132h98c21,0 21,34 0,34l-98,0 -80,134h-35l43,-133h-71l-24,30h-28l15,-47";
  78. planeImage.fill = chart.colors.getIndex(2).brighten(-0.2);
  79. planeImage.strokeOpacity = 0;
  80. var shadowPlane = shadowLineSeries.mapLines.getIndex(0).lineObjects.create();
  81. shadowPlane.position = 0;
  82. shadowPlane.width = 48;
  83. shadowPlane.height = 48;
  84. var shadowPlaneImage = shadowPlane.createChild(am4core.Sprite);
  85. shadowPlaneImage.scale = 0.05;
  86. shadowPlaneImage.horizontalCenter = "middle";
  87. shadowPlaneImage.verticalCenter = "middle";
  88. shadowPlaneImage.path = "m2,106h28l24,30h72l-44,-133h35l80,132h98c21,0 21,34 0,34l-98,0 -80,134h-35l43,-133h-71l-24,30h-28l15,-47";
  89. shadowPlaneImage.fill = am4core.color("#000");
  90. shadowPlaneImage.strokeOpacity = 0;
  91. shadowPlane.adapter.add("scale", function(scale, target) {
  92. target.opacity = (0.6 - (Math.abs(0.5 - target.position)));
  93. return 0.5 - 0.3 * (1 - (Math.abs(0.5 - target.position)));
  94. })
  95. // Plane animation
  96. var currentLine = 0;
  97. var direction = 1;
  98. function flyPlane() {
  99. // Get current line to attach plane to
  100. plane.mapLine = lineSeries.mapLines.getIndex(currentLine);
  101. plane.parent = lineSeries;
  102. shadowPlane.mapLine = shadowLineSeries.mapLines.getIndex(currentLine);
  103. shadowPlane.parent = shadowLineSeries;
  104. shadowPlaneImage.rotation = planeImage.rotation;
  105. // Set up animation
  106. var from, to;
  107. var numLines = lineSeries.mapLines.length;
  108. if (direction == 1) {
  109. from = 0
  110. to = 1;
  111. if (planeImage.rotation != 0) {
  112. planeImage.animate({ to: 0, property: "rotation" }, 1000).events.on("animationended", flyPlane);
  113. return;
  114. }
  115. }
  116. else {
  117. from = 1;
  118. to = 0;
  119. if (planeImage.rotation != 180) {
  120. planeImage.animate({ to: 180, property: "rotation" }, 1000).events.on("animationended", flyPlane);
  121. return;
  122. }
  123. }
  124. // Start the animation
  125. var animation = plane.animate({
  126. from: from,
  127. to: to,
  128. property: "position"
  129. }, 5000, am4core.ease.sinInOut);
  130. animation.events.on("animationended", flyPlane)
  131. /*animation.events.on("animationprogress", function(ev) {
  132. var progress = Math.abs(ev.progress - 0.5);
  133. //console.log(progress);
  134. //planeImage.scale += 0.2;
  135. });*/
  136. shadowPlane.animate({
  137. from: from,
  138. to: to,
  139. property: "position"
  140. }, 5000, am4core.ease.sinInOut);
  141. // Increment line, or reverse the direction
  142. currentLine += direction;
  143. if (currentLine < 0) {
  144. currentLine = 0;
  145. direction = 1;
  146. }
  147. else if ((currentLine + 1) > numLines) {
  148. currentLine = numLines - 1;
  149. direction = -1;
  150. }
  151. }
  152. // Go!
  153. flyPlane();
  154. }); // end am4core.ready()
  155. // bar chart
  156. $(".bar").peity("bar");
  157. }); // End of use strict