-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[ML] Data Grid Histograms #68359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ML] Data Grid Histograms #68359
Changes from all commits
202035a
b2f1f31
f1eb766
294eac6
4e2ef59
f3873bd
9e4423a
b571b9c
34bfb7a
072b698
6d3a878
5f7df12
50de160
6151122
53b34be
dfb6d11
4026c82
c4acf11
9364733
ebcef61
1b37d3f
3393f59
e79ca57
e270a90
17b8752
4a66f7d
c8a6980
730c8d3
510f7b6
813065d
4dadf58
90b5939
aaf6bdf
ff8903d
8364f20
fbc9221
a717964
6c6d9f7
8570a4b
eee4bfa
0deff76
1bc0bca
f9a1399
4da1352
82447ae
2f6f642
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| .mlDataGridChart__histogram { | ||
| width: 100%; | ||
| height: $euiSizeXL + $euiSizeXXL; | ||
| } | ||
|
|
||
| .mlDataGridChart__legend { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one can probably be improved a little.
Then you won't need all the overflow stuff, and can get rid of the line-heights and sizing.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the hint, fixed in 1b37d3f. |
||
| @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; | ||
| } | ||
| 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 && ( | ||
peteharverson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <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> | ||
| ); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ import React, { memo, useEffect, FC } from 'react'; | |
| import { i18n } from '@kbn/i18n'; | ||
|
|
||
| import { | ||
| EuiButtonEmpty, | ||
| EuiButtonIcon, | ||
| EuiCallOut, | ||
| EuiCodeBlock, | ||
|
|
@@ -27,6 +28,8 @@ import { INDEX_STATUS } from '../../data_frame_analytics/common'; | |
|
|
||
| import { euiDataGridStyle, euiDataGridToolbarSettings } from './common'; | ||
| import { UseIndexDataReturnType } from './types'; | ||
| // TODO Fix row hovering + bar highlighting | ||
| // import { hoveredRow$ } from './column_chart'; | ||
|
Comment on lines
+31
to
+32
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. commented code 👀
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be solved in a follow up. Originally this code was used to work with
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure it's fine to resolve in a follow-up, but with VCS there is no need in keeping the commented code 🙂 |
||
|
|
||
| export const DataGridTitle: FC<{ title: string }> = ({ title }) => ( | ||
| <EuiTitle size="xs"> | ||
|
|
@@ -54,7 +57,9 @@ type Props = PropsWithHeader | PropsWithoutHeader; | |
| export const DataGrid: FC<Props> = memo( | ||
| (props) => { | ||
| const { | ||
| columns, | ||
| chartsVisible, | ||
| chartsButtonVisible, | ||
| columnsWithCharts, | ||
| dataTestSubj, | ||
| errorMessage, | ||
| invalidSortingColumnns, | ||
|
|
@@ -70,9 +75,18 @@ export const DataGrid: FC<Props> = memo( | |
| status, | ||
| tableItems: data, | ||
| toastNotifications, | ||
| toggleChartVisibility, | ||
| visibleColumns, | ||
| } = props; | ||
|
|
||
| // TODO Fix row hovering + bar highlighting | ||
| // const getRowProps = (item: any) => { | ||
| // return { | ||
| // onMouseOver: () => hoveredRow$.next(item), | ||
| // onMouseLeave: () => hoveredRow$.next(null), | ||
| // }; | ||
| // }; | ||
|
|
||
|
Comment on lines
+82
to
+89
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. commented code |
||
| useEffect(() => { | ||
| if (invalidSortingColumnns.length > 0) { | ||
| invalidSortingColumnns.forEach((columnId) => { | ||
|
|
@@ -162,22 +176,50 @@ export const DataGrid: FC<Props> = memo( | |
| <EuiSpacer size="m" /> | ||
| </div> | ||
| )} | ||
| <EuiDataGrid | ||
| aria-label={isWithHeader(props) ? props.title : ''} | ||
| columns={columns} | ||
| columnVisibility={{ visibleColumns, setVisibleColumns }} | ||
| gridStyle={euiDataGridStyle} | ||
| rowCount={rowCount} | ||
| renderCellValue={renderCellValue} | ||
| sorting={{ columns: sortingColumns, onSort }} | ||
| toolbarVisibility={euiDataGridToolbarSettings} | ||
| pagination={{ | ||
| ...pagination, | ||
| pageSizeOptions: [5, 10, 25], | ||
| onChangeItemsPerPage, | ||
| onChangePage, | ||
| }} | ||
| /> | ||
| <div className="mlDataGrid"> | ||
| <EuiDataGrid | ||
| aria-label={isWithHeader(props) ? props.title : ''} | ||
| columns={columnsWithCharts.map((c) => { | ||
| c.initialWidth = 165; | ||
| return c; | ||
| })} | ||
| columnVisibility={{ visibleColumns, setVisibleColumns }} | ||
| gridStyle={euiDataGridStyle} | ||
| rowCount={rowCount} | ||
| renderCellValue={renderCellValue} | ||
| sorting={{ columns: sortingColumns, onSort }} | ||
| toolbarVisibility={{ | ||
| ...euiDataGridToolbarSettings, | ||
| ...(chartsButtonVisible | ||
| ? { | ||
| additionalControls: ( | ||
| <EuiButtonEmpty | ||
| aria-checked={chartsVisible} | ||
| className={`euiDataGrid__controlBtn${ | ||
| chartsVisible ? ' euiDataGrid__controlBtn--active' : '' | ||
| }`} | ||
| data-test-subj={`${dataTestSubj}HistogramButton`} | ||
| size="xs" | ||
| iconType="visBarVertical" | ||
| color="text" | ||
| onClick={toggleChartVisibility} | ||
| > | ||
| {i18n.translate('xpack.ml.dataGrid.histogramButtonText', { | ||
| defaultMessage: 'Histogram charts', | ||
| })} | ||
| </EuiButtonEmpty> | ||
| ), | ||
| } | ||
| : {}), | ||
| }} | ||
| pagination={{ | ||
| ...pagination, | ||
| pageSizeOptions: [5, 10, 25], | ||
| onChangeItemsPerPage, | ||
| onChangePage, | ||
| }} | ||
| /> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }, | ||
|
|
@@ -186,7 +228,7 @@ export const DataGrid: FC<Props> = memo( | |
|
|
||
| function pickProps(props: Props) { | ||
| return [ | ||
| props.columns, | ||
| props.columnsWithCharts, | ||
| props.dataTestSubj, | ||
| props.errorMessage, | ||
| props.invalidSortingColumnns, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.