Skip to content

Commit

Permalink
[Exploratory view] use percentages in distribution chart (#103080) (#…
Browse files Browse the repository at this point in the history
…103625)

Co-authored-by: Shahzad <shahzad.muhammad@elastic.co>
  • Loading branch information
kibanamachine and shahzad31 authored Jun 29, 2021
1 parent c9aa40f commit 1339f85
Show file tree
Hide file tree
Showing 12 changed files with 447 additions and 23 deletions.
3 changes: 3 additions & 0 deletions x-pack/plugins/lens/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export type {
CounterRateIndexPatternColumn,
DerivativeIndexPatternColumn,
MovingAverageIndexPatternColumn,
FormulaIndexPatternColumn,
MathIndexPatternColumn,
OverallSumIndexPatternColumn,
} from './indexpattern_datasource/types';
export type { LensEmbeddableInput } from './editor_frame_service/embeddable';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export {
export { CountIndexPatternColumn } from './count';
export { LastValueIndexPatternColumn } from './last_value';
export { RangeIndexPatternColumn } from './ranges';
export { FormulaIndexPatternColumn, MathIndexPatternColumn } from './formula';

// List of all operation definitions registered to this data source.
// If you want to implement a new operation, add the definition to this array and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ export {
OverallMinIndexPatternColumn,
OverallMaxIndexPatternColumn,
OverallAverageIndexPatternColumn,
FormulaIndexPatternColumn,
MathIndexPatternColumn,
} from './definitions';
3 changes: 3 additions & 0 deletions x-pack/plugins/lens/public/indexpattern_datasource/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export {
CounterRateIndexPatternColumn,
DerivativeIndexPatternColumn,
MovingAverageIndexPatternColumn,
FormulaIndexPatternColumn,
MathIndexPatternColumn,
OverallSumIndexPatternColumn,
} from './operations';

export type DraggedField = DragDropIdentifier & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
export const DEFAULT_TIME = { from: 'now-1h', to: 'now' };

export const RECORDS_FIELD = 'Records';
export const RECORDS_PERCENTAGE_FIELD = 'RecordsPercentage';

