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

Improve chart visualization #873

Open
wants to merge 37 commits into
base: dev
Choose a base branch
from

Conversation

yulia-bel
Copy link
Contributor

@yulia-bel yulia-bel commented Feb 16, 2023

Update. Chart visualization implemented in 2 ways:

  1. The default one - no parameter sent - for case of 'group by region':
  • if no origin filters received, level 0 regions will be shown on chart (countries)
  • if origin filters received and they are of level 0, their descendants of level 1 will be displayed
  • if origin filters received and they are of level 1, their descendants of level 2 will be displayed
  • if origin filters received and they are of level 2, the received regions will be displayed
  • if origin filters received and they are of different level, the chart will display regions and descendants of the lowest level received
  1. Optional parameter 'depth' - can be applied for any group by entity. No matter the parent levels of received filters, user can choose the depth / level to be displayed on the chart

In order to use optional parameter FE changes are needed (add parameter to request)

Tests added.

General description

Please write a description. If the PR is hard to understand, provide a quick explanation of the code.

Designs

Link to the related design prototypes (if applicable)

Testing instructions

Provide minimal instructions on how to test this PR.

  • Apart from the added feature / bug fix, check overall performance, styling...

Checklist before merging

  • Branch name / PR includes the related Jira ticket Id.
  • Tests to check core implementation / bug fix added.
  • All checks in Continuous Integration workflow pass.
  • Feature functionally tested by reviewer(s).
  • Code reviewed by reviewer(s).
  • Documentation updated (README, CHANGELOG...) (if required)

@vercel
Copy link

vercel bot commented Feb 16, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Comments Updated
landgriffon-client ⬜️ Ignored (Inspect) Mar 2, 2023 at 1:12PM (UTC)
landgriffon-cookie-traceability ⬜️ Ignored (Inspect) Mar 2, 2023 at 1:12PM (UTC)

@@ -161,6 +163,17 @@ export class GetRankedImpactTableDto extends BaseImpactTableDto {
@IsUUID(4)
scenarioId?: string;

@ApiPropertyOptional({
description:
'Optional property for groupBy region and chart view to choose level of admin regions to show',
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the msg is not correct as the grouping depends on the selected entity, so its not tied to 'admin-regions'

I would say something like:
"Select the depth of the tree for grouping elements, defaults to...."

@Type(() => Number)
@IsNumber()
@Min(1)
@Max(3)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the minimum should be 0, as discussed. If a user wants to select 6 countries and see a 4 ranked still at country level, that depth should equal 0

Also, I wouldn't set a fixed max limit. Even tho the current limit makes sense, I think its a better idea to not set a max limit and just uncollapse the tree as much as it can be uncollapsed.

i.e, users sends a 5 value but we have a maximum depth of 3, just send back a 3 level deep tree

@IsNumber()
@Min(1)
@Max(3)
level?: number;
Copy link
Collaborator

Choose a reason for hiding this comment

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

to be more consistent with other endpoints, I would name this parameter as

depth

// If chart is requested for regions and specific level is received, we get only the requested level from admin regions trees of the response

if (
rankedImpactTableDto.groupBy === 'region' &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

Following https://github.com/Vizzuality/landgriffon/pull/873/files#r1109319576, I still dont get why this is somehow tied to regions.

Does not make sense to apply this behaviour to any other entity that is a tree structure?

impactTableRows: ImpactTableRows[],
level: number,
): ImpactTableRows[] {
if (level === 1) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be 0, in order to uncollapse the whole thing

if (level === 1) {
return impactTableRows;
}
if (level < 1) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is not necessary, because:

  1. first level should be 0, which is a valid value
  2. there should be a default behaviour to default to

return impactTableRows;
},
[],
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is nice :)

However, maybe we should try to use immutability, thoughts?

const sourcingLocations: SourcingLocation[] = [];

for (const municipality of municipalities) {
const i: number = municipalities.indexOf(municipality);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a super lightweight improvement, but If you realise, for each element on municipalities, you are running through municipalities again to find the index.

You could either get the index in the for of loop, or use a native array method that can provide you the index as one of the parameters in its callback

response.body.impactTable[0].others.aggregatedValues[0].value,
).toBe(2000);
},
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice, very clean, creating preconditions just once etc...


dataSource = testApplication.get<DataSource>(DataSource);

({ jwtToken } = await setupTestUser(testApplication));
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is cool, I had no idea you could assign a value like this

@yulia-bel yulia-bel force-pushed the api/LANDGRIF-1154-improve-chart-visualization branch from de3dfa6 to a40b9e8 Compare March 1, 2023 08:48
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.

7 participants