Skip to content

Handle path details state within app - #75

Merged
easbar merged 37 commits into
masterfrom
path_details_component
Jun 11, 2021
Merged

easbar merged 37 commits into
masterfrom
path_details_component

Conversation

@easbar

@easbar easbar commented May 19, 2021 •

Copy link
Copy Markdown
Member

todo:

  • should the path details be shown underneath or within the map? -> within the map
  • allow hiding the path details (should or should we not use the toggle icon?)
  • make the details responsive (resize when browser window size changes)
  • hide the graph when no path was calculated

Comment thread src/App.module.css Resolved
Comment thread src/pathDetails/PathDetails.tsx Resolved
Comment thread src/stores/PathDetailsStore.ts Resolved
@easbar easbar mentioned this pull request May 25, 2021
5 of 6 tasks

@Janekdererste Janekdererste left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks good to me. I guess one can also see the limit of the used store pattern already. I think we are not there yet, but maybe soon.

Comment thread src/pathDetails/PathDetails.tsx Outdated
routeSegmentsSelectedCallback: onElevationSelected,
}
setGraph(new HeightGraph(containerRef.current, options, callbacks))
}, [containerRef])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the old heightgraph properly removed from the dom? I.e. when the large and small layouts are exhchanged this component will be unmounted. I don't know from just looking at this.

When the dependeny array is removed there are a lot of svg added to the dom which maybe indicate a missing cancel function as return value of this effect?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The height graph is just a collection of elements attached to some parent

, I think. So when we remove the div the heightgraph is also gone?! But no idea tbh. I saw we can use some clean up function as return value of useEffect, but I am not sure what to remove?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be gone and I just noticed it when removing the dependencies as long as there is the containerRef dependency, I don't see more svg elements than expected.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean there is nothing we need to do? :)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sorry about that comment. I typed it while thinking, not considering whether it would be helpful or not.

}, [containerRef])
const resizeGraph = () => {
graph?.resize({ width: containerRef.current?.clientWidth, height: containerRef.current?.clientHeight })
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed width to container's width

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks. Should the graph not use all available horizontal space? I thought this was kind of the original idea. But then it might 'collide' with the instructions list.. hm :)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I gave it a container, which sits on top of the map. As it was with the widget before. It will not collide with the instruction list this way.

const pathDetailsData = buildPathDetailsData(selectedPath)
graph?.setData(pathDetailsData.data, pathDetailsData.mappings)
}, [selectedPath, graph])
return (

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to hide the height graph if no route is selected. It doesn't look pleasant when empty something like:

return isPathPresent && 
        <div className={styles.layoutContainer}>
            <div className={styles.heightgraphContainer} ref={containerRef} />
        </div>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. This is somewhat related to our discussion about using null for missing values. The selectedPath is never null, but it might be missing. I would find it very intuitive to check if its null here :) Currently it might be an RouteStore#emptyPath, but to obtain the isPathPresent value here I need to figure this out by checking if the points of the path are empty or something like this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this but could not make it work yet :( I also wonder if we should or should not show the toggle button as in current master. I think it is useful to have the button so one can hide the graph if needed. Or maybe it should just be resizable in general? Previously I thought we would put the graph underneath the map so I removed the icon.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find a toggle button usefull.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I put back the toggle button, but I had to tweak the layout quite a bit for this. See my last commits

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The graph is no hidden when there is no path

Comment thread src/pathDetails/PathDetails.tsx Outdated
}
}

function createColorMapping(detail: any): any {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you've ported it from js, but maybe remove the anys? Probably future you will be happy about it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some types here even though I am not fully convinced this improved much :) But generally I agree that adding most or all the types will save time down the road. Here it is a bit awkward because we get these path details from the GH API which could either be [number, number, number][] or [number, number, string][] and there already is some code that needs to distinguish the two cases.

Comment thread src/stores/PathDetailsStore.ts Outdated
}

export default class PathDetailsStore extends Store<PathDetailsStoreState> {
constructor() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default constructor may be ommited

}

