Skip to content

Commit

Permalink
feat(graphin): TODO mock combo data
Browse files Browse the repository at this point in the history
  • Loading branch information
pomelo-nwu committed May 31, 2020
1 parent 3e7cec9 commit cd9a4ea
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions packages/graphin/src/utils/mock.ts
Expand Up @@ -23,6 +23,7 @@ export class Mock {
options: OptionType;

nodeIds: string[];
combosData: any;

constructor(count: number) {
this.options = defaultOptions;
Expand Down Expand Up @@ -55,13 +56,13 @@ export class Mock {
});
}
}
this.nodeIds = this.nodes.map((node) => node.id);
this.nodeIds = this.nodes.map(node => node.id);
};

expand = (snodes: NodeData[]) => {
this.edges = [];
this.nodes = [];
snodes.forEach((node) => {
snodes.forEach(node => {
for (let i = 0; i < this.options.nodeCount; i += 1) {
this.nodes.push({
id: `${node.id}-${i}`,
Expand All @@ -81,7 +82,7 @@ export class Mock {
};

type = (nodeType: string) => {
this.nodes = this.nodes.map((node) => {
this.nodes = this.nodes.map(node => {
return {
...node,
type: nodeType,
Expand Down Expand Up @@ -124,13 +125,13 @@ export class Mock {
const tree = new Tree();
const rootId = this.nodeIds[0];

this.nodeIds.forEach((id) => {
this.nodeIds.forEach(id => {
tree.addNode({
id,
});
});

tree.bfs((node) => {
tree.bfs(node => {
if (node.id !== rootId) {
this.edges.push({
source: node.parent && node.parent.id,
Expand All @@ -150,28 +151,50 @@ export class Mock {
edges: this.edges,
};
};
combos = (chunkSize: number) => {
const comboIds = new Set();
this.nodes = this.nodes.map((node, index) => {
const comboIndex = Math.ceil((index + 1) / chunkSize);
console.log('comboIndex', comboIndex);
const comboId = `combo-${comboIndex}`;
return {
...node,
comboId,
};
});
this.combosData = [...comboIds].map(c => {
return {
id: c,
label: c,
};
});

return this;
};

graphin = (): Data => {
return {
nodes: this.nodes.map((node) => {
nodes: this.nodes.map(node => {
return {
id: node.id,
label: `node-${node.id}`,
data: node,
shape: 'CircleNode',
comboId: node.comboId,
style: {
nodeSize: 24,
},
};
}),
edges: this.edges.map((edge) => {
edges: this.edges.map(edge => {
return {
source: edge.source,
target: edge.target,
label: edge.label,
data: edge,
};
}),
combos: this.combosData,
};
};
}
Expand Down

0 comments on commit cd9a4ea

Please sign in to comment.