Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-svg-worldmap

Package Overview
Dependencies
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-svg-worldmap - npm Package Compare versions

Comparing version 2.0.0-alpha.1 to 2.0.0-alpha.2

dist/components/Frame.d.ts.map

1

dist/components/Frame.d.ts

@@ -6,1 +6,2 @@ /// <reference types="react" />

export default function Frame({ color }: Props): JSX.Element | null;
//# sourceMappingURL=Frame.d.ts.map

10

dist/components/Frame.js

@@ -1,4 +0,8 @@

import React from "react";
export default function Frame({ color }) {
return (React.createElement("rect", { x: 0, y: 0, width: "100%", height: "100%", stroke: color, fill: "none" }));
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = require("react");
function Frame({ color }) {
return (react_1.default.createElement("rect", { x: 0, y: 0, width: "100%", height: "100%", stroke: color, fill: "none" }));
}
exports.default = Frame;
//# sourceMappingURL=Frame.js.map

@@ -1,8 +0,8 @@

import React from "react";
import type { ComponentProps } from "react";
export interface Props extends Omit<ComponentProps<"path">, "href"> {
strokeOpacity: string | number;
href?: ComponentProps<"a"> | string;
href?: ComponentProps<"a"> | string | undefined;
}
declare const _default: React.ForwardRefExoticComponent<Pick<Props, "string" | "filter" | "values" | "fill" | "max" | "type" | "accumulate" | "offset" | "key" | "id" | "media" | "origin" | "height" | "width" | "end" | "name" | "alignmentBaseline" | "baselineShift" | "clip" | "clipPath" | "clipRule" | "color" | "colorInterpolation" | "colorInterpolationFilters" | "cursor" | "direction" | "display" | "dominantBaseline" | "fillOpacity" | "fillRule" | "floodColor" | "floodOpacity" | "fontFamily" | "fontSize" | "fontSizeAdjust" | "fontStretch" | "fontStyle" | "fontVariant" | "fontWeight" | "imageRendering" | "letterSpacing" | "lightingColor" | "markerEnd" | "markerMid" | "markerStart" | "mask" | "opacity" | "order" | "overflow" | "paintOrder" | "pointerEvents" | "rotate" | "scale" | "shapeRendering" | "stopColor" | "stopOpacity" | "stroke" | "strokeDasharray" | "strokeDashoffset" | "strokeLinecap" | "strokeLinejoin" | "strokeMiterlimit" | "strokeOpacity" | "strokeWidth" | "textAnchor" | "textDecoration" | "textRendering" | "transform" | "unicodeBidi" | "visibility" | "wordSpacing" | "writingMode" | "alphabetic" | "hanging" | "ideographic" | "style" | "path" | "method" | "target" | "lang" | "className" | "children" | "tabIndex" | "orientation" | "local" | "x" | "y" | "mathematical" | "azimuth" | "colorRendering" | "glyphOrientationVertical" | "vectorEffect" | "additive" | "crossOrigin" | "href" | "min" | "role" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "accentHeight" | "allowReorder" | "amplitude" | "arabicForm" | "ascent" | "attributeName" | "attributeType" | "autoReverse" | "baseFrequency" | "baseProfile" | "bbox" | "begin" | "bias" | "by" | "calcMode" | "capHeight" | "clipPathUnits" | "colorProfile" | "contentScriptType" | "contentStyleType" | "cx" | "cy" | "d" | "decelerate" | "descent" | "diffuseConstant" | "divisor" | "dur" | "dx" | "dy" | "edgeMode" | "elevation" | "enableBackground" | "exponent" | "externalResourcesRequired" | "filterRes" | "filterUnits" | "focusable" | "format" | "from" | "fx" | "fy" | "g1" | "g2" | "glyphName" | "glyphOrientationHorizontal" | "glyphRef" | "gradientTransform" | "gradientUnits" | "horizAdvX" | "horizOriginX" | "in2" | "in" | "intercept" | "k1" | "k2" | "k3" | "k4" | "k" | "kernelMatrix" | "kernelUnitLength" | "kerning" | "keyPoints" | "keySplines" | "keyTimes" | "lengthAdjust" | "limitingConeAngle" | "markerHeight" | "markerUnits" | "markerWidth" | "maskContentUnits" | "maskUnits" | "mode" | "numOctaves" | "operator" | "orient" | "overlinePosition" | "overlineThickness" | "panose1" | "pathLength" | "patternContentUnits" | "patternTransform" | "patternUnits" | "points" | "pointsAtX" | "pointsAtY" | "pointsAtZ" | "preserveAlpha" | "preserveAspectRatio" | "primitiveUnits" | "r" | "radius" | "refX" | "refY" | "renderingIntent" | "repeatCount" | "repeatDur" | "requiredExtensions" | "requiredFeatures" | "restart" | "result" | "rx" | "ry" | "seed" | "slope" | "spacing" | "specularConstant" | "specularExponent" | "speed" | "spreadMethod" | "startOffset" | "stdDeviation" | "stemh" | "stemv" | "stitchTiles" | "strikethroughPosition" | "strikethroughThickness" | "surfaceScale" | "systemLanguage" | "tableValues" | "targetX" | "targetY" | "textLength" | "to" | "u1" | "u2" | "underlinePosition" | "underlineThickness" | "unicode" | "unicodeRange" | "unitsPerEm" | "vAlphabetic" | "version" | "vertAdvY" | "vertOriginX" | "vertOriginY" | "vHanging" | "vIdeographic" | "viewBox" | "viewTarget" | "vMathematical" | "widths" | "x1" | "x2" | "xChannelSelector" | "xHeight" | "xlinkActuate" | "xlinkArcrole" | "xlinkHref" | "xlinkRole" | "xlinkShow" | "xlinkTitle" | "xlinkType" | "xmlBase" | "xmlLang" | "xmlns" | "xmlnsXlink" | "xmlSpace" | "y1" | "y2" | "yChannelSelector" | "z" | "zoomAndPan" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture"> & React.RefAttributes<SVGPathElement>>;
declare const _default: any;
export default _default;
//# sourceMappingURL=Region.d.ts.map

@@ -1,3 +0,4 @@

import { __rest } from "tslib";
import React from "react";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = require("react");
function onMouseOver(strokeOpacity) {

@@ -15,9 +16,9 @@ return (event) => {

}
function Region(_a, ref) {
var { href } = _a, props = __rest(_a, ["href"]);
const path = (React.createElement("path", Object.assign({ onMouseOver: onMouseOver(Number(props.strokeOpacity)), onMouseOut: onMouseOut(Number(props.strokeOpacity)), ref: ref }, props)));
function Region({ href, ...props }, ref) {
const path = (react_1.default.createElement("path", { onMouseOver: onMouseOver(Number(props.strokeOpacity)), onMouseOut: onMouseOut(Number(props.strokeOpacity)), ref: ref, ...props }));
if (href)
return React.createElement("a", Object.assign({}, (typeof href === "string" ? { href } : href)), path);
return react_1.default.createElement("a", { ...(typeof href === "string" ? { href } : href) }, path);
return path;
}
export default React.forwardRef(Region);
exports.default = react_1.default.forwardRef(Region);
//# sourceMappingURL=Region.js.map

@@ -6,1 +6,2 @@ import type { ComponentProps } from "react";

export default function TextLabel({ label, ...props }: Props): JSX.Element;
//# sourceMappingURL=TextLabel.d.ts.map

@@ -1,6 +0,8 @@

import { __rest } from "tslib";
import React from "react";
export default function TextLabel(_a) {
var { label } = _a, props = __rest(_a, ["label"]);
return React.createElement("text", Object.assign({}, props), label);
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = require("react");
function TextLabel({ label, ...props }) {
return react_1.default.createElement("text", { ...props }, label);
}
exports.default = TextLabel;
//# sourceMappingURL=TextLabel.js.map

@@ -11,1 +11,2 @@ import type { RefObject } from "react";

export default Tooltip;
//# sourceMappingURL=Tooltip.d.ts.map

@@ -1,8 +0,12 @@

import { __rest } from "tslib";
import React from "react";
import { PathTooltip } from "react-path-tooltip";
export function Tooltip(_a) {
var { tip } = _a, props = __rest(_a, ["tip"]);
return tip ? React.createElement(PathTooltip, Object.assign({ fontSize: 12, tip: tip }, props)) : null;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Tooltip = void 0;
const react_1 = require("react");
const react_path_tooltip_1 = require("react-path-tooltip");
// TODO: need React.forwardRef to handle this
function Tooltip({ tip, ...props }) {
return tip ? react_1.default.createElement(react_path_tooltip_1.PathTooltip, { fontSize: 12, tip: tip, ...props }) : null;
}
export default Tooltip;
exports.Tooltip = Tooltip;
exports.default = Tooltip;
//# sourceMappingURL=Tooltip.js.map

@@ -7,3 +7,4 @@ import type { CSSProperties } from "react";

export declare const sizeMap: Record<SizeOption, number>;
export declare const defaultCountryStyle: (stroke: string, strokeOpacity: number) => (context: CountryContext) => CSSProperties;
export declare const defaultTooltip: (context: CountryContext) => string;
export declare const defaultCountryStyle: (stroke: string, strokeOpacity: number) => <T extends string | number>(context: CountryContext<T>) => CSSProperties;
export declare const defaultTooltip: <T extends string | number>(context: CountryContext<T>) => string;
//# sourceMappingURL=constants.d.ts.map

@@ -1,5 +0,8 @@

export const defaultSize = "xl";
export const defaultColor = "#dddddd";
export const heightRatio = 3 / 4;
export const sizeMap = {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultTooltip = exports.defaultCountryStyle = exports.sizeMap = exports.heightRatio = exports.defaultColor = exports.defaultSize = void 0;
exports.defaultSize = "xl";
exports.defaultColor = "#dddddd";
exports.heightRatio = 3 / 4;
exports.sizeMap = {
sm: 240,

@@ -11,7 +14,14 @@ md: 336,

};
export const defaultCountryStyle = (stroke, strokeOpacity) => (context) => {
const defaultCountryStyle = (stroke, strokeOpacity) => (context) => {
const { countryValue, minValue, maxValue, color } = context;
let opacityLevel = countryValue
? 0.2 + 0.6 * ((countryValue - minValue) / (maxValue - minValue))
const calculatedValue = typeof countryValue === "string"
? minValue
: // TODO bug in TS-ESLint; report this
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
countryValue;
let opacityLevel = calculatedValue !== undefined
? 0.2 + 0.6 * ((calculatedValue - minValue) / (maxValue - minValue))
: 0;
// If there's only one value, the calculation would be dividing by zero.
// We adjust it to the maximum value.
if (Number.isNaN(opacityLevel))

@@ -29,5 +39,8 @@ opacityLevel = 0.8;

};
export const defaultTooltip = (context) => {
exports.defaultCountryStyle = defaultCountryStyle;
const defaultTooltip = (context) => {
const { countryName, countryValue, prefix, suffix } = context;
return `${countryName} ${prefix} ${countryValue.toLocaleString()} ${suffix}`;
};
exports.defaultTooltip = defaultTooltip;
//# sourceMappingURL=constants.js.map

@@ -9,1 +9,2 @@ declare const _default: {

export default _default;
//# sourceMappingURL=countries.geo.d.ts.map
import type { RefObject } from "react";
export declare function drawTooltip(tip: string | undefined, tooltipBgColor: string, tooltipTextColor: string, triggerRef: RefObject<SVGElement>, containerRef: RefObject<SVGSVGElement>): JSX.Element | null;
//# sourceMappingURL=draw.d.ts.map

@@ -1,5 +0,10 @@

import React from "react";
import { PathTooltip } from "react-path-tooltip";
export function drawTooltip(tip, tooltipBgColor, tooltipTextColor, triggerRef, containerRef) {
return tip ? (React.createElement(PathTooltip, { fontSize: 12, bgColor: tooltipBgColor, textColor: tooltipTextColor, key: tip, pathRef: triggerRef, svgRef: containerRef, tip: tip })) : null;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.drawTooltip = void 0;
const react_1 = require("react");
const react_path_tooltip_1 = require("react-path-tooltip");
function drawTooltip(tip, tooltipBgColor, tooltipTextColor, triggerRef, containerRef) {
return tip ? (react_1.default.createElement(react_path_tooltip_1.PathTooltip, { fontSize: 12, bgColor: tooltipBgColor, textColor: tooltipTextColor, key: tip, pathRef: triggerRef, svgRef: containerRef, tip: tip })) : null;
}
exports.drawTooltip = drawTooltip;
//# sourceMappingURL=draw.js.map
/// <reference types="react" />
import type { Props } from "./types";
export type { ISOCode, SizeOption, DataItem, Data, CountryContext, Props, } from "./types";
export default function WorldMap(props: Props): JSX.Element;
export { WorldMap };
export default function WorldMap<T extends number | string>(props: Props<T>): JSX.Element;
declare const regions: {
name: string;
code: string;
}[];
export { WorldMap, regions };
//# sourceMappingURL=index.d.ts.map

@@ -1,27 +0,36 @@

import React, { useState, createRef } from "react";
import { geoMercator, geoPath } from "d3-geo";
import geoData from "./countries.geo";
import { defaultColor, defaultSize, heightRatio, defaultCountryStyle, defaultTooltip, } from "./constants";
import { useWindowWidth, responsify } from "./utils";
import { drawTooltip } from "./draw";
import Frame from "./components/Frame";
import Region from "./components/Region";
import TextLabel from "./components/TextLabel";
export default function WorldMap(props) {
const { data, title, valuePrefix = "", valueSuffix = "", color = defaultColor, strokeOpacity = 0.2, backgroundColor = "white", tooltipBgColor = "black", tooltipTextColor = "white", size = defaultSize, frame = false, frameColor = "black", borderColor = "black", richInteraction = false, styleFunction = defaultCountryStyle(borderColor, strokeOpacity), tooltipTextFunction = defaultTooltip, onClickFunction, hrefFunction, textLabelFunction = () => [], } = props;
const windowWidth = useWindowWidth();
const width = typeof size === "number" ? size : responsify(size, windowWidth);
const height = width * heightRatio;
const [scale, setScale] = useState(1);
const [translateX, setTranslateX] = useState(0);
const [translateY, setTranslateY] = useState(0);
const containerRef = createRef();
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.regions = exports.WorldMap = void 0;
const react_1 = require("react");
const d3_geo_1 = require("d3-geo");
const countries_geo_1 = require("./countries.geo");
const constants_1 = require("./constants");
const utils_1 = require("./utils");
const draw_1 = require("./draw");
const Frame_1 = require("./components/Frame");
const Region_1 = require("./components/Region");
const TextLabel_1 = require("./components/TextLabel");
function toValue({ value }) {
return typeof value === "string" ? 0 : value;
}
function WorldMap(props) {
const { data, title, valuePrefix = "", valueSuffix = "", color = constants_1.defaultColor, strokeOpacity = 0.2, backgroundColor = "white", tooltipBgColor = "black", tooltipTextColor = "white", size = constants_1.defaultSize, frame = false, frameColor = "black", borderColor = "black", richInteraction = false, styleFunction = (0, constants_1.defaultCountryStyle)(borderColor, strokeOpacity), tooltipTextFunction = constants_1.defaultTooltip, onClickFunction, hrefFunction, textLabelFunction = () => [], } = props;
const windowWidth = (0, utils_1.useWindowWidth)();
// Inits
const width = typeof size === "number" ? size : (0, utils_1.responsify)(size, windowWidth);
const height = width * constants_1.heightRatio;
const [scale, setScale] = (0, react_1.useState)(1);
const [translateX, setTranslateX] = (0, react_1.useState)(0);
const [translateY, setTranslateY] = (0, react_1.useState)(0);
const containerRef = (0, react_1.createRef)();
// Calc min/max values and build country map for direct access
const countryValueMap = Object.fromEntries(data.map(({ country, value }) => [country.toUpperCase(), value]));
const minValue = Math.min(...data.map(({ value }) => value));
const maxValue = Math.max(...data.map(({ value }) => value));
const projection = geoMercator();
const pathGenerator = geoPath().projection(projection);
const onClick = React.useCallback((context) => (event) => onClickFunction === null || onClickFunction === void 0 ? void 0 : onClickFunction(Object.assign(Object.assign({}, context), { event })), [onClickFunction]);
const regions = geoData.features.map((feature) => {
const triggerRef = createRef();
const minValue = Math.min(...data.map(toValue));
const maxValue = Math.max(...data.map(toValue));
// Build a path & a tooltip for each country
const projection = (0, d3_geo_1.geoMercator)();
const pathGenerator = (0, d3_geo_1.geoPath)().projection(projection);
const onClick = react_1.default.useCallback((context) => (event) => onClickFunction?.({ ...context, event }), [onClickFunction]);
const regions = countries_geo_1.default.features.map((feature) => {
const triggerRef = (0, react_1.createRef)();
const { I: isoCode, N: countryName, C: coordinates } = feature;

@@ -46,4 +55,4 @@ const geoFeature = {

};
const path = (React.createElement(Region, { ref: triggerRef, d: pathGenerator(geoFeature), style: styleFunction(context), onClick: onClick(context), strokeOpacity: strokeOpacity, href: hrefFunction === null || hrefFunction === void 0 ? void 0 : hrefFunction(context), key: countryName }));
const tooltip = drawTooltip(typeof context.countryValue === "undefined"
const path = (react_1.default.createElement(Region_1.default, { ref: triggerRef, d: pathGenerator(geoFeature), style: styleFunction(context), onClick: onClick(context), strokeOpacity: strokeOpacity, href: hrefFunction?.(context), key: countryName }));
const tooltip = (0, draw_1.drawTooltip)(typeof context.countryValue === "undefined"
? undefined

@@ -53,3 +62,5 @@ : tooltipTextFunction(context), tooltipBgColor, tooltipTextColor, triggerRef, containerRef);

});
// Build paths
const regionPaths = regions.map((entry) => entry.path);
// Build tooltips
const regionTooltips = regions.map((entry) => entry.highlightedTooltip);

@@ -77,10 +88,15 @@ const eventHandlers = {

};
return (React.createElement("figure", { className: "worldmap__figure-container", style: { backgroundColor } },
title && (React.createElement("figcaption", { className: "worldmap__figure-caption" }, title)),
React.createElement("svg", Object.assign({ ref: containerRef, height: `${height}px`, width: `${width}px` }, (richInteraction ? eventHandlers : undefined)),
frame && React.createElement(Frame, { color: frameColor }),
React.createElement("g", { transform: `translate(${translateX}, ${translateY}) scale(${(width / 960) * scale}) translate(0, 240)`, style: { transition: "all 0.2s" } }, regionPaths),
React.createElement("g", null, textLabelFunction(width).map((labelProps) => (React.createElement(TextLabel, Object.assign({}, labelProps, { key: labelProps.label }))))),
// Render the SVG
return (react_1.default.createElement("figure", { className: "worldmap__figure-container", style: { backgroundColor } },
title && (react_1.default.createElement("figcaption", { className: "worldmap__figure-caption" }, title)),
react_1.default.createElement("svg", { ref: containerRef, height: `${height}px`, width: `${width}px`, ...(richInteraction ? eventHandlers : undefined) },
frame && react_1.default.createElement(Frame_1.default, { color: frameColor }),
react_1.default.createElement("g", { transform: `translate(${translateX}, ${translateY}) scale(${(width / 960) * scale}) translate(0, 240)`, style: { transition: "all 0.2s" } }, regionPaths),
react_1.default.createElement("g", null, textLabelFunction(width).map((labelProps) => (react_1.default.createElement(TextLabel_1.default, { ...labelProps, key: labelProps.label })))),
regionTooltips)));
}
export { WorldMap };
exports.default = WorldMap;
exports.WorldMap = WorldMap;
const regions = countries_geo_1.default.features.map((g) => ({ name: g.N, code: g.I }));
exports.regions = regions;
//# sourceMappingURL=index.js.map

@@ -5,11 +5,11 @@ import type React from "react";

export declare type SizeOption = "sm" | "md" | "lg" | "xl" | "xxl";
export interface DataItem {
export interface DataItem<T extends string | number = number> {
country: ISOCode;
value: number;
value: T;
}
export declare type Data = DataItem[];
export interface CountryContext {
export declare type Data<T extends string | number = number> = DataItem<T>[];
export interface CountryContext<T extends string | number = number> {
countryCode: ISOCode;
countryName: string;
countryValue?: number;
countryValue?: T | undefined;
color: string;

@@ -21,4 +21,4 @@ minValue: number;

}
export interface Props {
data: DataItem[];
export interface Props<T extends string | number = number> {
data: DataItem<T>[];
title?: string;

@@ -37,9 +37,10 @@ valuePrefix?: string;

richInteraction?: boolean;
/** @deprecated */
type?: string;
styleFunction?: (context: CountryContext) => React.CSSProperties;
onClickFunction?: (context: CountryContext & {
styleFunction?: (context: CountryContext<T>) => React.CSSProperties;
onClickFunction?: (context: CountryContext<T> & {
event: React.MouseEvent<SVGElement, Event>;
}) => void;
tooltipTextFunction?: (context: CountryContext) => string;
hrefFunction?: (context: CountryContext) => React.ComponentProps<"a"> | string | undefined;
tooltipTextFunction?: (context: CountryContext<T>) => string;
hrefFunction?: (context: CountryContext<T>) => React.ComponentProps<"a"> | string | undefined;
textLabelFunction?: (width: number) => ({

@@ -50,1 +51,2 @@ label: string;

export {};
//# sourceMappingURL=types.d.ts.map

@@ -1,2 +0,5 @@

import geoData from "./countries.geo";
const isoCodes = geoData.features.map(({ I }) => I);
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const countries_geo_1 = require("./countries.geo");
const isoCodes = countries_geo_1.default.features.map(({ I }) => I);
//# sourceMappingURL=types.js.map
import { useLayoutEffect } from "react";
import type { SizeOption } from "./types";
/**
* This hook is like useLayoutEffect, but without the SSR warning
* It seems hacky but it's used in many React libs (Redux, Formik...)
* Also mentioned here: https://github.com/facebook/react/issues/16956
* It is useful when you need to update a ref as soon as possible after a React
* render (before `useEffect`)
*/
export declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
export declare function useWindowWidth(): number;
export declare function responsify(sizeOption: SizeOption | "responsive", windowWidth: number): number;
//# sourceMappingURL=utils.d.ts.map

@@ -1,7 +0,18 @@

import { useState, useLayoutEffect, useEffect } from "react";
import { sizeMap, defaultSize } from "./constants";
export const useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
export function useWindowWidth() {
const [width, setWidth] = useState(sizeMap[defaultSize]);
useIsomorphicLayoutEffect(() => {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.responsify = exports.useWindowWidth = exports.useIsomorphicLayoutEffect = void 0;
const react_1 = require("react");
const constants_1 = require("./constants");
/**
* This hook is like useLayoutEffect, but without the SSR warning
* It seems hacky but it's used in many React libs (Redux, Formik...)
* Also mentioned here: https://github.com/facebook/react/issues/16956
* It is useful when you need to update a ref as soon as possible after a React
* render (before `useEffect`)
*/
exports.useIsomorphicLayoutEffect = typeof window !== "undefined" ? react_1.useLayoutEffect : react_1.useEffect;
// Calculate window width
function useWindowWidth() {
const [width, setWidth] = (0, react_1.useState)(constants_1.sizeMap[constants_1.defaultSize]);
(0, exports.useIsomorphicLayoutEffect)(() => {
const updateWidth = () => {

@@ -16,15 +27,20 @@ setWidth(window.innerWidth);

}
export function responsify(sizeOption, windowWidth) {
var _a;
exports.useWindowWidth = useWindowWidth;
// Adjust responsive size
function responsify(sizeOption, windowWidth) {
if (sizeOption === "responsive") {
// Make component work in SSR
if (typeof window === "undefined")
return sizeMap[defaultSize];
return constants_1.sizeMap[constants_1.defaultSize];
return Math.min(window.innerHeight, window.innerWidth) * 0.75;
}
if (typeof window === "undefined")
return sizeMap[sizeOption];
const fittingSize = (_a = Object.values(sizeMap)
return constants_1.sizeMap[sizeOption];
// First size that fits window size
const fittingSize = Object.values(constants_1.sizeMap)
.reverse()
.find((size) => size <= windowWidth)) !== null && _a !== void 0 ? _a : sizeMap.sm;
return Math.min(fittingSize, sizeMap[sizeOption]);
.find((size) => size <= windowWidth) ?? constants_1.sizeMap.sm;
return Math.min(fittingSize, constants_1.sizeMap[sizeOption]);
}
exports.responsify = responsify;
//# sourceMappingURL=utils.js.map
{
"name": "react-svg-worldmap",
"version": "2.0.0-alpha.1",
"version": "2.0.0-alpha.2",
"license": "MIT",

@@ -21,7 +21,8 @@ "displayName": "React Worldmap",

"d3-geo": "^3.0.1",
"react-path-tooltip": "^1.0.17"
"react-path-tooltip": "^1.0.17",
"tslib": "^2.4.0"
},
"devDependencies": {
"@types/d3-geo": "^3.0.2",
"@types/geojson": "^7946.0.7"
"@types/geojson": "^7946.0.10"
},

@@ -28,0 +29,0 @@ "peerDependencies": {

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc