Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add/chart to popup #73

Merged
merged 30 commits into from
Oct 21, 2022
Merged

Add/chart to popup #73

merged 30 commits into from
Oct 21, 2022

Conversation

4lm
Copy link
Contributor

@4lm 4lm commented Oct 12, 2022

This PR adds dynamic titles, descriptions, charts, and sources to popups.

@4lm
Copy link
Contributor Author

4lm commented Oct 12, 2022

Hi @bmlancien :),

I would like to invite you to work with me in this branch (add/chart-to-popup). This branch is all about popups and charts in popups. I created a bar chart popup that fetches data via an AJAX GET request from a fake API endpoint (always same popup data in response). I need your CSS magic to make the popup styling look nice! Can you help me? Please :)

The popup is based on a template named results.html. I prepared the template for you by adding BEM CSS classes, but added zero styling yet. You can touch any class or add new ones, but your are forbidden to change the id attributes that start with "js-" prefixes (as usual).

You can also play with all chart and popup options in popup.js.

Please notice: you have to wait until the app loads and then go to "Ergebnisse" and click on a blackish municipality area for the popup to appear.
Please also notice: It's also OK for me if you extract the necessary code and work in the "RLI Design" repo, if that is easier for you!

Screenie of the unstyled popup with bar chart:

image

@bmlancien
Copy link
Contributor

I would like to invite you to work with me in this branch (add/chart-to-popup). This branch is all about popups and charts in popups. I created a bar chart popup that fetches data via an AJAX GET request from a fake API endpoint (always same popup data in response). I need your CSS magic to make the popup styling look nice! Can you help me? Please :)

Sure, I'd be pleased to work on this :)

@4lm
Copy link
Contributor Author

4lm commented Oct 13, 2022

@bmlancien, a small thing popped into my mind. I integrated the title for the chart, not in the chart, but via an h2-tag above the chart. Therefore there is quite a lot of white space at the top of the chart. I think the title should be integrated into the chart via the JS option object in popup.js.

Can you make the appropriate changes? Drop me a line if you need help with this!

Please also look at this screenie, then you should exactly know what I mean:

image

@bmlancien
Copy link
Contributor

@4lm Thanks for all the explanations. I preferred working on a mockups before starting implementing it. Here is the result:

Screenshot 2022-10-17 at 14 43 16

As mentioned to @nesnoj today, the text would go below the chart because we want to keep the focus on the chart. And the text should also be optional, because in this case (population growth) it is a bit redundant, so I would not even add anything. Important is to have something accessible, like stated in #66, it could for example be the aria-label from echarts that can read charts to screen readers.

Now that I have a mockup, I'm trying to work on the code side, but I am not able to add or change CSS styles to the popup in results.html Basically, trying to do something with the #js-results_popupor .popup divs is not successful. I even cannot see these divs in the Chrome inspector, only mapbox/maplibre classes. I am able to style the content, though, like .popup__title.

Screenshot 2022-10-17 at 15 06 51

Any idea why it is not working?

@4lm
Copy link
Contributor Author

4lm commented Oct 18, 2022

@4lm Thanks for all the explanations. I preferred working on a mockups before starting implementing it.

I love it :)

I'm trying to work on the code side, but I am not able to add or change CSS styles to the popup in results.html

I will have a look and report back!

@4lm
Copy link
Contributor Author

4lm commented Oct 18, 2022

I will have a look and report back!

Works. HTML is there. The results.html is just wrapped into Maplibre-specific popup HTML. The class popup is replaced by maplibregl-popup-content. But the rest of the classes are there. Look at this gist. There I added for you all the HTML that is getting rendered.

I also switched the CSS import order, so you can cleanly overwrite classes from Maplibre (see commit 216ea1f).

Please note: Maplibre is a fork of Mapbox; therefore, the team of Maplibre left all CSS identifiers named mapboxgl-* in there and just added their ones, maplibregl-* Edit: that's why I would target both identifiers so that we can switch easily between both libraries (even though we don't plan to use Mapbox in the future - just in case, I would say, because it makes nearly no extra work).

Please also note: my wire up SCSS example I created for you in digiplan/static/scss/components/_popup.scss

I wish you a happy styling session :)

@bmlancien
Copy link
Contributor

Ok, thanks for the explanations @4lm! This is what I thought so, the .popup class is not there anymore, because it is replaced, but I can then target the replacement classes to style the popup.

Please note: Maplibre is a fork of Mapbox; therefore, the team of Maplibre left all CSS identifiers named mapboxgl-* in there and just added their ones, maplibregl-* Edit: that's why I would target both identifiers so that we can switch easily between both libraries (even though we don't plan to use Mapbox in the future - just in case, I would say, because it makes nearly no extra work).

