forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: axis configuration (elastic#341)
* fix: remove debugging output * feat: axisConfig function * feat: add axis config ui * feat: use axis config in plot chart * feat: add horizontalBars arg to seriesStyle use the setting in the plot function
- Loading branch information
Showing
13 changed files
with
184 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export const axisConfig = () => ({ | ||
name: 'axisConfig', | ||
aliases: [], | ||
type: 'axisConfig', | ||
context: { | ||
types: ['datatable'], | ||
}, | ||
help: 'Configure axis of a visualization', | ||
args: { | ||
show: { | ||
types: ['boolean'], | ||
help: 'Show the axis labels?', | ||
default: true, | ||
}, | ||
position: { | ||
types: ['string'], | ||
help: 'Position of the axis labels', | ||
}, | ||
}, | ||
fn: (context, args) => { | ||
return { | ||
type: 'axisConfig', | ||
...args, | ||
}; | ||
}, | ||
}); |
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
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
16 changes: 16 additions & 0 deletions
16
public/expression_types/arg_types/axis_config/axis_config.less
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,16 @@ | ||
@import (reference) "../../../style/variables"; | ||
|
||
.canvas__argtype--axis_config--disabled { | ||
color: @mediumGrey; | ||
font-size: 0.8em; | ||
} | ||
|
||
.canvas__argtype--axis_config--configure { | ||
.form-group { | ||
display: flex; | ||
|
||
label { | ||
padding: @spacingXS @spacingS; | ||
} | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
public/expression_types/arg_types/axis_config/extended_template.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,70 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { get } from 'lodash'; | ||
import { set } from 'object-path-immutable'; | ||
import { LabeledInput } from '../../../components/labeled_input'; | ||
|
||
const defaultExpression = { | ||
type: 'expression', | ||
chain: [ | ||
{ | ||
type: 'function', | ||
function: 'axisConfig', | ||
arguments: {}, | ||
}, | ||
], | ||
}; | ||
|
||
export class ExtendedTemplate extends React.PureComponent { | ||
static propTypes = { | ||
onValueChange: PropTypes.func.isRequired, | ||
argValue: PropTypes.oneOfType([ | ||
PropTypes.bool, | ||
PropTypes.shape({ | ||
chain: PropTypes.array, | ||
}).isRequired, | ||
]), | ||
typeInstance: PropTypes.object.isRequired, | ||
}; | ||
|
||
// TODO: this should be in a helper, it's the same code from container_style | ||
getArgValue = (name, alt) => { | ||
return get(this.props.argValue, ['chain', 0, 'arguments', name, 0], alt); | ||
}; | ||
|
||
// TODO: this should be in a helper, it's the same code from container_style | ||
setArgValue = name => ev => { | ||
const val = ev.target.value; | ||
const { argValue, onValueChange } = this.props; | ||
const oldVal = typeof argValue === 'boolean' ? defaultExpression : argValue; | ||
const newValue = set(oldVal, ['chain', 0, 'arguments', name, 0], val); | ||
onValueChange(newValue); | ||
}; | ||
|
||
render() { | ||
const isDisabled = typeof this.props.argValue === 'boolean' && this.props.argValue === false; | ||
|
||
if (isDisabled) | ||
return <div className="canvas__argtype--axis_config--disabled">The axis is disabled</div>; | ||
|
||
const positions = { | ||
xaxis: ['bottom', 'top'], | ||
yaxis: ['left', 'right'], | ||
}; | ||
const argName = this.props.typeInstance.name; | ||
const position = this.getArgValue('position', positions[argName][0]); | ||
|
||
return ( | ||
<div className="canvas__argtype--axis_config--configure"> | ||
<LabeledInput | ||
type="select" | ||
className="position" | ||
label="Position" | ||
value={position} | ||
values={positions[argName]} | ||
onChange={this.setArgValue('position')} | ||
/> | ||
</div> | ||
); | ||
} | ||
} |
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,11 @@ | ||
import { SimpleTemplate } from './simple_template'; | ||
import { ExtendedTemplate } from './extended_template'; | ||
import './axis_config.less'; | ||
|
||
export const axisConfig = () => ({ | ||
name: 'axisConfig', | ||
displayName: 'Axis Config', | ||
help: 'Visualization axis configuration', | ||
simpleTemplate: SimpleTemplate, | ||
template: ExtendedTemplate, | ||
}); |
16 changes: 16 additions & 0 deletions
16
public/expression_types/arg_types/axis_config/simple_template.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,16 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Toggle } from '../../../components/toggle'; | ||
|
||
const isEnabled = argValue => typeof argValue !== 'boolean' || argValue !== false; | ||
|
||
export const SimpleTemplate = ({ onValueChange, argValue }) => ( | ||
<div className="canvas__argtype--axis_config--enable"> | ||
<Toggle value={isEnabled(argValue)} onChange={onValueChange} /> | ||
</div> | ||
); | ||
|
||
SimpleTemplate.propTypes = { | ||
onValueChange: PropTypes.func.isRequired, | ||
argValue: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]), | ||
}; |
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
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