-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for histogram charts to data grid columns. - Adds a toggle button to the data grid's header to enabled/disable column charts. - When enabled, the charts get rendered as part of the data grid header. - Histogram charts will get rendered for fields based on date, number, string and boolean.
- Loading branch information
Showing
24 changed files
with
996 additions
and
95 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
31 changes: 31 additions & 0 deletions
31
x-pack/plugins/ml/public/application/components/data_grid/column_chart.scss
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,31 @@ | ||
.mlDataGridChart__histogram { | ||
width: 100%; | ||
height: $euiSizeXL + $euiSizeXXL; | ||
} | ||
|
||
.mlDataGridChart__legend { | ||
@include euiTextTruncate; | ||
@include euiFontSizeXS; | ||
|
||
color: $euiColorMediumShade; | ||
display: block; | ||
overflow-x: hidden; | ||
margin: $euiSizeXS 0px 0px 0px; | ||
font-style: italic; | ||
font-weight: normal; | ||
text-align: left; | ||
} | ||
|
||
.mlDataGridChart__legend--numeric { | ||
text-align: right; | ||
} | ||
|
||
.mlDataGridChart__legendBoolean { | ||
width: 100%; | ||
td { text-align: center } | ||
} | ||
|
||
/* Override to align column header to bottom of cell when no chart is available */ | ||
.mlDataGrid .euiDataGridHeaderCell__content { | ||
margin-top: auto; | ||
} |
73 changes: 73 additions & 0 deletions
73
x-pack/plugins/ml/public/application/components/data_grid/column_chart.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,73 @@ | ||
/* | ||
* 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, { FC } from 'react'; | ||
import classNames from 'classnames'; | ||
|
||
import { BarSeries, Chart, Settings } from '@elastic/charts'; | ||
import { EuiDataGridColumn } from '@elastic/eui'; | ||
|
||
import './column_chart.scss'; | ||
|
||
import { isUnsupportedChartData, useColumnChart, ChartData } from './use_column_chart'; | ||
|
||
interface Props { | ||
chartData: ChartData; | ||
columnType: EuiDataGridColumn; | ||
dataTestSubj: string; | ||
} | ||
|
||
export const ColumnChart: FC<Props> = ({ chartData, columnType, dataTestSubj }) => { | ||
const { data, legendText, xScaleType } = useColumnChart(chartData, columnType); | ||
|
||
return ( | ||
<div data-test-subj={dataTestSubj}> | ||
{!isUnsupportedChartData(chartData) && data.length > 0 && ( | ||
<div className="mlDataGridChart__histogram" data-test-subj={`${dataTestSubj}-histogram`}> | ||
<Chart> | ||
<Settings | ||
theme={{ | ||
background: { color: 'transparent' }, | ||
chartMargins: { | ||
left: 0, | ||
right: 0, | ||
top: 0, | ||
bottom: 1, | ||
}, | ||
chartPaddings: { | ||
left: 0, | ||
right: 0, | ||
top: 0, | ||
bottom: 0, | ||
}, | ||
scales: { barsPadding: 0.1 }, | ||
}} | ||
/> | ||
<BarSeries | ||
id="histogram" | ||
name="count" | ||
xScaleType={xScaleType} | ||
yScaleType="linear" | ||
xAccessor="key" | ||
yAccessors={['doc_count']} | ||
styleAccessor={(d) => d.datum.color} | ||
data={data} | ||
/> | ||
</Chart> | ||
</div> | ||
)} | ||
<div | ||
className={classNames('mlDataGridChart__legend', { | ||
'mlDataGridChart__legend--numeric': columnType.schema === 'number', | ||
})} | ||
data-test-subj={`${dataTestSubj}-legend`} | ||
> | ||
{legendText} | ||
</div> | ||
<div data-test-subj={`${dataTestSubj}-id`}>{columnType.id}</div> | ||
</div> | ||
); | ||
}; |
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
Oops, something went wrong.