-
-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #12 <render> add mindmap for ledge render
- Loading branch information
Showing
6 changed files
with
144 additions
and
15 deletions.
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
4 changes: 3 additions & 1 deletion
4
src/app/shared/ledge-render/chart/ledge-mindmap/ledge-mindmap.component.html
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
<p>ledge-mindmap works!</p> | ||
<div class="mindmap reporter" #reporter> | ||
|
||
</div> |
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,7 @@ | ||
.reporter { | ||
width: auto; | ||
height: auto; | ||
min-width: 500px; | ||
min-height: 500px; | ||
max-width: 800px; | ||
} |
110 changes: 105 additions & 5 deletions
110
src/app/shared/ledge-render/chart/ledge-mindmap/ledge-mindmap.component.ts
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 |
---|---|---|
@@ -1,18 +1,118 @@ | ||
import { Component, Input, OnInit } from '@angular/core'; | ||
import { LedgeTable } from '../../../components/model/ledge-chart.model'; | ||
import { AfterViewInit, Component, ElementRef, Input, OnInit, ViewChild } from '@angular/core'; | ||
import { LedgeList } from '../../../components/model/ledge-chart.model'; | ||
import * as echarts from 'echarts'; | ||
|
||
@Component({ | ||
selector: 'ledge-mindmap', | ||
templateUrl: './ledge-mindmap.component.html', | ||
styleUrls: ['./ledge-mindmap.component.scss'] | ||
}) | ||
export class LedgeMindmapComponent implements OnInit { | ||
export class LedgeMindmapComponent implements OnInit, AfterViewInit { | ||
@Input() | ||
data: LedgeTable; | ||
data: LedgeList; | ||
|
||
constructor() { } | ||
@ViewChild('reporter', {}) reporter: ElementRef; | ||
|
||
constructor() { | ||
} | ||
|
||
ngOnInit(): void { | ||
console.log(this.data); | ||
} | ||
|
||
ngAfterViewInit(): void { | ||
const myChart = echarts.init(this.reporter.nativeElement); | ||
const treeData = this.toTreeData(this.data.children); | ||
const option = this.buildMindmapOption(treeData); | ||
console.log(option); | ||
myChart.setOption(option as any); | ||
} | ||
|
||
|
||
private toTreeData(data: any) { | ||
if (data.length === 1) { | ||
const anies = this.transformTreeData(data); | ||
return anies[0]; | ||
} | ||
|
||
const treeInfo = this.transformTreeData(data); | ||
return { | ||
name: '', | ||
children: treeInfo, | ||
config: data.config | ||
}; | ||
} | ||
|
||
private transformTreeData(data: any) { | ||
const nodes = []; | ||
for (const item of data) { | ||
const node: any = {}; | ||
node.name = item.name; | ||
if (item.children && item.children.length > 0) { | ||
node.children = this.transformTreeData(item.children); | ||
} | ||
nodes.push(node); | ||
} | ||
return nodes; | ||
} | ||
|
||
buildMindmapOption(data) { | ||
let height = '600px'; | ||
const dataStr = JSON.stringify(data); | ||
if (dataStr.length > 500) { | ||
height = '720px'; | ||
} | ||
|
||
return { | ||
feature: { | ||
saveAsImage: {} | ||
}, | ||
tooltip: { | ||
trigger: 'item', | ||
triggerOn: 'mousemove' | ||
}, | ||
series: [ | ||
{ | ||
height, | ||
type: 'tree', | ||
roam: true, | ||
id: 0, | ||
name: 'tree1', | ||
data: [data], | ||
top: '12%', | ||
left: '18%', | ||
bottom: '12%', | ||
right: '40%', | ||
symbolSize: 12, | ||
edgeShape: 'polyline', | ||
edgeForkPosition: '63%', | ||
initialTreeDepth: 3, | ||
lineStyle: { | ||
width: 2 | ||
}, | ||
|
||
label: { | ||
backgroundColor: '#fff', | ||
position: 'left', | ||
verticalAlign: 'middle', | ||
align: 'right', | ||
fontSize: 14 | ||
}, | ||
|
||
leaves: { | ||
label: { | ||
position: 'right', | ||
verticalAlign: 'middle', | ||
align: 'left' | ||
} | ||
}, | ||
|
||
expandAndCollapse: true, | ||
animationDuration: 550, | ||
animationDurationUpdate: 750 | ||
} | ||
] | ||
}; | ||
} | ||
|
||
} |
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
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 |
---|---|---|
|
@@ -3,6 +3,3 @@ | |
margin: 4em auto 0; | ||
} | ||
|
||
.charts { | ||
|
||
} |