Skip to content
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

[charts] Fix multilayer time axis styles #116749

Merged
merged 15 commits into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"@elastic/apm-synthtrace": "link:bazel-bin/packages/elastic-apm-synthtrace",
"@elastic/apm-rum": "^5.9.1",
"@elastic/apm-rum-react": "^1.3.1",
"@elastic/charts": "38.1.0",
"@elastic/charts": "38.1.3",
"@elastic/datemath": "link:bazel-bin/packages/elastic-datemath",
"@elastic/elasticsearch": "npm:@elastic/elasticsearch-canary@^8.0.0-canary.35",
"@elastic/ems-client": "8.0.0",
Expand Down
1 change: 1 addition & 0 deletions src/plugins/charts/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export {
ColorMode,
LabelRotation,
defaultCountLabel,
MULTILAYER_TIME_AXIS_STYLE,
} from './static';

export { ColorSchemaParams, Labels, Style } from './types';
2 changes: 2 additions & 0 deletions src/plugins/charts/common/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ export {
} from './color_maps';

export { ColorMode, LabelRotation, defaultCountLabel } from './components';

export * from './styles';
9 changes: 9 additions & 0 deletions src/plugins/charts/common/static/styles/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export * from './multilayer_timeaxis';
26 changes: 26 additions & 0 deletions src/plugins/charts/common/static/styles/multilayer_timeaxis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { Position, RecursivePartial, AxisStyle } from '@elastic/charts';

