UNPKG

@awsui/components-react

Version:

AWS UI is a collection of [React](https://reactjs.org/) components that help create intuitive, responsive, and accessible user experiences for web applications. It is developed by Amazon Web Services (AWS). This work is available under the terms of the [A

42 lines (41 loc) 2.23 kB
import React from 'react'; import clsx from 'clsx'; import styles from './styles.css.js'; function isStringData(data) { return data.length > 0 && typeof data[0].x === 'string'; } export default function BarSeries(_a) { var _b; var series = _a.series, color = _a.color, xScale = _a.xScale, yScale = _a.yScale, highlighted = _a.highlighted, dimmed = _a.dimmed, stackedBarOffsetMap = _a.stackedBarOffsetMap, totalSeriesCount = _a.totalSeriesCount, seriesIndex = _a.seriesIndex, innerHeight = _a.innerHeight, onClick = _a.onClick, onMouseOver = _a.onMouseOver, onMouseOut = _a.onMouseOut; if (series.type !== 'bar') { return null; } if (xScale.isCategorical() && yScale.isNumeric() && isStringData(series.data)) { var yContinousScale_1 = yScale.d3Scale; var barWidth_1 = xScale.d3Scale.bandwidth(); var PADDING_1 = 4; var MINWIDTH = 4; if (!stackedBarOffsetMap && totalSeriesCount > 1) { barWidth_1 = (xScale.d3Scale.bandwidth() - (totalSeriesCount - 1) * PADDING_1) / totalSeriesCount; if (barWidth_1 < MINWIDTH) { barWidth_1 = MINWIDTH; } } return (React.createElement("g", { "aria-label": series.title, style: { fill: color }, className: clsx(styles.series, styles['series--bar'], (_b = {}, _b[styles['series--highlighted']] = highlighted, _b[styles['series--dimmed']] = dimmed, _b)) }, series.data.map(function (d, i) { var yValue = d.y; var barX = xScale.d3Scale(d.x) || 0; if (stackedBarOffsetMap) { yValue = d.y + (stackedBarOffsetMap[d.x] || 0); stackedBarOffsetMap[d.x] = yValue; } else if (totalSeriesCount > 1) { barX += seriesIndex * (barWidth_1 + PADDING_1); } return (React.createElement("rect", { key: "bar-" + i, x: barX, y: yContinousScale_1(yValue), width: barWidth_1, height: innerHeight - (yContinousScale_1(d.y) || 0), onClick: onClick.bind(null, series, null), onMouseOver: onMouseOver.bind(null, series, null), onMouseOut: onMouseOut.bind(null) })); }))); } return null; }