-
Notifications
You must be signed in to change notification settings - Fork 59
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
feat: graph component #585
Draft
BoolKang222
wants to merge
1
commit into
uwdata:main
Choose a base branch
from
cmudig:graph_component
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
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 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,201 @@ | ||
import { | ||
Cosmograph, | ||
CosmographHistogram, | ||
CosmographSearch, | ||
CosmographTimeline | ||
} from '@cosmograph/cosmograph'; | ||
import { throttle } from './util/throttle.js'; | ||
|
||
export class CosmographClient { | ||
constructor(targetElement, histogramElement, searchElement, timelineElement) { | ||
// Create containers for all components | ||
this._element = targetElement || document.createElement('div'); | ||
this._histogramElement = histogramElement || document.createElement('div'); | ||
this._searchElement = searchElement || document.createElement('div'); | ||
this._timelineElement = timelineElement || document.createElement('div'); | ||
Comment on lines
+13
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's not do this yet until we have the graph fully working |
||
|
||
document.body.appendChild(this._element); | ||
document.body.appendChild(this._histogramElement); | ||
document.body.appendChild(this._searchElement); | ||
document.body.appendChild(this._timelineElement); | ||
|
||
// Initialize the main Cosmograph instance | ||
this._cosmograph = new Cosmograph(this._element, { | ||
nodeColor: (node) => node.color || '#b3b3b3', | ||
nodeSize: (node) => node.size || 4, | ||
linkWidth: 1, | ||
renderHoveredNodeRing: true, | ||
hoveredNodeRingColor: 'red', | ||
focusedNodeRingColor: 'yellow', | ||
showDynamicLabels: true, | ||
backgroundColor: '#222222', | ||
}); | ||
|
||
// Initialize the Histogram component | ||
this._histogram = new CosmographHistogram(this._cosmograph, this._histogramElement, { | ||
accessor: (node) => node.size, | ||
barCount: 30, | ||
}); | ||
|
||
// Initialize the Search component | ||
this._search = new CosmographSearch(this._cosmograph, this._searchElement, { | ||
accessors: [ | ||
{ label: 'name', accessor: (node) => node.name }, | ||
{ label: 'value', accessor: (node) => node.value }, | ||
], | ||
maxVisibleItems: 5, | ||
events: { | ||
onSelect: (node) => this.zoomToNode(node), | ||
}, | ||
}); | ||
|
||
// Initialize the Timeline component | ||
this._timeline = new CosmographTimeline(this._cosmograph, this._timelineElement, { | ||
accessor: (node) => node.time, | ||
animationSpeed: 50, | ||
events: { | ||
onAnimationPlay: () => console.log('Animation started'), | ||
onBarHover: (start, end) => console.log(`Hovered from ${start} to ${end}`), | ||
}, | ||
}); | ||
|
||
// Throttle updates for performance optimization | ||
this._requestUpdate = throttle(() => this.requestQuery(), true); | ||
|
||
// Attach event handlers | ||
this._cosmograph.onClick = this.onClick.bind(this); | ||
this._cosmograph.onZoom = this.onZoom.bind(this); | ||
this._cosmograph.onSimulationEnd = this.onSimulationEnd.bind(this); | ||
} | ||
|
||
/** Configuration Methods */ | ||
setConfig(config) { | ||
this._cosmograph.setConfig(config); | ||
return this; | ||
} | ||
|
||
setData(nodes, links) { | ||
this._cosmograph.setData(nodes, links); | ||
this._histogram.setConfig({ data: nodes }); | ||
this._search.setData(nodes); | ||
this._timeline.setConfig({ data: nodes }); | ||
return this; | ||
} | ||
|
||
setZoomLevel(value, duration = 0) { | ||
this._cosmograph.setZoomLevel(value, duration); | ||
} | ||
|
||
/** Node Methods */ | ||
selectNode(node, selectAdjacentNodes = false) { | ||
if (selectAdjacentNodes) { | ||
const adjacentNodes = this.getAdjacentNodes(node.id); | ||
this._cosmograph.selectNodes([node, ...adjacentNodes]); | ||
} else { | ||
this._cosmograph.selectNode(node); | ||
} | ||
} | ||
|
||
unselectNodes() { | ||
this._cosmograph.unselectNodes(); | ||
} | ||
|
||
focusNode(node) { | ||
this._cosmograph.focusNode(node); | ||
} | ||
|
||
getAdjacentNodes(id) { | ||
return this._cosmograph.getAdjacentNodes(id); | ||
} | ||
|
||
getSelectedNodes() { | ||
return this._cosmograph.getSelectedNodes(); | ||
} | ||
|
||
getNodePositions() { | ||
return this._cosmograph.getNodePositions(); | ||
} | ||
|
||
/** Zooming Methods */ | ||
fitView(duration = 250) { | ||
this._cosmograph.fitView(duration); | ||
} | ||
|
||
fitViewByNodeIds(ids, duration = 250) { | ||
this._cosmograph.fitViewByNodeIds(ids, duration); | ||
} | ||
|
||
zoomToNode(node) { | ||
this._cosmograph.zoomToNode(node); | ||
} | ||
|
||
getZoomLevel() { | ||
return this._cosmograph.getZoomLevel(); | ||
} | ||
|
||
/** Timeline Control */ | ||
playTimelineAnimation() { | ||
this._timeline.playAnimation(); | ||
} | ||
|
||
pauseTimelineAnimation() { | ||
this._timeline.pauseAnimation(); | ||
} | ||
|
||
stopTimelineAnimation() { | ||
this._timeline.stopAnimation(); | ||
} | ||
|
||
setTimelineSelection(range) { | ||
this._timeline.setSelection(range); | ||
} | ||
|
||
/** Simulation Methods */ | ||
start(alpha = 1) { | ||
this._cosmograph.start(alpha); | ||
} | ||
|
||
pause() { | ||
this._cosmograph.pause(); | ||
} | ||
|
||
restart() { | ||
this._cosmograph.restart(); | ||
} | ||
|
||
isSimulationRunning() { | ||
return this._cosmograph.isSimulationRunning; | ||
} | ||
|
||
/** Event Handlers */ | ||
onClick(clickedNode, index, position, event) { | ||
console.log(`Clicked on node ${clickedNode?.id || 'empty space'}`); | ||
} | ||
|
||
onZoom(event) { | ||
console.log('Zoom event:', event); | ||
} | ||
|
||
onSimulationEnd() { | ||
console.log('Simulation ended'); | ||
} | ||
|
||
/** Query and Update Handling */ | ||
requestQuery(query) { | ||
const q = query || this.query(); | ||
return this._coordinator.requestQuery(this, q).then((data) => { | ||
this.setData(data.nodes, data.links); | ||
}); | ||
} | ||
|
||
requestUpdate() { | ||
this._requestUpdate(); | ||
} | ||
|
||
/** Destroy Graph */ | ||
remove() { | ||
this._cosmograph.remove(); | ||
console.log('Graph instance destroyed'); | ||
} | ||
} | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should fail when there is no element provided