victory-histogram 36.8.2 → 36.8.4
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 +8 -0
- package/dist/victory-histogram.js +262 -402
- package/dist/victory-histogram.min.js +1 -1
- package/es/helper-methods.d.ts +6 -0
- package/es/helper-methods.js +35 -30
- package/es/index.d.ts +2 -46
- package/es/index.js +1 -1
- package/es/victory-histogram.d.ts +133 -0
- package/es/victory-histogram.js +28 -43
- package/lib/helper-methods.d.ts +6 -0
- package/lib/helper-methods.js +34 -31
- package/lib/index.d.ts +2 -46
- package/lib/index.js +11 -8
- package/lib/victory-histogram.d.ts +133 -0
- package/lib/victory-histogram.js +27 -48
- package/package.json +7 -4
- package/src/{helper-methods.js → helper-methods.ts} +65 -44
- package/src/index.ts +1 -0
- package/src/{victory-histogram.js → victory-histogram.tsx} +52 -37
- package/src/index.d.ts +0 -46
- package/src/index.js +0 -1
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { EventPropTypeInterface, NumberOrCallback, StringOrNumberOrCallback, VictoryCommonProps, VictoryDatableProps, VictoryMultiLabelableProps, VictoryStyleInterface, EventsMixinClass } from "victory-core";
|
|
3
|
+
export declare type VictoryHistogramTargetType = "data" | "labels" | "parent";
|
|
4
|
+
export interface VictoryHistogramProps extends Omit<VictoryCommonProps, "polar">, Omit<VictoryDatableProps, "y" | "y0">, VictoryMultiLabelableProps {
|
|
5
|
+
binSpacing?: number;
|
|
6
|
+
bins?: number | number[] | Date[];
|
|
7
|
+
cornerRadius?: NumberOrCallback | {
|
|
8
|
+
top?: NumberOrCallback;
|
|
9
|
+
topLeft?: NumberOrCallback;
|
|
10
|
+
topRight?: NumberOrCallback;
|
|
11
|
+
bottom?: NumberOrCallback;
|
|
12
|
+
bottomLeft?: NumberOrCallback;
|
|
13
|
+
bottomRight?: NumberOrCallback;
|
|
14
|
+
};
|
|
15
|
+
events?: EventPropTypeInterface<VictoryHistogramTargetType, number | string | number[] | string[]>[];
|
|
16
|
+
eventKey?: StringOrNumberOrCallback;
|
|
17
|
+
horizontal?: boolean;
|
|
18
|
+
style?: VictoryStyleInterface;
|
|
19
|
+
}
|
|
20
|
+
interface VictoryHistogramBase extends EventsMixinClass<VictoryHistogramProps> {
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Draw SVG histogram charts with React. VictoryHistogram is a composable component, so it doesn't include axes
|
|
24
|
+
* Check out VictoryChart for complete histogram charts and more.
|
|
25
|
+
*/
|
|
26
|
+
declare class VictoryHistogramBase extends React.Component<VictoryHistogramProps> {
|
|
27
|
+
static animationWhitelist: string[];
|
|
28
|
+
static displayName: string;
|
|
29
|
+
static role: string;
|
|
30
|
+
static defaultTransitions: {
|
|
31
|
+
onLoad: {
|
|
32
|
+
duration: number;
|
|
33
|
+
before: () => {
|
|
34
|
+
_y: number;
|
|
35
|
+
_y1: number;
|
|
36
|
+
_y0: number;
|
|
37
|
+
};
|
|
38
|
+
after: (datum: any) => {
|
|
39
|
+
_y: any;
|
|
40
|
+
_y1: any;
|
|
41
|
+
_y0: any;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
onExit: {
|
|
45
|
+
duration: number;
|
|
46
|
+
before: () => {
|
|
47
|
+
_y: number;
|
|
48
|
+
yOffset: number;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
onEnter: {
|
|
52
|
+
duration: number;
|
|
53
|
+
before: () => {
|
|
54
|
+
_y: number;
|
|
55
|
+
_y1: number;
|
|
56
|
+
_y0: number;
|
|
57
|
+
};
|
|
58
|
+
after: (datum: any) => {
|
|
59
|
+
_y: any;
|
|
60
|
+
_y1: any;
|
|
61
|
+
_y0: any;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
static getFormattedData: (...args: any[]) => any;
|
|
66
|
+
static defaultProps: VictoryHistogramProps;
|
|
67
|
+
static getDomain: (props: VictoryHistogramProps, axis: "y" | "x") => any;
|
|
68
|
+
static getData: (props: VictoryHistogramProps) => any;
|
|
69
|
+
static getBaseProps: (props: VictoryHistogramProps) => any;
|
|
70
|
+
static expectedComponents: Partial<keyof VictoryHistogramProps>[];
|
|
71
|
+
shouldAnimate(): boolean;
|
|
72
|
+
render(): React.ReactElement;
|
|
73
|
+
}
|
|
74
|
+
export declare const VictoryHistogram: {
|
|
75
|
+
new (props: import("victory-core").EventMixinCommonProps): {
|
|
76
|
+
state: {};
|
|
77
|
+
getEventState: (eventKey: string | number, namespace: string, childType?: string | undefined) => any;
|
|
78
|
+
getScopedEvents: (events: any, namespace: any, childType: any, baseProps: any) => {};
|
|
79
|
+
getEvents: (p: any, target: any, eventKey: any) => any;
|
|
80
|
+
externalMutations: {} | undefined;
|
|
81
|
+
calculatedState: {};
|
|
82
|
+
globalEvents: {};
|
|
83
|
+
prevGlobalEventKeys: string[];
|
|
84
|
+
boundGlobalEvents: {};
|
|
85
|
+
shouldComponentUpdate(nextProps: import("victory-core").EventMixinCommonProps): boolean;
|
|
86
|
+
componentDidMount(): void;
|
|
87
|
+
componentDidUpdate(prevProps: any): void;
|
|
88
|
+
componentWillUnmount(): void;
|
|
89
|
+
addGlobalListener(key: any): void;
|
|
90
|
+
removeGlobalListener(key: any): void;
|
|
91
|
+
getStateChanges(props: any): {};
|
|
92
|
+
applyExternalMutations(props: any, externalMutations: any): void;
|
|
93
|
+
getCalculatedValues(props: any): import("victory-core").EventMixinCalculatedValues;
|
|
94
|
+
getExternalMutations(props: import("victory-core").EventMixinCommonProps): {} | undefined;
|
|
95
|
+
cacheValues(obj: any): void;
|
|
96
|
+
getBaseProps(props: any, getSharedEventState: any): Record<string, object>;
|
|
97
|
+
getAllEvents(props: any): any;
|
|
98
|
+
getComponentProps(component: React.ReactNode, type: string, index: string | number): any;
|
|
99
|
+
renderContainer(component: any, children: any): React.DetailedReactHTMLElement<any, HTMLElement>;
|
|
100
|
+
animateComponent(props: import("victory-core").EventMixinCommonProps, defaultAnimationWhitelist: string[]): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
|
|
101
|
+
renderContinuousData(props: import("victory-core").EventMixinCommonProps): React.DetailedReactHTMLElement<any, HTMLElement>;
|
|
102
|
+
renderData(props: any, shouldRenderDatum?: ((datum: any) => boolean) | undefined): React.DetailedReactHTMLElement<any, HTMLElement>;
|
|
103
|
+
context: unknown;
|
|
104
|
+
setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<import("victory-core").EventMixinCommonProps>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
|
|
105
|
+
forceUpdate(callback?: (() => void) | undefined): void;
|
|
106
|
+
render(): React.ReactNode;
|
|
107
|
+
readonly props: Readonly<import("victory-core").EventMixinCommonProps>;
|
|
108
|
+
refs: {
|
|
109
|
+
[key: string]: React.ReactInstance;
|
|
110
|
+
};
|
|
111
|
+
componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
|
|
112
|
+
getSnapshotBeforeUpdate?(prevProps: Readonly<import("victory-core").EventMixinCommonProps>, prevState: Readonly<{}>): any;
|
|
113
|
+
componentWillMount?(): void;
|
|
114
|
+
UNSAFE_componentWillMount?(): void;
|
|
115
|
+
componentWillReceiveProps?(nextProps: Readonly<import("victory-core").EventMixinCommonProps>, nextContext: any): void;
|
|
116
|
+
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<import("victory-core").EventMixinCommonProps>, nextContext: any): void;
|
|
117
|
+
componentWillUpdate?(nextProps: Readonly<import("victory-core").EventMixinCommonProps>, nextState: Readonly<{}>, nextContext: any): void;
|
|
118
|
+
UNSAFE_componentWillUpdate?(nextProps: Readonly<import("victory-core").EventMixinCommonProps>, nextState: Readonly<{}>, nextContext: any): void;
|
|
119
|
+
componentEvents: import("victory-core/lib/victory-util/events").ComponentEvent[];
|
|
120
|
+
getSharedEventState: (key: string, value: string) => unknown;
|
|
121
|
+
baseProps: Record<string, object>;
|
|
122
|
+
dataKeys: string[];
|
|
123
|
+
hasEvents: unknown;
|
|
124
|
+
events: unknown;
|
|
125
|
+
};
|
|
126
|
+
getBaseProps?(props: import("victory-core").EventMixinCommonProps): Record<string, object>;
|
|
127
|
+
role?: string | undefined;
|
|
128
|
+
expectedComponents?: string[] | undefined;
|
|
129
|
+
getChildren?: ((props: import("victory-core").EventMixinCommonProps, childComponents?: React.ReactNode[] | undefined, calculatedProps?: import("victory-core").EventMixinCommonProps | undefined) => void) | undefined;
|
|
130
|
+
animationWhitelist?: string[] | undefined;
|
|
131
|
+
} & typeof VictoryHistogramBase;
|
|
132
|
+
export {};
|
|
133
|
+
//# sourceMappingURL=victory-histogram.d.ts.map
|
package/lib/victory-histogram.js
CHANGED
|
@@ -3,12 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.VictoryHistogram = void 0;
|
|
7
7
|
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
|
|
10
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
10
|
var _victoryBar = require("victory-bar");
|
|
13
11
|
|
|
14
12
|
var _victoryCore = require("victory-core");
|
|
@@ -17,12 +15,6 @@ var _helperMethods = require("./helper-methods");
|
|
|
17
15
|
|
|
18
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
17
|
|
|
20
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
21
|
-
|
|
22
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
23
|
-
|
|
24
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
25
|
-
|
|
26
18
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
27
19
|
|
|
28
20
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
@@ -48,20 +40,24 @@ var fallbackProps = {
|
|
|
48
40
|
height: 300,
|
|
49
41
|
padding: 50
|
|
50
42
|
};
|
|
51
|
-
var defaultData = [];
|
|
43
|
+
var defaultData = []; // eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
52
44
|
|
|
53
|
-
|
|
54
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Draw SVG histogram charts with React. VictoryHistogram is a composable component, so it doesn't include axes
|
|
47
|
+
* Check out VictoryChart for complete histogram charts and more.
|
|
48
|
+
*/
|
|
49
|
+
var VictoryHistogramBase = /*#__PURE__*/function (_React$Component) {
|
|
50
|
+
_inherits(VictoryHistogramBase, _React$Component);
|
|
55
51
|
|
|
56
|
-
var _super = _createSuper(
|
|
52
|
+
var _super = _createSuper(VictoryHistogramBase);
|
|
57
53
|
|
|
58
|
-
function
|
|
59
|
-
_classCallCheck(this,
|
|
54
|
+
function VictoryHistogramBase() {
|
|
55
|
+
_classCallCheck(this, VictoryHistogramBase);
|
|
60
56
|
|
|
61
57
|
return _super.apply(this, arguments);
|
|
62
58
|
}
|
|
63
59
|
|
|
64
|
-
_createClass(
|
|
60
|
+
_createClass(VictoryHistogramBase, [{
|
|
65
61
|
key: "shouldAnimate",
|
|
66
62
|
value: // Overridden in native versions
|
|
67
63
|
function shouldAnimate() {
|
|
@@ -70,8 +66,8 @@ var VictoryHistogram = /*#__PURE__*/function (_React$Component) {
|
|
|
70
66
|
}, {
|
|
71
67
|
key: "render",
|
|
72
68
|
value: function render() {
|
|
73
|
-
var animationWhitelist =
|
|
74
|
-
role =
|
|
69
|
+
var animationWhitelist = VictoryHistogramBase.animationWhitelist,
|
|
70
|
+
role = VictoryHistogramBase.role;
|
|
75
71
|
|
|
76
72
|
var props = _victoryCore.Helpers.modifyProps(this.props, fallbackProps, role);
|
|
77
73
|
|
|
@@ -85,14 +81,13 @@ var VictoryHistogram = /*#__PURE__*/function (_React$Component) {
|
|
|
85
81
|
}
|
|
86
82
|
}]);
|
|
87
83
|
|
|
88
|
-
return
|
|
84
|
+
return VictoryHistogramBase;
|
|
89
85
|
}(_react.default.Component);
|
|
90
86
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
VictoryHistogram.defaultTransitions = {
|
|
87
|
+
VictoryHistogramBase.animationWhitelist = ["data", "domain", "height", "padding", "style", "width"];
|
|
88
|
+
VictoryHistogramBase.displayName = "VictoryHistogram";
|
|
89
|
+
VictoryHistogramBase.role = "histogram";
|
|
90
|
+
VictoryHistogramBase.defaultTransitions = {
|
|
96
91
|
onLoad: {
|
|
97
92
|
duration: 2000,
|
|
98
93
|
before: function () {
|
|
@@ -137,22 +132,8 @@ VictoryHistogram.defaultTransitions = {
|
|
|
137
132
|
}
|
|
138
133
|
}
|
|
139
134
|
};
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
binSpacing: _victoryCore.PropTypes.nonNegative,
|
|
143
|
-
bins: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.instanceOf(Date)])), _victoryCore.PropTypes.nonNegative]),
|
|
144
|
-
cornerRadius: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.func, _propTypes.default.shape({
|
|
145
|
-
top: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.func]),
|
|
146
|
-
topLeft: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.func]),
|
|
147
|
-
topRight: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.func]),
|
|
148
|
-
bottom: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.func]),
|
|
149
|
-
bottomLeft: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.func]),
|
|
150
|
-
bottomRight: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.func])
|
|
151
|
-
})]),
|
|
152
|
-
getPath: _propTypes.default.func,
|
|
153
|
-
horizontal: _propTypes.default.bool
|
|
154
|
-
});
|
|
155
|
-
VictoryHistogram.defaultProps = {
|
|
135
|
+
VictoryHistogramBase.getFormattedData = _helperMethods.getFormattedData;
|
|
136
|
+
VictoryHistogramBase.defaultProps = {
|
|
156
137
|
containerComponent: /*#__PURE__*/_react.default.createElement(_victoryCore.VictoryContainer, null),
|
|
157
138
|
data: defaultData,
|
|
158
139
|
dataComponent: /*#__PURE__*/_react.default.createElement(_victoryBar.Bar, null),
|
|
@@ -165,15 +146,13 @@ VictoryHistogram.defaultProps = {
|
|
|
165
146
|
standalone: true,
|
|
166
147
|
theme: _victoryCore.VictoryTheme.grayscale
|
|
167
148
|
};
|
|
168
|
-
|
|
169
|
-
|
|
149
|
+
VictoryHistogramBase.getDomain = _helperMethods.getDomain;
|
|
150
|
+
VictoryHistogramBase.getData = _helperMethods.getData;
|
|
170
151
|
|
|
171
|
-
|
|
152
|
+
VictoryHistogramBase.getBaseProps = function (props) {
|
|
172
153
|
return (0, _helperMethods.getBaseProps)(props, fallbackProps);
|
|
173
154
|
};
|
|
174
155
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
exports.default = _default;
|
|
156
|
+
VictoryHistogramBase.expectedComponents = ["dataComponent", "labelComponent", "groupComponent", "containerComponent"];
|
|
157
|
+
var VictoryHistogram = (0, _victoryCore.addEvents)(VictoryHistogramBase);
|
|
158
|
+
exports.VictoryHistogram = VictoryHistogram;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "victory-histogram",
|
|
3
|
-
"version": "36.8.
|
|
3
|
+
"version": "36.8.4",
|
|
4
4
|
"description": "Histogram Component for Victory",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data visualization",
|
|
@@ -23,9 +23,12 @@
|
|
|
23
23
|
"lodash": "^4.17.19",
|
|
24
24
|
"prop-types": "^15.8.1",
|
|
25
25
|
"react-fast-compare": "^3.2.0",
|
|
26
|
-
"victory-bar": "^36.8.
|
|
27
|
-
"victory-core": "^36.8.
|
|
28
|
-
"victory-vendor": "^36.8.
|
|
26
|
+
"victory-bar": "^36.8.4",
|
|
27
|
+
"victory-core": "^36.8.4",
|
|
28
|
+
"victory-vendor": "^36.8.4"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"victory-histogram": "*"
|
|
29
32
|
},
|
|
30
33
|
"peerDependencies": {
|
|
31
34
|
"react": ">=16.6.0"
|
|
@@ -4,6 +4,7 @@ import { getBarPosition } from "victory-bar";
|
|
|
4
4
|
import isEqual from "react-fast-compare";
|
|
5
5
|
import * as d3Array from "victory-vendor/d3-array";
|
|
6
6
|
import * as d3Scale from "victory-vendor/d3-scale";
|
|
7
|
+
import { VictoryHistogramProps } from "./victory-histogram";
|
|
7
8
|
|
|
8
9
|
const cacheLastValue = (func) => {
|
|
9
10
|
let called = false;
|
|
@@ -25,9 +26,14 @@ const cacheLastValue = (func) => {
|
|
|
25
26
|
};
|
|
26
27
|
};
|
|
27
28
|
|
|
28
|
-
const dataOrBinsContainDates = ({
|
|
29
|
+
const dataOrBinsContainDates = ({
|
|
30
|
+
data,
|
|
31
|
+
bins,
|
|
32
|
+
x,
|
|
33
|
+
}: Pick<VictoryHistogramProps, "data" | "x" | "bins">) => {
|
|
29
34
|
const xAccessor = Helpers.createAccessor(x || "x");
|
|
30
|
-
const dataIsDates =
|
|
35
|
+
const dataIsDates =
|
|
36
|
+
data?.some((datum) => xAccessor(datum) instanceof Date) || false;
|
|
31
37
|
const binsHasDates =
|
|
32
38
|
Array.isArray(bins) && bins.some((bin) => bin instanceof Date);
|
|
33
39
|
|
|
@@ -39,7 +45,9 @@ const getBinningFunc = ({ data, x, bins, dataOrBinsContainsDates }) => {
|
|
|
39
45
|
const bin = d3Array.bin().value(xAccessor);
|
|
40
46
|
|
|
41
47
|
const niceScale = (
|
|
42
|
-
dataOrBinsContainsDates
|
|
48
|
+
(dataOrBinsContainsDates
|
|
49
|
+
? d3Scale.scaleTime()
|
|
50
|
+
: d3Scale.scaleLinear()) as any
|
|
43
51
|
)
|
|
44
52
|
.domain(d3Array.extent(data, xAccessor))
|
|
45
53
|
.nice();
|
|
@@ -61,8 +69,7 @@ const getBinningFunc = ({ data, x, bins, dataOrBinsContainsDates }) => {
|
|
|
61
69
|
if (dataOrBinsContainsDates) {
|
|
62
70
|
bin.domain(niceScale.domain());
|
|
63
71
|
bin.thresholds(niceScale.ticks());
|
|
64
|
-
|
|
65
|
-
return bin;
|
|
72
|
+
return bin as unknown as d3Array.HistogramGeneratorDate<Date, Date>;
|
|
66
73
|
}
|
|
67
74
|
|
|
68
75
|
bin.domain(niceScale.domain());
|
|
@@ -70,42 +77,52 @@ const getBinningFunc = ({ data, x, bins, dataOrBinsContainsDates }) => {
|
|
|
70
77
|
return bin;
|
|
71
78
|
};
|
|
72
79
|
|
|
73
|
-
export const getFormattedData = cacheLastValue(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (dataOrBinsContainsDates) {
|
|
82
|
-
return new Date(x0).getTime() !== new Date(x1).getTime();
|
|
80
|
+
export const getFormattedData = cacheLastValue(
|
|
81
|
+
({
|
|
82
|
+
data = [],
|
|
83
|
+
x,
|
|
84
|
+
bins,
|
|
85
|
+
}: Pick<VictoryHistogramProps, "data" | "x" | "bins">) => {
|
|
86
|
+
if ((!data || !data.length) && !Array.isArray(bins)) {
|
|
87
|
+
return [];
|
|
83
88
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
89
|
+
const dataOrBinsContainsDates = dataOrBinsContainDates({ data, bins, x });
|
|
90
|
+
const binFunc = getBinningFunc({ data, x, bins, dataOrBinsContainsDates });
|
|
91
|
+
const foo = binFunc(data);
|
|
92
|
+
const binnedData = [...foo].filter(({ x0, x1 }) => {
|
|
93
|
+
if (x0 instanceof Date && x1 instanceof Date) {
|
|
94
|
+
return new Date(x0).getTime() !== new Date(x1).getTime();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return x0 !== x1;
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const formattedData = binnedData.map((bin) => {
|
|
101
|
+
const x0 = dataOrBinsContainsDates
|
|
102
|
+
? new Date(bin.x0 as Date)
|
|
103
|
+
: bin.x0 || 0;
|
|
104
|
+
const x1 = dataOrBinsContainsDates
|
|
105
|
+
? new Date(bin.x1 as Date)
|
|
106
|
+
: bin.x1 || 0;
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
x0,
|
|
110
|
+
x1,
|
|
111
|
+
x: dataOrBinsContainsDates
|
|
112
|
+
? new Date(((x0 as Date).getTime() + (x1 as Date).getTime()) / 2)
|
|
113
|
+
: ((x0 as number) + (x1 as number)) / 2,
|
|
114
|
+
y: bin.length,
|
|
115
|
+
binnedData: [...bin],
|
|
116
|
+
};
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
return formattedData;
|
|
120
|
+
},
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
export const getData = (props: VictoryHistogramProps) => {
|
|
107
124
|
const { bins, data, x } = props;
|
|
108
|
-
const dataIsPreformatted = data
|
|
125
|
+
const dataIsPreformatted = data?.some(({ _y }) => !isNil(_y));
|
|
109
126
|
|
|
110
127
|
const formattedData = dataIsPreformatted
|
|
111
128
|
? data
|
|
@@ -113,7 +130,7 @@ export const getData = (props) => {
|
|
|
113
130
|
return Data.getData({ ...props, data: formattedData, x: "x" });
|
|
114
131
|
};
|
|
115
132
|
|
|
116
|
-
export const getDomain = (props, axis) => {
|
|
133
|
+
export const getDomain = (props: VictoryHistogramProps, axis: "x" | "y") => {
|
|
117
134
|
const data = getData(props);
|
|
118
135
|
|
|
119
136
|
if (!data.length) {
|
|
@@ -130,7 +147,7 @@ export const getDomain = (props, axis) => {
|
|
|
130
147
|
);
|
|
131
148
|
}
|
|
132
149
|
|
|
133
|
-
return props.data
|
|
150
|
+
return props.data?.length
|
|
134
151
|
? Domain.getDomainWithZero({ ...props, data }, "y")
|
|
135
152
|
: [0, 1];
|
|
136
153
|
};
|
|
@@ -164,9 +181,13 @@ const getCalculatedValues = (props) => {
|
|
|
164
181
|
return { style, data, scale, domain };
|
|
165
182
|
};
|
|
166
183
|
|
|
167
|
-
export const getBaseProps = (
|
|
168
|
-
const modifiedProps = Helpers.modifyProps(
|
|
169
|
-
|
|
184
|
+
export const getBaseProps = (initialProps, fallbackProps) => {
|
|
185
|
+
const modifiedProps = Helpers.modifyProps(
|
|
186
|
+
initialProps,
|
|
187
|
+
fallbackProps,
|
|
188
|
+
"histogram",
|
|
189
|
+
);
|
|
190
|
+
const props = assign({}, modifiedProps, getCalculatedValues(modifiedProps));
|
|
170
191
|
|
|
171
192
|
const {
|
|
172
193
|
binSpacing,
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./victory-histogram";
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import PropTypes from "prop-types";
|
|
3
2
|
import { Bar } from "victory-bar";
|
|
4
3
|
import {
|
|
5
4
|
Helpers,
|
|
6
5
|
VictoryLabel,
|
|
7
6
|
VictoryContainer,
|
|
8
7
|
VictoryTheme,
|
|
9
|
-
CommonProps,
|
|
10
8
|
addEvents,
|
|
11
|
-
PropTypes as CustomPropTypes,
|
|
12
9
|
UserProps,
|
|
10
|
+
EventPropTypeInterface,
|
|
11
|
+
NumberOrCallback,
|
|
12
|
+
StringOrNumberOrCallback,
|
|
13
|
+
VictoryCommonProps,
|
|
14
|
+
VictoryDatableProps,
|
|
15
|
+
VictoryMultiLabelableProps,
|
|
16
|
+
VictoryStyleInterface,
|
|
17
|
+
EventsMixinClass,
|
|
13
18
|
} from "victory-core";
|
|
14
19
|
import {
|
|
15
20
|
getBaseProps,
|
|
@@ -18,7 +23,34 @@ import {
|
|
|
18
23
|
getFormattedData,
|
|
19
24
|
} from "./helper-methods";
|
|
20
25
|
|
|
21
|
-
|
|
26
|
+
export type VictoryHistogramTargetType = "data" | "labels" | "parent";
|
|
27
|
+
|
|
28
|
+
export interface VictoryHistogramProps
|
|
29
|
+
extends Omit<VictoryCommonProps, "polar">,
|
|
30
|
+
Omit<VictoryDatableProps, "y" | "y0">,
|
|
31
|
+
VictoryMultiLabelableProps {
|
|
32
|
+
binSpacing?: number;
|
|
33
|
+
bins?: number | number[] | Date[];
|
|
34
|
+
cornerRadius?:
|
|
35
|
+
| NumberOrCallback
|
|
36
|
+
| {
|
|
37
|
+
top?: NumberOrCallback;
|
|
38
|
+
topLeft?: NumberOrCallback;
|
|
39
|
+
topRight?: NumberOrCallback;
|
|
40
|
+
bottom?: NumberOrCallback;
|
|
41
|
+
bottomLeft?: NumberOrCallback;
|
|
42
|
+
bottomRight?: NumberOrCallback;
|
|
43
|
+
};
|
|
44
|
+
events?: EventPropTypeInterface<
|
|
45
|
+
VictoryHistogramTargetType,
|
|
46
|
+
number | string | number[] | string[]
|
|
47
|
+
>[];
|
|
48
|
+
eventKey?: StringOrNumberOrCallback;
|
|
49
|
+
horizontal?: boolean;
|
|
50
|
+
style?: VictoryStyleInterface;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const fallbackProps: Partial<VictoryHistogramProps> = {
|
|
22
54
|
width: 450,
|
|
23
55
|
height: 300,
|
|
24
56
|
padding: 50,
|
|
@@ -26,7 +58,15 @@ const fallbackProps = {
|
|
|
26
58
|
|
|
27
59
|
const defaultData = [];
|
|
28
60
|
|
|
29
|
-
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
62
|
+
interface VictoryHistogramBase
|
|
63
|
+
extends EventsMixinClass<VictoryHistogramProps> {}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Draw SVG histogram charts with React. VictoryHistogram is a composable component, so it doesn't include axes
|
|
67
|
+
* Check out VictoryChart for complete histogram charts and more.
|
|
68
|
+
*/
|
|
69
|
+
class VictoryHistogramBase extends React.Component<VictoryHistogramProps> {
|
|
30
70
|
static animationWhitelist = [
|
|
31
71
|
"data",
|
|
32
72
|
"domain",
|
|
@@ -59,33 +99,7 @@ export class VictoryHistogram extends React.Component {
|
|
|
59
99
|
|
|
60
100
|
static getFormattedData = getFormattedData;
|
|
61
101
|
|
|
62
|
-
static
|
|
63
|
-
...CommonProps.baseProps,
|
|
64
|
-
...CommonProps.dataProps,
|
|
65
|
-
binSpacing: CustomPropTypes.nonNegative,
|
|
66
|
-
bins: PropTypes.oneOfType([
|
|
67
|
-
PropTypes.arrayOf(
|
|
68
|
-
PropTypes.oneOfType([PropTypes.number, PropTypes.instanceOf(Date)]),
|
|
69
|
-
),
|
|
70
|
-
CustomPropTypes.nonNegative,
|
|
71
|
-
]),
|
|
72
|
-
cornerRadius: PropTypes.oneOfType([
|
|
73
|
-
PropTypes.number,
|
|
74
|
-
PropTypes.func,
|
|
75
|
-
PropTypes.shape({
|
|
76
|
-
top: PropTypes.oneOfType([PropTypes.number, PropTypes.func]),
|
|
77
|
-
topLeft: PropTypes.oneOfType([PropTypes.number, PropTypes.func]),
|
|
78
|
-
topRight: PropTypes.oneOfType([PropTypes.number, PropTypes.func]),
|
|
79
|
-
bottom: PropTypes.oneOfType([PropTypes.number, PropTypes.func]),
|
|
80
|
-
bottomLeft: PropTypes.oneOfType([PropTypes.number, PropTypes.func]),
|
|
81
|
-
bottomRight: PropTypes.oneOfType([PropTypes.number, PropTypes.func]),
|
|
82
|
-
}),
|
|
83
|
-
]),
|
|
84
|
-
getPath: PropTypes.func,
|
|
85
|
-
horizontal: PropTypes.bool,
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
static defaultProps = {
|
|
102
|
+
static defaultProps: VictoryHistogramProps = {
|
|
89
103
|
containerComponent: <VictoryContainer />,
|
|
90
104
|
data: defaultData,
|
|
91
105
|
dataComponent: <Bar />,
|
|
@@ -99,8 +113,9 @@ export class VictoryHistogram extends React.Component {
|
|
|
99
113
|
|
|
100
114
|
static getDomain = getDomain;
|
|
101
115
|
static getData = getData;
|
|
102
|
-
static getBaseProps = (props) =>
|
|
103
|
-
|
|
116
|
+
static getBaseProps = (props: VictoryHistogramProps) =>
|
|
117
|
+
getBaseProps(props, fallbackProps);
|
|
118
|
+
static expectedComponents: Partial<keyof VictoryHistogramProps>[] = [
|
|
104
119
|
"dataComponent",
|
|
105
120
|
"labelComponent",
|
|
106
121
|
"groupComponent",
|
|
@@ -112,8 +127,8 @@ export class VictoryHistogram extends React.Component {
|
|
|
112
127
|
return !!this.props.animate;
|
|
113
128
|
}
|
|
114
129
|
|
|
115
|
-
render() {
|
|
116
|
-
const { animationWhitelist, role } =
|
|
130
|
+
render(): React.ReactElement {
|
|
131
|
+
const { animationWhitelist, role } = VictoryHistogramBase;
|
|
117
132
|
const props = Helpers.modifyProps(this.props, fallbackProps, role);
|
|
118
133
|
|
|
119
134
|
if (this.shouldAnimate()) {
|
|
@@ -130,4 +145,4 @@ export class VictoryHistogram extends React.Component {
|
|
|
130
145
|
}
|
|
131
146
|
}
|
|
132
147
|
|
|
133
|
-
export
|
|
148
|
+
export const VictoryHistogram = addEvents(VictoryHistogramBase);
|
package/src/index.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import {
|
|
3
|
-
EventPropTypeInterface,
|
|
4
|
-
NumberOrCallback,
|
|
5
|
-
StringOrNumberOrCallback,
|
|
6
|
-
VictoryCommonProps,
|
|
7
|
-
VictoryDatableProps,
|
|
8
|
-
VictoryMultiLabelableProps,
|
|
9
|
-
VictoryStyleInterface,
|
|
10
|
-
} from "victory-core";
|
|
11
|
-
|
|
12
|
-
export type VictoryHistogramTargetType = "data" | "labels" | "parent";
|
|
13
|
-
|
|
14
|
-
export interface VictoryHistogramProps
|
|
15
|
-
extends Omit<VictoryCommonProps, "polar">,
|
|
16
|
-
Omit<VictoryDatableProps, "y" | "y0">,
|
|
17
|
-
VictoryMultiLabelableProps {
|
|
18
|
-
binSpacing?: number;
|
|
19
|
-
bins?: number | number[] | Date[];
|
|
20
|
-
cornerRadius?:
|
|
21
|
-
| NumberOrCallback
|
|
22
|
-
| {
|
|
23
|
-
top?: NumberOrCallback;
|
|
24
|
-
topLeft?: NumberOrCallback;
|
|
25
|
-
topRight?: NumberOrCallback;
|
|
26
|
-
bottom?: NumberOrCallback;
|
|
27
|
-
bottomLeft?: NumberOrCallback;
|
|
28
|
-
bottomRight?: NumberOrCallback;
|
|
29
|
-
};
|
|
30
|
-
events?: EventPropTypeInterface<
|
|
31
|
-
VictoryHistogramTargetType,
|
|
32
|
-
number | string | number[] | string[]
|
|
33
|
-
>[];
|
|
34
|
-
eventKey?: StringOrNumberOrCallback;
|
|
35
|
-
horizontal?: boolean;
|
|
36
|
-
style?: VictoryStyleInterface;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Draw SVG histogram charts with React. VictoryHistogram is a composable component, so it doesn't include axes
|
|
41
|
-
* Check out VictoryChart for complete histogram charts and more.
|
|
42
|
-
*/
|
|
43
|
-
export class VictoryHistogram extends React.Component<
|
|
44
|
-
VictoryHistogramProps,
|
|
45
|
-
any
|
|
46
|
-
> {}
|
package/src/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as VictoryHistogram } from "./victory-histogram";
|