|
| 1 | +import {Fragment} from 'react'; |
| 2 | +import styled from '@emotion/styled'; |
| 3 | +import moment from 'moment-timezone'; |
| 4 | + |
| 5 | +import JSXNode from 'sentry/components/stories/jsxNode'; |
| 6 | +import SizingWindow from 'sentry/components/stories/sizingWindow'; |
| 7 | +import storyBook from 'sentry/stories/storyBook'; |
| 8 | +import type {DateString} from 'sentry/types/core'; |
| 9 | +import usePageFilters from 'sentry/utils/usePageFilters'; |
| 10 | + |
| 11 | +import type {TimeseriesData} from '../common/types'; |
| 12 | + |
| 13 | +import {BarChartWidget} from './barChartWidget'; |
| 14 | +import sampleLatencyTimeSeries from './sampleLatencyTimeSeries.json'; |
| 15 | +import sampleSpanDurationTimeSeries from './sampleSpanDurationTimeSeries.json'; |
| 16 | + |
| 17 | +export default storyBook(BarChartWidget, story => { |
| 18 | + story('Getting Started', () => { |
| 19 | + return ( |
| 20 | + <Fragment> |
| 21 | + <p> |
| 22 | + <JSXNode name="BarChartWidget" /> is a Dashboard Widget Component. It displays a |
| 23 | + timeseries chart with multiple timeseries, and the timeseries are stacked and |
| 24 | + discontinuous. In all other ways, it behaves like{' '} |
| 25 | + <JSXNode name="AreaChartWidget" /> |
| 26 | + </p> |
| 27 | + <p> |
| 28 | + <em>NOTE:</em> Prefer <JSXNode name="LineChartWidget" /> and{' '} |
| 29 | + <JSXNode name="AreaChartWidget" /> for timeseries visualizations! This should be |
| 30 | + used for discontinuous categorized data. |
| 31 | + </p> |
| 32 | + </Fragment> |
| 33 | + ); |
| 34 | + }); |
| 35 | + |
| 36 | + story('Visualization', () => { |
| 37 | + const {selection} = usePageFilters(); |
| 38 | + const {datetime} = selection; |
| 39 | + const {start, end} = datetime; |
| 40 | + |
| 41 | + const latencyTimeSeries = toTimeSeriesSelection( |
| 42 | + sampleLatencyTimeSeries as unknown as TimeseriesData, |
| 43 | + start, |
| 44 | + end |
| 45 | + ); |
| 46 | + |
| 47 | + const spanDurationTimeSeries = toTimeSeriesSelection( |
| 48 | + sampleSpanDurationTimeSeries as unknown as TimeseriesData, |
| 49 | + start, |
| 50 | + end |
| 51 | + ); |
| 52 | + |
| 53 | + return ( |
| 54 | + <Fragment> |
| 55 | + <p> |
| 56 | + The visualization of <JSXNode name="BarChartWidget" /> is a stacked bar chart. |
| 57 | + It has some bells and whistles including automatic axes labels, and a hover |
| 58 | + tooltip. Like other widgets, it automatically fills the parent element. |
| 59 | + </p> |
| 60 | + <SmallSizingWindow> |
| 61 | + <BarChartWidget |
| 62 | + title="Duration Breakdown" |
| 63 | + description="Explains what proportion of total duration is taken up by latency vs. span duration" |
| 64 | + timeseries={[latencyTimeSeries, spanDurationTimeSeries]} |
| 65 | + /> |
| 66 | + </SmallSizingWindow> |
| 67 | + </Fragment> |
| 68 | + ); |
| 69 | + }); |
| 70 | +}); |
| 71 | + |
| 72 | +const SmallSizingWindow = styled(SizingWindow)` |
| 73 | + width: 50%; |
| 74 | + height: 300px; |
| 75 | +`; |
| 76 | + |
| 77 | +function toTimeSeriesSelection( |
| 78 | + timeSeries: TimeseriesData, |
| 79 | + start: DateString | null, |
| 80 | + end: DateString | null |
| 81 | +): TimeseriesData { |
| 82 | + return { |
| 83 | + ...timeSeries, |
| 84 | + data: timeSeries.data.filter(datum => { |
| 85 | + if (start && moment(datum.timestamp).isBefore(moment.utc(start))) { |
| 86 | + return false; |
| 87 | + } |
| 88 | + |
| 89 | + if (end && moment(datum.timestamp).isAfter(moment.utc(end))) { |
| 90 | + return false; |
| 91 | + } |
| 92 | + |
| 93 | + return true; |
| 94 | + }), |
| 95 | + }; |
| 96 | +} |
0 commit comments