Map.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import styled from "styled-components";
  2. import React, { FC } 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: FC<Props> = ({ data }) => {
  41. const [mostVisits] = data.sort((a, b) => (b.value - a.value > 0 ? 1 : -1));
  42. return (
  43. <>
  44. {world.layers.map(layer => (
  45. <Tooltip
  46. key={layer.id}
  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. <Svg
  56. xmlns="http://www.w3.org/2000/svg"
  57. aria-label="world map"
  58. viewBox={world.viewBox}
  59. >
  60. {world.layers.map(layer => (
  61. <path
  62. key={layer.id}
  63. data-tip
  64. data-for={`${layer.id}-tooltip-country`}
  65. className={`country-${Math.ceil(
  66. ((data.find(d => d.name.toLowerCase() === layer.id)?.value || 0) /
  67. mostVisits?.value || 0) * 6
  68. )}`}
  69. aria-label={layer.name}
  70. d={layer.d}
  71. />
  72. ))}
  73. </Svg>
  74. </>
  75. );
  76. };
  77. export default Map;