-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Show appropriate date when date is part of grouped data on chart. #2857
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
Merged
texodus
merged 6 commits into
perspective-dev:master
from
onesimus-wiafe:plugin/fix_epoch_time_to_date_on_axis_label
Feb 27, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ab28549
fix date issue on various charts when group data with date field is s…
sarpong4 2f967db
Update packages/perspective-viewer-d3fc/src/ts/legend/filter.ts
onesimus-wiafe 1ec1d26
futher refactored solution
sarpong4 a0ebd8c
lint formatting
sarpong4 7b7d8b3
fixes add based on pr comments
sarpong4 bc0736f
fix added from PR comments
sarpong4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
324 changes: 324 additions & 0 deletions
324
packages/perspective-viewer-d3fc/test/js/axisLabel.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,324 @@ | ||
| // ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ | ||
| // ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃ | ||
| // ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃ | ||
| // ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃ | ||
| // ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃ | ||
| // ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ | ||
| // ┃ Copyright (c) 2017, the Perspective Authors. ┃ | ||
| // ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃ | ||
| // ┃ This file is part of the Perspective library, distributed under the terms ┃ | ||
| // ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ | ||
| // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ | ||
|
|
||
| import { expect, test } from "@finos/perspective-test"; | ||
|
|
||
| test.beforeEach(async ({ page }) => { | ||
| await page.goto("/tools/perspective-test/src/html/basic-test.html"); | ||
| await page.evaluate(async () => { | ||
| while (!window["__TEST_PERSPECTIVE_READY__"]) { | ||
| await new Promise((x) => setTimeout(x, 10)); | ||
| } | ||
| }); | ||
|
|
||
| await page.evaluate(async () => { | ||
| let viewer = document.querySelector("perspective-viewer"); | ||
| await viewer!.restore({ | ||
| plugin: "Datagrid", | ||
| group_by: ["Order Date", "Profit"], | ||
| x_axis: ["Row ID"], | ||
| }); | ||
|
|
||
| return await viewer.save(); | ||
| }); | ||
|
|
||
| await page.click("#settings_button"); | ||
| await page.click(".plugin-select-item"); | ||
| }); | ||
|
|
||
| function confirmDataIsDate(dateValues: any[]) { | ||
| if (dateValues.length === 0) { | ||
| throw Error("No date values recorded"); | ||
| } | ||
|
|
||
| const filtered_dates = dateValues.filter((_) => isNaN(Date.parse(_))); | ||
|
|
||
| expect(filtered_dates.length).toEqual(0); | ||
| } | ||
|
|
||
| function confirmDataIsNotEpochForm(dateValues: any[]) { | ||
| confirmDataIsDate(dateValues); | ||
|
|
||
| const isEpoch = (date: any): boolean => { | ||
| return !isNaN(date) && (date.length === 10 || date.length === 13); | ||
| }; | ||
|
|
||
| const filtered_dates = dateValues.filter((_) => isEpoch(_)); | ||
|
|
||
| expect(filtered_dates.length).toEqual(0); | ||
| } | ||
|
|
||
| test.describe("Axis Values With Grouped Data With A Date Field In The Group", () => { | ||
| test("X Bar y-axis label with grouped data", async ({ page }) => { | ||
| await page.click('div[data-plugin="X Bar"]'); | ||
| await page.waitForSelector("perspective-viewer"); | ||
onesimus-wiafe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const dateValues = await page.evaluate(async () => { | ||
| let viewer = document.querySelector("perspective-viewer"); | ||
|
|
||
| if (!viewer) { | ||
| return Error("Invalid Viewer"); | ||
| } | ||
|
|
||
| const plugin_element = viewer.querySelector( | ||
| `perspective-viewer-d3fc-xbar` | ||
| ); | ||
|
|
||
| if (!plugin_element) { | ||
| throw Error("Invalid Plugin Element"); | ||
| } | ||
|
|
||
| const shadowRoot = plugin_element.shadowRoot; | ||
| const dateTextElements = shadowRoot.querySelectorAll( | ||
| "div d3fc-group d3fc-svg.y-axis.left-axis svg g.group:last-child g.tick text" | ||
| ); | ||
onesimus-wiafe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // collect and return the actual date data to be used. | ||
| return Array.from(dateTextElements).map((el) => | ||
| el.textContent?.trim() | ||
| ); | ||
| }); | ||
|
|
||
| confirmDataIsNotEpochForm(dateValues); | ||
| }); | ||
|
|
||
| test("Y Bar x-axis label with grouped data", async ({ page }) => { | ||
| await page.click('div[data-plugin="Y Bar"]'); | ||
| await page.waitForSelector("perspective-viewer"); | ||
|
|
||
| const dateValues = await page.evaluate(async () => { | ||
| let viewer = document.querySelector("perspective-viewer"); | ||
|
|
||
| if (!viewer) { | ||
| return Error("Invalid Viewer"); | ||
| } | ||
|
|
||
| const plugin_element = viewer.querySelector( | ||
| `perspective-viewer-d3fc-ybar` | ||
| ); | ||
|
|
||
| if (!plugin_element) { | ||
| throw Error("Invalid Plugin Element"); | ||
| } | ||
|
|
||
| const shadowRoot = plugin_element.shadowRoot; | ||
| const dateTextElements = shadowRoot.querySelectorAll( | ||
| "div d3fc-group d3fc-svg.x-axis.bottom-axis svg g.group:last-child g.tick text" | ||
| ); | ||
|
|
||
| // collect and return the actual date data to be used. | ||
| return Array.from(dateTextElements).map((el) => | ||
| el.textContent?.trim() | ||
| ); | ||
| }); | ||
|
|
||
| confirmDataIsNotEpochForm(dateValues); | ||
| }); | ||
|
|
||
| test("OHLC x-axis label with grouped data", async ({ page }) => { | ||
| await page.click('div[data-plugin="OHLC"]'); | ||
| await page.waitForSelector("perspective-viewer"); | ||
|
|
||
| const dateValues = await page.evaluate(async () => { | ||
| let viewer = document.querySelector("perspective-viewer"); | ||
|
|
||
| if (!viewer) { | ||
| return Error("Invalid Viewer"); | ||
| } | ||
|
|
||
| const plugin_element = viewer.querySelector( | ||
| `perspective-viewer-d3fc-ohlc` | ||
| ); | ||
|
|
||
| if (!plugin_element) { | ||
| throw Error("Invalid Plugin Element"); | ||
| } | ||
|
|
||
| const shadowRoot = plugin_element.shadowRoot; | ||
| const dateTextElements = shadowRoot.querySelectorAll( | ||
| "div d3fc-group d3fc-svg.x-axis.bottom-axis svg g.group:last-child g.tick text" | ||
| ); | ||
|
|
||
| // collect and return the actual date data to be used. | ||
| return Array.from(dateTextElements).map((el) => | ||
| el.textContent?.trim() | ||
| ); | ||
| }); | ||
|
|
||
| confirmDataIsNotEpochForm(dateValues); | ||
| }); | ||
|
|
||
| test("Heatmap x-axis label with grouped data", async ({ page }) => { | ||
| await page.click('div[data-plugin="Heatmap"]'); | ||
| await page.waitForSelector("perspective-viewer"); | ||
|
|
||
| const dateValues = await page.evaluate(async () => { | ||
| let viewer = document.querySelector("perspective-viewer"); | ||
|
|
||
| if (!viewer) { | ||
| return Error("Invalid Viewer"); | ||
| } | ||
|
|
||
| const plugin_element = viewer.querySelector( | ||
| `perspective-viewer-d3fc-heatmap` | ||
| ); | ||
|
|
||
| if (!plugin_element) { | ||
| throw Error("Invalid Plugin Element"); | ||
| } | ||
|
|
||
| const shadowRoot = plugin_element.shadowRoot; | ||
| const dateTextElements = shadowRoot.querySelectorAll( | ||
| "div d3fc-group d3fc-svg.x-axis.bottom-axis svg g.group:last-child g.tick text" | ||
| ); | ||
|
|
||
| // collect and return the actual date data to be used. | ||
| return Array.from(dateTextElements).map((el) => | ||
| el.textContent?.trim() | ||
| ); | ||
| }); | ||
|
|
||
| confirmDataIsNotEpochForm(dateValues); | ||
| }); | ||
|
|
||
| test("Y Line x-axis label with grouped data", async ({ page }) => { | ||
| await page.click('div[data-plugin="Y Line"]'); | ||
| await page.waitForSelector("perspective-viewer"); | ||
|
|
||
| const dateValues = await page.evaluate(async () => { | ||
| let viewer = document.querySelector("perspective-viewer"); | ||
|
|
||
| if (!viewer) { | ||
| return Error("Invalid Viewer"); | ||
| } | ||
|
|
||
| const plugin_element = viewer.querySelector( | ||
| `perspective-viewer-d3fc-yline` | ||
| ); | ||
|
|
||
| if (!plugin_element) { | ||
| throw Error("Invalid Plugin Element"); | ||
| } | ||
|
|
||
| const shadowRoot = plugin_element.shadowRoot; | ||
| const dateTextElements = shadowRoot.querySelectorAll( | ||
| "div d3fc-group d3fc-svg.x-axis.bottom-axis svg g.group:last-child g.tick text" | ||
| ); | ||
|
|
||
| // collect and return the actual date data to be used. | ||
| return Array.from(dateTextElements).map((el) => | ||
| el.textContent?.trim() | ||
| ); | ||
| }); | ||
|
|
||
| confirmDataIsNotEpochForm(dateValues); | ||
| }); | ||
|
|
||
| test("Y Area x-axis label with grouped data", async ({ page }) => { | ||
| await page.click('div[data-plugin="Y Area"]'); | ||
| await page.waitForSelector("perspective-viewer"); | ||
|
|
||
| const dateValues = await page.evaluate(async () => { | ||
| let viewer = document.querySelector("perspective-viewer"); | ||
|
|
||
| if (!viewer) { | ||
| return Error("Invalid Viewer"); | ||
| } | ||
|
|
||
| const plugin_element = viewer.querySelector( | ||
| `perspective-viewer-d3fc-yarea` | ||
| ); | ||
|
|
||
| if (!plugin_element) { | ||
| throw Error("Invalid Plugin Element"); | ||
| } | ||
|
|
||
| const shadowRoot = plugin_element.shadowRoot; | ||
| const dateTextElements = shadowRoot.querySelectorAll( | ||
| "div d3fc-group d3fc-svg.x-axis.bottom-axis svg g.group:last-child g.tick text" | ||
| ); | ||
|
|
||
| // collect and return the actual date data to be used. | ||
| return Array.from(dateTextElements).map((el) => | ||
| el.textContent?.trim() | ||
| ); | ||
| }); | ||
|
|
||
| confirmDataIsNotEpochForm(dateValues); | ||
| }); | ||
|
|
||
| test("Y Scatter x-axis label with grouped data", async ({ page }) => { | ||
| await page.click('div[data-plugin="Y Scatter"]'); | ||
| await page.waitForSelector("perspective-viewer"); | ||
|
|
||
| const dateValues = await page.evaluate(async () => { | ||
| let viewer = document.querySelector("perspective-viewer"); | ||
|
|
||
| if (!viewer) { | ||
| return Error("Invalid Viewer"); | ||
| } | ||
|
|
||
| const plugin_element = viewer.querySelector( | ||
| `perspective-viewer-d3fc-yscatter` | ||
| ); | ||
|
|
||
| if (!plugin_element) { | ||
| throw Error("Invalid Plugin Element"); | ||
| } | ||
|
|
||
| const shadowRoot = plugin_element.shadowRoot; | ||
| const dateTextElements = shadowRoot.querySelectorAll( | ||
| "div d3fc-group d3fc-svg.x-axis.bottom-axis svg g.group:last-child g.tick text" | ||
| ); | ||
|
|
||
| // collect and return the actual date data to be used. | ||
| return Array.from(dateTextElements).map((el) => | ||
| el.textContent?.trim() | ||
| ); | ||
| }); | ||
|
|
||
| confirmDataIsNotEpochForm(dateValues); | ||
| }); | ||
|
|
||
| test("CandleStick x-axis label with grouped data", async ({ page }) => { | ||
| await page.click('div[data-plugin="Candlestick"]'); | ||
| await page.waitForSelector("perspective-viewer"); | ||
|
|
||
| const dateValues = await page.evaluate(async () => { | ||
| let viewer = document.querySelector("perspective-viewer"); | ||
|
|
||
| if (!viewer) { | ||
| return Error("Invalid Viewer"); | ||
| } | ||
|
|
||
| const plugin_element = viewer.querySelector( | ||
| `perspective-viewer-d3fc-candlestick` | ||
| ); | ||
|
|
||
| if (!plugin_element) { | ||
| throw Error("Invalid Plugin Element"); | ||
| } | ||
|
|
||
| const shadowRoot = plugin_element.shadowRoot; | ||
| const dateTextElements = shadowRoot.querySelectorAll( | ||
| "div d3fc-group d3fc-svg.x-axis.bottom-axis svg g.group:last-child g.tick text" | ||
| ); | ||
|
|
||
| // collect and return the actual date data to be used. | ||
| return Array.from(dateTextElements).map((el) => | ||
| el.textContent?.trim() | ||
| ); | ||
| }); | ||
|
|
||
| confirmDataIsNotEpochForm(dateValues); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.