Add option for BigNumber to not start y-axis at 0 (#5552)

* Add option to not start y-axis at 0

* Update language to positive.
This commit is contained in:
Krist Wongsuphasawat 2018-08-06 14:32:29 -07:00 committed by Chris Williams
parent b7f9dabc44
commit aa14bac5c7
3 changed files with 18 additions and 2 deletions

View File

@ -1480,6 +1480,14 @@ export const controls = {
description: t('Whether to display the trend line'), description: t('Whether to display the trend line'),
}, },
start_y_axis_at_zero: {
type: 'CheckboxControl',
label: t('Start y-axis at 0'),
renderTrigger: true,
default: true,
description: t('Start y-axis at zero. Uncheck to start y-axis at minimum value in the data.'),
},
x_axis_showminmax: { x_axis_showminmax: {
type: 'CheckboxControl', type: 'CheckboxControl',
label: t('X bounds'), label: t('X bounds'),

View File

@ -1251,7 +1251,7 @@ export const visTypes = {
controlSetRows: [ controlSetRows: [
['compare_lag', 'compare_suffix'], ['compare_lag', 'compare_suffix'],
['y_axis_format', null], ['y_axis_format', null],
['show_trend_line', null], ['show_trend_line', 'start_y_axis_at_zero'],
], ],
}, },
], ],

View File

@ -53,6 +53,7 @@ const propTypes = {
formatBigNumber: PropTypes.func, formatBigNumber: PropTypes.func,
subheader: PropTypes.string, subheader: PropTypes.string,
showTrendline: PropTypes.bool, showTrendline: PropTypes.bool,
startYAxisAtZero: PropTypes.bool,
trendlineData: PropTypes.array, trendlineData: PropTypes.array,
mainColor: PropTypes.string, mainColor: PropTypes.string,
gradientId: PropTypes.string, gradientId: PropTypes.string,
@ -63,6 +64,7 @@ const defaultProps = {
formatBigNumber: identity, formatBigNumber: identity,
subheader: '', subheader: '',
showTrendline: false, showTrendline: false,
startYAxisAtZero: true,
trendlineData: null, trendlineData: null,
mainColor: brandColor, mainColor: brandColor,
gradientId: '', gradientId: '',
@ -152,12 +154,16 @@ class BigNumberVis extends React.Component {
subheader, subheader,
renderTooltip, renderTooltip,
gradientId, gradientId,
startYAxisAtZero,
} = this.props; } = this.props;
return ( return (
<XYChart <XYChart
ariaLabel={`Big number visualization ${subheader}`} ariaLabel={`Big number visualization ${subheader}`}
xScale={{ type: 'timeUtc' }} xScale={{ type: 'timeUtc' }}
yScale={{ type: 'linear' }} yScale={{
type: 'linear',
includeZero: startYAxisAtZero,
}}
width={width} width={width}
height={maxHeight} height={maxHeight}
margin={CHART_MARGIN} margin={CHART_MARGIN}
@ -227,6 +233,7 @@ function adaptor(slice, payload) {
const compareLag = Number(payload.data.compare_lag); const compareLag = Number(payload.data.compare_lag);
const supportTrendline = formData.viz_type === 'big_number'; const supportTrendline = formData.viz_type === 'big_number';
const showTrendline = supportTrendline && formData.show_trend_line; const showTrendline = supportTrendline && formData.show_trend_line;
const startYAxisAtZero = formData.start_y_axis_at_zero;
const formatValue = d3FormatPreset(formData.y_axis_format); const formatValue = d3FormatPreset(formData.y_axis_format);
const bigNumber = supportTrendline ? data[data.length - 1][1] : data[0][0]; const bigNumber = supportTrendline ? data[data.length - 1][1] : data[0][0];
@ -262,6 +269,7 @@ function adaptor(slice, payload) {
formatBigNumber={formatValue} formatBigNumber={formatValue}
subheader={formattedSubheader} subheader={formattedSubheader}
showTrendline={showTrendline} showTrendline={showTrendline}
startYAxisAtZero={startYAxisAtZero}
trendlineData={trendlineData} trendlineData={trendlineData}
mainColor={brandColor} mainColor={brandColor}
gradientId={`big_number_${containerId}`} gradientId={`big_number_${containerId}`}