Skip to content

Commit b7d27c5

Browse files
committed
DRY style and share it from charts plugin
1 parent 5f2f84e commit b7d27c5

9 files changed

Lines changed: 57 additions & 65 deletions

File tree

src/plugins/charts/common/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export {
3434
ColorMode,
3535
LabelRotation,
3636
defaultCountLabel,
37+
MULTILAYER_TIME_AXIS_STYLE,
3738
} from './static';
3839

3940
export { ColorSchemaParams, Labels, Style } from './types';

src/plugins/charts/common/static/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ export {
1919
} from './color_maps';
2020

2121
export { ColorMode, LabelRotation, defaultCountLabel } from './components';
22+
23+
export * from './styles';
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
export * from './multilayer_timeaxis';
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
import { Position, RecursivePartial, AxisStyle } from '@elastic/charts';
10+
11+
export const MULTILAYER_TIME_AXIS_STYLE: RecursivePartial<AxisStyle> = {
12+
tickLabel: {
13+
visible: true,
14+
padding: 0,
15+
rotation: 0,
16+
alignment: {
17+
vertical: Position.Bottom,
18+
horizontal: Position.Left,
19+
},
20+
},
21+
tickLine: {
22+
visible: true,
23+
size: 0.0001,
24+
padding: 4,
25+
},
26+
};

src/plugins/charts/public/static/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
export * from './colors';
1010
export * from './components';
1111
export * from './utils';
12+
export * from '../../common/static/styles';

