Skip to content
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: add 4.5 contrast for text in partition slices #608

Merged
merged 78 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
02f2f53
feat: move luminance value code from kibana in charts
rshen91 Mar 26, 2020
325b5bd
feat: textColor takes into account contrast with background slice
rshen91 Mar 31, 2020
6acca30
feat: account for initial non black or white textColor
rshen91 Mar 31, 2020
8f4ddf5
feat: add background color knob for xy charts
rshen91 Apr 10, 2020
23eb310
test: fix backgrounds to white for vrt
rshen91 Apr 13, 2020
d4b43ca
fix: add color background functionality to partition chart simple
rshen91 Apr 14, 2020
361200e
docs: add story for partition in styling
rshen91 Apr 14, 2020
963572b
feat: add combine color helper function
rshen91 Apr 15, 2020
01d1e2e
Merge remote-tracking branch 'upstream/master' into luminance-pie
rshen91 Apr 15, 2020
c7eec32
Merge remote-tracking branch 'upstream/master' into luminance-pie
rshen91 Apr 16, 2020
c36c79a
feat: add background to geometries
rshen91 Apr 20, 2020
fe5be74
fix: improve contrast
rshen91 Apr 20, 2020
cd31813
Merge remote-tracking branch 'upstream/master' into luminance-pie
rshen91 Apr 21, 2020
38e1250
fix: add updated story file
rshen91 Apr 21, 2020
69168b6
Merge remote-tracking branch 'upstream/master' into luminance-pie
rshen91 Apr 21, 2020
c1bc892
feat: update colorIsDark to adjust text for contrast
rshen91 Apr 21, 2020
7c3c7b0
Merge remote-tracking branch 'upstream/master' into luminance-pie
rshen91 Apr 22, 2020
69a2cc0
fix: readd textInvertible functionality in fill_text_layout
rshen91 Apr 22, 2020
7059318
Merge remote-tracking branch 'upstream/master' into luminance-pie
rshen91 Apr 22, 2020
f9a824d
WIP
rshen91 Apr 23, 2020
9bc19ba
Merge remote-tracking branch 'upstream/master' into luminance-pie
rshen91 Apr 23, 2020
65d8bc8
feat: improve makeHighContrastColor()
rshen91 Apr 23, 2020
71b512e
Merge remote-tracking branch 'upstream/master' into luminance-pie
rshen91 Apr 24, 2020
ba1b1cf
Merge remote-tracking branch 'upstream/master' into luminance-pie
rshen91 Apr 27, 2020
016cc7d
fix: merge conflicts
rshen91 Apr 27, 2020
9d0d6e7
WIP
rshen91 Apr 27, 2020
c0a56e0
feat: add link label contrast functionality
rshen91 Apr 27, 2020
878635c
chore: merge remote-tracking branch 'upstream/master' into luminance-pie
rshen91 Apr 28, 2020
94d69ec
test: update contrast logic and vrts
rshen91 Apr 28, 2020
1152d96
Merge remote-tracking branch 'upstream/master' into luminance-pie
rshen91 Apr 29, 2020
0688de9
Merge remote-tracking branch 'upstream/master' into luminance-pie
rshen91 Apr 29, 2020
e083865
fix: remove broken playground
rshen91 Apr 29, 2020
7ede9a3
fix: add playground from current master
rshen91 Apr 29, 2020
fc86b2a
test: add unit tests for calc file
rshen91 Apr 29, 2020
1fa7fb8
chore: merge remote-tracking branch 'upstream/master' into luminance-pie
rshen91 Apr 30, 2020
08f1dd7
WIP
rshen91 Apr 30, 2020
a957653
WIP
rshen91 Apr 30, 2020
876062a
merging with master but broken build
rshen91 Apr 30, 2020
9492c23
WIP
rshen91 May 2, 2020
fcc7cfe
Merge remote-tracking branch 'upstream/master' into luminance-pie
rshen91 May 2, 2020
8035d6c
Merge remote-tracking branch 'upstream/master' into luminance-pie
rshen91 May 4, 2020
5b3b11f
feat: playground add foreground color functionality
rshen91 May 4, 2020
572cbdd
feat: error handling in conbineColors
rshen91 May 4, 2020
336ae5e
Merge remote-tracking branch 'upstream/master' into luminance-pie
rshen91 May 4, 2020
c09dfca
Merge remote-tracking branch 'upstream/master' into luminance-pie
rshen91 May 5, 2020
08768fa
feat: add contrastText prop and opacity in playground
rshen91 May 5, 2020
1800133
Merge remote-tracking branch 'upstream/master' into luminance-pie
rshen91 May 5, 2020
ee33cfd
fix: fix brightness lightness calc
rshen91 May 5, 2020
4f4801b
chore: merge commit
rshen91 May 8, 2020
7412a60
Merge remote-tracking branch 'upstream/master' into luminance-pie
rshen91 May 8, 2020
0a24a5e
feat: add textContrast number functionality
rshen91 May 11, 2020
1c04a77
feat: fix contrast with luminance over lightness for colorIsDark
rshen91 May 12, 2020
511b5b4
test: add unit tests and add class to playground
rshen91 May 13, 2020
48ec0fa
Merge remote-tracking branch 'upstream/master' into luminance-pie
rshen91 May 19, 2020
f8619e2
feat: low hanging fruit
rshen91 May 20, 2020
b411301
feat: add code review changes
rshen91 May 21, 2020
88e42d3
fix: add internal tag to LinkLabelsViewModelSpec
rshen91 May 21, 2020
41314f9
Merge remote-tracking branch 'upstream/master' into luminance-pie
rshen91 May 26, 2020
8a4c825
fix: cp tmp/charts.api.md to api/chart.api.md
rshen91 May 26, 2020
0946501
Merge remote-tracking branch 'upstream/master' into luminance-pie
rshen91 May 27, 2020
545e78e
feat: add chart background to own component
rshen91 May 27, 2020
ef78e4b
fix: fix order for <ChartBackground />
rshen91 May 27, 2020
299f90e
fix: add styling fix for legend
rshen91 May 28, 2020
aa48c17
chore: merge remote-tracking branch 'upstream/master' into luminance-pie
rshen91 May 28, 2020
69cd5d8
test: add unit test for combine colors and correct contrast
rshen91 May 28, 2020
462debe
Merge remote-tracking branch 'upstream/master' into luminance-pie
rshen91 May 28, 2020
01b7052
docs: add docs to storybook docs about textContrast
rshen91 May 29, 2020
9bb1e8e
Merge remote-tracking branch 'upstream/master' into luminance-pie
rshen91 Jun 1, 2020
36baf2e
feat: update baseThemes
rshen91 Jun 2, 2020
1864be2
Merge branch 'master' into luminance-pie
nickofthyme Jun 7, 2020
f14f2fa
fix: update pr with remaining checks
nickofthyme Jun 8, 2020
33aeb59
refactor: return types and rgb format
markov00 Jun 8, 2020
979ffe0
fix: get correct theme via selector and minor refactoring
markov00 Jun 8, 2020
af65d11
fix: refactor chart size
markov00 Jun 8, 2020
9012b54
fix: cleanup theme colors and add color check
markov00 Jun 8, 2020
20a11c0
fix: api docs
markov00 Jun 8, 2020
44e5101
Merge branch 'master' into luminance-pie
markov00 Jun 8, 2020
9c91e74
fix: broken tests, update prop naming
nickofthyme Jun 8, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
226 changes: 220 additions & 6 deletions .playground/playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,230 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License. */

import React from 'react';
import { Example } from '../stories/treemap/6_custom_style';
import {
makeHighContrastColor,
combineColors,
getContrast,
} from '../src/chart_types/partition_chart/layout/utils/calcs';

type PlaygroundState = {
backgroundColor: string;
foregroundColor: string;
textColor: string;
value: any;
opacityColor: number;
};
export class Playground extends React.Component<{}, PlaygroundState> {
constructor(props: any) {
super(props);
this.state = {
backgroundColor: 'rgba(113, 128, 172, 0.75)',
foregroundColor: 'rgba(168, 208, 20, 0.3)',
textColor: 'rgba(163, 122, 116, 1)',
value: 'rgba(113, 128, 172, 0.75)',
opacityColor: 1,
};
}

// https://stackoverflow.com/questions/21646738/convert-hex-to-rgba
hexToRGB = (hex: string, alpha?: string) => {
const r = parseInt(hex.slice(1, 3), 16),
g = parseInt(hex.slice(3, 5), 16),
b = parseInt(hex.slice(5, 7), 16);

if (alpha) {
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
} else {
return `rgb(${r}, ${g}, ${b})`;
}
};

// https://jsfiddle.net/Mottie/xcqpF/1/light/
RGBToHex = (rgba: string) => {
if (rgba !== null) {
const newRgba = rgba.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
return newRgba && rgba.length === 4
? `#${`0${parseInt(newRgba[1], 10).toString(16)}`.slice(-2)}${`0${parseInt(newRgba[2], 10).toString(16)}`.slice(
-2,
)}${`0${parseInt(newRgba[3], 10).toString(16)}`.slice(-2)}`
: '';
}
};

updateForegroundColor = (event: any) => {
this.setState({
foregroundColor: this.hexToRGB(event.target.value),
});
};

updateTextColor = (event: any) => {
this.setState({
textColor: this.hexToRGB(event.target.value),
});
};

updateColorAlpha = (event: any) => {
this.setState({
opacityColor: event.target.value,
foregroundColor: this.combineOpacityToRGB(this.state.foregroundColor, event.target.value),
});
};

export class Playground extends React.Component {
combineOpacityToRGB = (rgb: string, opacity: string) => {
const [r, g, b] = rgb
.replace('rgb(', '')
.replace(')', '')
.split(',');
return `${r.trim()}, ${g.trim()}, ${b.trim()}, ${opacity})`;
};
render() {
const { backgroundColor, foregroundColor, textColor, value, opacityColor } = this.state;
const combinedColors = combineColors(foregroundColor, backgroundColor);
const makeContrasted = makeHighContrastColor(textColor, combinedColors, 4.5);
return (
<div className="testing">
<div className="chart">{Example()}</div>
</div>
<form
className="background echChart"
style={{
backgroundColor: backgroundColor,
position: 'absolute',
width: 425,
height: 500,
top: 10,
left: 10,
}}
>
<div
className="foreground"
style={{
backgroundColor: foregroundColor,
position: 'absolute',
width: 200,
height: 400,
top: 10,
left: 200,
opacity: opacityColor,
}}
>
<label>foreground color input </label>
<input
type="color"
name="foregroundColor"
defaultValue={this.RGBToHex(value)}
onChange={this.updateForegroundColor.bind(this)}
/>
<br />
<input
type="range"
id="alpha"
onChange={this.updateColorAlpha.bind(this)}
min="0.3"
max="1"
step="0.1"
defaultValue={this.state.value}
/>
<p
style={{
paddingTop: 40,
paddingBottom: 40,
}}
>
This is the foreground color
<br />
<br />
{foregroundColor}
</p>
<p
className="text"
style={{
color: textColor,
padding: 20,
}}
>
Here is the original text color
</p>
<label>text color input </label>
<input
type="color"
name="textColor"
defaultValue={this.RGBToHex(value)}
onChange={this.updateTextColor.bind(this)}
/>
<p
className="text"
style={{
color: makeContrasted,
padding: 20,
}}
>
Here is some text with contrasted color
</p>
<button
style={{
border: '2px solid black',
color: 'lavender',
background: 'grey',
}}
onClick={() => makeHighContrastColor(textColor, combineColors(foregroundColor, backgroundColor))}
>
Calculate new contrast
</button>
<br />
<br />
</div>
<div
className="showCalculations"
style={{
position: 'absolute',
width: 200,
height: 400,
top: 40,
left: 450,
}}
>
<p
style={{
paddingBottom: 40,
}}
>
Contrast between original text color and combinedBackground color
<br />
<br />
<b>{getContrast(textColor, combinedColors).toFixed(3)}</b>
</p>
<p>
Contrast between contrast-computed text color and combinedBackground color
<br />
<br />
<b>{getContrast(makeContrasted, combinedColors).toFixed(3)}</b>
</p>
</div>
<div
className="combinedforeground"
style={{
backgroundColor: combineColors(foregroundColor, backgroundColor),
position: 'absolute',
width: 200,
height: 400,
top: 10,
left: 700,
}}
>
<p
style={{
margin: 'auto',
padding: 10,
}}
>
This is the combined background and container background using the combineColors function
<br />
<br />
The rgba of this div is:
<br />
<b>{combineColors(foregroundColor, backgroundColor)}</b>
</p>
</div>
</form>
);
}
}
13 changes: 11 additions & 2 deletions api/charts.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ export interface AxisStyle {
tickLabelPadding?: number;
}

// Warning: (ae-missing-release-tag) "BackgroundStyles" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
export interface BackgroundStyles {
// (undocumented)
color: string;
}

// Warning: (ae-forgotten-export) The symbol "SpecRequiredProps" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "SpecOptionalProps" needs to be exported by the entry point index.d.ts
// Warning: (ae-missing-release-tag) "BarSeries" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
Expand Down Expand Up @@ -1403,6 +1411,7 @@ export interface Theme {
areaSeriesStyle: AreaSeriesStyle;
// (undocumented)
axes: AxisConfig;
background: BackgroundStyles;
barSeriesStyle: BarSeriesStyle;
bubbleSeriesStyle: BubbleSeriesStyle;
chartMargins: Margins;
Expand Down Expand Up @@ -1534,8 +1543,8 @@ export interface XYChartSeriesIdentifier extends SeriesIdentifier {

// Warnings were encountered during analysis:
//
// src/chart_types/partition_chart/layout/types/config_types.ts:117:5 - (ae-forgotten-export) The symbol "TimeMs" needs to be exported by the entry point index.d.ts
// src/chart_types/partition_chart/layout/types/config_types.ts:118:5 - (ae-forgotten-export) The symbol "AnimKeyframe" needs to be exported by the entry point index.d.ts
// src/chart_types/partition_chart/layout/types/config_types.ts:120:5 - (ae-forgotten-export) The symbol "TimeMs" needs to be exported by the entry point index.d.ts
// src/chart_types/partition_chart/layout/types/config_types.ts:121:5 - (ae-forgotten-export) The symbol "AnimKeyframe" needs to be exported by the entry point index.d.ts
// src/chart_types/partition_chart/specs/index.ts:47:13 - (ae-forgotten-export) The symbol "NodeColorAccessor" needs to be exported by the entry point index.d.ts
// src/commons/series_id.ts:37:3 - (ae-forgotten-export) The symbol "SeriesKey" needs to be exported by the entry point index.d.ts

Expand Down
Loading