-
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.
Added progress elements Added progress view Added unit tests for progress common function Fixed prop type in toggle arg Renamed vert -> vertical and horiz -> horizontal Adjusted progress element dimensions Removed check for null context in progress function Refactored progress shapes Added unicorn shape Adds labelPosition arg Added tests for labelPosition
- Loading branch information
Showing
24 changed files
with
783 additions
and
5 deletions.
There are no files selected for viewing
Binary file added
BIN
+11.4 KB
...ck/plugins/canvas/canvas_plugin_src/elements/horizontal_progress_bar/header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions
24
x-pack/plugins/canvas/canvas_plugin_src/elements/horizontal_progress_bar/index.js
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,24 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { openSans } from '../../../common/lib/fonts'; | ||
import header from './header.png'; | ||
|
||
export const horizontalProgressBar = () => ({ | ||
name: 'horizontalProgressBar', | ||
displayName: 'Horizontal Progress Bar', | ||
help: 'Displays progress as a portion of a horizontal bar', | ||
width: 200, | ||
height: 50, | ||
image: header, | ||
expression: `filters | ||
| demodata | ||
| math "sum(min(cost) / max(cost))" | ||
| progress shape="horizontalBar" label={formatnumber 0%} font={font size=24 family="${ | ||
openSans.value | ||
}" color="#000000" align=center} | ||
| render`, | ||
}); |
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
Binary file added
BIN
+26.2 KB
x-pack/plugins/canvas/canvas_plugin_src/elements/progress_gauge/header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions
24
x-pack/plugins/canvas/canvas_plugin_src/elements/progress_gauge/index.js
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,24 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { openSans } from '../../../common/lib/fonts'; | ||
import header from './header.png'; | ||
|
||
export const progressGauge = () => ({ | ||
name: 'progressGauge', | ||
displayName: 'Progress Gauge', | ||
help: 'Displays progress as a portion of a gauge', | ||
width: 200, | ||
height: 200, | ||
image: header, | ||
expression: `filters | ||
| demodata | ||
| math "sum(min(cost) / max(cost))" | ||
| progress shape="gauge" label={formatnumber 0%} font={font size=24 family="${ | ||
openSans.value | ||
}" color="#000000" align=center} | ||
| render`, | ||
}); |
Binary file added
BIN
+35.5 KB
x-pack/plugins/canvas/canvas_plugin_src/elements/progress_wheel/header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions
24
x-pack/plugins/canvas/canvas_plugin_src/elements/progress_wheel/index.js
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,24 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { openSans } from '../../../common/lib/fonts'; | ||
import header from './header.png'; | ||
|
||
export const progressWheel = () => ({ | ||
name: 'progressWheel', | ||
displayName: 'Progress Wheel', | ||
help: 'Displays progress as a portion of a wheel', | ||
width: 200, | ||
height: 200, | ||
image: header, | ||
expression: `filters | ||
| demodata | ||
| math "sum(min(cost) / max(cost))" | ||
| progress shape="wheel" label={formatnumber 0%} font={font size=24 family="${ | ||
openSans.value | ||
}" color="#000000" align=center} | ||
| render`, | ||
}); |
Binary file added
BIN
+13.5 KB
x-pack/plugins/canvas/canvas_plugin_src/elements/vertical_progress_bar/header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions
24
x-pack/plugins/canvas/canvas_plugin_src/elements/vertical_progress_bar/index.js
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,24 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { openSans } from '../../../common/lib/fonts'; | ||
import header from './header.png'; | ||
|
||
export const verticalProgressBar = () => ({ | ||
name: 'verticalProgressBar', | ||
displayName: 'Vertical Progress Bar', | ||
help: 'Displays progress as a portion of a vertical bar', | ||
width: 50, | ||
height: 200, | ||
image: header, | ||
expression: `filters | ||
| demodata | ||
| math "sum(min(cost) / max(cost))" | ||
| progress shape="verticalBar" label={formatnumber 0%} font={font size=24 family="${ | ||
openSans.value | ||
}" color="#000000" align=center} | ||
| render`, | ||
}); |
190 changes: 190 additions & 0 deletions
190
x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/progress.js
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,190 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import expect from 'expect.js'; | ||
import { progress } from '../progress'; | ||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper'; | ||
import { fontStyle } from './fixtures/test_styles'; | ||
|
||
describe('progress', () => { | ||
const fn = functionWrapper(progress); | ||
const value = 0.33; | ||
|
||
it('returns a render as progress', () => { | ||
const result = fn(0.2); | ||
expect(result) | ||
.to.have.property('type', 'render') | ||
.and.to.have.property('as', 'progress'); | ||
}); | ||
|
||
it('sets the progress to context', () => { | ||
const result = fn(0.58); | ||
expect(result.value).to.have.property('value', 0.58); | ||
}); | ||
|
||
it(`throws when context is outside of the valid range`, () => { | ||
expect(fn) | ||
.withArgs(3) | ||
.to.throwException(e => { | ||
expect(e.message).to.be('Context must be between 0 and 1'); | ||
}); | ||
}); | ||
|
||
describe('args', () => { | ||
describe('shape', () => { | ||
it('sets the progress element shape', () => { | ||
const result = fn(value, { | ||
shape: 'wheel', | ||
}); | ||
expect(result.value).to.have.property('shape', 'wheel'); | ||
}); | ||
|
||
it(`defaults to 'gauge'`, () => { | ||
const result = fn(value); | ||
expect(result.value).to.have.property('shape', 'gauge'); | ||
}); | ||
}); | ||
|
||
describe('max', () => { | ||
it('sets the maximum value', () => { | ||
const result = fn(value, { | ||
max: 2, | ||
}); | ||
expect(result.value).to.have.property('max', 2); | ||
}); | ||
|
||
it('defaults to 1', () => { | ||
const result = fn(value); | ||
expect(result.value).to.have.property('max', 1); | ||
}); | ||
|
||
it('throws if max <= 0', () => { | ||
expect(fn) | ||
.withArgs(value, { max: -0.5 }) | ||
.to.throwException(e => { | ||
expect(e.message).to.be(`'max' must be greater than 0`); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('valueColor', () => { | ||
it('sets the color of the progress bar', () => { | ||
const result = fn(value, { | ||
valueColor: '#000000', | ||
}); | ||
expect(result.value).to.have.property('valueColor', '#000000'); | ||
}); | ||
|
||
it(`defaults to '#1785b0'`, () => { | ||
const result = fn(value); | ||
expect(result.value).to.have.property('valueColor', '#1785b0'); | ||
}); | ||
}); | ||
|
||
describe('barColor', () => { | ||
it('sets the color of the background bar', () => { | ||
const result = fn(value, { | ||
barColor: '#FFFFFF', | ||
}); | ||
expect(result.value).to.have.property('barColor', '#FFFFFF'); | ||
}); | ||
|
||
it(`defaults to '#f0f0f0'`, () => { | ||
const result = fn(value); | ||
expect(result.value).to.have.property('barColor', '#f0f0f0'); | ||
}); | ||
}); | ||
|
||
describe('weight', () => { | ||
it('sets the thickness of the bars', () => { | ||
const result = fn(value, { | ||
weight: 100, | ||
}); | ||
|
||
expect(result.value).to.have.property('weight', 100); | ||
}); | ||
|
||
it(`defaults to 20`, () => { | ||
const result = fn(value); | ||
expect(result.value).to.have.property('weight', 20); | ||
}); | ||
}); | ||
|
||
describe('label', () => { | ||
it('sets the label of the progress', () => { | ||
const result = fn(value, { label: 'foo' }); | ||
|
||
expect(result.value).to.have.property('label', 'foo'); | ||
}); | ||
|
||
it('hides the label if false', () => { | ||
const result = fn(value, { | ||
label: false, | ||
}); | ||
expect(result.value).to.have.property('label', ''); | ||
}); | ||
|
||
it('defaults to true which sets the context as the label', () => { | ||
const result = fn(value); | ||
expect(result.value).to.have.property('label', '0.33'); | ||
}); | ||
}); | ||
|
||
describe('labelPosition', () => { | ||
it('sets the position of the label', () => { | ||
let result = fn(value, { labelPosition: 'center' }); | ||
expect(result.value).to.have.property('labelPosition', 'center'); | ||
|
||
result = fn(value, { labelPosition: 'above' }); | ||
expect(result.value).to.have.property('labelPosition', 'above'); | ||
|
||
result = fn(value, { labelPosition: 'below' }); | ||
expect(result.value).to.have.property('labelPosition', 'below'); | ||
|
||
result = fn(value, { labelPosition: 'left' }); | ||
expect(result.value).to.have.property('labelPosition', 'left'); | ||
|
||
result = fn(value, { labelPosition: 'right' }); | ||
expect(result.value).to.have.property('labelPosition', 'right'); | ||
}); | ||
|
||
it(`defaults to 'center'`, () => { | ||
const result = fn(value); | ||
expect(result.value).to.have.property('labelPosition', 'center'); | ||
}); | ||
|
||
it('throws if given an invalid position', () => { | ||
expect(fn) | ||
.withArgs(value, { labelPosition: 'foo' }) | ||
.to.throwException(e => { | ||
expect(e.message).to.be(`'labelPosition' must be center, above, below, left, or right`); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('font', () => { | ||
it('sets the font style for the label', () => { | ||
const result = fn(value, { | ||
font: fontStyle, | ||
}); | ||
|
||
expect(result.value).to.have.property('font'); | ||
expect(result.value.font).to.have.keys(Object.keys(fontStyle)); | ||
expect(result.value.font.spec).to.have.keys(Object.keys(fontStyle.spec)); | ||
}); | ||
|
||
it('sets fill to color', () => { | ||
const result = fn(value, { | ||
font: fontStyle, | ||
}); | ||
expect(result.value.font.spec).to.have.property('fill', fontStyle.spec.color); | ||
}); | ||
|
||
// TODO: write test when using an instance of the interpreter | ||
// it("sets a default style for the label when not provided", () => {}); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.