source: node_modules/recharts/es6/util/ReactUtils.js@ ba17441

Last change on this file since ba17441 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 2.6 KB
RevLine 
[a762898]1import get from 'es-toolkit/compat/get';
2import { Children } from 'react';
3import { isFragment } from 'react-is';
4import { isNullish } from './DataUtils';
5export var SCALE_TYPES = ['auto', 'linear', 'pow', 'sqrt', 'log', 'identity', 'time', 'band', 'point', 'ordinal', 'quantile', 'quantize', 'utc', 'sequential', 'threshold'];
6
7/**
8 * @deprecated instead find another approach that does not depend on displayName.
9 * Get the display name of a component
10 * @param {Object} Comp Specified Component
11 * @return {String} Display name of Component
12 */
13export var getDisplayName = Comp => {
14 if (typeof Comp === 'string') {
15 return Comp;
16 }
17 if (!Comp) {
18 return '';
19 }
20 return Comp.displayName || Comp.name || 'Component';
21};
22
23// `toArray` gets called multiple times during the render
24// so we can memoize last invocation (since reference to `children` is the same)
25var lastChildren = null;
26var lastResult = null;
27
28/**
29 * @deprecated instead find another approach that does not require reading React Elements from DOM.
30 *
31 * @param children do not use
32 * @return deprecated do not use
33 */
34export var toArray = children => {
35 if (children === lastChildren && Array.isArray(lastResult)) {
36 return lastResult;
37 }
38 var result = [];
39 Children.forEach(children, child => {
40 if (isNullish(child)) return;
41 if (isFragment(child)) {
42 result = result.concat(toArray(child.props.children));
43 } else {
44 // @ts-expect-error this could still be Iterable<ReactNode> and TS does not like that
45 result.push(child);
46 }
47 });
48 lastResult = result;
49 lastChildren = children;
50 return result;
51};
52
53/**
54 * @deprecated instead find another approach that does not require reading React Elements from DOM.
55 *
56 * Find and return all matched children by type.
57 * `type` must be a React.ComponentType
58 *
59 * @param children do not use
60 * @param type do not use
61 * @return deprecated do not use
62 */
63export function findAllByType(children, type) {
64 var result = [];
65 var types = [];
66 if (Array.isArray(type)) {
67 types = type.map(t => getDisplayName(t));
68 } else {
69 types = [getDisplayName(type)];
70 }
71 toArray(children).forEach(child => {
72 // @ts-expect-error toArray and lodash.get are not compatible. Let's get rid of the whole findAllByType function
73 var childType = get(child, 'type.displayName') || get(child, 'type.name');
74 if (childType && types.indexOf(childType) !== -1) {
75 result.push(child);
76 }
77 });
78 return result;
79}
80export var isClipDot = dot => {
81 if (dot && typeof dot === 'object' && 'clipDot' in dot) {
82 return Boolean(dot.clipDot);
83 }
84 return true;
85};
Note: See TracBrowser for help on using the repository browser.