GeezerVison is showing github.com — Build the image URLs of the stories from the configured image base path · Issue #1332 · maxGraph/maxGraph
Build the image URLs of the stories from the configured image base path #1332DescriptionIs your technical request related to a problem? Please describe.
The Storybook stories build the URLs of their images in two different ways:
- 8 stories derive them from the configured base path, such as
`${Client.imageBasePath}/connector.gif`: ContextIcons, DynamicToolbar, Events, HoverIcons, Permissions, SwimLanes, Toolbar, Tree.
- 19 stories hard-code a page-relative path,
'images/...' or './images/...': AutoLayout, Collapse, Control, DragSource, DynamicToolbar, FixedIcons, Grid, HoverIcons, ImageBundle, Images, LabelPosition, MenuStyle, OrgChart, Overlays, PortRefs, Scrollbars, SegmentConnectorZoom, Toolbar, Wires. OrgChart alone has 17 of them. DynamicToolbar, HoverIcons and Toolbar mix both forms in the same file.
Everything works today, because the demo sets Client.setImageBasePath('./images') and the literal paths resolve to the same folder. But the literal paths silently ignore the setting, so a reader who copies a story into an application with another image location has to find and fix each of them, while the stories using Client.imageBasePath follow the configuration.
The mix is inherited from the mxGraph examples, which mostly used literal images/... paths (30 example files) and only rarely mxClient.imageBasePath (3 files).
Describe the solution you'd like
Build every image URL of the stories from Client.imageBasePath, for the images passed to the maxGraph API: ImageBox, style.image, CellOverlay, popup menu and toolbar items, domUtils.createImage, and the <img> tags written in HTML labels. The demo then has a single place deciding where the images are, and every story shows the pattern an application should follow.
CSS backgrounds set on the containers, such as url(./images/grid.gif) in shared/configure.js, Grid, Scrollbars, SegmentConnectorZoom and Wires, are not configured through maxGraph and can stay literal.
[UPDATE 2026-11-20] changed, based on feedback of #1337 (review): CSS backgrounds built in JavaScript or in HTML template strings, such as url(./images/grid.gif) in shared/configure.js, Grid, Scrollbars, SegmentConnectorZoom and Wires, also build their URL from the configured image base path, through string interpolation: `url(${Client.imageBasePath}/grid.gif)`. Only static .css files, which cannot read Client.imageBasePath, keep literal paths.
Describe alternatives you've considered
Implementation variant: instead of writing `${Client.imageBasePath}/...` at each call site, add a function to stories/shared, for instance getImagePath('icons48/keys.png'), which receives the path of the image relative to the images folder and returns the full path built from Client.imageBasePath. The call sites get shorter, the way the full path is built lives in a single place, and a story still shows that the path depends on a configuration. The drawback is that a reader copying a story also has to copy the function, or replace its calls with the Client.imageBasePath expression, since it is not part of the maxGraph API.
Keep the literal paths and document that the stories expect the images under ./images. This costs nothing, but leaves the stories inconsistent with each other and with the configuration they rely on.
Additional context
Found while reviewing the change that sets the image base path once for all stories in packages/html/.storybook/preview.ts, instead of in each story. The other default image of maxGraph that ignores the base path is tracked in #1331. ActivityMittalnew commented on Nov 18, 2026 I'd like to take this one. I'd build the URLs of all the images passed to the maxGraph API (ImageBox, style.image, CellOverlay, popup menu/toolbar items, domUtils.createImage and <img> in HTML labels) from Client.imageBasePath in the 19 stories you listed, OrgChart included, and leave the CSS url(./images/...) backgrounds as literals as you suggested. I'd use ${Client.imageBasePath}/... inline at each call site so every story stays copy-paste friendly, unless you'd rather have a shared getImagePath() helper in stories/shared. I'll check every story in Storybook afterwards. Could you assign it to me? redfish4ktc commented on Nov 18, 2026 Hi, and thanks for offering to help with this!
I've assigned the issue to you.
I would prefer using the shared getImagePath function. This keeps the logic centralized and makes future changes easier.
In particular, we will probably refactor the Client class in 2027 to align it with the configuration objects such as GlobalConfig and HandleConfig.
Using getImagePath should make this future refactoring easier.
Would that work for you? Mittalnew commented on Nov 18, 2026 Yes, that works for me. I'll use the shared getImagePath helper from stories/shared in all 19 stories so the logic stays in one place for the 2027 Client refactor. Thanks for assigning it!
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|