victory-core 37.1.2 → 37.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/dist/victory-core.js +293 -168
- package/dist/victory-core.min.js +1 -1
- package/es/types/prop-types.d.ts +1 -0
- package/es/victory-portal/victory-portal.js +3 -2
- package/es/victory-theme/clean.js +86 -44
- package/es/victory-theme/grayscale.js +36 -6
- package/es/victory-theme/material.js +36 -5
- package/es/victory-theme/types.d.ts +16 -0
- package/es/victory-util/style.d.ts +3 -1
- package/es/victory-util/style.js +29 -10
- package/es/victory-util/wrapper.d.ts +3 -3
- package/es/victory-util/wrapper.js +16 -15
- package/lib/types/prop-types.d.ts +1 -0
- package/lib/victory-portal/victory-portal.js +3 -2
- package/lib/victory-theme/clean.js +86 -44
- package/lib/victory-theme/grayscale.js +36 -6
- package/lib/victory-theme/material.js +36 -5
- package/lib/victory-theme/types.d.ts +16 -0
- package/lib/victory-util/style.d.ts +3 -1
- package/lib/victory-util/style.js +28 -10
- package/lib/victory-util/wrapper.d.ts +3 -3
- package/lib/victory-util/wrapper.js +17 -16
- package/package.json +2 -2
- package/src/types/prop-types.ts +1 -0
- package/src/victory-portal/victory-portal.tsx +3 -3
- package/src/victory-theme/clean.tsx +104 -45
- package/src/victory-theme/grayscale.tsx +49 -6
- package/src/victory-theme/material.tsx +50 -6
- package/src/victory-theme/types.ts +26 -0
- package/src/victory-util/style.ts +37 -22
- package/src/victory-util/wrapper.tsx +18 -27
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VictoryThemeDefinition } from "./types";
|
|
1
|
+
import { VictoryThemeDefinition, VictoryThemePalette } from "./types";
|
|
2
2
|
|
|
3
3
|
// *
|
|
4
4
|
// * Colors
|
|
@@ -9,7 +9,7 @@ const lime300 = "#DCE775";
|
|
|
9
9
|
const lightGreen500 = "#8BC34A";
|
|
10
10
|
const teal700 = "#00796B";
|
|
11
11
|
const cyan900 = "#006064";
|
|
12
|
-
const
|
|
12
|
+
const colorScale = [
|
|
13
13
|
deepOrange600,
|
|
14
14
|
yellow200,
|
|
15
15
|
lime300,
|
|
@@ -21,6 +21,39 @@ const blueGrey50 = "#ECEFF1";
|
|
|
21
21
|
const blueGrey300 = "#90A4AE";
|
|
22
22
|
const blueGrey700 = "#455A64";
|
|
23
23
|
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
|
+
|
|
24
57
|
// *
|
|
25
58
|
// * Typography
|
|
26
59
|
// *
|
|
@@ -61,6 +94,17 @@ const strokeLinecap = "round";
|
|
|
61
94
|
const strokeLinejoin = "round";
|
|
62
95
|
|
|
63
96
|
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
|
+
},
|
|
64
108
|
area: Object.assign(
|
|
65
109
|
{
|
|
66
110
|
style: {
|
|
@@ -182,7 +226,7 @@ export const material: VictoryThemeDefinition = {
|
|
|
182
226
|
),
|
|
183
227
|
group: Object.assign(
|
|
184
228
|
{
|
|
185
|
-
colorScale
|
|
229
|
+
colorScale,
|
|
186
230
|
},
|
|
187
231
|
baseProps,
|
|
188
232
|
),
|
|
@@ -200,7 +244,7 @@ export const material: VictoryThemeDefinition = {
|
|
|
200
244
|
baseProps,
|
|
201
245
|
),
|
|
202
246
|
legend: {
|
|
203
|
-
colorScale
|
|
247
|
+
colorScale,
|
|
204
248
|
gutter: 10,
|
|
205
249
|
orientation: "vertical",
|
|
206
250
|
titleOrientation: "top",
|
|
@@ -228,7 +272,7 @@ export const material: VictoryThemeDefinition = {
|
|
|
228
272
|
),
|
|
229
273
|
pie: Object.assign(
|
|
230
274
|
{
|
|
231
|
-
colorScale
|
|
275
|
+
colorScale,
|
|
232
276
|
style: {
|
|
233
277
|
data: {
|
|
234
278
|
padding,
|
|
@@ -256,7 +300,7 @@ export const material: VictoryThemeDefinition = {
|
|
|
256
300
|
),
|
|
257
301
|
stack: Object.assign(
|
|
258
302
|
{
|
|
259
|
-
colorScale
|
|
303
|
+
colorScale,
|
|
260
304
|
},
|
|
261
305
|
baseProps,
|
|
262
306
|
),
|
|
@@ -72,7 +72,33 @@ export interface VictoryAxisCommonProps {
|
|
|
72
72
|
export type VerticalAnchorType = "start" | "middle" | "end";
|
|
73
73
|
// #region Victory Theme
|
|
74
74
|
// Note: Many SVG attributes are missed in CSSProperties interface
|
|
75
|
+
type VictoryThemePaletteKeys =
|
|
76
|
+
| "blue"
|
|
77
|
+
| "pink"
|
|
78
|
+
| "teal"
|
|
79
|
+
| "purple"
|
|
80
|
+
| "green"
|
|
81
|
+
| "orange"
|
|
82
|
+
| "cyan"
|
|
83
|
+
| "red"
|
|
84
|
+
| "yellow";
|
|
85
|
+
|
|
86
|
+
export type VictoryThemePalette = {
|
|
87
|
+
[key in VictoryThemePaletteKeys]?: string;
|
|
88
|
+
};
|
|
89
|
+
|
|
75
90
|
export interface VictoryThemeDefinition {
|
|
91
|
+
palette?: {
|
|
92
|
+
colors?: VictoryThemePalette;
|
|
93
|
+
grayscale?: string[];
|
|
94
|
+
qualitative?: string[];
|
|
95
|
+
heatmap?: string[];
|
|
96
|
+
warm?: string[];
|
|
97
|
+
cool?: string[];
|
|
98
|
+
red?: string[];
|
|
99
|
+
blue?: string[];
|
|
100
|
+
green?: string[];
|
|
101
|
+
};
|
|
76
102
|
area?: {
|
|
77
103
|
style?: {
|
|
78
104
|
data?: VictoryStyleObject;
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
VictoryTheme,
|
|
3
|
+
VictoryThemeDefinition,
|
|
4
|
+
} from "../victory-theme/victory-theme";
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* Given an object with CSS/SVG transform definitions, return the string value
|
|
3
8
|
* for use with the `transform` CSS property or SVG attribute. Note that we
|
|
@@ -33,29 +38,39 @@ export const toTransformString = function (obj, ...more) {
|
|
|
33
38
|
* of 5 hex string values in that color scale. If no 'name' parameter
|
|
34
39
|
* is given, it will return the Victory default grayscale.
|
|
35
40
|
* @param {String} name The name of the color scale to return (optional).
|
|
41
|
+
* @param {Object} theme The theme object to retrieve the color scale from (optional).
|
|
36
42
|
* @returns {Array} An array of 5 hex string values composing a color scale.
|
|
37
43
|
*/
|
|
38
|
-
export function getColorScale(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"#
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
44
|
+
export function getColorScale(
|
|
45
|
+
name?: string,
|
|
46
|
+
theme: VictoryThemeDefinition = VictoryTheme.material,
|
|
47
|
+
) {
|
|
48
|
+
const {
|
|
49
|
+
palette: {
|
|
50
|
+
grayscale = ["#cccccc", "#969696", "#636363", "#252525"],
|
|
51
|
+
qualitative = [],
|
|
52
|
+
heatmap = [],
|
|
53
|
+
warm = [],
|
|
54
|
+
cool = [],
|
|
55
|
+
red = [],
|
|
56
|
+
blue = [],
|
|
57
|
+
green = [],
|
|
58
|
+
} = {},
|
|
59
|
+
} = theme;
|
|
60
|
+
|
|
61
|
+
const scales: Record<string, string[]> = {
|
|
62
|
+
grayscale,
|
|
63
|
+
qualitative,
|
|
64
|
+
heatmap,
|
|
65
|
+
warm,
|
|
66
|
+
cool,
|
|
67
|
+
red,
|
|
68
|
+
blue,
|
|
69
|
+
green,
|
|
59
70
|
};
|
|
60
|
-
|
|
71
|
+
|
|
72
|
+
const selectedScale =
|
|
73
|
+
name && scales[name]?.length ? scales[name] : scales.grayscale;
|
|
74
|
+
|
|
75
|
+
return selectedScale;
|
|
61
76
|
}
|
|
@@ -298,7 +298,8 @@ export function getAllEvents(props) {
|
|
|
298
298
|
return events || [];
|
|
299
299
|
}
|
|
300
300
|
|
|
301
|
-
|
|
301
|
+
// eslint-disable-next-line max-params
|
|
302
|
+
export function getColor(calculatedProps, child, index, theme) {
|
|
302
303
|
// check for styles first
|
|
303
304
|
const { style } = calculatedProps;
|
|
304
305
|
let { colorScale, color } = calculatedProps;
|
|
@@ -313,7 +314,7 @@ export function getColor(calculatedProps, child, index) {
|
|
|
313
314
|
}
|
|
314
315
|
const colors = Array.isArray(colorScale)
|
|
315
316
|
? colorScale
|
|
316
|
-
: Style.getColorScale(colorScale);
|
|
317
|
+
: Style.getColorScale(colorScale, theme);
|
|
317
318
|
return color || colors[index % colors.length];
|
|
318
319
|
}
|
|
319
320
|
|
|
@@ -323,7 +324,8 @@ export function getStyle(theme, style, role) {
|
|
|
323
324
|
return Helpers.getStyles(style, defaultStyle);
|
|
324
325
|
}
|
|
325
326
|
|
|
326
|
-
|
|
327
|
+
// eslint-disable-next-line max-params
|
|
328
|
+
export function getChildStyle(child, index, calculatedProps, theme) {
|
|
327
329
|
const { style, role } = calculatedProps;
|
|
328
330
|
const childStyle = child.props.style || {};
|
|
329
331
|
if (Array.isArray(childStyle)) {
|
|
@@ -331,7 +333,9 @@ export function getChildStyle(child, index, calculatedProps) {
|
|
|
331
333
|
}
|
|
332
334
|
const childRole = child.type && child.type.role;
|
|
333
335
|
const defaultFill =
|
|
334
|
-
childRole === "stack"
|
|
336
|
+
childRole === "stack"
|
|
337
|
+
? undefined
|
|
338
|
+
: getColor(calculatedProps, child, index, theme);
|
|
335
339
|
const defaultColor =
|
|
336
340
|
childRole === "line"
|
|
337
341
|
? { fill: "none", stroke: defaultFill }
|
|
@@ -352,19 +356,13 @@ export function getChildStyle(child, index, calculatedProps) {
|
|
|
352
356
|
};
|
|
353
357
|
}
|
|
354
358
|
|
|
355
|
-
export function
|
|
359
|
+
export function getStringsFromChildrenCategories(childComponents, axis) {
|
|
356
360
|
const iteratee = (child) => {
|
|
357
|
-
|
|
358
|
-
if (!Domain.isDomainComponent(child) || !childProps.categories) {
|
|
361
|
+
if (!Domain.isDomainComponent(child)) {
|
|
359
362
|
return null;
|
|
360
363
|
}
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
? childProps.categories[axis]
|
|
364
|
-
: childProps.props.categories;
|
|
365
|
-
const categoryStrings =
|
|
366
|
-
categories && categories.filter((val) => typeof val === "string");
|
|
367
|
-
return categoryStrings ? Collection.removeUndefined(categoryStrings) : [];
|
|
364
|
+
const childProps = child.props || {};
|
|
365
|
+
return Data.getStringsFromCategories(childProps, axis);
|
|
368
366
|
};
|
|
369
367
|
return Helpers.reduceChildren(childComponents.slice(0), iteratee);
|
|
370
368
|
}
|
|
@@ -413,15 +411,14 @@ export function getCategoryAndAxisStringsFromChildren(
|
|
|
413
411
|
axis,
|
|
414
412
|
childComponents,
|
|
415
413
|
) {
|
|
416
|
-
const categories =
|
|
417
|
-
? props.categories[axis]
|
|
418
|
-
: props.categories;
|
|
414
|
+
const categories = Data.getStringsFromCategories(props, axis);
|
|
419
415
|
const axisComponent = Axis.getAxisComponent(childComponents, axis);
|
|
420
416
|
const axisStrings = axisComponent
|
|
421
417
|
? Data.getStringsFromAxes(axisComponent.props, axis)
|
|
422
418
|
: [];
|
|
423
|
-
const categoryStrings =
|
|
424
|
-
categories
|
|
419
|
+
const categoryStrings = categories.length
|
|
420
|
+
? categories
|
|
421
|
+
: getStringsFromChildrenCategories(childComponents, axis);
|
|
425
422
|
return uniq([...categoryStrings, ...axisStrings].flat());
|
|
426
423
|
}
|
|
427
424
|
|
|
@@ -441,15 +438,9 @@ export function getStringsFromChildren(props, childComponents) {
|
|
|
441
438
|
|
|
442
439
|
export function getCategories(props, childComponents, allStrings?) {
|
|
443
440
|
const xPropCategories =
|
|
444
|
-
props.categories &&
|
|
445
|
-
? props.categories.x
|
|
446
|
-
: props.categories;
|
|
447
|
-
|
|
441
|
+
props.categories && Data.getStringsFromCategories(props, "x");
|
|
448
442
|
const yPropCategories =
|
|
449
|
-
props.categories &&
|
|
450
|
-
? props.categories.y
|
|
451
|
-
: props.categories;
|
|
452
|
-
|
|
443
|
+
props.categories && Data.getStringsFromCategories(props, "y");
|
|
453
444
|
const fallbackRequired = !xPropCategories || !yPropCategories;
|
|
454
445
|
|
|
455
446
|
const fallbackProps = fallbackRequired
|