The row's product.
The variants shown for this row (already deduped by
resolveDisplayedVariants); ignored for a flattened variant row.
Recorded series keyed by series id (from getProductPriceHistory or a bulk preload).
The points to graph, or undefined when there's no drawable trend.
const points = resolveRowTrendPoints(product, displayedVariants, history);
if (points) render(<PriceSparkline points={points} />);
export function resolveRowTrendPoints(
product: Product,
displayedVariants: readonly Variant[],
history: ReadonlyMap<string, PriceHistoryEntry>,
): readonly PricePoint[] | undefined {
if (product.priceSeriesKey !== undefined) {
const points = history.get(product.priceSeriesKey)?.points;
return points !== undefined && points.length >= 2 ? points : undefined;
}
const productKey = productSeriesKey(product);
const seriesFor = (variant: Variant): PriceHistoryEntry | undefined => {
const key = variant === product ? productKey : variantSeriesKey(product, variant);
return key !== undefined ? history.get(key) : undefined;
};
const displayedSeries = displayedVariants
.map(seriesFor)
.filter((series): series is PriceHistoryEntry => series !== undefined);
const basePoints = productKey !== undefined ? history.get(productKey)?.points : undefined;
const aggregate = displayedSeries.length > 0 ? buildAggregateSeries(displayedSeries) : basePoints;
return aggregate !== undefined && aggregate.length >= 2 ? aggregate : undefined;
}
Resolve the price series a results-table row should graph, shared by the collapsed trend column and the expanded detail panel so the two never diverge. A flattened variant row (identified by its stamped Product.priceSeriesKey) graphs its own variant series; any other row graphs the mean of its displayed variants (see buildAggregateSeries), falling back to the base product series. Returns
undefinedwhen there aren't two points to draw a line.