src/plugins/discover/public/application/apps/main/components/chart/histogram.tsx

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ import {
2323
Settings,
2424
TooltipType,
2525
XYChartElementEvent,
26-
AxisStyle,
27-
RecursivePartial,
2826
} from '@elastic/charts';
2927
import { IUiSettingsClient } from 'kibana/public';
3028
import {
@@ -37,7 +35,7 @@ import { DataCharts$, DataChartsMessage } from '../../services/use_saved_search'
3735
import { FetchStatus } from '../../../../types';
3836
import { DiscoverServices } from '../../../../../build_services';
3937
import { useDataState } from '../../utils/use_data_state';
40-
import { LEGACY_TIME_AXIS } from '../../../../../../../charts/common';
38+
import { LEGACY_TIME_AXIS, MULTILAYER_TIME_AXIS_STYLE } from '../../../../../../../charts/common';
4139

4240
export interface DiscoverHistogramProps {
4341
savedSearchData$: DataCharts$;
@@ -184,24 +182,6 @@ export function DiscoverHistogram({
184182

185183
const useLegacyTimeAxis = uiSettings.get(LEGACY_TIME_AXIS, false);
186184

187-
const xAxisStyle: RecursivePartial<AxisStyle> = useLegacyTimeAxis
188-
? {}
189-
: {
190-
tickLine: {
191-
size: 0.0001,
192-
strokeWidth: 1,
193-
padding: 4,
194-
visible: true,
195-
},
196-
tickLabel: {
197-
padding: 0,
198-
alignment: {
199-
vertical: Position.Bottom,
200-
horizontal: Position.Left,
201-
},
202-
},
203-
};
204-
205185
return (
206186
<React.Fragment>
207187
<div className="dscHistogram" data-test-subj="discoverChart" data-time-range={timeRangeText}>
@@ -227,7 +207,7 @@ export function DiscoverHistogram({
227207
position={Position.Bottom}
228208
tickFormat={formatXValue}
229209
timeAxisLayerCount={useLegacyTimeAxis ? 0 : 2}
230-
style={xAxisStyle}
210+
style={useLegacyTimeAxis ? {} : MULTILAYER_TIME_AXIS_STYLE}
231211
/>
232212
<CurrentTime isDarkMode={isDarkMode} domainEnd={domainEnd} />
233213
<Endzones

src/plugins/vis_types/timeseries/public/application/visualizations/views/timeseries/index.js

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ import { getBaseTheme, getChartClasses } from './utils/theme';
3232
import { TOOLTIP_MODES } from '../../../../../common/enums';
3333
import { getValueOrEmpty } from '../../../../../common/empty_label';
3434
import { getSplitByTermsColor } from '../../../lib/get_split_by_terms_color';
35-
import { renderEndzoneTooltip, useActiveCursor } from '../../../../../../../charts/public';
35+
import {
36+
MULTILAYER_TIME_AXIS_STYLE,
37+
renderEndzoneTooltip,
38+
useActiveCursor,
39+
} from '../../../../../../../charts/public';
3640
import { getAxisLabelString } from '../../../components/lib/get_axis_label_string';
3741
import { calculateDomainForSeries } from './utils/series_domain_calculation';
3842

@@ -147,23 +151,6 @@ export const TimeSeries = ({
147151

148152
const shouldUseNewTimeAxis =
149153
series.some(({ stack }) => stack !== STACKED_OPTIONS.NONE) && !useLegacyTimeAxis;
150-
const xAxisStyle = shouldUseNewTimeAxis
151-
? {
152-
tickLabel: {
153-
visible: true,
154-
padding: 0,
155-
alignment: {
156-
vertical: Position.Bottom,
157-
horizontal: Position.Left,
158-
},
159-
},
160-
tickLine: {
161-
size: 0.0001,
162-
padding: 4,
163-
visible: true,
164-
},
165-
}
166-
: {};
167154

168155
return (
169156
<Chart ref={chartRef} renderer="canvas" className={classes}>
@@ -354,7 +341,7 @@ export const TimeSeries = ({
354341
title={getAxisLabelString(interval)}
355342
tickFormat={xAxisFormatter}
356343
gridLine={gridLineStyle}
357-
style={xAxisStyle}
344+
style={shouldUseNewTimeAxis ? MULTILAYER_TIME_AXIS_STYLE : undefined}
358345
timeAxisLayerCount={shouldUseNewTimeAxis ? 3 : 0}
359346
/>
360347
</Chart>

src/plugins/vis_types/xy/public/config/get_axis.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,11 @@
88

99
import { identity } from 'lodash';
1010

11-
import {
12-
AxisSpec,
13-
TickFormatter,
14-
YDomainRange,
15-
ScaleType as ECScaleType,
16-
Position,
17-
} from '@elastic/charts';
11+
import { AxisSpec, TickFormatter, YDomainRange, ScaleType as ECScaleType } from '@elastic/charts';
1812

1913
import { LabelRotation } from '../../../../charts/public';
2014
import { BUCKET_TYPES } from '../../../../data/public';
15+
import { MULTILAYER_TIMEAXIS_STYLE } from '../../../../charts/common';
2116

2217
import {
2318
Aspect,
@@ -164,18 +159,13 @@ function getAxisStyle(
164159
): AxisSpec['style'] {
165160
return isMultiLayerTimeAxis
166161
? {
162+
...MULTILAYER_TIMEAXIS_STYLE,
167163
tickLabel: {
164+
...MULTILAYER_TIMEAXIS_STYLE.tickLabel,
168165
visible: Boolean(ticks?.show),
169-
rotation: 0, // rotation is disabled on new time axis
170-
padding: 0,
171-
alignment: {
172-
vertical: Position.Bottom,
173-
horizontal: Position.Left,
174-
},
175166
},
176167
tickLine: {
177-
size: 0.0001,
178-
padding: 4,
168+
...MULTILAYER_TIMEAXIS_STYLE.tickLine,
179169
visible: Boolean(ticks?.show),
180170
},
181171
axisTitle: {
@@ -187,7 +177,7 @@ function getAxisStyle(
187177
visible: (title ?? '').trim().length > 0,
188178
},
189179
tickLabel: {
190-
visible: ticks?.show,
180+
visible: Boolean(ticks?.show),
191181
rotation: -(ticks?.rotation ?? rotationFallback),
192182
},
193183
};

x-pack/plugins/lens/public/xy_visualization/expression.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import { search } from '../../../../../src/plugins/data/public';
5454
import {
5555
ChartsPluginSetup,
5656
ChartsPluginStart,
57+
MULTILAYER_TIME_AXIS_STYLE,
5758
PaletteRegistry,
5859
SeriesLayer,
5960
useActiveCursor,
@@ -569,18 +570,13 @@ export function XYChart({
569570
};
570571
const xAxisStyle: RecursivePartial<AxisStyle> = shouldUseNewTimeAxis
571572
? {
573+
...MULTILAYER_TIME_AXIS_STYLE,
572574
tickLabel: {
575+
...MULTILAYER_TIME_AXIS_STYLE.tickLabel,
573576
visible: Boolean(tickLabelsVisibilitySettings?.x),
574-
rotation: 0, // rotation is disabled on new time axis
575-
padding: 0,
576-
alignment: {
577-
vertical: Position.Bottom,
578-
horizontal: Position.Left,
579-
},
580577
},
581578
tickLine: {
582-
size: 0.0001,
583-
padding: 4,
579+
...MULTILAYER_TIME_AXIS_STYLE.tickLine,
584580
visible: Boolean(tickLabelsVisibilitySettings?.x),
585581
},
586582
axisTitle: {

0 commit comments

Comments
 (0)