export const FieldLabels: Record<string, string> = {
'user_agent.name': BROWSER_FAMILY_LABEL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,23 @@ describe('Lens Attribute', () => {
});

it('should return main y axis', function () {
expect(lnsAttr.getMainYAxis(layerConfig)).toEqual({
expect(lnsAttr.getMainYAxis(layerConfig, 'layer0', '')).toEqual({
dataType: 'number',
isBucketed: false,
label: 'Pages loaded',
operationType: 'count',
operationType: 'formula',
params: {
format: {
id: 'percent',
params: {
decimals: 0,
},
},
formula: 'count() / overall_sum(count())',
isFormulaBroken: false,
},
references: ['y-axis-column-layer0X4'],
scale: 'ratio',
sourceField: 'Records',
});
});

Expand Down Expand Up @@ -230,7 +240,15 @@ describe('Lens Attribute', () => {
it('should return first layer', function () {
expect(lnsAttr.getLayers()).toEqual({
layer0: {
columnOrder: ['x-axis-column-layer0', 'y-axis-column-layer0'],
columnOrder: [
'x-axis-column-layer0',
'y-axis-column-layer0',
'y-axis-column-layer0X0',
'y-axis-column-layer0X1',
'y-axis-column-layer0X2',
'y-axis-column-layer0X3',
'y-axis-column-layer0X4',
],
columns: {
'x-axis-column-layer0': {
dataType: 'number',
Expand All @@ -253,16 +271,98 @@ describe('Lens Attribute', () => {
},
'y-axis-column-layer0': {
dataType: 'number',
filter: {
language: 'kuery',
query:
'transaction.type: page-load and processor.event: transaction and transaction.type : *',
},
isBucketed: false,
label: 'Pages loaded',
operationType: 'formula',
params: {
format: {
id: 'percent',
params: {
decimals: 0,
},
},
formula:
"count(kql='transaction.type: page-load and processor.event: transaction and transaction.type : *') / overall_sum(count(kql='transaction.type: page-load and processor.event: transaction and transaction.type : *'))",
isFormulaBroken: false,
},
references: ['y-axis-column-layer0X4'],
scale: 'ratio',
},
'y-axis-column-layer0X0': {
customLabel: true,
dataType: 'number',
filter: {
language: 'kuery',
query:
'transaction.type: page-load and processor.event: transaction and transaction.type : *',
},
isBucketed: false,
label: 'Part of count() / overall_sum(count())',
operationType: 'count',
scale: 'ratio',
sourceField: 'Records',
},
'y-axis-column-layer0X1': {
customLabel: true,
dataType: 'number',
filter: {
language: 'kuery',
query:
'transaction.type: page-load and processor.event: transaction and transaction.type : *',
},
isBucketed: false,
label: 'Part of count() / overall_sum(count())',
operationType: 'count',
scale: 'ratio',
sourceField: 'Records',
},
'y-axis-column-layer0X2': {
customLabel: true,
dataType: 'number',
isBucketed: false,
label: 'Part of count() / overall_sum(count())',
operationType: 'math',
params: {
tinymathAst: 'y-axis-column-layer0X1',
},
references: ['y-axis-column-layer0X1'],
scale: 'ratio',
},
'y-axis-column-layer0X3': {
customLabel: true,
dataType: 'number',
isBucketed: false,
label: 'Part of count() / overall_sum(count())',
operationType: 'overall_sum',
references: ['y-axis-column-layer0X2'],
scale: 'ratio',
},
'y-axis-column-layer0X4': {
customLabel: true,
dataType: 'number',
isBucketed: false,
label: 'Part of count() / overall_sum(count())',
operationType: 'math',
params: {
tinymathAst: {
args: ['y-axis-column-layer0X0', 'y-axis-column-layer0X3'],
location: {
max: 30,
min: 0,
},
name: 'divide',
text:
"count(kql='transaction.type: page-load and processor.event: transaction and transaction.type : *') / overall_sum(count(kql='transaction.type: page-load and processor.event: transaction and transaction.type : *'))",
type: 'function',
},
},
references: ['y-axis-column-layer0X0', 'y-axis-column-layer0X3'],
scale: 'ratio',
},
},
incompleteColumns: {},
Expand Down Expand Up @@ -326,7 +426,16 @@ describe('Lens Attribute', () => {
]);

expect(lnsAttr.layers.layer0).toEqual({
columnOrder: ['x-axis-column-layer0', 'breakdown-column-layer0', 'y-axis-column-layer0'],
columnOrder: [
'x-axis-column-layer0',
'breakdown-column-layer0',
'y-axis-column-layer0',
'y-axis-column-layer0X0',
'y-axis-column-layer0X1',
'y-axis-column-layer0X2',
'y-axis-column-layer0X3',
'y-axis-column-layer0X4',
],
columns: {
'breakdown-column-layer0': {
dataType: 'string',
Expand All @@ -353,24 +462,112 @@ describe('Lens Attribute', () => {
operationType: 'range',
params: {
maxBars: 'auto',
ranges: [{ from: 0, label: '', to: 1000 }],
ranges: [
{
from: 0,
label: '',
to: 1000,
},
],
type: 'histogram',
},
scale: 'interval',
sourceField: 'transaction.duration.us',
},
'y-axis-column-layer0': {
dataType: 'number',
filter: {
language: 'kuery',
query:
'transaction.type: page-load and processor.event: transaction and transaction.type : *',
},
isBucketed: false,
label: 'Pages loaded',
operationType: 'formula',
params: {
format: {
id: 'percent',
params: {
decimals: 0,
},
},
formula:
"count(kql='transaction.type: page-load and processor.event: transaction and transaction.type : *') / overall_sum(count(kql='transaction.type: page-load and processor.event: transaction and transaction.type : *'))",
isFormulaBroken: false,
},
references: ['y-axis-column-layer0X4'],
scale: 'ratio',
},
'y-axis-column-layer0X0': {
customLabel: true,
dataType: 'number',
filter: {
language: 'kuery',
query:
'transaction.type: page-load and processor.event: transaction and transaction.type : *',
},
isBucketed: false,
label: 'Part of count() / overall_sum(count())',
operationType: 'count',
scale: 'ratio',
sourceField: 'Records',
},
'y-axis-column-layer0X1': {
customLabel: true,
dataType: 'number',
filter: {
language: 'kuery',
query:
'transaction.type: page-load and processor.event: transaction and transaction.type : *',
},
isBucketed: false,
label: 'Part of count() / overall_sum(count())',
operationType: 'count',
scale: 'ratio',
sourceField: 'Records',
},
'y-axis-column-layer0X2': {
customLabel: true,
dataType: 'number',
isBucketed: false,
label: 'Part of count() / overall_sum(count())',
operationType: 'math',
params: {
tinymathAst: 'y-axis-column-layer0X1',
},
references: ['y-axis-column-layer0X1'],
scale: 'ratio',
},
'y-axis-column-layer0X3': {
customLabel: true,
dataType: 'number',
isBucketed: false,
label: 'Part of count() / overall_sum(count())',
operationType: 'overall_sum',
references: ['y-axis-column-layer0X2'],
scale: 'ratio',
},
'y-axis-column-layer0X4': {
customLabel: true,
dataType: 'number',
isBucketed: false,
label: 'Part of count() / overall_sum(count())',
operationType: 'math',
params: {
tinymathAst: {
args: ['y-axis-column-layer0X0', 'y-axis-column-layer0X3'],
location: {
max: 30,
min: 0,
},
name: 'divide',
text:
"count(kql='transaction.type: page-load and processor.event: transaction and transaction.type : *') / overall_sum(count(kql='transaction.type: page-load and processor.event: transaction and transaction.type : *'))",
type: 'function',
},
},
references: ['y-axis-column-layer0X0', 'y-axis-column-layer0X3'],
scale: 'ratio',
},
},
incompleteColumns: {},
Expand Down
Loading

0 comments on commit 1339f85

Please sign in to comment.