-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bar_chart): add shadow prop for value labels (#785)
Value labels fill can be tweaked with advanced parameters to increase the contrast with the background, using a border parameter. A new textInverted parameter gives also the ability to better respect contrast requirements, enabling an auto tuning of the fill color based on the bar color. BREAKING CHANGE: The `DisplayValueStyle` `fill` property can now express a border color and width, or let the library pick the best match based on contrast using the textInvertible parameter.
- Loading branch information
Showing
45 changed files
with
255 additions
and
26 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
Binary file added
BIN
+30.2 KB
...l-stories-bar-chart-with-value-label-advanced-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+3.37 KB
(110%)
...rizontal-alignment-center-place-the-value-labels-on-the-correct-area-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+3.43 KB
(110%)
...horizontal-alignment-left-place-the-value-labels-on-the-correct-area-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+3.62 KB
(120%)
...orizontal-alignment-right-place-the-value-labels-on-the-correct-area-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+4.39 KB
(120%)
...rizontal-alignment-center-place-the-value-labels-on-the-correct-area-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+4.32 KB
(120%)
...horizontal-alignment-left-place-the-value-labels-on-the-correct-area-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+4.58 KB
(120%)
...orizontal-alignment-right-place-the-value-labels-on-the-correct-area-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+4.49 KB
(120%)
...rizontal-alignment-center-place-the-value-labels-on-the-correct-area-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+4.35 KB
(120%)
...horizontal-alignment-left-place-the-value-labels-on-the-correct-area-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+4.58 KB
(120%)
...orizontal-alignment-right-place-the-value-labels-on-the-correct-area-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+4.49 KB
(120%)
...rizontal-alignment-center-place-the-value-labels-on-the-correct-area-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+4.61 KB
(120%)
...horizontal-alignment-left-place-the-value-labels-on-the-correct-area-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+4.65 KB
(120%)
...orizontal-alignment-right-place-the-value-labels-on-the-correct-area-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+4.19 KB
(120%)
...rizontal-alignment-center-place-the-value-labels-on-the-correct-area-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+4.36 KB
(120%)
...horizontal-alignment-left-place-the-value-labels-on-the-correct-area-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+4.51 KB
(120%)
...orizontal-alignment-right-place-the-value-labels-on-the-correct-area-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+3.04 KB
(110%)
...rizontal-alignment-center-place-the-value-labels-on-the-correct-area-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+3.02 KB
(110%)
...horizontal-alignment-left-place-the-value-labels-on-the-correct-area-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+3.5 KB
(110%)
...orizontal-alignment-right-place-the-value-labels-on-the-correct-area-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+4.72 KB
(120%)
...rizontal-alignment-center-place-the-value-labels-on-the-correct-area-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+4.38 KB
(120%)
...horizontal-alignment-left-place-the-value-labels-on-the-correct-area-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+4.6 KB
(120%)
...orizontal-alignment-right-place-the-value-labels-on-the-correct-area-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+4.69 KB
(120%)
...rizontal-alignment-center-place-the-value-labels-on-the-correct-area-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+4.32 KB
(120%)
...horizontal-alignment-left-place-the-value-labels-on-the-correct-area-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+4.55 KB
(120%)
...orizontal-alignment-right-place-the-value-labels-on-the-correct-area-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+4.57 KB
(120%)
...rizontal-alignment-center-place-the-value-labels-on-the-correct-area-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+4.1 KB
(120%)
...horizontal-alignment-left-place-the-value-labels-on-the-correct-area-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+4.37 KB
(120%)
...orizontal-alignment-right-place-the-value-labels-on-the-correct-area-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+4.68 KB
(120%)
...rizontal-alignment-center-place-the-value-labels-on-the-correct-area-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+4.57 KB
(120%)
...horizontal-alignment-left-place-the-value-labels-on-the-correct-area-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+4.31 KB
(120%)
...orizontal-alignment-right-place-the-value-labels-on-the-correct-area-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+4.63 KB
(120%)
...rizontal-alignment-center-place-the-value-labels-on-the-correct-area-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+4.53 KB
(120%)
...horizontal-alignment-left-place-the-value-labels-on-the-correct-area-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+4.27 KB
(120%)
...orizontal-alignment-right-place-the-value-labels-on-the-correct-area-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+4.54 KB
(120%)
...rizontal-alignment-center-place-the-value-labels-on-the-correct-area-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+4.5 KB
(120%)
...horizontal-alignment-left-place-the-value-labels-on-the-correct-area-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+4.23 KB
(120%)
...orizontal-alignment-right-place-the-value-labels-on-the-correct-area-1-snap.png
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { boolean, color, number, select } from '@storybook/addon-knobs'; | ||
import React from 'react'; | ||
|
||
import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '../../src'; | ||
import { SeededDataGenerator } from '../../src/mocks/utils'; | ||
import { getChartRotationKnob } from '../utils/knobs'; | ||
|
||
const dataGen = new SeededDataGenerator(); | ||
function generateDataWithAdditional(num: number) { | ||
return [...dataGen.generateSimpleSeries(num), { x: num, y: 0.25, g: 0 }, { x: num + 1, y: 8, g: 0 }]; | ||
} | ||
const frozenDataSmallVolume = generateDataWithAdditional(10); | ||
const frozenDataMediumVolume = generateDataWithAdditional(50); | ||
const frozenDataHighVolume = generateDataWithAdditional(1500); | ||
|
||
const frozenData: { [key: string]: any[] } = { | ||
s: frozenDataSmallVolume, | ||
m: frozenDataMediumVolume, | ||
h: frozenDataHighVolume, | ||
}; | ||
|
||
export const Example = () => { | ||
const showValueLabel = boolean('show value label', true); | ||
const isAlternatingValueLabel = boolean('alternating value label', false); | ||
const isValueContainedInElement = boolean('contain value label within bar element', false); | ||
const hideClippedValue = boolean('hide clipped value', false); | ||
|
||
const displayValueSettings = { | ||
showValueLabel, | ||
isAlternatingValueLabel, | ||
isValueContainedInElement, | ||
hideClippedValue, | ||
}; | ||
|
||
const debug = boolean('debug', false); | ||
const useInverted = boolean('textInverted', false); | ||
const valueColor = color('value color', '#fff'); | ||
const borderColor = color('value border color', 'rgba(0,0,0,1)'); | ||
const borderSize = number('value border width', 1.5); | ||
|
||
const theme = { | ||
barSeriesStyle: { | ||
displayValue: { | ||
fontSize: number('value font size', 10), | ||
fontFamily: "'Open Sans', Helvetica, Arial, sans-serif", | ||
fontStyle: 'normal', | ||
padding: 0, | ||
fill: useInverted | ||
? { textInverted: useInverted, textContrast: true, textBorder: borderSize } | ||
: { color: valueColor, borderColor, borderWidth: borderSize }, | ||
offsetX: number('offsetX', 0), | ||
offsetY: number('offsetY', 0), | ||
alignment: { | ||
horizontal: select( | ||
'Horizontal alignment', | ||
{ | ||
Default: undefined, | ||
Left: 'left', | ||
Center: 'center', | ||
Right: 'right', | ||
}, | ||
undefined, | ||
), | ||
vertical: select( | ||
'Vertical alignment', | ||
{ | ||
Default: undefined, | ||
Top: 'top', | ||
Middle: 'middle', | ||
Bottom: 'bottom', | ||
}, | ||
undefined, | ||
), | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const dataSize = select( | ||
'data volume size', | ||
{ | ||
'small volume': 's', | ||
'medium volume': 'm', | ||
'high volume': 'h', | ||
}, | ||
's', | ||
); | ||
const data = frozenData[dataSize]; | ||
|
||
const isSplitSeries = boolean('split series', false); | ||
const isStackedSeries = boolean('stacked series', false); | ||
|
||
const splitSeriesAccessors = isSplitSeries ? ['g'] : undefined; | ||
const stackAccessors = isStackedSeries ? ['x'] : undefined; | ||
return ( | ||
<Chart renderer="canvas" className="story-chart"> | ||
<Settings theme={theme} debug={debug} rotation={getChartRotationKnob()} showLegend showLegendExtra /> | ||
<Axis id="bottom" position={Position.Bottom} title="Bottom axis" showOverlappingTicks /> | ||
<Axis id="left2" title="Left axis" position={Position.Left} tickFormat={(d: any) => Number(d).toFixed(2)} /> | ||
<BarSeries | ||
id="bars" | ||
displayValueSettings={displayValueSettings} | ||
xScaleType={ScaleType.Linear} | ||
yScaleType={ScaleType.Linear} | ||
xAccessor="x" | ||
yAccessors={['y']} | ||
splitSeriesAccessors={splitSeriesAccessors} | ||
stackAccessors={stackAccessors} | ||
data={data} | ||
/> | ||
<BarSeries | ||
id="bars2" | ||
displayValueSettings={displayValueSettings} | ||
xScaleType={ScaleType.Linear} | ||
yScaleType={ScaleType.Linear} | ||
xAccessor="x" | ||
yAccessors={['y']} | ||
stackAccessors={['x']} | ||
splitSeriesAccessors={['g']} | ||
data={[ | ||
{ x: 0, y: 2, g: 'a' }, | ||
{ x: 1, y: 7, g: 'a' }, | ||
{ x: 2, y: 3, g: 'a' }, | ||
{ x: 3, y: 6, g: 'a' }, | ||
{ x: 0, y: 4, g: 'b' }, | ||
{ x: 1, y: 5, g: 'b' }, | ||
{ x: 2, y: 8, g: 'b' }, | ||
{ x: 3, y: 2, g: 'b' }, | ||
]} | ||
/> | ||
</Chart> | ||
); | ||
}; |
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