Skip to content

Commit

Permalink
Replaced ViewState by selectStopPointIdx.
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancescoPazz committed Nov 20, 2024
1 parent 0b0f58e commit 050ac6a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
12 changes: 6 additions & 6 deletions lib/ReactViews/Custom/Chart/BottomDockChart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ const labelColor = "#efefef";
class BottomDockChart extends React.Component {
static propTypes = {
terria: PropTypes.object.isRequired,
viewState: PropTypes.object,
parentWidth: PropTypes.number,
width: PropTypes.number,
height: PropTypes.number,
chartItems: PropTypes.array.isRequired,
xAxis: PropTypes.object.isRequired,
margin: PropTypes.object,
chartItemKeyForPointMouseNear: PropTypes.string,
onPointMouseNear: PropTypes.func
onPointMouseNear: PropTypes.func,
selectedStopPointIdx: PropTypes.number
};

static defaultProps = {
Expand All @@ -62,7 +62,7 @@ class BottomDockChart extends React.Component {
)}
chartItemKeyForPointMouseNear={this.props.chartItemKeyForPointMouseNear}
onPointMouseNear={this.props.onPointMouseNear}
viewState={this.props.viewState}
viewState={this.props.selectedStopPointIdx}
/>
);
}
Expand All @@ -74,14 +74,14 @@ export default withParentSize(BottomDockChart);
class Chart extends React.Component {
static propTypes = {
terria: PropTypes.object.isRequired,
viewState: PropTypes.object,
width: PropTypes.number,
height: PropTypes.number,
chartItems: PropTypes.array.isRequired,
xAxis: PropTypes.object.isRequired,
margin: PropTypes.object,
chartItemKeyForPointMouseNear: PropTypes.string,
onPointMouseNear: PropTypes.func
onPointMouseNear: PropTypes.func,
selectedStopPointIdx: PropTypes.number
};

static defaultProps = {
Expand Down Expand Up @@ -258,7 +258,7 @@ class Chart extends React.Component {

componentDidMount() {
this.disposeReaction = reaction(
() => this.props.viewState.selectedStopPointIdx,
() => this.props.selectedStopPointIdx,
(idx) => {
if (idx !== null && this.props.chartItems) {
const sumDistances =
Expand Down
7 changes: 1 addition & 6 deletions lib/ReactViews/Custom/Chart/MeasurableGeometryChartPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,15 @@ const MeasurableGeometryChartPanel = observer((props: Props) => {
(!chartPoint?.current || chartPoint.current !== newPoint)
) {
chartPoint.current = newPoint;
console.log("newPoint", newPoint);
const pointIndex = chartItems
?.find((item) => item.key === ChartKeys.GroundChart)
?.points.findIndex((elem) => elem === newPoint);
console.log("pointIndex", pointIndex);
if (!pointIndex) return;
const coords = terria?.measurableGeom?.sampledPoints?.[pointIndex];
console.log("coords", coords);
if (!coords) return;
console.log("chartItems: ", chartItems);
const airPointIndex = chartItems
?.find((item) => item.key === ChartKeys.AirChart)
?.points.findIndex((elem) => elem.y === newPoint.y);
console.log("airPointIndex", airPointIndex);
viewState.setSelectedStopPointIdx(
airPointIndex && airPointIndex !== -1 ? airPointIndex : null
);
Expand Down Expand Up @@ -199,7 +194,6 @@ const MeasurableGeometryChartPanel = observer((props: Props) => {
{chartItems && (
<Chart
terria={terria}
viewState={viewState}
chartItems={chartItems}
xAxis={{
scale: "linear",
Expand All @@ -208,6 +202,7 @@ const MeasurableGeometryChartPanel = observer((props: Props) => {
height={CHART_HEIGHT}
chartItemKeyForPointMouseNear={ChartKeys.GroundChart}
onPointMouseNear={updateChartPointNearMouse}
selectedStopPointIdx={viewState.selectedStopPointIdx}
/>
)}
</div>
Expand Down

0 comments on commit 050ac6a

Please sign in to comment.