source: node_modules/recharts/es6/cartesian/Line.js

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

Added visualizations

  • Property mode set to 100644
File size: 24.3 KB
RevLine 
[a762898]1var _excluded = ["id"],
2 _excluded2 = ["type", "layout", "connectNulls", "needClip", "shape"],
3 _excluded3 = ["activeDot", "animateNewValues", "animationBegin", "animationDuration", "animationEasing", "connectNulls", "dot", "hide", "isAnimationActive", "label", "legendType", "xAxisId", "yAxisId", "id"];
4function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
5function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
8function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
9function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
10function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
11function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
12import * as React from 'react';
13import { Component, useCallback, useMemo, useRef, useState } from 'react';
14import { clsx } from 'clsx';
15import { Layer } from '../container/Layer';
16import { CartesianLabelListContextProvider, LabelListFromLabelProp } from '../component/LabelList';
17import { Dots } from '../component/Dots';
18import { interpolate, isNullish, noop } from '../util/DataUtils';
19import { isClipDot } from '../util/ReactUtils';
20import { getCateCoordinateOfLine, getTooltipNameProp, getValueByDataKey } from '../util/ChartUtils';
21import { ActivePoints } from '../component/ActivePoints';
22import { SetTooltipEntrySettings } from '../state/SetTooltipEntrySettings';
23import { SetErrorBarContext } from '../context/ErrorBarContext';
24import { GraphicalItemClipPath, useNeedsClip } from './GraphicalItemClipPath';
25import { useChartLayout } from '../context/chartLayoutContext';
26import { useIsPanorama } from '../context/PanoramaContext';
27import { selectLinePoints } from '../state/selectors/lineSelectors';
28import { useAppSelector } from '../state/hooks';
29import { SetLegendPayload } from '../state/SetLegendPayload';
30import { useAnimationId } from '../util/useAnimationId';
31import { resolveDefaultProps } from '../util/resolveDefaultProps';
32import { usePlotArea } from '../hooks';
33import { RegisterGraphicalItemId } from '../context/RegisterGraphicalItemId';
34import { SetCartesianGraphicalItem } from '../state/SetGraphicalItem';
35import { svgPropertiesNoEvents } from '../util/svgPropertiesNoEvents';
36import { JavascriptAnimate } from '../animation/JavascriptAnimate';
37import { svgPropertiesAndEvents } from '../util/svgPropertiesAndEvents';
38import { getRadiusAndStrokeWidthFromDot } from '../util/getRadiusAndStrokeWidthFromDot';
39import { Shape } from '../util/ActiveShapeUtils';
40import { ZIndexLayer } from '../zIndex/ZIndexLayer';
41import { DefaultZIndexes } from '../zIndex/DefaultZIndexes';
42import { propsAreEqual } from '../util/propsAreEqual';
43
44/**
45 * Internal props, combination of external props + defaultProps + private Recharts state
46 */
47
48/**
49 * External props, intended for end users to fill in
50 */
51
52/**
53 * Because of naming conflict, we are forced to ignore certain (valid) SVG attributes.
54 */
55
56var computeLegendPayloadFromAreaData = props => {
57 var {
58 dataKey,
59 name,
60 stroke,
61 legendType,
62 hide
63 } = props;
64 return [{
65 inactive: hide,
66 dataKey,
67 type: legendType,
68 color: stroke,
69 value: getTooltipNameProp(name, dataKey),
70 payload: props
71 }];
72};
73var SetLineTooltipEntrySettings = /*#__PURE__*/React.memo(_ref => {
74 var {
75 dataKey,
76 data,
77 stroke,
78 strokeWidth,
79 fill,
80 name,
81 hide,
82 unit,
83 tooltipType,
84 id
85 } = _ref;
86 var tooltipEntrySettings = {
87 dataDefinedOnItem: data,
88 getPosition: noop,
89 settings: {
90 stroke,
91 strokeWidth,
92 fill,
93 dataKey,
94 nameKey: undefined,
95 name: getTooltipNameProp(name, dataKey),
96 hide,
97 type: tooltipType,
98 color: stroke,
99 unit,
100 graphicalItemId: id
101 }
102 };
103 return /*#__PURE__*/React.createElement(SetTooltipEntrySettings, {
104 tooltipEntrySettings: tooltipEntrySettings
105 });
106});
107var generateSimpleStrokeDasharray = (totalLength, length) => {
108 return "".concat(length, "px ").concat(totalLength - length, "px");
109};
110function repeat(lines, count) {
111 var linesUnit = lines.length % 2 !== 0 ? [...lines, 0] : lines;
112 var result = [];
113 for (var i = 0; i < count; ++i) {
114 result = [...result, ...linesUnit];
115 }
116 return result;
117}
118var getStrokeDasharray = (length, totalLength, lines) => {
119 var lineLength = lines.reduce((pre, next) => pre + next);
120
121 // if lineLength is 0 return the default when no strokeDasharray is provided
122 if (!lineLength) {
123 return generateSimpleStrokeDasharray(totalLength, length);
124 }
125 var count = Math.floor(length / lineLength);
126 var remainLength = length % lineLength;
127 var restLength = totalLength - length;
128 var remainLines = [];
129 for (var i = 0, sum = 0; i < lines.length; sum += (_lines$i = lines[i]) !== null && _lines$i !== void 0 ? _lines$i : 0, ++i) {
130 var _lines$i;
131 var lineValue = lines[i];
132 if (lineValue != null && sum + lineValue > remainLength) {
133 remainLines = [...lines.slice(0, i), remainLength - sum];
134 break;
135 }
136 }
137 var emptyLines = remainLines.length % 2 === 0 ? [0, restLength] : [restLength];
138 return [...repeat(lines, count), ...remainLines, ...emptyLines].map(line => "".concat(line, "px")).join(', ');
139};
140function LineDotsWrapper(_ref2) {
141 var {
142 clipPathId,
143 points,
144 props
145 } = _ref2;
146 var {
147 dot,
148 dataKey,
149 needClip
150 } = props;
151
152 /*
153 * Exclude ID from the props passed to the Dots component
154 * because then the ID would be applied to multiple dots, and it would no longer be unique.
155 */
156 var {
157 id
158 } = props,
159 propsWithoutId = _objectWithoutProperties(props, _excluded);
160 var lineProps = svgPropertiesNoEvents(propsWithoutId);
161 return /*#__PURE__*/React.createElement(Dots, {
162 points: points,
163 dot: dot,
164 className: "recharts-line-dots",
165 dotClassName: "recharts-line-dot",
166 dataKey: dataKey,
167 baseProps: lineProps,
168 needClip: needClip,
169 clipPathId: clipPathId
170 });
171}
172function LineLabelListProvider(_ref3) {
173 var {
174 showLabels,
175 children,
176 points
177 } = _ref3;
178 var labelListEntries = useMemo(() => {
179 return points === null || points === void 0 ? void 0 : points.map(point => {
180 var _point$x, _point$y;
181 var viewBox = {
182 x: (_point$x = point.x) !== null && _point$x !== void 0 ? _point$x : 0,
183 y: (_point$y = point.y) !== null && _point$y !== void 0 ? _point$y : 0,
184 width: 0,
185 lowerWidth: 0,
186 upperWidth: 0,
187 height: 0
188 };
189 return _objectSpread(_objectSpread({}, viewBox), {}, {
190 value: point.value,
191 payload: point.payload,
192 viewBox,
193 /*
194 * Line is not passing parentViewBox to the LabelList so the labels can escape - looks like a bug, should we pass parentViewBox?
195 * Or should this just be the root chart viewBox?
196 */
197 parentViewBox: undefined,
198 fill: undefined
199 });
200 });
201 }, [points]);
202 return /*#__PURE__*/React.createElement(CartesianLabelListContextProvider, {
203 value: showLabels ? labelListEntries : undefined
204 }, children);
205}
206function StaticCurve(_ref4) {
207 var {
208 clipPathId,
209 pathRef,
210 points,
211 strokeDasharray,
212 props
213 } = _ref4;
214 var {
215 type,
216 layout,
217 connectNulls,
218 needClip,
219 shape
220 } = props,
221 others = _objectWithoutProperties(props, _excluded2);
222 var curveProps = _objectSpread(_objectSpread({}, svgPropertiesAndEvents(others)), {}, {
223 fill: 'none',
224 className: 'recharts-line-curve',
225 clipPath: needClip ? "url(#clipPath-".concat(clipPathId, ")") : undefined,
226 points,
227 type,
228 layout,
229 connectNulls,
230 strokeDasharray: strokeDasharray !== null && strokeDasharray !== void 0 ? strokeDasharray : props.strokeDasharray
231 });
232 return /*#__PURE__*/React.createElement(React.Fragment, null, (points === null || points === void 0 ? void 0 : points.length) > 1 && /*#__PURE__*/React.createElement(Shape, _extends({
233 shapeType: "curve",
234 option: shape
235 }, curveProps, {
236 pathRef: pathRef
237 })), /*#__PURE__*/React.createElement(LineDotsWrapper, {
238 points: points,
239 clipPathId: clipPathId,
240 props: props
241 }));
242}
243function getTotalLength(mainCurve) {
244 try {
245 return mainCurve && mainCurve.getTotalLength && mainCurve.getTotalLength() || 0;
246 } catch (_unused) {
247 return 0;
248 }
249}
250function CurveWithAnimation(_ref5) {
251 var {
252 clipPathId,
253 props,
254 pathRef,
255 previousPointsRef,
256 longestAnimatedLengthRef
257 } = _ref5;
258 var {
259 points,
260 strokeDasharray,
261 isAnimationActive,
262 animationBegin,
263 animationDuration,
264 animationEasing,
265 animateNewValues,
266 width,
267 height,
268 onAnimationEnd,
269 onAnimationStart
270 } = props;
271 var prevPoints = previousPointsRef.current;
272 var animationId = useAnimationId(points, 'recharts-line-');
273 var animationIdRef = useRef(animationId);
274 var [isAnimating, setIsAnimating] = useState(false);
275 var showLabels = !isAnimating;
276 var handleAnimationEnd = useCallback(() => {
277 if (typeof onAnimationEnd === 'function') {
278 onAnimationEnd();
279 }
280 setIsAnimating(false);
281 }, [onAnimationEnd]);
282 var handleAnimationStart = useCallback(() => {
283 if (typeof onAnimationStart === 'function') {
284 onAnimationStart();
285 }
286 setIsAnimating(true);
287 }, [onAnimationStart]);
288 var totalLength = getTotalLength(pathRef.current);
289 /*
290 * Here we want to detect if the length animation has been interrupted.
291 * For that we keep a reference to the furthest length that has been animated.
292 *
293 * And then, to keep things smooth, we add to it the current length that is being animated right now.
294 *
295 * If we did Math.max then it makes the length animation "pause" but we want to keep it smooth
296 * so in case we have some "leftover" length from the previous animation we add it to the current length.
297 *
298 * This is not perfect because the animation changes speed due to easing. The default easing is 'ease' which is not linear
299 * and makes it stand out. But it's good enough I suppose.
300 * If we want to fix it then we need to keep track of multiple animations and their easing and timings.
301 *
302 * If you want to see this in action, try to change the dataKey of the line chart while the initial animation is running.
303 * The Line begins with zero length and slowly grows to the full length. While this growth is in progress,
304 * change the dataKey and the Line will continue growing from where it has grown so far.
305 *
306 * This is for the case when new animation triggers. When that happens we get new points, everything re-renders,
307 * and we get fresh new state in this component and use the ref stored above.
308 *
309 * In case when we get render without new animation - for example when opacity changes, or color changes,
310 * then the animationId remains the same, and we do not update the starting point.
311 * See https://github.com/recharts/recharts/issues/6044
312 */
313 var startingPointRef = useRef(0);
314 if (animationIdRef.current !== animationId) {
315 startingPointRef.current = longestAnimatedLengthRef.current;
316 animationIdRef.current = animationId;
317 }
318 var startingPoint = startingPointRef.current;
319 return /*#__PURE__*/React.createElement(LineLabelListProvider, {
320 points: points,
321 showLabels: showLabels
322 }, props.children, /*#__PURE__*/React.createElement(JavascriptAnimate, {
323 animationId: animationId,
324 begin: animationBegin,
325 duration: animationDuration,
326 isActive: isAnimationActive,
327 easing: animationEasing,
328 onAnimationEnd: handleAnimationEnd,
329 onAnimationStart: handleAnimationStart,
330 key: animationId
331 }, t => {
332 var lengthInterpolated = interpolate(startingPoint, totalLength + startingPoint, t);
333 var curLength = Math.min(lengthInterpolated, totalLength);
334 var currentStrokeDasharray;
335 if (isAnimationActive) {
336 if (strokeDasharray) {
337 var lines = "".concat(strokeDasharray).split(/[,\s]+/gim).map(num => parseFloat(num));
338 currentStrokeDasharray = getStrokeDasharray(curLength, totalLength, lines);
339 } else {
340 currentStrokeDasharray = generateSimpleStrokeDasharray(totalLength, curLength);
341 }
342 } else {
343 currentStrokeDasharray = strokeDasharray == null ? undefined : String(strokeDasharray);
344 }
345
346 /*
347 * Here it is important to wait a little bit with updating the previousPointsRef
348 * before the animation has a time to initialize.
349 * If we set the previous pointsRef immediately, we set it before the Legend height it calculated
350 * and before pathRef is set.
351 * If that happens, the Line will re-render again after Legend had reported its height
352 * which will start a new animation with the previous points as the starting point
353 * which gives the effect of the Line animating slightly upwards (where the animation distance equals the Legend height).
354 * Waiting for t > 0 is indirect but good enough to ensure that the Legend height is calculated and animation works properly.
355 *
356 * Total length similarly is calculated from the pathRef. We should not update the previousPointsRef
357 * before the pathRef is set, otherwise we will have a wrong total length.
358 */
359 if (t > 0 && totalLength > 0) {
360 // eslint-disable-next-line no-param-reassign
361 previousPointsRef.current = points;
362 /*
363 * totalLength is set from a ref and is not updated in the first tick of the animation.
364 * It defaults to zero which is exactly what we want here because we want to grow from zero,
365 * however the same happens when the data change.
366 *
367 * In that case we want to remember the previous length and continue from there, and only animate the shape.
368 *
369 * Therefore the totalLength > 0 check.
370 *
371 * The Animate is about to fire handleAnimationStart which will update the state
372 * and cause a re-render and read a new proper totalLength which will be used in the next tick
373 * and update the longestAnimatedLengthRef.
374 *
375 * Why Math.max? Sometimes the curve goes through a smaller length than previously recorded.
376 * If we just set it to curLength, then the next animation would start from a smaller length
377 * which looks weird. So we keep the longest length ever reached and then animate from there.
378 */
379 // eslint-disable-next-line no-param-reassign
380 longestAnimatedLengthRef.current = Math.max(longestAnimatedLengthRef.current, curLength);
381 }
382 if (prevPoints) {
383 var prevPointsDiffFactor = prevPoints.length / points.length;
384 var stepData = t === 1 ? points : points.map((entry, index) => {
385 var prevPointIndex = Math.floor(index * prevPointsDiffFactor);
386 if (prevPoints[prevPointIndex]) {
387 var prev = prevPoints[prevPointIndex];
388 return _objectSpread(_objectSpread({}, entry), {}, {
389 x: interpolate(prev.x, entry.x, t),
390 y: interpolate(prev.y, entry.y, t)
391 });
392 }
393
394 // magic number of faking previous x and y location
395 if (animateNewValues) {
396 return _objectSpread(_objectSpread({}, entry), {}, {
397 x: interpolate(width * 2, entry.x, t),
398 y: interpolate(height / 2, entry.y, t)
399 });
400 }
401 return _objectSpread(_objectSpread({}, entry), {}, {
402 x: entry.x,
403 y: entry.y
404 });
405 });
406 // eslint-disable-next-line no-param-reassign
407 previousPointsRef.current = stepData;
408 return /*#__PURE__*/React.createElement(StaticCurve, {
409 props: props,
410 points: stepData,
411 clipPathId: clipPathId,
412 pathRef: pathRef,
413 strokeDasharray: currentStrokeDasharray
414 });
415 }
416 return /*#__PURE__*/React.createElement(StaticCurve, {
417 props: props,
418 points: points,
419 clipPathId: clipPathId,
420 pathRef: pathRef,
421 strokeDasharray: currentStrokeDasharray
422 });
423 }), /*#__PURE__*/React.createElement(LabelListFromLabelProp, {
424 label: props.label
425 }));
426}
427function RenderCurve(_ref6) {
428 var {
429 clipPathId,
430 props
431 } = _ref6;
432 var previousPointsRef = useRef(null);
433 var longestAnimatedLengthRef = useRef(0);
434 var pathRef = useRef(null);
435 return /*#__PURE__*/React.createElement(CurveWithAnimation, {
436 props: props,
437 clipPathId: clipPathId,
438 previousPointsRef: previousPointsRef,
439 longestAnimatedLengthRef: longestAnimatedLengthRef,
440 pathRef: pathRef
441 });
442}
443var errorBarDataPointFormatter = (dataPoint, dataKey) => {
444 var _dataPoint$x, _dataPoint$y;
445 return {
446 x: (_dataPoint$x = dataPoint.x) !== null && _dataPoint$x !== void 0 ? _dataPoint$x : undefined,
447 y: (_dataPoint$y = dataPoint.y) !== null && _dataPoint$y !== void 0 ? _dataPoint$y : undefined,
448 value: dataPoint.value,
449 // @ts-expect-error getValueByDataKey does not validate the output type
450 errorVal: getValueByDataKey(dataPoint.payload, dataKey)
451 };
452};
453
454// eslint-disable-next-line react/prefer-stateless-function
455class LineWithState extends Component {
456 render() {
457 var {
458 hide,
459 dot,
460 points,
461 className,
462 xAxisId,
463 yAxisId,
464 top,
465 left,
466 width,
467 height,
468 id,
469 needClip,
470 zIndex
471 } = this.props;
472 if (hide) {
473 return null;
474 }
475 var layerClass = clsx('recharts-line', className);
476 var clipPathId = id;
477 var {
478 r,
479 strokeWidth
480 } = getRadiusAndStrokeWidthFromDot(dot);
481 var clipDot = isClipDot(dot);
482 var dotSize = r * 2 + strokeWidth;
483 var activePointsClipPath = needClip ? "url(#clipPath-".concat(clipDot ? '' : 'dots-').concat(clipPathId, ")") : undefined;
484 return /*#__PURE__*/React.createElement(ZIndexLayer, {
485 zIndex: zIndex
486 }, /*#__PURE__*/React.createElement(Layer, {
487 className: layerClass
488 }, needClip && /*#__PURE__*/React.createElement("defs", null, /*#__PURE__*/React.createElement(GraphicalItemClipPath, {
489 clipPathId: clipPathId,
490 xAxisId: xAxisId,
491 yAxisId: yAxisId
492 }), !clipDot && /*#__PURE__*/React.createElement("clipPath", {
493 id: "clipPath-dots-".concat(clipPathId)
494 }, /*#__PURE__*/React.createElement("rect", {
495 x: left - dotSize / 2,
496 y: top - dotSize / 2,
497 width: width + dotSize,
498 height: height + dotSize
499 }))), /*#__PURE__*/React.createElement(SetErrorBarContext, {
500 xAxisId: xAxisId,
501 yAxisId: yAxisId,
502 data: points,
503 dataPointFormatter: errorBarDataPointFormatter,
504 errorBarOffset: 0
505 }, /*#__PURE__*/React.createElement(RenderCurve, {
506 props: this.props,
507 clipPathId: clipPathId
508 }))), /*#__PURE__*/React.createElement(ActivePoints, {
509 activeDot: this.props.activeDot,
510 points: points,
511 mainColor: this.props.stroke,
512 itemDataKey: this.props.dataKey,
513 clipPath: activePointsClipPath
514 }));
515 }
516}
517export var defaultLineProps = {
518 activeDot: true,
519 animateNewValues: true,
520 animationBegin: 0,
521 animationDuration: 1500,
522 animationEasing: 'ease',
523 connectNulls: false,
524 dot: true,
525 fill: '#fff',
526 hide: false,
527 isAnimationActive: 'auto',
528 label: false,
529 legendType: 'line',
530 stroke: '#3182bd',
531 strokeWidth: 1,
532 xAxisId: 0,
533 yAxisId: 0,
534 zIndex: DefaultZIndexes.line,
535 type: 'linear'
536};
537function LineImpl(props) {
538 var _resolveDefaultProps = resolveDefaultProps(props, defaultLineProps),
539 {
540 activeDot,
541 animateNewValues,
542 animationBegin,
543 animationDuration,
544 animationEasing,
545 connectNulls,
546 dot,
547 hide,
548 isAnimationActive,
549 label,
550 legendType,
551 xAxisId,
552 yAxisId,
553 id
554 } = _resolveDefaultProps,
555 everythingElse = _objectWithoutProperties(_resolveDefaultProps, _excluded3);
556 var {
557 needClip
558 } = useNeedsClip(xAxisId, yAxisId);
559 var plotArea = usePlotArea();
560 var layout = useChartLayout();
561 var isPanorama = useIsPanorama();
562 var points = useAppSelector(state => selectLinePoints(state, xAxisId, yAxisId, isPanorama, id));
563 if (layout !== 'horizontal' && layout !== 'vertical' || points == null || plotArea == null) {
564 // Cannot render Line in an unsupported layout
565 return null;
566 }
567 var {
568 height,
569 width,
570 x: left,
571 y: top
572 } = plotArea;
573 return /*#__PURE__*/React.createElement(LineWithState, _extends({}, everythingElse, {
574 id: id,
575 connectNulls: connectNulls,
576 dot: dot,
577 activeDot: activeDot,
578 animateNewValues: animateNewValues,
579 animationBegin: animationBegin,
580 animationDuration: animationDuration,
581 animationEasing: animationEasing,
582 isAnimationActive: isAnimationActive,
583 hide: hide,
584 label: label,
585 legendType: legendType,
586 xAxisId: xAxisId,
587 yAxisId: yAxisId,
588 points: points,
589 layout: layout,
590 height: height,
591 width: width,
592 left: left,
593 top: top,
594 needClip: needClip
595 }));
596}
597export function computeLinePoints(_ref7) {
598 var {
599 layout,
600 xAxis,
601 yAxis,
602 xAxisTicks,
603 yAxisTicks,
604 dataKey,
605 bandSize,
606 displayedData
607 } = _ref7;
608 return displayedData.map((entry, index) => {
609 // @ts-expect-error getValueByDataKey does not validate the output type
610 var value = getValueByDataKey(entry, dataKey);
611 if (layout === 'horizontal') {
612 var _x = getCateCoordinateOfLine({
613 axis: xAxis,
614 ticks: xAxisTicks,
615 bandSize,
616 entry,
617 index
618 });
619 var _y = isNullish(value) ? null : yAxis.scale.map(value);
620 return {
621 x: _x,
622 y: _y !== null && _y !== void 0 ? _y : null,
623 value,
624 payload: entry
625 };
626 }
627 var x = isNullish(value) ? null : xAxis.scale.map(value);
628 var y = getCateCoordinateOfLine({
629 axis: yAxis,
630 ticks: yAxisTicks,
631 bandSize,
632 entry,
633 index
634 });
635 if (x == null || y == null) {
636 return null;
637 }
638 return {
639 x,
640 y,
641 value,
642 payload: entry
643 };
644 }).filter(Boolean);
645}
646function LineFn(outsideProps) {
647 var props = resolveDefaultProps(outsideProps, defaultLineProps);
648 var isPanorama = useIsPanorama();
649 return /*#__PURE__*/React.createElement(RegisterGraphicalItemId, {
650 id: props.id,
651 type: "line"
652 }, id => /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(SetLegendPayload, {
653 legendPayload: computeLegendPayloadFromAreaData(props)
654 }), /*#__PURE__*/React.createElement(SetLineTooltipEntrySettings, {
655 dataKey: props.dataKey,
656 data: props.data,
657 stroke: props.stroke,
658 strokeWidth: props.strokeWidth,
659 fill: props.fill,
660 name: props.name,
661 hide: props.hide,
662 unit: props.unit,
663 tooltipType: props.tooltipType,
664 id: id
665 }), /*#__PURE__*/React.createElement(SetCartesianGraphicalItem, {
666 type: "line",
667 id: id,
668 data: props.data,
669 xAxisId: props.xAxisId,
670 yAxisId: props.yAxisId,
671 zAxisId: 0,
672 dataKey: props.dataKey,
673 hide: props.hide,
674 isPanorama: isPanorama
675 }), /*#__PURE__*/React.createElement(LineImpl, _extends({}, props, {
676 id: id
677 }))));
678}
679
680/**
681 * @provides LabelListContext
682 * @provides ErrorBarContext
683 * @consumes CartesianChartContext
684 */
685export var Line = /*#__PURE__*/React.memo(LineFn, propsAreEqual);
686Line.displayName = 'Line';
Note: See TracBrowser for help on using the repository browser.