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

fix: Most recent filter + interactive time range #2085

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ You can also check the

# Unreleased

Nothing yet.
- Fixes
- Charts that use most recent date filter and interactive time range filter
are initialized correctly now

# [5.2.2] - 2025-02-05

Expand Down
11 changes: 9 additions & 2 deletions app/charts/shared/brush/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ export const BrushTime = () => {
setSelectionExtent(0);
}
};

const { from, to } = timeRange;
const {
brushOverlayColor,
brushSelectionColor,
Expand Down Expand Up @@ -121,6 +119,15 @@ export const BrushTime = () => {
const { width, margins, chartHeight } = bounds;
const scaleTimeRange =
chartType === "bar" ? yScaleTimeRange : xScaleTimeRange;

let { from, to } = timeRange;

// FIXME: Should be fixed in useSyncInteractiveFilters where we try to parse
// the date that can be a string (VISUALIZE_MOST_RECENT_VALUE).
Comment on lines +125 to +126
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this something worth opening an issue for? Or how urgent is this? Any specific timeline we want to tackle this? - sorry for all the questions 😅

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry for such late notification @noahonyejese (automatic review request as code owner), I didn't expect a review at such time, but wanted to open a PR so we have it documented (but thank you for the review 🔝). This is a hot-fix just before the PROD release tomorrow in the morning, but I'll open an issue to fix it properly 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if (isNaN(to?.getTime() ?? 0)) {
to = scaleTimeRange.domain()[1];
}

const brushLabelsWidth =
getTextWidth(formatDate(scaleTimeRange.domain()[0]), {
fontSize: labelFontSize,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
{
"key": "pnV1OjlbiPU4",
"data": {
"state": "PUBLISHED",
"key": "pnV1OjlbiPU4",
"layout": {
"meta": {
"label": {
"de": "",
"en": "",
"fr": "",
"it": ""
},
"title": {
"de": "",
"en": "",
"fr": "",
"it": ""
},
"description": {
"de": "",
"en": "",
"fr": "",
"it": ""
}
},
"type": "tab",
"blocks": [
{
"key": "wtCcf965i01W",
"type": "chart",
"initialized": false
}
]
},
"version": "4.2.0",
"dataSource": {
"url": "https://lindas-cached.cluster.ldbar.ch/query",
"type": "sparql"
},
"chartConfigs": [
{
"key": "wtCcf965i01W",
"meta": {
"label": {
"de": "",
"en": "",
"fr": "",
"it": ""
},
"title": {
"de": "",
"en": "",
"fr": "",
"it": ""
},
"description": {
"de": "",
"en": "",
"fr": "",
"it": ""
}
},
"cubes": [
{
"iri": "https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen/10",
"filters": {
"https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen(VISUALIZE.ADMIN_COMPONENT_ID_SEPARATOR)https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen/Kanton": {
"type": "single",
"value": "https://ld.admin.ch/canton/1"
},
"https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen(VISUALIZE.ADMIN_COMPONENT_ID_SEPARATOR)https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen/Jahr": {
"to": "VISUALIZE_MOST_RECENT_VALUE",
"from": "2015",
"type": "range"
}
}
}
],
"fields": {
"x": {
"sorting": {
"sortingType": "byAuto",
"sortingOrder": "asc"
},
"componentId": "https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen(VISUALIZE.ADMIN_COMPONENT_ID_SEPARATOR)https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen/Jahr"
},
"y": {
"componentId": "https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen(VISUALIZE.ADMIN_COMPONENT_ID_SEPARATOR)https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen/AnzahlAnlagen"
},
"color": {
"type": "single",
"color": "#006699",
"paletteId": "category10"
}
},
"version": "4.1.0",
"chartType": "column",
"activeField": "x",
"interactiveFiltersConfig": {
"legend": {
"active": false,
"componentId": ""
},
"timeRange": {
"active": true,
"presets": {
"to": "VISUALIZE_MOST_RECENT_VALUE",
"from": "2015",
"type": "range"
},
"componentId": "https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen(VISUALIZE.ADMIN_COMPONENT_ID_SEPARATOR)https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen/Jahr"
},
"calculation": {
"type": "identity",
"active": false
},
"dataFilters": {
"active": false,
"componentIds": []
}
}
}
],
"activeChartKey": "wtCcf965i01W",
"dashboardFilters": {
"timeRange": {
"active": false,
"presets": {
"to": "",
"from": ""
},
"timeUnit": ""
},
"dataFilters": {
"filters": {},
"componentIds": []
}
}
}
}
18 changes: 16 additions & 2 deletions e2e/interactive-filters.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { setup } from "./common";

const { test } = setup();
const { expect, test } = setup();

test("it should display values in interactive filters as hierarchie", async ({
test.skip("it should display values in interactive filters as hierarchie", async ({
page,
selectors,
within,
Expand All @@ -18,3 +18,17 @@ test("it should display values in interactive filters as hierarchie", async ({
await selectors.mui.popover().getByText("Nouvelle plage").click();
await selectors.chart.loaded();
});

test("it should not initialize interactive time range filter in a broken state", async ({
page,
selectors,
}) => {
await page.goto("/en/__test/prod/most-recent-time-range-interactive-filter");
await selectors.chart.loaded();
const chart = page.locator("#chart-svg");
const [startHandle, endHandle] = await chart.locator(".handle").all();
const startHandleBox = await startHandle.boundingBox();
const endHandleBox = await endHandle.boundingBox();

expect(endHandleBox.x).toBeGreaterThan(startHandleBox.x);
});
Loading