Rename leafes/nodes to topic

This commit is contained in:
Thomas Nordquist
2019-01-22 15:57:11 +01:00
parent 796233da18
commit 28cc72a868
7 changed files with 28 additions and 24 deletions

View File

@@ -60,7 +60,6 @@
} }
</style> </style>
<script src="http://localhost:35729/livereload.js"></script> <script src="http://localhost:35729/livereload.js"></script>
</head> </head>
<body> <body>
<div id="splash"><div id="splash1"></div></div> <div id="splash"><div id="splash1"></div></div>

View File

@@ -53,7 +53,7 @@ export const filterTopics = (filterStr: string) => (dispatch: Dispatch<any>, get
return Boolean(messageMatches) return Boolean(messageMatches)
} }
const resultTree = tree.leafes() const resultTree = tree.childTopics()
.filter(nodeFilter) .filter(nodeFilter)
.map((node) => { .map((node) => {
const clone = node.unconnectedClone() const clone = node.unconnectedClone()

View File

@@ -18,7 +18,7 @@ class NodeStats extends React.Component<Props, {}> {
return ( return (
<div> <div>
<Typography>Messages: #{node.messages}</Typography> <Typography>Messages: #{node.messages}</Typography>
<Typography>Subtopics: {node.leafCount()}</Typography> <Typography>Subtopics: {node.childTopicCount()}</Typography>
<Typography>Messages Subtopics: #{node.leafMessageCount()}</Typography> <Typography>Messages Subtopics: #{node.leafMessageCount()}</Typography>
</div> </div>
) )

View File

@@ -90,7 +90,7 @@ class Tree extends React.Component<Props, {}> {
animateChages={true} animateChages={true}
isRoot={true} isRoot={true}
treeNode={tree} treeNode={tree}
name="/" name={'"root"'}
lastUpdate={tree.lastUpdate} lastUpdate={tree.lastUpdate}
collapsed={false} collapsed={false}
performanceCallback={this.performanceCallback} performanceCallback={this.performanceCallback}

View File

@@ -42,7 +42,7 @@ class TreeNodeSubnodes extends React.Component<Props, State> {
nodes = nodes.sort((a, b) => b.leafMessageCount() - a.leafMessageCount()) nodes = nodes.sort((a, b) => b.leafMessageCount() - a.leafMessageCount())
} }
if (topicOrder === TopicOrder.topics) { if (topicOrder === TopicOrder.topics) {
nodes = nodes.sort((a, b) => b.leafCount() - a.leafCount()) nodes = nodes.sort((a, b) => b.childTopicCount() - a.childTopicCount())
} }
return nodes return nodes

View File

@@ -84,7 +84,7 @@ class TreeNodeTitle extends React.Component<TreeNodeProps, {}> {
} }
const messages = this.props.treeNode.leafMessageCount() const messages = this.props.treeNode.leafMessageCount()
return <span style={this.getStyles().collapsedSubnodes}>({this.props.treeNode.leafCount()} nodes, {messages} messages)</span> return <span style={this.getStyles().collapsedSubnodes}>({this.props.treeNode.childTopicCount()} topics, {messages} messages)</span>
} }
} }

View File

@@ -16,9 +16,10 @@ export class TreeNode {
public onMessage = new EventDispatcher<Message, TreeNode>(this) public onMessage = new EventDispatcher<Message, TreeNode>(this)
public isTree = false public isTree = false
private cachedLeafes?: TreeNode[] private cachedPath?: string
private cachedChildTopics?: TreeNode[]
private cachedLeafMessageCount?: number private cachedLeafMessageCount?: number
private cachedLeafCount?: number private cachedChildTopicCount?: number
public unconnectedClone() { public unconnectedClone() {
const node = new TreeNode() const node = new TreeNode()
@@ -39,8 +40,8 @@ export class TreeNode {
message && this.setMessage(message) message && this.setMessage(message)
this.onMerge.subscribe(() => { this.onMerge.subscribe(() => {
this.cachedLeafes = undefined this.cachedChildTopics = undefined
this.cachedLeafCount = undefined this.cachedChildTopicCount = undefined
this.cachedLeafMessageCount = undefined this.cachedLeafMessageCount = undefined
this.lastUpdate = Date.now() this.lastUpdate = Date.now()
}) })
@@ -67,10 +68,14 @@ export class TreeNode {
} }
public path(): string { public path(): string {
return this.branch() if (!this.cachedPath) {
.map(node => (node.sourceEdge && node.sourceEdge.name)) return this.branch()
.filter(name => name !== undefined) .map(node => (node.sourceEdge && node.sourceEdge.name))
.join('/') .filter(name => name !== undefined)
.join('/')
}
return this.cachedPath
} }
private previous(): TreeNode | undefined { private previous(): TreeNode | undefined {
@@ -117,30 +122,30 @@ export class TreeNode {
return this.cachedLeafMessageCount return this.cachedLeafMessageCount
} }
public leafCount(): number { public childTopicCount(): number {
if (this.cachedLeafCount === undefined) { if (this.cachedChildTopicCount === undefined) {
this.cachedLeafCount = this.edgeArray this.cachedChildTopicCount = this.edgeArray
.map(e => e.target.leafCount()) .map(e => e.target.childTopicCount())
.reduce((a, b) => a + b, this.edgeArray.length === 0 ? 1 : 0) .reduce((a, b) => a + b, this.edgeArray.length === 0 ? 1 : 0)
} }
return this.cachedLeafCount return this.cachedChildTopicCount
} }
public edgeCount(): number { public edgeCount(): number {
return this.edgeArray.length return this.edgeArray.length
} }
public leafes(): TreeNode[] { public childTopics(): TreeNode[] {
if (this.cachedLeafes === undefined) { if (this.cachedChildTopics === undefined) {
const initialValue = this.message && this.message.value ? [this] : [] const initialValue = this.message && this.message.value ? [this] : []
this.cachedLeafes = this.edgeArray this.cachedChildTopics = this.edgeArray
.map(e => e.target.leafes()) .map(e => e.target.childTopics())
.reduce((a, b) => a.concat(b), initialValue) .reduce((a, b) => a.concat(b), initialValue)
} }
return this.cachedLeafes return this.cachedChildTopics
} }
private mergeEdges(node: TreeNode) { private mergeEdges(node: TreeNode) {