[feature] Add option to show node labels only after hitting a certain zoom level#419
Conversation
Node labels now prefer 'label', then 'name', then 'id' for display. Added dynamic label visibility in graph mode based on zoom scale, controlled by 'graphLabelScaleThreshold' and scale limits, with debounce to avoid excessive updates.
nemesifier
left a comment
There was a problem hiding this comment.
Good progress on this @cestercian, it looks encouraging!
Here's a few details I have observed.
Labels are visible on initial page load with default settings
When I load the basic example, the labels are visible:
Consider a situation like the following, this is a screenshot from a prod system taken right after page load:
On real world systems, when the chart is busy, it doesn't make sense to show the labels after the page loads, it would be better to show the only after a certain level of zoom.
Can we configure the default setting of the library so that this happens automatically?
The users will still be able to tweak the settings if needed.
I expanded these concepts in #420, which we can work on at a later stage.
This reverts commit 97c4729.
Simplifies label visibility logic by using a label formatter that checks the current zoom level, instead of dynamically toggling label show/hide. Updates the example template to set showGraphLabelsAtZoom to 2 for clearer demonstration.
Simplifies node name assignment logic for clarity and consistency. Replaces Object.assign with spread syntax for cloning objects and updating series configuration, improving readability and maintainability.
Screen.Recording.2025-08-22.at.4.14.15.AM.movHi @nemesifier — I’ve addressed your changes and fixed a related bug. Graph Mode
Labels
|
Introduces tests to verify graph and map label visibility logic, including zoom-based label toggling and fallback to name/label/id. Also adds tests for stable series id assignment and event handler registration for resize and label toggling.
Simplifies node name assignment to use only the label property and refactors echarts option updates to set the entire option object instead of just the series. Also replaces object spread with Object.assign for link config in map options.
Node names are now determined by checking 'label', then 'name', and finally 'id' if neither is available. This ensures that nodes always have a meaningful name when rendered on the map.
Clarifies the behavior of the label-visibility threshold for graph mode in the README and updates the default value of `showGraphLabelsAtZoom` to 1 in the configuration. This makes label display more predictable and documents how to disable thresholding.
Simplified code formatting in netjsongraph.render.js for better readability and consistency. Updated test cases in netjsongraph.render.test.js to use more concise array and function calls, improving clarity and maintainability.
…ongraph.js into fix-zoom-labels
Changed ECharts series IDs from 'graph-series' and 'map-nodes' to 'network-graph' and 'geo-map' for consistency. Improved label visibility threshold logic for graph mode: now disabled by default and only enabled when a positive value is set. Updated related tests and documentation to reflect these changes.
nemesifier
left a comment
There was a problem hiding this comment.
@cestercian let's proceed with the improvements discussed today, see my comments below for further input.
Simplifies the logic for toggling graph labels based on zoom threshold by extracting zoom retrieval into a helper function and removing redundant try-catch blocks. Labels are now toggled only when crossing the threshold during zoom events, ignoring pan.
Simplified the label visibility logic in graph mode by introducing a shared helper for retrieving the current zoom level. Updated documentation to reflect the new default threshold value for label visibility.
Refactored the label display logic to directly check the zoom value from the first series in the ECharts option, removing unnecessary helper functions and improving readability.
Replaces usage of _labelsShown with LabelShown to ensure correct tracking of label visibility state in NetJSONGraphRender. This resolves potential issues with label display logic.
This reverts commit 9a3460d.
[chores] Revert Reduced Redundancy This reverts commit a03cacc.
e053346 to
96f20a1
Compare


Node labels now prefer
label, thenname, thenidfor display. Added dynamic label visibility in graph mode based on zoom scale, controlled bygraphLabelScaleThresholdand scale limits, with debounce to avoid excessive updates.Checklist
Reference to Existing Issue
Closes #148.
Description of Changes
node.label→ fallback tonode.name→ fallback tonode.id.graphLabelScaleThreshold(default:1.0).Screenshot