Alright :)

@4lm
Copy link
Contributor Author

4lm commented Oct 18, 2022

@bmlancien, please not. I made changes to the test API JSON and dependent JS implementation in this PR branch to reflect changes made in #77. Please look those changes made in 391ac4c. Should be self-explanatory, If not, drop me a line, I'm happy to help!

@bmlancien
Copy link
Contributor

@4lm I updated the popup with the new design. Please check that I haven't destroyed anything :)

There are also two other things:

  • The tooltip is doesn't appear on hover. I'm not sure why. I've tried a few things but couldn't make it to work.
  • I know this can give a headache, but in the best of the worlds, the key values would have a comma or a dot as a thousands separator (depending on the language), or at least a space. Is this something that will be worked on in the future?

@4lm
Copy link
Contributor Author

4lm commented Oct 20, 2022

@4lm I updated the popup with the new design. Please check that I haven't destroyed anything :)

Very nice. Looks good to me. Thank you.

There are also two other things:

OK :)

The tooltip is doesn't appear on hover. I'm not sure why. I've tried a few things but couldn't make it to work.

This is by design. Changing this would also require other changes to make it acceptable to the user. We also had this behavior (click on a municipality to show a popup) in the prior Stemp ABW app. I would suggest keeping it like it is for now, and if we have later time and still want to change this, look at it. OK?

I know this can give a headache, but in the best of the worlds, the key values would have a comma or a dot as a thousands separator (depending on the language), or at least a space. Is this something that will be worked on in the future?

No problem. I will integrate this before I open this PR for review.

@4lm 4lm marked this pull request as ready for review October 20, 2022 11:14
@4lm
Copy link
Contributor Author

4lm commented Oct 20, 2022

@henhuy, this PR is ready for review now. Please merge on approval.

@4lm 4lm requested a review from henhuy October 20, 2022 11:15
Copy link
Collaborator

@henhuy henhuy left a comment

Choose a reason for hiding this comment

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

Thanks for implementing charts in popups. Looks very nice indeed.
Only some little change requests..

const {chart: {data: {series}}} = response;
const xAxisData = createListByName("key", series);
const yAxisData = createListByName("value", series);
const option = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would suggest loading a chart option style file with named options for different charts from outside.
And afterwards fill remaining fields with data from visualization request.
What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, of course, but not in this PR - I would suggest. This version lacks a proper API and only has one fixed chart type. The code in this PR is a first step, a MacGyver Implementation, held together by a thread, a piece of chewing gum, and some Gaffa tape. I would suggest implementing your suggestion in another PR when we have more data to play with and, therefore, different chart types. As said before, I want to make smaller PRs, to move faster. What do you think? Is this OK for you? I do not insist on my points if they are not absolutely important to me, and this one is NOT absolutely important to me!

</span>
`;
}
if (field === "description") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If clauses for title, municipality and description almost look the same - maybe refactor to DRY?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I also suggest postponing this to a different PR. Because as you can see in the many TODO comments, this code implementation will change a lot in the future. No stone will be left untouched. But for now, I would leave it like this because it makes IMO little sense to change something that will totally be changed in the future. If I keep the if-clauses, work with switch-cases or some function calls is TBD and would be determined in the future. Is that OK for you?


{{ block.super }}

{% compress css %}
Copy link
Collaborator

Choose a reason for hiding this comment

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

why did you add a second compress block?

Copy link
Contributor Author

@4lm 4lm Oct 20, 2022

Choose a reason for hiding this comment

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

To implicitly make clear to others that there is the possibility to also add css after the super block. I don't know, I felt like it, maybe a YAGNI case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will remove the second compress block.

@bmlancien
Copy link
Contributor

@4lm

This is by design. Changing this would also require other changes to make it acceptable to the user. We also had this behavior (click on a municipality to show a popup) in the prior Stemp ABW app. I would suggest keeping it like it is for now, and if we have later time and still want to change this, look at it. OK?

No problem for me. Let's see later, maybe with user testing, how it integrated well in the app

No problem. I will integrate this before I open this PR for review.

Cool, thanks! :)

@4lm
Copy link
Contributor Author

4lm commented Oct 20, 2022

@henhuy, from my point of view, this PR is ready for re-review. As written, I would postpone some requested changes to a future PR.

@4lm 4lm requested a review from henhuy October 20, 2022 15:47
@henhuy henhuy merged commit 330b512 into dev Oct 21, 2022
@henhuy henhuy deleted the add/chart-to-popup branch October 21, 2022 11:20
@nesnoj nesnoj mentioned this pull request Feb 16, 2023
3 tasks
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