Fix linting
This commit is contained in:
@@ -48,24 +48,21 @@ const GraphControl = ({ disableHoverEffect }: { disableHoverEffect?: boolean })
|
|||||||
*/
|
*/
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (sigmaGraph && sigma) {
|
if (sigmaGraph && sigma) {
|
||||||
// 确保 sigma 实例内部的 graph 引用被更新
|
// Ensure sigma binding to sigmaGraph
|
||||||
try {
|
try {
|
||||||
// 尝试直接设置 sigma 实例的 graph 引用
|
|
||||||
if (typeof sigma.setGraph === 'function') {
|
if (typeof sigma.setGraph === 'function') {
|
||||||
sigma.setGraph(sigmaGraph as unknown as AbstractGraph<NodeType, EdgeType>);
|
sigma.setGraph(sigmaGraph as unknown as AbstractGraph<NodeType, EdgeType>);
|
||||||
console.log('Directly set graph on sigma instance');
|
console.log('Binding graph to sigma instance');
|
||||||
} else {
|
} else {
|
||||||
// 如果 setGraph 方法不存在,尝试直接设置 graph 属性
|
|
||||||
(sigma as any).graph = sigmaGraph;
|
(sigma as any).graph = sigmaGraph;
|
||||||
console.log('Set graph property on sigma instance');
|
console.warn('Simgma missing setGraph function, set graph property directly');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error setting graph on sigma instance:', error);
|
console.error('Error setting graph on sigma instance:', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 应用布局
|
|
||||||
assignLayout();
|
assignLayout();
|
||||||
console.log('Layout applied to graph');
|
console.log('Initial layout applied to graph');
|
||||||
}
|
}
|
||||||
}, [sigma, sigmaGraph, assignLayout, maxIterations])
|
}, [sigma, sigmaGraph, assignLayout, maxIterations])
|
||||||
|
|
||||||
|
@@ -93,7 +93,7 @@ export const GraphSearchInput = ({
|
|||||||
const loadOptions = useCallback(
|
const loadOptions = useCallback(
|
||||||
async (query?: string): Promise<OptionItem[]> => {
|
async (query?: string): Promise<OptionItem[]> => {
|
||||||
if (onFocus) onFocus(null)
|
if (onFocus) onFocus(null)
|
||||||
|
|
||||||
// Safety checks to prevent crashes
|
// Safety checks to prevent crashes
|
||||||
if (!graph || !searchEngine) {
|
if (!graph || !searchEngine) {
|
||||||
// Reset cache to ensure fresh search engine initialization on next render
|
// Reset cache to ensure fresh search engine initialization on next render
|
||||||
|
@@ -22,10 +22,10 @@ const ZoomControl = () => {
|
|||||||
// First clear any custom bounding box and refresh
|
// First clear any custom bounding box and refresh
|
||||||
sigma.setCustomBBox(null)
|
sigma.setCustomBBox(null)
|
||||||
sigma.refresh()
|
sigma.refresh()
|
||||||
|
|
||||||
// Get graph after refresh
|
// Get graph after refresh
|
||||||
const graph = sigma.getGraph()
|
const graph = sigma.getGraph()
|
||||||
|
|
||||||
// Check if graph has nodes before accessing them
|
// Check if graph has nodes before accessing them
|
||||||
if (!graph || graph.nodes().length === 0) {
|
if (!graph || graph.nodes().length === 0) {
|
||||||
reset()
|
reset()
|
||||||
@@ -35,7 +35,7 @@ const ZoomControl = () => {
|
|||||||
// Get container dimensions for aspect ratio
|
// Get container dimensions for aspect ratio
|
||||||
const container = sigma.getContainer()
|
const container = sigma.getContainer()
|
||||||
const containerWidth = container.offsetWidth
|
const containerWidth = container.offsetWidth
|
||||||
const containerHeight = container.offsetHeight
|
const containerHeight = container.offsetHeight
|
||||||
console.log('Container W:', containerWidth, 'H:', containerHeight)
|
console.log('Container W:', containerWidth, 'H:', containerHeight)
|
||||||
|
|
||||||
// Get all node positions
|
// Get all node positions
|
||||||
@@ -43,24 +43,24 @@ const ZoomControl = () => {
|
|||||||
x: graph.getNodeAttribute(node, 'x'),
|
x: graph.getNodeAttribute(node, 'x'),
|
||||||
y: graph.getNodeAttribute(node, 'y')
|
y: graph.getNodeAttribute(node, 'y')
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// Calculate bounding box
|
// Calculate bounding box
|
||||||
const minX = Math.min(...nodePositions.map(pos => pos.x))
|
const minX = Math.min(...nodePositions.map(pos => pos.x))
|
||||||
const maxX = Math.max(...nodePositions.map(pos => pos.x))
|
const maxX = Math.max(...nodePositions.map(pos => pos.x))
|
||||||
const minY = Math.min(...nodePositions.map(pos => pos.y))
|
const minY = Math.min(...nodePositions.map(pos => pos.y))
|
||||||
const maxY = Math.max(...nodePositions.map(pos => pos.y))
|
const maxY = Math.max(...nodePositions.map(pos => pos.y))
|
||||||
|
|
||||||
// Calculate graph dimensions with minimal padding
|
// Calculate graph dimensions with minimal padding
|
||||||
const width = maxX - minX
|
const width = maxX - minX
|
||||||
const height = maxY - minY
|
const height = maxY - minY
|
||||||
const padding = Math.max(width, height) * 0.05
|
const padding = Math.max(width, height) * 0.05
|
||||||
console.log('Graph W:', Math.round(width*100)/100, 'H:', Math.round(height*100)/100)
|
console.log('Graph W:', Math.round(width*100)/100, 'H:', Math.round(height*100)/100)
|
||||||
|
|
||||||
// Calculate base scale
|
// Calculate base scale
|
||||||
const scale = Math.min(
|
const scale = Math.min(
|
||||||
containerWidth / (width + padding * 2),
|
containerWidth / (width + padding * 2),
|
||||||
containerHeight / (height + padding * 2)
|
containerHeight / (height + padding * 2)
|
||||||
)
|
)
|
||||||
// Apply scaling factor (just don't know why)
|
// Apply scaling factor (just don't know why)
|
||||||
const ratio = (1 / scale) * 10
|
const ratio = (1 / scale) * 10
|
||||||
|
|
||||||
|
@@ -577,7 +577,7 @@ const useLightrangeGraph = () => {
|
|||||||
|
|
||||||
// Update the dynamic edge map and invalidate search cache
|
// Update the dynamic edge map and invalidate search cache
|
||||||
rawGraph.buildDynamicMap();
|
rawGraph.buildDynamicMap();
|
||||||
|
|
||||||
// Force search engine rebuild by invalidating cache
|
// Force search engine rebuild by invalidating cache
|
||||||
searchCache.graph = null;
|
searchCache.graph = null;
|
||||||
searchCache.searchEngine = null;
|
searchCache.searchEngine = null;
|
||||||
@@ -724,7 +724,7 @@ const useLightrangeGraph = () => {
|
|||||||
|
|
||||||
// Rebuild the dynamic edge map and invalidate search cache
|
// Rebuild the dynamic edge map and invalidate search cache
|
||||||
rawGraph.buildDynamicMap();
|
rawGraph.buildDynamicMap();
|
||||||
|
|
||||||
// Force search engine rebuild by invalidating cache
|
// Force search engine rebuild by invalidating cache
|
||||||
searchCache.graph = null;
|
searchCache.graph = null;
|
||||||
searchCache.searchEngine = null;
|
searchCache.searchEngine = null;
|
||||||
|
Reference in New Issue
Block a user