protected getInitialState(): PathDetailsStoreState {
return {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it nice to not have null or undefined values. Other than Java Typescript somewhat forces us to never have undefined values since it is necessary to separately declare that type. Not having undefined and null removes a lot of places where one has to test for presence.

If you can make it work maybe it is possible to supply an empty but valid state initially and design the components so that they always display the right thing also with an initial state.

@easbar easbar Jun 7, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I also noticed this. Using types like <type> | null does seem a bit strange indeed. Then again it kind of expresses exactly what I want. pathDetailsPoint is the point on the map that corresponds to the mouse hover position in the height graph. When the mouse is not positioned above the heightgraph there is no such point and I use null to cover this state. What would be the alternative? We could use some special point value like [600,600] to represent 'no point selected', but so far I do not see why this would be better (and I think its worse tbh). Sure we would not need the extra | null in the typing but then we need to do another comparison like point !== [600,600] elsewhere. In this specific example there is only one place where we check if the point is null and this is the place where we have to decide whether there should or should not be a marker on the map. I think it would be the same if we had to check for some special value.

But generally I agree that thinking about null or undefined values can make the code worse and my default assumption is also that nothing is null or undefined (same in Java btw) unless cases like this where there is a notion of a value possibly 'missing'. Hm, another possibility could be adding something like pointSelected: boolean to the state?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that it makes sense in this case. I also agree that the special value approach would be worse.

easbar added 4 commits June 7, 2021 10:31
# Conflicts:
#	src/App.module.css
#	src/App.tsx
#	src/actions/Actions.ts
#	src/index.tsx
#	src/map/Map.tsx
#	src/map/Mapbox.ts
#	src/sidebar/search/AddressInput.module.css
#	src/sidebar/search/AddressInput.tsx
#	src/sidebar/search/GeocodingResult.tsx
#	src/stores/MapOptionsStore.ts
@easbar

easbar commented Jun 7, 2021

Copy link
Copy Markdown
Member Author

Overall this looks good to me. I guess one can also see the limit of the used store pattern already. I think we are not there yet, but maybe soon.

Why do you think we are getting closer to this limit? There is quite a bit of boiler-plate code needed, but this PR does not really do anything we did not do elsewhere yet? But sure probably at some point we should think about our current approach again.

@easbar easbar changed the title WIP: Move path details below map and handle state within app Handle path details state within app Jun 7, 2021
@Janekdererste

Copy link
Copy Markdown
Collaborator

Why do you think we are getting closer to this limit?

Because we add more and more stores. Probably, this would be somthing a library would structure for us.

Now, thinking about this comment a second time. Maybe having more and more stores could also indicate that it is an easy pattern to use and we"re still all good :-)

@easbar

easbar commented Jun 8, 2021 •

Copy link
Copy Markdown
Member Author

Probably, this would be somthing a library would structure for us.

Yes maybe at some point we should do a little comparison but currently I think our approach does the trick.

Can you please have a final look? From my side this is ready to merge. Note that the path detail graph now takes the maximum (as much as the instructions side bar allows) space in horizontal direction. If you do not like feel free to make it more narrow.

Oh and maybe you want to adjust the fonts used in the path detail graph panel?

@Janekdererste

Copy link
Copy Markdown
Collaborator

There is still a layout issue in firefox. I will look into it.

…tails_component

# Conflicts:
#	src/pathDetails/PathDetails.module.css
#	src/pathDetails/PathDetails.tsx
…Component from App.tsx

Make sure the graph always has the correct width
@Janekdererste

Janekdererste commented Jun 9, 2021 •

Copy link
Copy Markdown
Collaborator

Okay, I solved the layout issues on firefox by making things simpler.

I put the glue code to figure out the width of the graph back into the component. The component's container now forces the component to have the correct size. The width parameter which gets pushed down the heightgraph module is taken from that container.

The height of the component's container is determined by the component itself I set it to 14rem which looks good on my screen and is slightly smaller than the default. I also limited the width to 1000px, which will make it span over all the available width on most screens I'd assume.

The toggle button comes with its own background-color, corner-radius and drop-shadow. Maybe we can remove that. The code for this is not in our code base at the moment.

Oh and maybe you want to adjust the fonts used in the path detail graph panel?

I didn't see an option to change it. If it is easily possible it would be great. It would also be nice to style the toggle button accordinto our other controls.

I guess it is your tunr @easbar to have a final look now.

@easbar

easbar commented Jun 9, 2021

Copy link
Copy Markdown
Member Author

Cool, thanks 👍 Your version works for me. I like that the graph resizing code is in PathDetails.tsx again. I think I could not make this work because I was missing this overflow: hidden rule or something (the container would not shrink). Also the close button is now shown at its proper position :) Did you remove the box shadow on purpose? The sidebar has it but the path details do not.

The height of the component's container is determined by the component itself I set it to 14rem which looks good on my screen and is slightly smaller than the default. I also limited the width to 1000px, which will make it span over all the available width on most screens I'd assume.

Sure

I didn't see an option to change it. If it is easily possible it would be great. It would also be nice to style the toggle button accordinto our other controls.

Regarding the styles of the toggle icon and the fonts: They are defined in node_modules/leaflet.heightgraph/src/heightgraph.css. We can change this upstream to whatever we want or even ignore this file entirely and create out own version of it here, but can we not also overwrite these styles in our app somehow? If not, what would be the best way to make this more configurable upstream?

@Janekdererste

Copy link
Copy Markdown
Collaborator

Did you remove the box shadow on purpose

The box shadow wouldn't show when attached to the heightgraph directly. So I removed it because I wanted to finish. But it should have one. I can take another look at it.

Also the close button is now shown at its proper position

The button relies on the component's container to have position: relative. If you want to use the heightgraph component somewhere else, it needs its own container which has that attribute.

but can we not also overwrite these styles in our app somehow?

Probably that's the appropriate thing to do.

@easbar

easbar commented Jun 10, 2021

Copy link
Copy Markdown
Member Author

Ok, but if these styling issues (box shadow, fonts etc.) aren't so easy to fix I'd say let's finish here now. For #87 I also had the problem that I did not manage to integrate the 'flag' that is shown on the map when we hover the path details and this might be related. And I am also not sure if we maybe should just move the entire diagram into our code base, so I think it's better to move on and postpone this for now unless there is a quick fix for the styling. I also do not understand why the font is now larger than in master since we did not really change it?

# Conflicts:
#	src/map/Mapbox.ts
@easbar
easbar merged commit 798a797 into master Jun 11, 2021
@easbar
easbar deleted the path_details_component branch June 11, 2021 06:43
@easbar

easbar commented Jun 11, 2021

Copy link
Copy Markdown
Member Author

I opened #105 for the remaining styling issues

ZeroGxMax pushed a commit to minhhpkp/graphhopper-maps that referenced this pull request Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants