victory-core 37.1.1 → 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.
Files changed (42) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/victory-core.js +608 -41
  3. package/dist/victory-core.min.js +1 -1
  4. package/es/types/prop-types.d.ts +1 -0
  5. package/es/victory-portal/victory-portal.js +2 -1
  6. package/es/victory-theme/clean.d.ts +3 -0
  7. package/es/victory-theme/clean.js +457 -0
  8. package/es/victory-theme/grayscale.js +36 -6
  9. package/es/victory-theme/material.js +36 -5
  10. package/es/victory-theme/types.d.ts +17 -0
  11. package/es/victory-theme/victory-theme.d.ts +1 -0
  12. package/es/victory-theme/victory-theme.js +3 -1
  13. package/es/victory-util/style.d.ts +3 -1
  14. package/es/victory-util/style.js +29 -10
  15. package/es/victory-util/textsize.js +5 -0
  16. package/es/victory-util/wrapper.d.ts +2 -2
  17. package/es/victory-util/wrapper.js +8 -4
  18. package/lib/types/prop-types.d.ts +1 -0
  19. package/lib/victory-portal/victory-portal.js +2 -1
  20. package/lib/victory-theme/clean.d.ts +3 -0
  21. package/lib/victory-theme/clean.js +463 -0
  22. package/lib/victory-theme/grayscale.js +36 -6
  23. package/lib/victory-theme/material.js +36 -5
  24. package/lib/victory-theme/types.d.ts +17 -0
  25. package/lib/victory-theme/victory-theme.d.ts +1 -0
  26. package/lib/victory-theme/victory-theme.js +3 -1
  27. package/lib/victory-util/style.d.ts +3 -1
  28. package/lib/victory-util/style.js +28 -10
  29. package/lib/victory-util/textsize.js +5 -0
  30. package/lib/victory-util/wrapper.d.ts +2 -2
  31. package/lib/victory-util/wrapper.js +8 -4
  32. package/package.json +2 -2
  33. package/src/types/prop-types.ts +1 -0
  34. package/src/victory-portal/victory-portal.tsx +2 -2
  35. package/src/victory-theme/clean.tsx +448 -0
  36. package/src/victory-theme/grayscale.tsx +49 -6
  37. package/src/victory-theme/material.tsx +50 -6
  38. package/src/victory-theme/types.ts +27 -0
  39. package/src/victory-theme/victory-theme.tsx +3 -1
  40. package/src/victory-util/style.ts +37 -22
  41. package/src/victory-util/textsize.ts +5 -0
  42. package/src/victory-util/wrapper.tsx +8 -4
@@ -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
  }
@@ -4,6 +4,7 @@ import { defaults, memoize } from "lodash";
4
4
 
5
5
  // Based on measuring specific character widths
6
6
  // as in the following example https://bl.ocks.org/tophtucker/62f93a4658387bb61e4510c37e2e97cf
7
+ // For new fonts: pull gist, open index.html locally, add font files (if not generic), enter font name in `font-family` input
7
8
  // prettier-ignore
8
9
  const fonts = {
9
10
  "American Typewriter": {
@@ -62,6 +63,10 @@ const fonts = {
62
63
  widths: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.2359375,0.2234375,0.3921875,0.7125,0.49375,0.8859375,0.771875,0.2125,0.3078125,0.309375,0.375,0.4234375,0.234375,0.3125,0.234375,0.3,0.5828125,0.365625,0.434375,0.3921875,0.5234375,0.3984375,0.5125,0.4328125,0.46875,0.5125,0.234375,0.234375,0.515625,0.4234375,0.515625,0.340625,0.7609375,0.7359375,0.6359375,0.721875,0.8125,0.6375,0.5875,0.8078125,0.853125,0.4296875,0.503125,0.78125,0.609375,0.9609375,0.8515625,0.8140625,0.6125,0.8140625,0.71875,0.49375,0.7125,0.76875,0.771875,1.125,0.7765625,0.7734375,0.65625,0.321875,0.3078125,0.321875,0.3546875,0.5,0.3375,0.446875,0.5359375,0.45,0.5296875,0.4546875,0.425,0.4921875,0.54375,0.2671875,0.240625,0.5390625,0.25,0.815625,0.5375,0.5234375,0.5390625,0.5421875,0.365625,0.36875,0.35625,0.5171875,0.5015625,0.75,0.5,0.509375,0.44375,0.2421875,0.14375,0.2421875,0.35],
63
64
  avg: 0.5116447368421051
64
65
  },
66
+ "Inter": {
67
+ widths: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.2796875,0.2890625,0.4671875,0.634375,0.6421875,0.9828125,0.6453125,0.3,0.365625,0.365625,0.5015625,0.6625,0.2890625,0.4609375,0.2890625,0.3609375,0.63125,0.4078125,0.6109375,0.61875,0.646875,0.59375,0.6203125,0.5671875,0.61875,0.6203125,0.2890625,0.303125,0.6625,0.6625,0.6625,0.5125,0.9671875,0.690625,0.6546875,0.73125,0.721875,0.6015625,0.590625,0.746875,0.74375,0.26875,0.571875,0.671875,0.565625,0.9046875,0.7546875,0.765625,0.6390625,0.765625,0.64375,0.6421875,0.646875,0.7453125,0.690625,0.9859375,0.6828125,0.6796875,0.6296875,0.365625,0.3609375,0.365625,0.471875,0.45625,0.3234375,0.5625,0.6125,0.571875,0.6125,0.584375,0.3703125,0.6140625,0.5921875,0.2421875,0.2548828125,0.55,0.2421875,0.8765625,0.5921875,0.6,0.6125,0.6125,0.3765625,0.528125,0.328125,0.5921875,0.5625,0.81875,0.546875,0.5625,0.553125,0.4265625,0.3328125,0.4265625,0.6625],
68
+ avg: 0.5624362664473683
69
+ },
65
70
  "Montserrat": {
66
71
  widths: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.2625,0.2609375,0.3734375,0.696875,0.615625,0.8296875,0.6703125,0.203125,0.3296875,0.3296875,0.3875,0.575,0.2125,0.3828125,0.2125,0.3953125,0.6625,0.3625,0.56875,0.5640625,0.6625,0.5671875,0.609375,0.5890625,0.6390625,0.609375,0.2125,0.2125,0.575,0.575,0.575,0.5671875,1.034375,0.7171875,0.7546875,0.7203125,0.8265625,0.6703125,0.634375,0.7734375,0.8140625,0.303125,0.5078125,0.7125,0.5890625,0.95625,0.8140625,0.8390625,0.71875,0.8390625,0.7234375,0.615625,0.575,0.7921875,0.6984375,1.1125,0.65625,0.6359375,0.6515625,0.31875,0.396875,0.31875,0.5765625,0.5,0.6,0.590625,0.678125,0.5640625,0.678125,0.6046875,0.375,0.6875,0.678125,0.2703125,0.365625,0.6015625,0.2703125,1.0625,0.678125,0.628125,0.678125,0.678125,0.4015625,0.4890625,0.40625,0.6734375,0.5421875,0.8796875,0.534375,0.5671875,0.5125,0.334375,0.2953125,0.334375,0.575],
67
72
  avg: 0.571792763157895
@@ -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 }