Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c70ca5e
:sparkles: Make xy suggestor data type aware again
dej611 Sep 24, 2020
405c05d
:white_check_mark: Add test for numeric histogram extended suggestion
dej611 Sep 24, 2020
aa4aad1
Merge remote-tracking branch 'upstream/master' into feature/lens/inte…
dej611 Oct 6, 2020
9f33112
Merge remote-tracking branch 'upstream/master' into feature/lens/inte…
dej611 Oct 6, 2020
b328ff8
:recycle: Restore previous state
dej611 Oct 8, 2020
9265253
:sparkles: Tuning for numeric histogram
dej611 Oct 8, 2020
3eb6809
:white_mark_check: Add test for numeric histogram
dej611 Oct 8, 2020
49f7458
:fire: Remove some development cruft
dej611 Oct 8, 2020
24a2d61
Merge remote-tracking branch 'upstream/master' into feature/lens/inte…
dej611 Oct 8, 2020
ef21c11
Merge branch 'master' into feature/lens/intervals-suggestions
kibanamachine Oct 8, 2020
7614d1d
Merge remote-tracking branch 'upstream/master' into feature/lens/inte…
dej611 Oct 13, 2020
988aeec
:ok_hand: Revisit implementation to remove over time suggestion for n…
dej611 Oct 13, 2020
6f1448a
Merge branch 'feature/lens/intervals-suggestions' of github.com:dej61…
dej611 Oct 13, 2020
73ead33
Merge branch 'master' into feature/lens/intervals-suggestions
kibanamachine Oct 13, 2020
05f68da
:fire: Remove code for previous behaviour
dej611 Oct 14, 2020
eefab3b
Merge branch 'feature/lens/intervals-suggestions' of github.com:dej61…
dej611 Oct 14, 2020
ae5406f
:white_check_mark: Add custom range test case + adds better comments
dej611 Oct 15, 2020
6224b9d
Merge branch 'master' into feature/lens/intervals-suggestions
kibanamachine Oct 16, 2020
4909c52
Merge branch 'master' into feature/lens/intervals-suggestions
kibanamachine Oct 19, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,51 @@ describe('IndexPattern Data Source suggestions', () => {
);
});

it('does not create an over time suggestion if tables with numeric buckets with time dimension', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a test when the aggregation is the "Custom ranges" mode?

const initialState = testInitialState();
const state: IndexPatternPrivateState = {
...initialState,
layers: {
first: {
indexPatternId: '1',
columnOrder: ['colb', 'cola'],
columns: {
cola: {
dataType: 'number',
isBucketed: false,
sourceField: 'dest',
label: 'Unique count of dest',
operationType: 'cardinality',
},
colb: {
label: 'My Op',
dataType: 'number',
isBucketed: true,
operationType: 'range',
sourceField: 'bytes',
scale: 'interval',
params: {
type: 'histogram',
maxBars: 100,
ranges: [],
},
},
},
},
},
};

expect(getDatasourceSuggestionsFromCurrentState(state)).not.toContainEqual(
expect.objectContaining({
table: {
isMultiRow: true,
label: 'Over time',
layerId: 'first',
},
})
);
});

it('does not create an over time suggestion if there is no default time field', async () => {
const initialState = testInitialState();
const state: IndexPatternPrivateState = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@ export function getDatasourceSuggestionsFromCurrentState(
({ name }) => name === indexPattern.timeFieldName
);

const hasNumericDimension =
buckets.length === 1 &&
buckets.some((columnId) => layer.columns[columnId].dataType === 'number');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of looking for numeric operations, which can include the number range aggregation too, could you filter for any existing column.scale === 'interval'? This should allow the timestamp to be added when it's a "Custom ranges" option, which is currently not added.


const suggestions: Array<DatasourceSuggestion<IndexPatternPrivateState>> = [];
if (metrics.length === 0) {
// intermediary chart without metric, don't try to suggest reduced versions
Expand Down Expand Up @@ -482,7 +486,7 @@ export function getDatasourceSuggestionsFromCurrentState(
} else {
suggestions.push(...createSimplifiedTableSuggestions(state, layerId));

if (!timeDimension && timeField) {
if (!timeDimension && timeField && !hasNumericDimension) {
// suggest current configuration over time if there is a default time field
// and no time dimension yet
suggestions.push(createSuggestionWithDefaultDateHistogram(state, layerId, timeField));
Expand Down Expand Up @@ -653,10 +657,18 @@ function createSuggestionWithDefaultDateHistogram(
field: timeField,
suggestedPriority: undefined,
});
const shouldSwitchTimeWithBuckets = layer.columns[buckets[0]]?.dataType === 'number';

const updatedLayer = {
indexPatternId: layer.indexPatternId,
columns: { ...layer.columns, [newId]: timeColumn },
columnOrder: [...buckets, newId, ...metrics],
columns: {
...layer.columns,
[newId]: timeColumn,
},
columnOrder: shouldSwitchTimeWithBuckets
? // in this case the order is very important to assign the split accessor!
[newId, ...buckets, ...metrics]
: [...buckets, newId, ...metrics],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? If so, can you please write a test for it?

};
return buildSuggestion({
state,
Expand All @@ -665,7 +677,7 @@ function createSuggestionWithDefaultDateHistogram(
label: i18n.translate('xpack.lens.indexpattern.suggestions.overTimeLabel', {
defaultMessage: 'Over time',
}),
changeType: 'extended',
changeType: shouldSwitchTimeWithBuckets ? 'reorder' : 'extended',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This suggestion should always be extended because it should always add a new column. Calling it a reorder will affect how the XY charts use the suggestion, which I don't think is intentional.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. All the code in this function needs to be removed as it was shaped to make it work the initial way.

});
}

Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/lens/public/xy_visualization/xy_suggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ function flipSeriesType(seriesType: SeriesType) {
return 'bar_stacked';
case 'bar':
return 'bar_horizontal';
case 'bar_horizontal_stacked':
return 'bar_stacked';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right to me, why was this removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a duplicate. At line 116 there's exactly the same case.

case 'bar_horizontal_percentage_stacked':
return 'bar_percentage_stacked';
case 'bar_percentage_stacked':
Expand Down