@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
45 lines (44 loc) • 1.82 kB
JavaScript
import { __assign } from "tslib";
import React from 'react';
import clsx from 'clsx';
import styles from './styles.css.js';
import { line } from 'd3-shape';
export default function LineSeries(_a) {
var _b;
var series = _a.series, color = _a.color, xScale = _a.xScale, yScale = _a.yScale, highlighted = _a.highlighted, dimmed = _a.dimmed, onClick = _a.onClick, onMouseOver = _a.onMouseOver, onMouseOut = _a.onMouseOut;
if (yScale.isCategorical()) {
return null;
}
var commonProps = {
'aria-label': series.title,
stroke: color,
className: clsx(styles.series, styles["series--" + series.type], (_b = {},
_b[styles['series--highlighted']] = highlighted,
_b[styles['series--dimmed']] = dimmed,
_b)),
onClick: onClick.bind(null, series, null),
onMouseOver: onMouseOver.bind(null, series, null),
onMouseOut: onMouseOut.bind(null)
};
if (yScale.isNumeric()) {
if (series.type === 'line') {
var lineGenerator = line()
.x(function (d) {
var x = xScale.d3Scale(d.x) || 0;
if (xScale.isCategorical()) {
var offset = Math.max(0, xScale.d3Scale.bandwidth() - 1) / 2;
x += offset;
}
return x;
})
.y(function (d) { return yScale.d3Scale(d.y) || 0; });
return (React.createElement("path", __assign({}, commonProps, { d: lineGenerator(series.data) || '' })));
}
else {
var range = xScale.d3Scale.range();
var y = yScale.d3Scale(series.y);
return React.createElement("line", __assign({}, commonProps, { x1: range[0], x2: range[1], y1: y, y2: y }));
}
}
return null;
}