waitForPlotly.ts 926 B

123456789101112131415161718192021222324252627282930313233
  1. /**
  2. * Copyright (c) Jupyter Development Team.
  3. * Distributed under the terms of the Modified BSD License.
  4. */
  5. import * as playwright from 'playwright';
  6. /**
  7. * Wait for width to be changed to greater than the default of 700px which happens after rendering is done.
  8. */
  9. export default async function waitForPlotly({
  10. widgetID,
  11. page
  12. }: {
  13. widgetID: string;
  14. page: playwright.Page;
  15. }): Promise<void> {
  16. await page.waitForFunction(
  17. (widgetID: string) => {
  18. const selector = `#${widgetID} .svg-container`;
  19. console.log(`selector=${selector}`);
  20. const el = document.querySelector(selector);
  21. if (!el) {
  22. return false;
  23. }
  24. const width = (el as HTMLDivElement).style['width'];
  25. console.log(` width=${width}`);
  26. // It's 100px originally, then 700px, then finally is recieved to page width
  27. return width !== '700px' && width !== '100px';
  28. },
  29. {},
  30. widgetID
  31. );
  32. }