Map.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import styled from "styled-components";
  2. import React from "react";
  3. // import { VectorMap } from "@south-paw/react-vector-maps";
  4. import { Colors } from "../../consts";
  5. import Tooltip from "../Tooltip";
  6. import world from "./world.json";
  7. const Svg = styled.svg`
  8. path {
  9. fill: ${Colors.Map0};
  10. stroke: #fff;
  11. }
  12. path.country-6 {
  13. fill: ${Colors.Map06};
  14. stroke: #fff;
  15. }
  16. path.country-5 {
  17. fill: ${Colors.Map05};
  18. stroke: #fff;
  19. }
  20. path.country-4 {
  21. fill: ${Colors.Map04};
  22. stroke: #fff;
  23. }
  24. path.country-3 {
  25. fill: ${Colors.Map03};
  26. stroke: #fff;
  27. }
  28. path.country-2 {
  29. fill: ${Colors.Map02};
  30. stroke: #fff;
  31. }
  32. path.country-1 {
  33. fill: ${Colors.Map01};
  34. stroke: #fff;
  35. }
  36. `;
  37. interface Props {
  38. data: Array<{ name: string; value: number }>;
  39. }
  40. const Map = ({ data }) => {
  41. const [mostVisits] = data.sort((a, b) => (a > b ? 1 : -1));
  42. return (
  43. <>
  44. {world.layers.map(layer => (
  45. <>
  46. <Tooltip
  47. type="light"
  48. effect="float"
  49. id={`${layer.id}-tooltip-country`}
  50. >
  51. {layer.name}:{" "}
  52. {data.find(d => d.name.toLowerCase() === layer.id)?.value || 0}
  53. </Tooltip>
  54. </>
  55. ))}
  56. <Svg
  57. xmlns="http://www.w3.org/2000/svg"
  58. aria-label="world map"
  59. viewBox={world.viewBox}
  60. >
  61. {world.layers.map(layer => (
  62. <>
  63. <path
  64. data-tip
  65. data-for={`${layer.id}-tooltip-country`}
  66. className={`country-${Math.ceil(
  67. ((data.find(d => d.name.toLowerCase() === layer.id)?.value ||
  68. 0) / mostVisits?.value || 0) * 6
  69. )}`}
  70. key={layer.id}
  71. aria-label={layer.name}
  72. d={layer.d}
  73. />
  74. </>
  75. ))}
  76. </Svg>
  77. </>
  78. );
  79. };
  80. export default Map;