Skip to content

Commit 1ed6957

Browse files
authored
refactor: decouple tooltip from XY chart (#553)
This commit will decouple the tooltip component from the XY chart to allow Partition and other chart type an ease use. BREAKING CHANGE: the `SeriesIdentifier` type is generalized into a simplified object with two values in common: `specId` and `key`. A specialized `XYChartSeriesIdentifier` extends now the base `SeriesIdentifier`. The `SettingsSpec` prop `showLegendDisplayValue` is renamed to `showLegendExtra` and its default value is now `false` hiding the current/last value on the legend by default. close #246
1 parent 8262d19 commit 1ed6957

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+959
-849
lines changed

.playground/playground.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { Chart, ScaleType, Position, Axis, getAxisId, timeFormatter, getSpecId, AreaSeries } from '../src';
2+
import { Chart, ScaleType, Position, Axis, getAxisId, timeFormatter, getSpecId, AreaSeries, Settings } from '../src';
33
import { KIBANA_METRICS } from '../src/utils/data_samples/test_dataset_kibana';
44
export class Playground extends React.Component {
55
chartRef: React.RefObject<Chart> = React.createRef();
@@ -13,6 +13,7 @@ export class Playground extends React.Component {
1313
<>
1414
<div className="chart">
1515
<Chart className={'story-chart'}>
16+
<Settings showLegend={true} />
1617
<Axis
1718
id={getAxisId('bottom')}
1819
title={'timestamp per 1 minute'}
@@ -33,7 +34,10 @@ export class Playground extends React.Component {
3334
yScaleType={ScaleType.Linear}
3435
xAccessor={0}
3536
yAccessors={[1]}
36-
data={KIBANA_METRICS.metrics.kibana_os_load[0].data}
37+
y0Accessors={[2]}
38+
data={KIBANA_METRICS.metrics.kibana_os_load[0].data.map((d) => {
39+
return [...d, d[1] - 10];
40+
})}
3741
/>
3842
</Chart>
3943
</div>

docs/0-Intro/1-Overview.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ Return types:
233233
```ts
234234
type BarStyleAccessor = (
235235
datum: RawDataSeriesDatum,
236-
seriesIdentifier: SeriesIdentifier,
236+
seriesIdentifier: XYChartSeriesIdentifier,
237237
) => RecursivePartial<BarSeriesStyle> | Color | null;
238238
```
239239

@@ -250,7 +250,7 @@ Return types:
250250
```ts
251251
type PointStyleAccessor = (
252252
datum: RawDataSeriesDatum,
253-
seriesIdentifier: SeriesIdentifier,
253+
seriesIdentifier: XYChartSeriesIdentifier,
254254
) => RecursivePartial<PointStyle> | Color | null;
255255
```
256256

src/chart_types/partition_chart/state/chart_state.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,13 @@ export class PartitionState implements InternalChartState {
2727
getPointerCursor() {
2828
return 'default';
2929
}
30+
isTooltipVisible() {
31+
return false;
32+
}
33+
getTooltipInfo() {
34+
return undefined;
35+
}
36+
getTooltipAnchor() {
37+
return null;
38+
}
3039
}

src/chart_types/xy_chart/crosshair/crosshair_utils.test.ts

Lines changed: 41 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getFinalTooltipPosition } from './crosshair_utils';
1+
import { getFinalTooltipPosition } from '../../../components/tooltip/utils';
22

33
describe('Tooltip position', () => {
44
const container = {
@@ -19,15 +19,11 @@ describe('Tooltip position', () => {
1919
container,
2020
tooltip,
2121
{
22-
isRotatedHorizontal: true,
23-
vPosition: {
24-
bandHeight: 0,
25-
bandTop: 0,
26-
},
27-
hPosition: {
28-
bandWidth: 0,
29-
bandLeft: 10,
30-
},
22+
isRotated: false,
23+
y1: 0,
24+
y0: 0,
25+
x0: 10,
26+
x1: 10,
3127
},
3228
5,
3329
);
@@ -39,15 +35,11 @@ describe('Tooltip position', () => {
3935
container,
4036
tooltip,
4137
{
42-
isRotatedHorizontal: true,
43-
vPosition: {
44-
bandHeight: 0,
45-
bandTop: 90,
46-
},
47-
hPosition: {
48-
bandWidth: 0,
49-
bandLeft: 10,
50-
},
38+
isRotated: false,
39+
y0: 90,
40+
y1: 90,
41+
x0: 10,
42+
x1: 10,
5143
},
5244
5,
5345
);
@@ -59,15 +51,11 @@ describe('Tooltip position', () => {
5951
container,
6052
tooltip,
6153
{
62-
isRotatedHorizontal: true,
63-
vPosition: {
64-
bandHeight: 0,
65-
bandTop: 0,
66-
},
67-
hPosition: {
68-
bandWidth: 0,
69-
bandLeft: 100,
70-
},
54+
isRotated: false,
55+
y0: 0,
56+
y1: 0,
57+
x0: 100,
58+
x1: 100,
7159
},
7260
5,
7361
);
@@ -79,15 +67,11 @@ describe('Tooltip position', () => {
7967
container,
8068
tooltip,
8169
{
82-
isRotatedHorizontal: true,
83-
vPosition: {
84-
bandHeight: 0,
85-
bandTop: 90,
86-
},
87-
hPosition: {
88-
bandWidth: 0,
89-
bandLeft: 100,
90-
},
70+
isRotated: false,
71+
y0: 90,
72+
y1: 90,
73+
x0: 100,
74+
x1: 100,
9175
},
9276
5,
9377
);
@@ -101,15 +85,11 @@ describe('Tooltip position', () => {
10185
container,
10286
tooltip,
10387
{
104-
isRotatedHorizontal: false,
105-
vPosition: {
106-
bandHeight: 0,
107-
bandTop: 0,
108-
},
109-
hPosition: {
110-
bandWidth: 0,
111-
bandLeft: 10,
112-
},
88+
isRotated: true,
89+
y0: 0,
90+
y1: 0,
91+
x1: 10,
92+
x0: 10,
11393
},
11494
5,
11595
);
@@ -121,15 +101,11 @@ describe('Tooltip position', () => {
121101
container,
122102
tooltip,
123103
{
124-
isRotatedHorizontal: false,
125-
vPosition: {
126-
bandHeight: 0,
127-
bandTop: 90,
128-
},
129-
hPosition: {
130-
bandWidth: 0,
131-
bandLeft: 10,
132-
},
104+
isRotated: true,
105+
y0: 90,
106+
y1: 90,
107+
x1: 10,
108+
x0: 10,
133109
},
134110
5,
135111
);
@@ -141,15 +117,11 @@ describe('Tooltip position', () => {
141117
container,
142118
tooltip,
143119
{
144-
isRotatedHorizontal: false,
145-
vPosition: {
146-
bandHeight: 0,
147-
bandTop: 0,
148-
},
149-
hPosition: {
150-
bandWidth: 0,
151-
bandLeft: 100,
152-
},
120+
isRotated: true,
121+
y0: 0,
122+
y1: 0,
123+
x1: 100,
124+
x0: 100,
153125
},
154126
5,
155127
);
@@ -161,15 +133,11 @@ describe('Tooltip position', () => {
161133
container,
162134
tooltip,
163135
{
164-
isRotatedHorizontal: false,
165-
vPosition: {
166-
bandHeight: 0,
167-
bandTop: 90,
168-
},
169-
hPosition: {
170-
bandWidth: 0,
171-
bandLeft: 100,
172-
},
136+
isRotated: true,
137+
y0: 90,
138+
y1: 90,
139+
x1: 100,
140+
x0: 100,
173141
},
174142
5,
175143
);

0 commit comments

Comments
 (0)