import * as React from 'react'; import { Config, getFlowMagnitude } from './types'; import { Location } from './types'; import styled from '@emotion/styled'; import * as d3Format from 'd3-format'; import { Flow, LocationPickingInfo } from '@flowmap.gl/core'; type OuterProps = { width: number }; const Outer = styled.div( ({ width }: OuterProps) => ` font-size: 10px; width: ${width}px; display: flex; flex-direction: column; & > * + * { margin-top: 2px; } ` ); const Title = styled.div` font-weight: bold; margin-bottom: 5px; `; const Comment = styled.div` font-size: 9px; opacity: 0.3; margin-top: 0.75em; text-align: center; `; const Row = styled.div` display: flex; flex-direction: row; width: 100%; `; const Label = styled.div` display: flex; flex-grow: 1; opacity: 0.7; margin-right: 10px; `; const Value = styled.div` display: flex; flex-grow: 1; justify-content: flex-end; `; export const formatCount = d3Format.format(',.0f'); interface Props { locationInfo: LocationPickingInfo; isSelected: boolean; isSelectionEmpty: boolean; config: Config; } export const LocationTooltipContent = ({ locationInfo, isSelected, isSelectionEmpty, config, }: Props) => { const { object: location, totalIn, totalOut, totalWithin } = locationInfo; return ( {location.name || location.id} {formatCount(totalIn)} {formatCount(totalOut)} {formatCount(totalWithin)} {isSelected ? `Click to remove from selection` : isSelectionEmpty ? `Click to select this location` : `Shift+click to add to selection`} ); }; export const FlowTooltipContent = ({ flow, origin, dest, config, }: { flow: Flow; origin: Location; dest: Location; config: Config; }) => { return ( {origin.name || origin.id} → {dest.name || dest.id} {formatCount(getFlowMagnitude(flow))} ); };