victory-core 37.1.2 → 37.2.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.
@@ -73,17 +73,27 @@ const green = {
73
73
  "900": "#338A17",
74
74
  };
75
75
 
76
- const colors = [
77
- blue["500"],
78
- pink["500"],
79
- teal["500"],
80
- purple["500"],
81
- green["500"],
82
- orange["500"],
83
- cyan["500"],
84
- red["500"],
85
- yellow["500"],
86
- ];
76
+ const colors = {
77
+ blue: blue["500"],
78
+ pink: pink["500"],
79
+ teal: teal["500"],
80
+ purple: purple["500"],
81
+ green: green["500"],
82
+ orange: orange["500"],
83
+ cyan: cyan["500"],
84
+ red: red["500"],
85
+ yellow: yellow["500"],
86
+ };
87
+
88
+ const colorScale = Object.values(colors);
89
+ const grayscale = [gray["200"], gray["400"], gray["600"], gray["900"]];
90
+ const warm = [yellow["500"], orange["500"], red["500"], pink["500"]];
91
+ const cool = [cyan["500"], teal["500"], blue["500"], purple["500"]];
92
+ const heatmap = [green["500"], yellow["500"], red["500"]];
93
+ const redPalette = [red["500"], red["300"], red["100"]];
94
+ const greenPalette = [green["500"], green["300"], green["100"]];
95
+ const bluePalette = [blue["500"], blue["300"], blue["100"]];
96
+
87
97
  // *
88
98
  // * Typography
89
99
  // *
@@ -99,7 +109,7 @@ const baseProps = {
99
109
  width: 450,
100
110
  height: 300,
101
111
  padding: 50,
102
- colorScale: colors,
112
+ colorScale,
103
113
  };
104
114
  // *
105
115
  // * Labels
@@ -130,11 +140,24 @@ const borderRadius = 1;
130
140
  // * Theme
131
141
  // *
132
142
  export const clean: VictoryThemeDefinition = {
143
+ palette: {
144
+ colors,
145
+ grayscale,
146
+ qualitative: colorScale,
147
+ heatmap,
148
+ warm,
149
+ cool,
150
+ red: redPalette,
151
+ green: greenPalette,
152
+ blue: bluePalette,
153
+ },
133
154
  area: Object.assign(
134
155
  {
135
156
  style: {
136
157
  data: {
137
- fill: cyan["500"],
158
+ fill: blue["500"],
159
+ strokeWidth: 2,
160
+ fillOpacity: 0.5,
138
161
  },
139
162
  labels: baseLabelStyles,
140
163
  },
@@ -146,7 +169,7 @@ export const clean: VictoryThemeDefinition = {
146
169
  style: {
147
170
  axis: {
148
171
  fill: "transparent",
149
- stroke: gray["300"],
172
+ stroke: gray["500"],
150
173
  strokeWidth: 1,
151
174
  strokeLinecap,
152
175
  strokeLinejoin,
@@ -173,10 +196,10 @@ export const clean: VictoryThemeDefinition = {
173
196
  polarAxis: Object.assign({
174
197
  style: {
175
198
  axis: {
176
- stroke: gray["300"],
199
+ stroke: gray["500"],
177
200
  },
178
201
  grid: {
179
- stroke: gray["200"],
202
+ stroke: gray["400"],
180
203
  strokeDasharray,
181
204
  strokeLinecap,
182
205
  strokeLinejoin,
@@ -185,7 +208,7 @@ export const clean: VictoryThemeDefinition = {
185
208
  ticks: {
186
209
  fill: "transparent",
187
210
  size: 5,
188
- stroke: gray["200"],
211
+ stroke: gray["400"],
189
212
  strokeWidth: 1,
190
213
  strokeLinecap,
191
214
  strokeLinejoin,
@@ -196,10 +219,10 @@ export const clean: VictoryThemeDefinition = {
196
219
  polarDependentAxis: Object.assign({
197
220
  style: {
198
221
  axis: {
199
- stroke: gray["300"],
222
+ stroke: gray["500"],
200
223
  },
201
224
  grid: {
202
- stroke: gray["200"],
225
+ stroke: gray["400"],
203
226
  strokeDasharray,
204
227
  strokeLinecap,
205
228
  strokeLinejoin,
@@ -208,7 +231,7 @@ export const clean: VictoryThemeDefinition = {
208
231
  ticks: {
209
232
  fill: "transparent",
210
233
  size: 5,
211
- stroke: gray["200"],
234
+ stroke: gray["300"],
212
235
  strokeWidth: 1,
213
236
  strokeLinecap,
214
237
  strokeLinejoin,
@@ -222,7 +245,8 @@ export const clean: VictoryThemeDefinition = {
222
245
  data: {
223
246
  fill: blue["500"],
224
247
  padding,
225
- strokeWidth: 0,
248
+ strokeWidth: 1,
249
+ fillOpacity: 0.5,
226
250
  },
227
251
  labels: baseLabelStyles,
228
252
  },
@@ -239,9 +263,9 @@ export const clean: VictoryThemeDefinition = {
239
263
  medianLabels: Object.assign({}, baseLabelStyles, { padding: 3 }),
240
264
  min: { padding, stroke: gray["400"], strokeWidth: 2 },
241
265
  minLabels: Object.assign({}, baseLabelStyles, { padding: 3 }),
242
- q1: { padding, fill: teal["500"], rx: borderRadius },
266
+ q1: { padding, fill: teal["500"], rx: borderRadius, strokeWidth: 2 },
243
267
  q1Labels: Object.assign({}, baseLabelStyles, { padding: 3 }),
244
- q3: { padding, fill: teal["500"], rx: borderRadius },
268
+ q3: { padding, fill: cyan["500"], rx: borderRadius },
245
269
  q3Labels: Object.assign({}, baseLabelStyles, { padding: 3 }),
246
270
  },
247
271
  boxWidth: 20,
@@ -285,7 +309,7 @@ export const clean: VictoryThemeDefinition = {
285
309
  ),
286
310
  group: Object.assign(
287
311
  {
288
- colorScale: colors,
312
+ colorScale,
289
313
  },
290
314
  baseProps,
291
315
  ),
@@ -294,8 +318,7 @@ export const clean: VictoryThemeDefinition = {
294
318
  style: {
295
319
  data: {
296
320
  fill: cyan["500"],
297
- stroke: "transparent",
298
- strokeWidth: 0,
321
+ fillOpacity: 0.5,
299
322
  },
300
323
  labels: baseLabelStyles,
301
324
  },
@@ -306,16 +329,18 @@ export const clean: VictoryThemeDefinition = {
306
329
  ),
307
330
  label: baseLabelStyles,
308
331
  legend: {
309
- colorScale: colors,
310
- gutter: 10,
311
- orientation: "vertical",
332
+ colorScale,
333
+ gutter: 24,
334
+ borderPadding: 10,
335
+ orientation: "horizontal",
312
336
  titleOrientation: "top",
337
+ centerTitle: true,
313
338
  style: {
314
339
  data: {
315
340
  type: "circle",
316
341
  },
317
- labels: { ...baseLabelStyles, fontSize: 14 },
318
- title: Object.assign({}, baseLabelStyles, { padding, fontSize: 20 }),
342
+ labels: { ...baseLabelStyles, fontSize: 12 },
343
+ title: Object.assign({}, baseLabelStyles, { padding, fontSize: 16 }),
319
344
  border: { stroke: gray["200"], strokeWidth: 2, padding: 16 },
320
345
  },
321
346
  },
@@ -325,7 +350,7 @@ export const clean: VictoryThemeDefinition = {
325
350
  data: {
326
351
  fill: "transparent",
327
352
  opacity: 1,
328
- stroke: pink["500"],
353
+ stroke: blue["500"],
329
354
  strokeWidth: 2,
330
355
  strokeLinecap,
331
356
  strokeLinejoin,
@@ -338,14 +363,22 @@ export const clean: VictoryThemeDefinition = {
338
363
  pie: Object.assign(
339
364
  {
340
365
  style: {
366
+ parent: {
367
+ backgroundColor: gray.white,
368
+ },
341
369
  data: {
342
370
  padding,
343
371
  stroke: gray.white,
344
372
  strokeWidth: 1,
345
373
  },
346
- labels: Object.assign({}, baseLabelStyles, { padding: 20 }),
374
+ labels: {
375
+ ...baseLabelStyles,
376
+ padding: 20,
377
+ fill: gray["600"],
378
+ fontSize: 10,
379
+ },
347
380
  },
348
- colorScale: colors,
381
+ colorScale,
349
382
  cornerRadius: borderRadius,
350
383
  },
351
384
  baseProps,
@@ -359,14 +392,17 @@ export const clean: VictoryThemeDefinition = {
359
392
  stroke: "transparent",
360
393
  strokeWidth: 0,
361
394
  },
362
- labels: baseLabelStyles,
395
+ labels: {
396
+ ...baseLabelStyles,
397
+ padding: 20,
398
+ },
363
399
  },
364
400
  },
365
401
  baseProps,
366
402
  ),
367
403
  stack: Object.assign(
368
404
  {
369
- colorScale: colors,
405
+ colorScale,
370
406
  },
371
407
  baseProps,
372
408
  ),
@@ -376,7 +412,7 @@ export const clean: VictoryThemeDefinition = {
376
412
  pointerEvents: "none",
377
413
  }),
378
414
  flyoutStyle: {
379
- stroke: gray["500"],
415
+ stroke: gray["300"],
380
416
  strokeWidth: 2,
381
417
  fill: gray.white,
382
418
  pointerEvents: "none",
@@ -389,9 +425,10 @@ export const clean: VictoryThemeDefinition = {
389
425
  {
390
426
  style: {
391
427
  data: {
392
- fill: red["100"],
393
- stroke: red["500"],
428
+ fill: blue["100"],
429
+ stroke: blue["500"],
394
430
  strokeWidth: 2,
431
+ opacity: 0.4,
395
432
  },
396
433
  labels: Object.assign({}, baseLabelStyles, {
397
434
  padding: 5,
@@ -3,7 +3,19 @@ import { VictoryThemeDefinition } from "./types";
3
3
  // *
4
4
  // * Colors
5
5
  // *
6
- const colors = [
6
+ const colors = {
7
+ blue: "#4F7DA1",
8
+ pink: "#E2A37F",
9
+ teal: "#00796B",
10
+ purple: "#DF948A",
11
+ green: "#8BC34A",
12
+ orange: "#F4511E",
13
+ cyan: "#006064",
14
+ red: "#DF5A49",
15
+ yellow: "#FFF59D",
16
+ };
17
+
18
+ const colorScale = [
7
19
  "#252525",
8
20
  "#525252",
9
21
  "#737373",
@@ -15,6 +27,26 @@ const colors = [
15
27
 
16
28
  const charcoal = "#252525";
17
29
  const grey = "#969696";
30
+
31
+ const qualitative = [
32
+ "#334D5C",
33
+ "#45B29D",
34
+ "#EFC94C",
35
+ "#E27A3F",
36
+ "#DF5A49",
37
+ "#4F7DA1",
38
+ "#55DBC1",
39
+ "#EFDA97",
40
+ "#E2A37F",
41
+ "#DF948A",
42
+ ];
43
+ const heatmap = ["#428517", "#77D200", "#D6D305", "#EC8E19", "#C92B05"];
44
+ const warm = ["#940031", "#C43343", "#DC5429", "#FF821D", "#FFAF55"];
45
+ const cool = ["#2746B9", "#0B69D4", "#2794DB", "#31BB76", "#60E83B"];
46
+ const red = ["#FCAE91", "#FB6A4A", "#DE2D26", "#A50F15", "#750B0E"];
47
+ const green = ["#354722", "#466631", "#649146", "#8AB25C", "#A9C97E"];
48
+ const blue = ["#002C61", "#004B8F", "#006BC9", "#3795E5", "#65B4F4"];
49
+
18
50
  // *
19
51
  // * Typography
20
52
  // *
@@ -28,7 +60,7 @@ const baseProps = {
28
60
  width: 450,
29
61
  height: 300,
30
62
  padding: 50,
31
- colorScale: colors,
63
+ colorScale,
32
64
  };
33
65
  // *
34
66
  // * Labels
@@ -53,6 +85,17 @@ const strokeLinecap = "round";
53
85
  const strokeLinejoin = "round";
54
86
 
55
87
  export const grayscale: VictoryThemeDefinition = {
88
+ palette: {
89
+ colors,
90
+ grayscale: colorScale,
91
+ qualitative,
92
+ heatmap,
93
+ warm,
94
+ cool,
95
+ red,
96
+ green,
97
+ blue,
98
+ },
56
99
  area: Object.assign(
57
100
  {
58
101
  style: {
@@ -156,7 +199,7 @@ export const grayscale: VictoryThemeDefinition = {
156
199
  ),
157
200
  group: Object.assign(
158
201
  {
159
- colorScale: colors,
202
+ colorScale,
160
203
  },
161
204
  baseProps,
162
205
  ),
@@ -174,7 +217,7 @@ export const grayscale: VictoryThemeDefinition = {
174
217
  baseProps,
175
218
  ),
176
219
  legend: {
177
- colorScale: colors,
220
+ colorScale,
178
221
  gutter: 10,
179
222
  orientation: "vertical",
180
223
  titleOrientation: "top",
@@ -208,7 +251,7 @@ export const grayscale: VictoryThemeDefinition = {
208
251
  },
209
252
  labels: Object.assign({}, baseLabelStyles, { padding: 20 }),
210
253
  },
211
- colorScale: colors,
254
+ colorScale,
212
255
  width: 400,
213
256
  height: 400,
214
257
  padding: 50,
@@ -228,7 +271,7 @@ export const grayscale: VictoryThemeDefinition = {
228
271
  ),
229
272
  stack: Object.assign(
230
273
  {
231
- colorScale: colors,
274
+ colorScale,
232
275
  },
233
276
  baseProps,
234
277
  ),
@@ -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 colors = [
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: colors,
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: colors,
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: colors,
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: colors,
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(name) {
39
- const scales = {
40
- grayscale: ["#cccccc", "#969696", "#636363", "#252525"],
41
- qualitative: [
42
- "#334D5C",
43
- "#45B29D",
44
- "#EFC94C",
45
- "#E27A3F",
46
- "#DF5A49",
47
- "#4F7DA1",
48
- "#55DBC1",
49
- "#EFDA97",
50
- "#E2A37F",
51
- "#DF948A",
52
- ],
53
- heatmap: ["#428517", "#77D200", "#D6D305", "#EC8E19", "#C92B05"],
54
- warm: ["#940031", "#C43343", "#DC5429", "#FF821D", "#FFAF55"],
55
- cool: ["#2746B9", "#0B69D4", "#2794DB", "#31BB76", "#60E83B"],
56
- red: ["#FCAE91", "#FB6A4A", "#DE2D26", "#A50F15", "#750B0E"],
57
- blue: ["#002C61", "#004B8F", "#006BC9", "#3795E5", "#65B4F4"],
58
- green: ["#354722", "#466631", "#649146", "#8AB25C", "#A9C97E"],
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
- return name ? scales[name] : scales.grayscale;
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
- export function getColor(calculatedProps, child, index) {
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
- export function getChildStyle(child, index, calculatedProps) {
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" ? undefined : getColor(calculatedProps, child, index);
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 }