export const MULTILAYER_TIME_AXIS_STYLE: RecursivePartial<AxisStyle> = {
tickLabel: {
visible: true,
padding: 0,
rotation: 0,
alignment: {
vertical: Position.Bottom,
horizontal: Position.Left,
},
},
tickLine: {
visible: true,
size: 0.0001,
padding: 4,
},
};
1 change: 1 addition & 0 deletions src/plugins/charts/public/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
export * from './colors';
export * from './components';
export * from './utils';
export * from '../../common/static/styles';
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ import {
Settings,
TooltipType,
XYChartElementEvent,
GridLineStyle,
AxisStyle,
RecursivePartial,
} from '@elastic/charts';
import { IUiSettingsClient } from 'kibana/public';
import {
Expand All @@ -38,7 +35,7 @@ import { DataCharts$, DataChartsMessage } from '../../services/use_saved_search'
import { FetchStatus } from '../../../../types';
import { DiscoverServices } from '../../../../../build_services';
import { useDataState } from '../../utils/use_data_state';
import { LEGACY_TIME_AXIS } from '../../../../../../../charts/common';
import { LEGACY_TIME_AXIS, MULTILAYER_TIME_AXIS_STYLE } from '../../../../../../../charts/common';

export interface DiscoverHistogramProps {
savedSearchData$: DataCharts$;
Expand Down Expand Up @@ -184,46 +181,6 @@ export function DiscoverHistogram({
const xAxisFormatter = services.data.fieldFormats.deserialize(chartData.yAxisFormat);

const useLegacyTimeAxis = uiSettings.get(LEGACY_TIME_AXIS, false);
const gridLineStyle: RecursivePartial<GridLineStyle> = useLegacyTimeAxis
? {}
: { strokeWidth: 0.1, stroke: isDarkMode ? 'white' : 'black' };
const verticalAxisStyle: RecursivePartial<AxisStyle> = useLegacyTimeAxis
? {}
: {
axisLine: {
visible: false,
},
tickLabel: {
fontSize: 11,
},
};
const xAxisStyle: RecursivePartial<AxisStyle> = useLegacyTimeAxis
? {}
: {
axisLine: {
stroke: isDarkMode ? 'lightgray' : 'darkgray',
strokeWidth: 1,
},
tickLine: {
size: 12,
strokeWidth: 0.15,
stroke: isDarkMode ? 'white' : 'black',
padding: -10,
visible: true,
},
tickLabel: {
fontSize: 11,
padding: 0,
alignment: {
vertical: Position.Bottom,
horizontal: Position.Left,
},
offset: {
x: 1.5,
y: 0,
},
},
};

return (
<React.Fragment>
Expand All @@ -244,16 +201,13 @@ export function DiscoverHistogram({
ticks={2}
integersOnly
tickFormat={(value) => xAxisFormatter.convert(value)}
gridLine={gridLineStyle}
style={verticalAxisStyle}
/>
<Axis
id="discover-histogram-bottom-axis"
position={Position.Bottom}
tickFormat={formatXValue}
timeAxisLayerCount={useLegacyTimeAxis ? 0 : 2}
gridLine={gridLineStyle}
style={xAxisStyle}
style={useLegacyTimeAxis ? {} : MULTILAYER_TIME_AXIS_STYLE}
/>
<CurrentTime isDarkMode={isDarkMode} domainEnd={domainEnd} />
<Endzones
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ discover-app {
}

.dscHistogram {
height: $euiSize * 8;
padding: $euiSizeS $euiSizeS $euiSizeS $euiSizeS;
height: $euiSize * 7;
padding: 0 $euiSizeS $euiSizeS * 2 $euiSizeS;
}

.dscHistogramTimeRange {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ import { getBaseTheme, getChartClasses } from './utils/theme';
import { TOOLTIP_MODES } from '../../../../../common/enums';
import { getValueOrEmpty } from '../../../../../common/empty_label';
import { getSplitByTermsColor } from '../../../lib/get_split_by_terms_color';
import { renderEndzoneTooltip, useActiveCursor } from '../../../../../../../charts/public';
import {
MULTILAYER_TIME_AXIS_STYLE,
renderEndzoneTooltip,
useActiveCursor,
} from '../../../../../../../charts/public';
import { getAxisLabelString } from '../../../components/lib/get_axis_label_string';
import { calculateDomainForSeries } from './utils/series_domain_calculation';

Expand Down Expand Up @@ -140,49 +144,15 @@ export const TimeSeries = ({
[palettesService, series, syncColors]
);

const darkMode = uiSettings.get('theme:darkMode');
const gridLineStyle = !useLegacyTimeAxis
? {
visible: showGrid,
strokeWidth: 0.1,
stroke: darkMode ? 'white' : 'black',
}
: {
...GRID_LINE_CONFIG,
visible: showGrid,
};
const xAxisStyle = !useLegacyTimeAxis
? {
tickLabel: {
visible: true,
fontSize: 11,
padding: 0,
alignment: {
vertical: Position.Bottom,
horizontal: Position.Left,
},
offset: {
x: 1.5,
y: 0,
},
},
axisLine: {
stroke: darkMode ? 'lightgray' : 'darkgray',
strokeWidth: 1,
},
tickLine: {
size: 12,
strokeWidth: 0.15,
stroke: darkMode ? 'white' : 'black',
padding: -10,
visible: true,
},
axisTitle: {
visible: true,
padding: 0,
},
}
: {};
const gridLineStyle = {
...GRID_LINE_CONFIG,
visible: showGrid,
};

const shouldUseNewTimeAxis =
series.every(
({ stack, bars, lines }) => (bars?.show && stack !== STACKED_OPTIONS.NONE) || lines?.show
) && !useLegacyTimeAxis;

return (
<Chart ref={chartRef} renderer="canvas" className={classes}>
Expand Down Expand Up @@ -361,10 +331,8 @@ export const TimeSeries = ({
position={position}
domain={domain}
hide={hide}
gridLine={{
...GRID_LINE_CONFIG,
visible: showGrid,
}}
gridLine={gridLineStyle}
ticks={5}
tickFormat={tickFormatter}
/>
))}
Expand All @@ -375,8 +343,8 @@ export const TimeSeries = ({
title={getAxisLabelString(interval)}
tickFormat={xAxisFormatter}
gridLine={gridLineStyle}
style={xAxisStyle}
timeAxisLayerCount={useLegacyTimeAxis ? 0 : 3}
style={shouldUseNewTimeAxis ? MULTILAYER_TIME_AXIS_STYLE : undefined}
timeAxisLayerCount={shouldUseNewTimeAxis ? 3 : 0}
/>
</Chart>
);
Expand Down
33 changes: 6 additions & 27 deletions src/plugins/vis_types/xy/public/config/get_axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,11 @@

import { identity } from 'lodash';

import {
AxisSpec,
TickFormatter,
YDomainRange,
ScaleType as ECScaleType,
Position,
} from '@elastic/charts';
import { AxisSpec, TickFormatter, YDomainRange, ScaleType as ECScaleType } from '@elastic/charts';

import { LabelRotation } from '../../../../charts/public';
import { BUCKET_TYPES } from '../../../../data/public';
import { MULTILAYER_TIME_AXIS_STYLE } from '../../../../charts/common';

import {
Aspect,
Expand Down Expand Up @@ -164,29 +159,13 @@ function getAxisStyle(
): AxisSpec['style'] {
return isMultiLayerTimeAxis
? {
...MULTILAYER_TIME_AXIS_STYLE,
tickLabel: {
...MULTILAYER_TIME_AXIS_STYLE.tickLabel,
visible: Boolean(ticks?.show),
rotation: 0, // rotation is disabled on new time axis
fontSize: 11,
padding: 0,
alignment: {
vertical: Position.Bottom,
horizontal: Position.Left,
},
offset: {
x: 1.5,
y: 0,
},
},
axisLine: {
stroke: darkMode ? 'lightgray' : 'darkgray',
strokeWidth: 1,
},
tickLine: {
size: 12,
strokeWidth: 0.15,
stroke: darkMode ? 'white' : 'black',
padding: -10,
...MULTILAYER_TIME_AXIS_STYLE.tickLine,
visible: Boolean(ticks?.show),
},
axisTitle: {
Expand All @@ -198,7 +177,7 @@ function getAxisStyle(
visible: (title ?? '').trim().length > 0,
},
tickLabel: {
visible: ticks?.show,
visible: Boolean(ticks?.show),
rotation: -(ticks?.rotation ?? rotationFallback),
},
};
Expand Down
Loading