import {Fragment} from 'react'; import {useTheme} from '@emotion/react'; import styled from '@emotion/styled'; import moment from 'moment-timezone'; import JSXNode from 'sentry/components/stories/jsxNode'; import SideBySide from 'sentry/components/stories/sideBySide'; import storyBook from 'sentry/stories/storyBook'; import type {DateString} from 'sentry/types/core'; import usePageFilters from 'sentry/utils/usePageFilters'; import type {TimeseriesData} from '../common/types'; import {LineChartWidget} from './lineChartWidget'; import sampleDurationTimeSeries from './sampleDurationTimeSeries.json'; import sampleThroughputTimeSeries from './sampleThroughputTimeSeries.json'; const sampleDurationTimeSeries2 = { ...sampleDurationTimeSeries, field: 'p50(span.duration)', data: sampleDurationTimeSeries.data.map(datum => { return { ...datum, value: datum.value * 0.3 + 30 * Math.random(), }; }), }; export default storyBook(LineChartWidget, story => { story('Getting Started', () => { return (

is a Dashboard Widget Component. It displays a timeseries chart with one or more timeseries. Used to visualize data that changes over time in Project Details, Dashboards, Performance, and other UIs.

); }); story('Visualization', () => { const {selection} = usePageFilters(); const {datetime} = selection; const {start, end} = datetime; const throughputTimeSeries = toTimeSeriesSelection( sampleThroughputTimeSeries as unknown as TimeseriesData, start, end ); const durationTimeSeries1 = toTimeSeriesSelection( sampleDurationTimeSeries as unknown as TimeseriesData, start, end ); const durationTimeSeries2 = toTimeSeriesSelection( sampleDurationTimeSeries2, start, end ); return (

The visualization of a line chart. It has some bells and whistles including automatic axes labels, and a hover tooltip.

The utc prop controls whether the X Axis timestamps are shown in UTC or not

); }); story('Colors', () => { const theme = useTheme(); return (

You can control the color of each timeseries by setting the color{' '} attribute to a string that contains a valid hex color code.

); }); }); const MediumWidget = styled('div')` width: 420px; `; function toTimeSeriesSelection( timeSeries: TimeseriesData, start: DateString | null, end: DateString | null ): TimeseriesData { return { ...timeSeries, data: timeSeries.data.filter(datum => { if (start && moment(datum.timestamp).isBefore(moment.utc(start))) { return false; } if (end && moment(datum.timestamp).isAfter(moment.utc(end))) { return false; } return true; }), }; }