-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(bar_chart): add shadow prop for value labels #785
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9c0d1be
feat(bar_chart): add shadow prop for value labels
dej611 f2d0f69
docs: sync API with new labels shadow feature
dej611 7051c92
feat: implement textInverted logic for value labels
dej611 8570d67
chore: remove shadow reference in demo
dej611 e42ad56
docs: sync new API for fill value
dej611 0499acc
test: add missing test snapshot
dej611 14a26f2
feat: implemented various suggestions from review
dej611 0035949
Merge remote-tracking branch 'upstream/master' into feature/value-lab…
dej611 bf9b841
docs: updated api changes
dej611 5857623
test: remade snapshot image
dej611 86dad5d
Merge remote-tracking branch 'upstream/master' into feature/value-lab…
dej611 58a5651
refactor: armonize with latest master and alignment pr
dej611 5777029
test: fixing visual snapshots for new features
dej611 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been testing and I think for the example white fill color looks better with a dark shadow:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also increased the size of the value font size to 12.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it should be a default setting or just a better starting point for this example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was seeing the other charts where we have labels/values on top and normally they are black or with
textInvertible: true
So for consistency, I think we should keep the value labels black and just increase the size to 12.
How do you feel of then creating a second example to show that the value label can be customized? In this new example, you would use white value labels with a shadow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@miukimiu which would you prefer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my understanding when it flips the color on text the shadow should change too.
But you are right, there is also the additional scenario where the shadow is not enabled (
transparent
?) and only the text changes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah thats true but I was actually thinking that the shadow be
null
orundefined
, as it's not needed when the text contrast is dynamic.