-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[XY] Usable reference lines for
xyVis
. (#132192)
* ReferenceLineLayer -> referenceLine. * Added the referenceLine and splitted the logic at ReferenceLineAnnotations. * Fixed formatters of referenceLines * Added referenceLines keys. * Added test for the referenceLine fn. * Added some tests for reference_lines. * Unified the two different approaches of referenceLines. * Fixed types at tests and limits.
- Loading branch information
1 parent
6bdef36
commit 3982bfd
Showing
35 changed files
with
1,615 additions
and
808 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 0 additions & 25 deletions
25
...expressions/expression_xy/common/expression_functions/common_reference_line_layer_args.ts
This file was deleted.
Oops, something went wrong.
50 changes: 0 additions & 50 deletions
50
...rt_expressions/expression_xy/common/expression_functions/extended_reference_line_layer.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
...lugins/chart_expressions/expression_xy/common/expression_functions/reference_line.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { createMockExecutionContext } from '@kbn/expressions-plugin/common/mocks'; | ||
import { ReferenceLineArgs, ReferenceLineConfigResult } from '../types'; | ||
import { referenceLineFunction } from './reference_line'; | ||
|
||
describe('referenceLine', () => { | ||
test('produces the correct arguments for minimum arguments', async () => { | ||
const args: ReferenceLineArgs = { | ||
value: 100, | ||
}; | ||
|
||
const result = referenceLineFunction.fn(null, args, createMockExecutionContext()); | ||
|
||
const expectedResult: ReferenceLineConfigResult = { | ||
type: 'referenceLine', | ||
layerType: 'referenceLine', | ||
lineLength: 0, | ||
yConfig: [ | ||
{ | ||
type: 'referenceLineYConfig', | ||
...args, | ||
textVisibility: false, | ||
}, | ||
], | ||
}; | ||
expect(result).toEqual(expectedResult); | ||
}); | ||
|
||
test('produces the correct arguments for maximum arguments', async () => { | ||
const args: ReferenceLineArgs = { | ||
name: 'some value', | ||
value: 100, | ||
icon: 'alert', | ||
iconPosition: 'below', | ||
axisMode: 'bottom', | ||
lineStyle: 'solid', | ||
lineWidth: 10, | ||
color: '#fff', | ||
fill: 'below', | ||
textVisibility: true, | ||
}; | ||
|
||
const result = referenceLineFunction.fn(null, args, createMockExecutionContext()); | ||
|
||
const expectedResult: ReferenceLineConfigResult = { | ||
type: 'referenceLine', | ||
layerType: 'referenceLine', | ||
lineLength: 0, | ||
yConfig: [ | ||
{ | ||
type: 'referenceLineYConfig', | ||
...args, | ||
}, | ||
], | ||
}; | ||
expect(result).toEqual(expectedResult); | ||
}); | ||
|
||
test('adds text visibility if name is provided ', async () => { | ||
const args: ReferenceLineArgs = { | ||
name: 'some name', | ||
value: 100, | ||
}; | ||
|
||
const result = referenceLineFunction.fn(null, args, createMockExecutionContext()); | ||
|
||
const expectedResult: ReferenceLineConfigResult = { | ||
type: 'referenceLine', | ||
layerType: 'referenceLine', | ||
lineLength: 0, | ||
yConfig: [ | ||
{ | ||
type: 'referenceLineYConfig', | ||
...args, | ||
textVisibility: true, | ||
}, | ||
], | ||
}; | ||
expect(result).toEqual(expectedResult); | ||
}); | ||
|
||
test('hides text if textVisibility is true and no text is provided', async () => { | ||
const args: ReferenceLineArgs = { | ||
value: 100, | ||
textVisibility: true, | ||
}; | ||
|
||
const result = referenceLineFunction.fn(null, args, createMockExecutionContext()); | ||
|
||
const expectedResult: ReferenceLineConfigResult = { | ||
type: 'referenceLine', | ||
layerType: 'referenceLine', | ||
lineLength: 0, | ||
yConfig: [ | ||
{ | ||
type: 'referenceLineYConfig', | ||
...args, | ||
textVisibility: false, | ||
}, | ||
], | ||
}; | ||
expect(result).toEqual(expectedResult); | ||
}); | ||
|
||
test('applies text visibility if name is provided', async () => { | ||
const checktextVisibility = (textVisibility: boolean = false) => { | ||
const args: ReferenceLineArgs = { | ||
value: 100, | ||
name: 'some text', | ||
textVisibility, | ||
}; | ||
|
||
const result = referenceLineFunction.fn(null, args, createMockExecutionContext()); | ||
|
||
const expectedResult: ReferenceLineConfigResult = { | ||
type: 'referenceLine', | ||
layerType: 'referenceLine', | ||
lineLength: 0, | ||
yConfig: [ | ||
{ | ||
type: 'referenceLineYConfig', | ||
...args, | ||
textVisibility, | ||
}, | ||
], | ||
}; | ||
expect(result).toEqual(expectedResult); | ||
}; | ||
|
||
checktextVisibility(); | ||
checktextVisibility(true); | ||
}); | ||
}); |
114 changes: 114 additions & 0 deletions
114
src/plugins/chart_expressions/expression_xy/common/expression_functions/reference_line.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { | ||
AvailableReferenceLineIcons, | ||
FillStyles, | ||
IconPositions, | ||
LayerTypes, | ||
LineStyles, | ||
REFERENCE_LINE, | ||
REFERENCE_LINE_Y_CONFIG, | ||
YAxisModes, | ||
} from '../constants'; | ||
import { ReferenceLineFn } from '../types'; | ||
import { strings } from '../i18n'; | ||
|
||
export const referenceLineFunction: ReferenceLineFn = { | ||
name: REFERENCE_LINE, | ||
aliases: [], | ||
type: REFERENCE_LINE, | ||
help: strings.getRLHelp(), | ||
inputTypes: ['datatable', 'null'], | ||
args: { | ||
name: { | ||
types: ['string'], | ||
help: strings.getReferenceLineNameHelp(), | ||
}, | ||
value: { | ||
types: ['number'], | ||
help: strings.getReferenceLineValueHelp(), | ||
required: true, | ||
}, | ||
axisMode: { | ||
types: ['string'], | ||
options: [...Object.values(YAxisModes)], | ||
help: strings.getAxisModeHelp(), | ||
default: YAxisModes.AUTO, | ||
strict: true, | ||
}, | ||
color: { | ||
types: ['string'], | ||
help: strings.getColorHelp(), | ||
}, | ||
lineStyle: { | ||
types: ['string'], | ||
options: [...Object.values(LineStyles)], | ||
help: i18n.translate('expressionXY.yConfig.lineStyle.help', { | ||
defaultMessage: 'The style of the reference line', | ||
}), | ||
default: LineStyles.SOLID, | ||
strict: true, | ||
}, | ||
lineWidth: { | ||
types: ['number'], | ||
help: i18n.translate('expressionXY.yConfig.lineWidth.help', { | ||
defaultMessage: 'The width of the reference line', | ||
}), | ||
default: 1, | ||
}, | ||
icon: { | ||
types: ['string'], | ||
help: i18n.translate('expressionXY.yConfig.icon.help', { | ||
defaultMessage: 'An optional icon used for reference lines', | ||
}), | ||
options: [...Object.values(AvailableReferenceLineIcons)], | ||
strict: true, | ||
}, | ||
iconPosition: { | ||
types: ['string'], | ||
options: [...Object.values(IconPositions)], | ||
help: i18n.translate('expressionXY.yConfig.iconPosition.help', { | ||
defaultMessage: 'The placement of the icon for the reference line', | ||
}), | ||
default: IconPositions.AUTO, | ||
strict: true, | ||
}, | ||
textVisibility: { | ||
types: ['boolean'], | ||
help: i18n.translate('expressionXY.yConfig.textVisibility.help', { | ||
defaultMessage: 'Visibility of the label on the reference line', | ||
}), | ||
}, | ||
fill: { | ||
types: ['string'], | ||
options: [...Object.values(FillStyles)], | ||
help: i18n.translate('expressionXY.yConfig.fill.help', { | ||
defaultMessage: 'Fill', | ||
}), | ||
default: FillStyles.NONE, | ||
strict: true, | ||
}, | ||
}, | ||
fn(table, args) { | ||
const textVisibility = | ||
args.name !== undefined && args.textVisibility === undefined | ||
? true | ||
: args.name === undefined | ||
? false | ||
: args.textVisibility; | ||
|
||
return { | ||
type: REFERENCE_LINE, | ||
layerType: LayerTypes.REFERENCELINE, | ||
lineLength: table?.rows.length ?? 0, | ||
yConfig: [{ ...args, textVisibility, type: REFERENCE_LINE_Y_CONFIG }], | ||
}; | ||
}, | ||
}; |
Oops, something went wrong.