Skip to content

Commit 6b0f69e

Browse files
committed
fix: Display third graph on opening
1 parent b77e286 commit 6b0f69e

File tree

2 files changed

+17
-29
lines changed

2 files changed

+17
-29
lines changed

dist/components/d3_line_rect/index.js

+8-15
Original file line numberDiff line numberDiff line change
@@ -402,21 +402,14 @@ class ViewerLineRect extends _react.default.Component {
402402
const {
403403
subViewerAt
404404
} = uiSt;
405-
let selectFeature = null;
406-
if (subViewerAt && subViewerAt.x) {
407-
const {
408-
features
409-
} = (0, _extractParams.extractParams)(subEntities[entityIdx], 0, 1);
410-
const arrPageValues = features.map(fe => fe.pageValue);
411-
const closestPage = (0, _calc.findClosest)(arrPageValues, subViewerAt.x);
412-
const filteredFeatures = features.filter(fe => {
413-
const {
414-
pageValue
415-
} = fe;
416-
return pageValue === closestPage;
417-
});
418-
[selectFeature] = filteredFeatures;
419-
}
405+
const {
406+
features
407+
} = (0, _extractParams.extractParams)(subEntities[entityIdx], 0, 1);
408+
if (features.length === 0) return null;
409+
const arrPageValues = features.map(fe => fe.pageValue);
410+
const hasValidClick = subViewerAt && subViewerAt.x !== undefined;
411+
const closestPage = hasValidClick ? (0, _calc.findClosest)(arrPageValues, subViewerAt.x) : arrPageValues[Math.floor(arrPageValues.length / 2)];
412+
const [selectFeature] = features.filter(fe => fe.pageValue === closestPage);
420413
return selectFeature;
421414
}
422415
render() {

src/components/d3_line_rect/index.js

+9-14
Original file line numberDiff line numberDiff line change
@@ -353,20 +353,15 @@ class ViewerLineRect extends React.Component {
353353
const { isNegative } = tic;
354354
const entityIdx = isNegative ? 2 : 1;
355355
const { subViewerAt } = uiSt;
356-
let selectFeature = null;
357-
358-
if (subViewerAt && subViewerAt.x) {
359-
const {
360-
features,
361-
} = extractParams(subEntities[entityIdx], 0, 1);
362-
const arrPageValues = features.map((fe) => fe.pageValue);
363-
const closestPage = findClosest(arrPageValues, subViewerAt.x);
364-
const filteredFeatures = features.filter((fe) => {
365-
const { pageValue } = fe;
366-
return pageValue === closestPage;
367-
});
368-
[selectFeature] = filteredFeatures;
369-
}
356+
const { features } = extractParams(subEntities[entityIdx], 0, 1);
357+
if (features.length === 0) return null;
358+
359+
const arrPageValues = features.map((fe) => fe.pageValue);
360+
const hasValidClick = subViewerAt && subViewerAt.x !== undefined;
361+
const closestPage = hasValidClick
362+
? findClosest(arrPageValues, subViewerAt.x)
363+
: arrPageValues[Math.floor(arrPageValues.length / 2)];
364+
const [selectFeature] = features.filter((fe) => fe.pageValue === closestPage);
370365
return selectFeature;
371366
}
372367

0 commit comments

Comments
 (0)