ChartActiveDot.js
1 month ago
ChartCrosshair.js
1 month ago
ChartTooltip.js
1 month ago
EngagementAreaChart.js
1 month ago
RetentionTooltip.js
1 month ago
chartTheme.js
1 month ago
index.js
1 month ago
RetentionTooltip.js
71 lines
| 1 | import { __ } from "@wordpress/i18n"; |
| 2 | import { |
| 3 | TOOLTIP_BG, |
| 4 | TOOLTIP_BORDER, |
| 5 | TOOLTIP_SHADOW, |
| 6 | TOOLTIP_RADIUS, |
| 7 | TOOLTIP_TEXT_PRIMARY, |
| 8 | CHART_COLOR, |
| 9 | } from "./chartTheme"; |
| 10 | import { formatHMS } from "../../utils"; |
| 11 | |
| 12 | /** |
| 13 | * Compact tooltip for the RetentionChart. |
| 14 | * Shows the video timestamp and viewer count. |
| 15 | */ |
| 16 | const RetentionTooltip = ({ active, payload, label }) => { |
| 17 | if (!active || !payload || payload.length === 0) return null; |
| 18 | |
| 19 | const value = payload[0]?.value; |
| 20 | const formattedLabel = typeof label === "number" ? formatHMS(label) : label; |
| 21 | |
| 22 | return ( |
| 23 | <div |
| 24 | style={{ |
| 25 | background: TOOLTIP_BG, |
| 26 | border: `1px solid ${TOOLTIP_BORDER}`, |
| 27 | borderRadius: `${TOOLTIP_RADIUS}px`, |
| 28 | boxShadow: TOOLTIP_SHADOW, |
| 29 | padding: "8px 12px", |
| 30 | fontVariantNumeric: "tabular-nums", |
| 31 | }} |
| 32 | > |
| 33 | {formattedLabel && ( |
| 34 | <div |
| 35 | style={{ |
| 36 | fontSize: "11px", |
| 37 | fontWeight: 400, |
| 38 | color: TOOLTIP_TEXT_PRIMARY, |
| 39 | marginBottom: "4px", |
| 40 | }} |
| 41 | > |
| 42 | {formattedLabel} |
| 43 | </div> |
| 44 | )} |
| 45 | <div style={{ display: "flex", alignItems: "center", gap: "6px" }}> |
| 46 | <span |
| 47 | style={{ |
| 48 | width: "8px", |
| 49 | height: "8px", |
| 50 | borderRadius: "50%", |
| 51 | backgroundColor: CHART_COLOR, |
| 52 | display: "inline-block", |
| 53 | }} |
| 54 | /> |
| 55 | <span |
| 56 | style={{ |
| 57 | fontSize: "12px", |
| 58 | fontWeight: 600, |
| 59 | color: TOOLTIP_TEXT_PRIMARY, |
| 60 | }} |
| 61 | > |
| 62 | {__("Viewers:", "presto-player")}{" "} |
| 63 | {typeof value === "number" ? value.toLocaleString() : value} |
| 64 | </span> |
| 65 | </div> |
| 66 | </div> |
| 67 | ); |
| 68 | }; |
| 69 | |
| 70 | export default RetentionTooltip; |
| 71 |