Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd5114e3

Browse files
committed
Add layout feature
1 parent8499a51 commitd5114e3

File tree

12 files changed

+158
-97
lines changed

12 files changed

+158
-97
lines changed

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name":"algorithm-visualizer",
3-
"version":"2.2.1",
3+
"version":"2.3.0",
44
"description":"Visualization Library for JavaScript",
55
"keywords": [
66
"algorithm",

‎src/Array1DTracer.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@ import { Array2DTracer, ChartTracer } from './';
22

33
classArray1DTracerextendsArray2DTracer{
44
set(array1d?:any[]): this{
5-
returnthis.addTrace('set',arguments);
5+
returnthis.command('set',arguments);
66
}
77

88
patch(x:number,v?:any): this{
9-
returnthis.addTrace('patch',arguments);
9+
returnthis.command('patch',arguments);
1010
}
1111

1212
depatch(x:number): this{
13-
returnthis.addTrace('depatch',arguments);
13+
returnthis.command('depatch',arguments);
1414
}
1515

1616
select(sx:number,ex?:number): this{
17-
returnthis.addTrace('select',arguments);
17+
returnthis.command('select',arguments);
1818
}
1919

2020
deselect(sx:number,ex?:number): this{
21-
returnthis.addTrace('deselect',arguments);
21+
returnthis.command('deselect',arguments);
2222
}
2323

2424
chart(chartTracer:ChartTracer): this{
25-
returnthis.addTrace('chart',arguments);
25+
returnthis.command('chart',arguments);
2626
}
2727
}
2828

‎src/Array2DTracer.ts‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,39 @@ import { Tracer } from './';
22

33
classArray2DTracerextendsTracer{
44
set(array2d?:any[][]): this{
5-
returnthis.addTrace('set',arguments);
5+
returnthis.command('set',arguments);
66
}
77

88
patch(x:number,y:number,v?:any): this{
9-
returnthis.addTrace('patch',arguments);
9+
returnthis.command('patch',arguments);
1010
}
1111

1212
depatch(x:number,y:number): this{
13-
returnthis.addTrace('depatch',arguments);
13+
returnthis.command('depatch',arguments);
1414
}
1515

1616
select(sx:number,sy:number,ex?:number,ey?:number): this{
17-
returnthis.addTrace('select',arguments);
17+
returnthis.command('select',arguments);
1818
}
1919

2020
selectRow(x:number,sy:number,ey:number): this{
21-
returnthis.addTrace('selectRow',arguments);
21+
returnthis.command('selectRow',arguments);
2222
}
2323

2424
selectCol(y:number,sx:number,ex:number): this{
25-
returnthis.addTrace('selectCol',arguments);
25+
returnthis.command('selectCol',arguments);
2626
}
2727

2828
deselect(sx:number,sy:number,ex?:number,ey?:number): this{
29-
returnthis.addTrace('deselect',arguments);
29+
returnthis.command('deselect',arguments);
3030
}
3131

3232
deselectRow(x:number,sy:number,ey:number): this{
33-
returnthis.addTrace('deselectRow',arguments);
33+
returnthis.command('deselectRow',arguments);
3434
}
3535

3636
deselectCol(y:number,sx:number,ex:number): this{
37-
returnthis.addTrace('deselectCol',arguments);
37+
returnthis.command('deselectCol',arguments);
3838
}
3939
}
4040

‎src/Commander.ts‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import{Randomize}from'./';
2+
3+
constMAX_COMMANDS=1000000;
4+
constMAX_OBJECTS=100;
5+
6+
interfaceCommand{
7+
key:string|null,
8+
method:string,
9+
args:Array<any>,
10+
}
11+
12+
classCommander{
13+
privatestatickeyRandomizer=newRandomize.String(8,'abcdefghijklmnopqrstuvwxyz0123456789');
14+
privatestaticobjectCount=0;
15+
publicstaticcommands:Command[]=[];
16+
17+
staticcommand(key:string|null,method:string,iArguments:IArguments):void{
18+
constargs=Array.from(iArguments);
19+
this.commands.push({
20+
key,
21+
method,
22+
args:JSON.parse(JSON.stringify(args)),
23+
});
24+
if(this.commands.length>MAX_COMMANDS)thrownewError('Too Many Commands');
25+
if(this.objectCount>MAX_OBJECTS)thrownewError('Too Many Objects');
26+
}
27+
28+
staticsetRoot(child:Commander){
29+
this.command(null,'setRoot',arguments);
30+
}
31+
32+
staticdelay(){
33+
this.command(null,'delay',arguments);
34+
}
35+
36+
privatereadonlykey:string;
37+
38+
constructor(iArguments:IArguments){
39+
constclassName=(<any>this).constructor.name;
40+
this.key=Commander.keyRandomizer.create();
41+
this.command(className,iArguments);
42+
}
43+
44+
destroy(){
45+
Commander.objectCount--;
46+
returnthis.command('destroy',arguments);
47+
}
48+
49+
command(method:string,iArguments:IArguments): this{
50+
Commander.command(this.key,method,iArguments);
51+
returnthis;
52+
}
53+
54+
delay(): this{
55+
Commander.delay();
56+
returnthis;
57+
}
58+
59+
toJSON(){
60+
returnthis.key;
61+
}
62+
}
63+
64+
const{ALGORITHM_VISUALIZER}=process.env;
65+
if(!ALGORITHM_VISUALIZER){
66+
constaxios=require('axios');
67+
constopn=require('opn');
68+
process.on('beforeExit',()=>{
69+
axios.post('https://algorithm-visualizer.org/api/visualizations',{content:JSON.stringify(Commander.commands)})
70+
.then((response:any)=>opn(response.data,{wait:false}))
71+
.catch(console.error)
72+
.finally(()=>process.exit());
73+
});
74+
}
75+
76+
exportdefaultCommander;

‎src/GraphTracer.ts‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,71 +2,71 @@ import { LogTracer, Tracer } from './';
22

33
classGraphTracerextendsTracer{
44
set(array2d?:any[][]): this{
5-
returnthis.addTrace('set',arguments);
5+
returnthis.command('set',arguments);
66
}
77

88
directed(isDirected?:boolean): this{
9-
returnthis.addTrace('directed',arguments);
9+
returnthis.command('directed',arguments);
1010
}
1111

1212
weighted(isWeighted?:boolean): this{
13-
returnthis.addTrace('weighted',arguments);
13+
returnthis.command('weighted',arguments);
1414
}
1515

1616
addNode(id:any,weight?:any,x?:number,y?:number,visitedCount?:number,selectedCount?:number): this{
17-
returnthis.addTrace('addNode',arguments);
17+
returnthis.command('addNode',arguments);
1818
}
1919

2020
updateNode(id:any,weight?:any,x?:number,y?:number,visitedCount?:number,selectedCount?:number): this{
21-
returnthis.addTrace('updateNode',arguments);
21+
returnthis.command('updateNode',arguments);
2222
}
2323

2424
removeNode(id:any): this{
25-
returnthis.addTrace('removeNode',arguments);
25+
returnthis.command('removeNode',arguments);
2626
}
2727

2828
addEdge(source:any,target:any,weight?:any,visitedCount?:number,selectedCount?:number): this{
29-
returnthis.addTrace('addEdge',arguments);
29+
returnthis.command('addEdge',arguments);
3030
}
3131

3232
updateEdge(source:any,target:any,weight?:any,visitedCount?:number,selectedCount?:number): this{
33-
returnthis.addTrace('updateEdge',arguments);
33+
returnthis.command('updateEdge',arguments);
3434
}
3535

3636
removeEdge(source:any,target:any): this{
37-
returnthis.addTrace('removeEdge',arguments);
37+
returnthis.command('removeEdge',arguments);
3838
}
3939

4040
layoutCircle(){
41-
returnthis.addTrace('layoutCircle',arguments);
41+
returnthis.command('layoutCircle',arguments);
4242
}
4343

4444
layoutTree(root?:any,sorted?:boolean){
45-
returnthis.addTrace('layoutTree',arguments);
45+
returnthis.command('layoutTree',arguments);
4646
}
4747

4848
layoutRandom(){
49-
returnthis.addTrace('layoutRandom',arguments);
49+
returnthis.command('layoutRandom',arguments);
5050
}
5151

5252
visit(target:any,source?:any,weight?:any){
53-
returnthis.addTrace('visit',arguments);
53+
returnthis.command('visit',arguments);
5454
}
5555

5656
leave(target:any,source?:any,weight?:any){
57-
returnthis.addTrace('leave',arguments);
57+
returnthis.command('leave',arguments);
5858
}
5959

6060
select(target:any,source?:any){
61-
returnthis.addTrace('select',arguments);
61+
returnthis.command('select',arguments);
6262
}
6363

6464
deselect(target:any,source?:any){
65-
returnthis.addTrace('deselect',arguments);
65+
returnthis.command('deselect',arguments);
6666
}
6767

6868
log(logTracer:LogTracer){
69-
returnthis.addTrace('log',arguments);
69+
returnthis.command('log',arguments);
7070
}
7171
}
7272

‎src/HorizontalLayout.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import{Layout}from'./';
2+
3+
classHorizontalLayoutextendsLayout{
4+
}
5+
6+
exportdefaultHorizontalLayout;

‎src/Layout.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import{Commander}from'./';
2+
3+
classLayoutextendsCommander{
4+
constructor(children:[Commander]){
5+
super(arguments);
6+
}
7+
8+
add(child:Commander,index?:Number): this{
9+
returnthis.command('add',arguments);
10+
}
11+
12+
remove(child:Commander): this{
13+
returnthis.command('remove',arguments);
14+
}
15+
16+
removeAll(): this{
17+
returnthis.command('removeAll',arguments);
18+
}
19+
}
20+
21+
exportdefaultLayout;

‎src/LogTracer.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ import { Tracer } from './';
22

33
classLogTracerextendsTracer{
44
set(log?:string): this{
5-
returnthis.addTrace('set',arguments);
5+
returnthis.command('set',arguments);
66
}
77

88
print(message:any): this{
9-
returnthis.addTrace('print',arguments);
9+
returnthis.command('print',arguments);
1010
}
1111

1212
println(message:any): this{
13-
returnthis.addTrace('println',arguments);
13+
returnthis.command('println',arguments);
1414
}
1515

1616
printf(format:string, ...args:any[]): this{
17-
returnthis.addTrace('printf',arguments);
17+
returnthis.command('printf',arguments);
1818
}
1919
}
2020

‎src/Tracer.ts‎

Lines changed: 5 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,17 @@
1-
constMAX_TRACES=1000000;
2-
constMAX_TRACERS=100;
3-
4-
interfaceTrace{
5-
tracerKey:string,
6-
method:string,
7-
args:Array<any>,
8-
}
9-
10-
classTracer{
11-
privatestatictracerCount:number=0;
12-
publicstatictraces:Trace[]=[];
13-
privatereadonlykey:string;
14-
15-
staticaddTracer(className:string,title:string):string{
16-
constkey=`${this.tracerCount++}-${className}-${title}`;
17-
constmethod='construct';
18-
constargs=[className,title];
19-
this.addTrace(key,method,args);
20-
returnkey;
21-
}
22-
23-
staticaddTrace(tracerKey:string,method:string,args:any[]):void{
24-
this.traces.push({
25-
tracerKey,
26-
method,
27-
args:JSON.parse(JSON.stringify(args)),
28-
});
29-
if(this.traces.length>MAX_TRACES)thrownewError('Traces Limit Exceeded');
30-
if(this.tracerCount>MAX_TRACERS)thrownewError('Tracers Limit Exceeded');
31-
}
1+
import{Commander}from'./';
322

3+
classTracerextendsCommander{
334
constructor(title?:string){
34-
constclassName:string=(<any>this).constructor.name;
35-
if(title===undefined)title=className;
36-
this.key=Tracer.addTracer(className,title);
37-
}
38-
39-
addTrace(method:string,iArguments:IArguments): this{
40-
constargs=Array.from(iArguments).map(arg=>arginstanceofTracer ?arg.key :arg);
41-
Tracer.addTrace(this.key,method,args);
42-
returnthis;
5+
super(arguments);
436
}
447

458
set(): this{
46-
returnthis.addTrace('set',arguments);
9+
returnthis.command('set',arguments);
4710
}
4811

4912
reset(): this{
50-
returnthis.addTrace('reset',arguments);
51-
}
52-
53-
delay(): this{
54-
returnthis.addTrace('delay',arguments);
13+
returnthis.command('reset',arguments);
5514
}
5615
}
5716

58-
const{ALGORITHM_VISUALIZER}=process.env;
59-
if(!ALGORITHM_VISUALIZER){
60-
constaxios=require('axios');
61-
constopn=require('opn');
62-
process.on('beforeExit',()=>{
63-
axios.post('https://algorithm-visualizer.org/api/visualizations',{content:JSON.stringify(Tracer.traces)})
64-
.then((response:any)=>opn(response.data,{wait:false}))
65-
.catch(console.error)
66-
.finally(()=>process.exit());
67-
});
68-
}
69-
7017
exportdefaultTracer;

‎src/VerticalLayout.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import{Layout}from'./';
2+
3+
classVerticalLayoutextendsLayout{
4+
}
5+
6+
exportdefaultVerticalLayout;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp