Skip to content

Commit 3b04136

Browse files
author
Stef Williams
committed
fix: address PR feedback
1 parent 076980f commit 3b04136

File tree

8 files changed

+82
-38
lines changed

8 files changed

+82
-38
lines changed

demo/ts/components/victory-bar-demo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export default class VictoryBarDemo extends React.Component<
151151
<div className="demo" style={containerStyle}>
152152
<ChartWrap>
153153
<VictoryBar
154-
theme={VictoryTheme.material}
154+
theme={VictoryTheme.clean}
155155
style={{
156156
data: { fill: VictoryTheme.clean.palette?.colors?.pink },
157157
}}

demo/ts/components/victory-histogram-demo.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,9 @@ export default class App extends React.Component<{}, VictoryBarDemoState> {
246246
},
247247
},
248248
],
249-
onMouseOut: () => [
250-
{
251-
mutation: (props) => {},
252-
},
253-
],
249+
onMouseOut: () => ({
250+
mutation: () => null,
251+
}),
254252
},
255253
},
256254
]}

demo/ts/components/victory-polar-axis-demo.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import { VictoryGroup } from "victory-group";
1313
import { VictoryTooltip } from "victory-tooltip";
1414
import { VictoryStack } from "victory-stack";
1515
import { random, range, keys } from "lodash";
16-
import { VictoryTheme, VictoryLabel } from "victory-core";
17-
import { VictoryThemePalette } from "victory-core/src/victory-theme/types";
16+
import { VictoryTheme, VictoryLabel, VictoryThemePalette } from "victory-core";
1817

1918
type multiAxisDataListType = {
2019
strength?: number;

packages/victory-core/src/victory-theme/clean.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { random } from "lodash";
21
import { VictoryThemeDefinition } from "./victory-theme";
32

43
// *

packages/victory-core/src/victory-theme/grayscale.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ const strokeLinecap = "round";
5353
const strokeLinejoin = "round";
5454

5555
export const grayscale: VictoryThemeDefinition = {
56+
palette: {
57+
grayscale: colors,
58+
},
5659
area: Object.assign(
5760
{
5861
style: {

packages/victory-core/src/victory-theme/material.tsx

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { VictoryThemeDefinition } from "./types";
1+
import { VictoryThemeDefinition, VictoryThemePalette } from "./types";
22

33
// *
44
// * Colors
@@ -9,7 +9,7 @@ const lime300 = "#DCE775";
99
const lightGreen500 = "#8BC34A";
1010
const teal700 = "#00796B";
1111
const cyan900 = "#006064";
12-
const colors = [
12+
const colorScale = [
1313
deepOrange600,
1414
yellow200,
1515
lime300,
@@ -21,6 +21,39 @@ const blueGrey50 = "#ECEFF1";
2121
const blueGrey300 = "#90A4AE";
2222
const blueGrey700 = "#455A64";
2323
const grey900 = "#212121";
24+
25+
const colors: VictoryThemePalette = {
26+
blue: "#4F7DA1",
27+
pink: "#E2A37F",
28+
teal: teal700,
29+
purple: "#DF948A",
30+
green: lightGreen500,
31+
orange: deepOrange600,
32+
cyan: cyan900,
33+
red: "#DF5A49",
34+
yellow: yellow200,
35+
};
36+
37+
const grayscale = [blueGrey50, blueGrey300, blueGrey700, grey900];
38+
const qualitative = [
39+
"#334D5C",
40+
"#45B29D",
41+
"#EFC94C",
42+
"#E27A3F",
43+
"#DF5A49",
44+
"#4F7DA1",
45+
"#55DBC1",
46+
"#EFDA97",
47+
"#E2A37F",
48+
"#DF948A",
49+
];
50+
const heatmap = ["#428517", "#77D200", "#D6D305", "#EC8E19", "#C92B05"];
51+
const warm = ["#940031", "#C43343", "#DC5429", "#FF821D", "#FFAF55"];
52+
const cool = ["#2746B9", "#0B69D4", "#2794DB", "#31BB76", "#60E83B"];
53+
const red = ["#FCAE91", "#FB6A4A", "#DE2D26", "#A50F15", "#750B0E"];
54+
const green = ["#354722", "#466631", "#649146", "#8AB25C", "#A9C97E"];
55+
const blue = ["#002C61", "#004B8F", "#006BC9", "#3795E5", "#65B4F4"];
56+
2457
// *
2558
// * Typography
2659
// *
@@ -61,6 +94,17 @@ const strokeLinecap = "round";
6194
const strokeLinejoin = "round";
6295

6396
export const material: VictoryThemeDefinition = {
97+
palette: {
98+
colors,
99+
grayscale,
100+
qualitative,
101+
heatmap,
102+
warm,
103+
cool,
104+
red,
105+
green,
106+
blue,
107+
},
64108
area: Object.assign(
65109
{
66110
style: {
@@ -182,7 +226,7 @@ export const material: VictoryThemeDefinition = {
182226
),
183227
group: Object.assign(
184228
{
185-
colorScale: colors,
229+
colorScale,
186230
},
187231
baseProps,
188232
),
@@ -200,7 +244,7 @@ export const material: VictoryThemeDefinition = {
200244
baseProps,
201245
),
202246
legend: {
203-
colorScale: colors,
247+
colorScale,
204248
gutter: 10,
205249
orientation: "vertical",
206250
titleOrientation: "top",
@@ -228,7 +272,7 @@ export const material: VictoryThemeDefinition = {
228272
),
229273
pie: Object.assign(
230274
{
231-
colorScale: colors,
275+
colorScale,
232276
style: {
233277
data: {
234278
padding,
@@ -256,7 +300,7 @@ export const material: VictoryThemeDefinition = {
256300
),
257301
stack: Object.assign(
258302
{
259-
colorScale: colors,
303+
colorScale,
260304
},
261305
baseProps,
262306
),

packages/victory-core/src/victory-util/style.ts

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { VictoryThemeDefinition } from "../victory-theme/victory-theme";
1+
import {
2+
VictoryTheme,
3+
VictoryThemeDefinition,
4+
} from "../victory-theme/victory-theme";
25

36
/**
47
* Given an object with CSS/SVG transform definitions, return the string value
@@ -38,32 +41,24 @@ export const toTransformString = function (obj, ...more) {
3841
* @param {Object} theme The theme object to retrieve the color scale from (optional).
3942
* @returns {Array} An array of 5 hex string values composing a color scale.
4043
*/
41-
export function getColorScale(name?: string, theme?: VictoryThemeDefinition) {
44+
export function getColorScale(
45+
name?: keyof VictoryThemeDefinition["palette"],
46+
theme: VictoryThemeDefinition = VictoryTheme.material,
47+
) {
4248
const {
4349
palette: {
4450
grayscale = ["#cccccc", "#969696", "#636363", "#252525"],
45-
qualitative = [
46-
"#334D5C",
47-
"#45B29D",
48-
"#EFC94C",
49-
"#E27A3F",
50-
"#DF5A49",
51-
"#4F7DA1",
52-
"#55DBC1",
53-
"#EFDA97",
54-
"#E2A37F",
55-
"#DF948A",
56-
],
57-
heatmap = ["#428517", "#77D200", "#D6D305", "#EC8E19", "#C92B05"],
58-
warm = ["#940031", "#C43343", "#DC5429", "#FF821D", "#FFAF55"],
59-
cool = ["#2746B9", "#0B69D4", "#2794DB", "#31BB76", "#60E83B"],
60-
red = ["#FCAE91", "#FB6A4A", "#DE2D26", "#A50F15", "#750B0E"],
61-
blue = ["#002C61", "#004B8F", "#006BC9", "#3795E5", "#65B4F4"],
62-
green = ["#354722", "#466631", "#649146", "#8AB25C", "#A9C97E"],
51+
qualitative = [],
52+
heatmap = [],
53+
warm = [],
54+
cool = [],
55+
red = [],
56+
blue = [],
57+
green = [],
6358
} = {},
64-
} = theme || {};
59+
} = theme;
6560

66-
const scales = {
61+
const scales: Record<string, string[]> = {
6762
grayscale,
6863
qualitative,
6964
heatmap,
@@ -73,5 +68,9 @@ export function getColorScale(name?: string, theme?: VictoryThemeDefinition) {
7368
blue,
7469
green,
7570
};
76-
return name ? scales[name] : scales.grayscale;
71+
72+
const selectedScale =
73+
name && scales[name]?.length ? scales[name] : scales.grayscale;
74+
75+
return selectedScale;
7776
}

packages/victory-core/src/victory-util/wrapper.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ export function getAllEvents(props) {
298298
return events || [];
299299
}
300300

301+
// eslint-disable-next-line max-params
301302
export function getColor(calculatedProps, child, index, theme) {
302303
// check for styles first
303304
const { style } = calculatedProps;
@@ -323,6 +324,7 @@ export function getStyle(theme, style, role) {
323324
return Helpers.getStyles(style, defaultStyle);
324325
}
325326

327+
// eslint-disable-next-line max-params
326328
export function getChildStyle(child, index, calculatedProps, theme) {
327329
const { style, role } = calculatedProps;
328330
const childStyle = child.props.style || {};

0 commit comments

Comments
 (0)