-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…37317) * move charts to separate components * replace areachart * apply custom styles * customize barchart color * customize color for areachart * move reusable functions into common * exchange x & y value in barchart dataset * replace pure component with react memo and upgrade enzyme adapter
- Loading branch information
Showing
15 changed files
with
1,060 additions
and
1,213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
x-pack/plugins/siem/public/components/charts/areachart.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { | ||
Axis, | ||
AreaSeries, | ||
Chart, | ||
getAxisId, | ||
getSpecId, | ||
Position, | ||
ScaleType, | ||
} from '@elastic/charts'; | ||
import '@elastic/charts/dist/style.css'; | ||
import { | ||
AreaChartData, | ||
ChartHolder, | ||
getSeriesStyle, | ||
numberFormatter, | ||
WrappedByAutoSizer, | ||
} from './common'; | ||
import { AutoSizer } from '../auto_sizer'; | ||
|
||
const dateFormatter = (d: string) => { | ||
return d.toLocaleString().split('T')[0]; | ||
}; | ||
|
||
const getSeriesLineStyle = (color: string | undefined) => { | ||
return color | ||
? { | ||
area: { | ||
fill: color, | ||
opacity: 0.04, | ||
visible: true, | ||
}, | ||
line: { | ||
stroke: color, | ||
strokeWidth: 1, | ||
visible: true, | ||
}, | ||
border: { | ||
visible: false, | ||
strokeWidth: 1, | ||
stroke: color, | ||
}, | ||
point: { | ||
visible: false, | ||
radius: 0.2, | ||
stroke: color, | ||
strokeWidth: 1, | ||
opacity: 1, | ||
}, | ||
} | ||
: undefined; | ||
}; | ||
|
||
export const AreaChartBaseComponent = React.memo<{ | ||
data: AreaChartData[]; | ||
width: number | null | undefined; | ||
height: number | null | undefined; | ||
}>(({ data, ...chartConfigs }) => { | ||
return chartConfigs.width && chartConfigs.height ? ( | ||
<div style={{ height: chartConfigs.height, width: chartConfigs.width, position: 'relative' }}> | ||
<Chart> | ||
{data.map(series => { | ||
const seriesKey = series.key; | ||
const seriesSpecId = getSpecId(seriesKey); | ||
return series.value != null ? ( | ||
<AreaSeries | ||
id={seriesSpecId} | ||
key={seriesKey} | ||
name={series.key.replace('Histogram', '')} | ||
data={series.value} | ||
xScaleType={ScaleType.Ordinal} | ||
yScaleType={ScaleType.Linear} | ||
xAccessor="x" | ||
yAccessors={['y']} | ||
areaSeriesStyle={getSeriesLineStyle(series.color)} | ||
customSeriesColors={getSeriesStyle(seriesKey, series.color)} | ||
/> | ||
) : null; | ||
})} | ||
|
||
<Axis | ||
id={getAxisId(`group-${data[0].key}-x`)} | ||
position={Position.Bottom} | ||
showOverlappingTicks={false} | ||
tickFormat={dateFormatter} | ||
tickSize={0} | ||
/> | ||
<Axis | ||
id={getAxisId(`group-${data[0].key}-y`)} | ||
position={Position.Left} | ||
tickSize={0} | ||
tickFormat={numberFormatter} | ||
/> | ||
</Chart> | ||
</div> | ||
) : null; | ||
}); | ||
|
||
export const AreaChartWithCustomPrompt = React.memo<{ | ||
data: AreaChartData[] | null | undefined; | ||
height: number | null | undefined; | ||
width: number | null | undefined; | ||
}>(({ data, height, width }) => { | ||
return data != null && | ||
data.length && | ||
data.every( | ||
({ value }) => | ||
value != null && | ||
value.length > 0 && | ||
value.every(chart => chart.x != null && chart.y != null) | ||
) ? ( | ||
<AreaChartBaseComponent height={height} width={width} data={data} /> | ||
) : ( | ||
<ChartHolder /> | ||
); | ||
}); | ||
|
||
export const AreaChart = React.memo<{ areaChart: AreaChartData[] | null | undefined }>( | ||
({ areaChart }) => ( | ||
<AutoSizer detectAnyWindowResize={false} content> | ||
{({ measureRef, content: { height, width } }) => ( | ||
<WrappedByAutoSizer innerRef={measureRef}> | ||
<AreaChartWithCustomPrompt data={areaChart} height={height} width={width} /> | ||
</WrappedByAutoSizer> | ||
)} | ||
</AutoSizer> | ||
) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.