Skip to content

Commit e083755

Browse files
authored
feat: fit functions for null y1 values (#416)
Add ability to fit data of non-stacked line and area charts with a specified fit function type * add fit functions for null y1 values * allow end values to be explicitly set as fallback * add visual regression tests * add unit tests and better testing utils Note: Does not *yet* support stacked charts or `y0` values. This is a future enhancement is being tracked in #450. related to #388
1 parent f2c7bd9 commit e083755

File tree

116 files changed

+2869
-155
lines changed

Some content is hidden

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

116 files changed

+2869
-155
lines changed

.eslintrc.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ module.exports = {
5252
},
5353
],
5454
'sort-keys': 'off',
55-
'import/no-default-export': 'error',
5655
'import/no-unresolved': 'error',
5756
'no-irregular-whitespace': 'error',
5857
'no-unused-expressions': 'error',
@@ -78,7 +77,7 @@ module.exports = {
7877
},
7978
overrides: [
8079
{
81-
files: ['*.js'],
80+
files: ['*.js', '*test.ts'],
8281
rules: {
8382
'@typescript-eslint/no-var-requires': 0,
8483
},

.playground/playgroud.tsx

Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,66 @@
11
import React from 'react';
2-
import {
3-
Axis,
4-
Chart,
5-
getAxisId,
6-
getSpecId,
7-
Position,
8-
ScaleType,
9-
HistogramBarSeries,
10-
DARK_THEME,
11-
Settings,
12-
} from '../src';
13-
import { KIBANA_METRICS } from '../src/utils/data_samples/test_dataset_kibana';
2+
import { Axis, Chart, getAxisId, getSpecId, Position, ScaleType, Settings, LineSeries } from '../src';
3+
import { Fit } from '../src/chart_types/xy_chart/utils/specs';
4+
5+
const data = [
6+
{ x: 0, y: null },
7+
{ x: 1, y: 3 },
8+
{ x: 2, y: 5 },
9+
{ x: 3, y: null },
10+
{ x: 4, y: 4 },
11+
{ x: 5, y: null },
12+
{ x: 6, y: 5 },
13+
{ x: 7, y: 6 },
14+
{ x: 8, y: null },
15+
{ x: 9, y: null },
16+
{ x: 10, y: null },
17+
{ x: 11, y: 12 },
18+
{ x: 12, y: null },
19+
];
1420

1521
export class Playground extends React.Component {
1622
render() {
17-
const data = KIBANA_METRICS.metrics.kibana_os_load[0].data.slice(0, 5);
1823
return (
19-
<div className="chart">
20-
<Chart>
21-
<Settings theme={DARK_THEME} rotation={180} />
22-
<Axis id={getAxisId('x')} position={Position.Bottom} />
23-
<Axis id={getAxisId('y')} position={Position.Left} />
24-
25-
<HistogramBarSeries
26-
id={getSpecId('series bars chart')}
27-
xScaleType={ScaleType.Linear}
28-
yScaleType={ScaleType.Linear}
29-
xAccessor={0}
30-
yAccessors={[1]}
31-
data={data}
32-
yScaleToDataExtent={true}
33-
/>
34-
</Chart>
35-
</div>
24+
<>
25+
<div className="chart">
26+
<Chart className="story-chart">
27+
<Settings
28+
showLegend
29+
theme={{
30+
areaSeriesStyle: {
31+
point: {
32+
visible: true,
33+
},
34+
},
35+
}}
36+
/>
37+
<Axis
38+
id={getAxisId('bottom')}
39+
position={Position.Bottom}
40+
title={'Bottom axis'}
41+
showOverlappingTicks={true}
42+
/>
43+
<Axis id={getAxisId('left')} title={'Left axis'} position={Position.Left} />
44+
<LineSeries
45+
id={getSpecId('test')}
46+
xScaleType={ScaleType.Linear}
47+
yScaleType={ScaleType.Linear}
48+
xAccessor={'x'}
49+
yAccessors={['y']}
50+
// curve={2}
51+
// splitSeriesAccessors={['g']}
52+
// stackAccessors={['x']}
53+
fit={Fit.Linear}
54+
data={data}
55+
// fit={{
56+
// type: Fit.Average,
57+
// endValue: 0,
58+
// }}
59+
// data={data}
60+
/>
61+
</Chart>
62+
</div>
63+
</>
3664
);
3765
}
3866
}

global.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// https://github.com/jest-community/jest-extended
2+
import 'jest-extended';

integration/helpers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function requireAllStories() {
2424
function encodeString(string: string) {
2525
return string
2626
.replace(/\//gi, ' ')
27+
.replace(/-/g, ' ')
2728
.replace(/[^a-z|A-Z|0-9|\s|\/]+/gi, '')
2829
.trim()
2930
.replace(/\s+/g, '-')

integration/page_objects/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class CommonPage {
107107

108108
expect(chart).toMatchImageSnapshot();
109109
} catch (error) {
110-
throw new Error(error);
110+
throw new Error(`${error}\n\n${url}`);
111111
}
112112
}
113113
async loadChartFromURL(url: string) {

0 commit comments

Comments
 (0)