Skip to content

Commit 8b98f8f

Browse files
committed
feat(Output Node): Add selection from device + Add display in select card + Add styling in view
1 parent 67b0828 commit 8b98f8f

File tree

4 files changed

+68
-10
lines changed

4 files changed

+68
-10
lines changed

src/app/devices/selector.device.ts

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,6 @@ selectorDevice.setNeuronLight = function(options: SetNeuronOptions): void {
204204
const isSelected = options.isSelected || null;
205205
const isDisabled = options.isDisabled || null;
206206

207-
const {
208-
neuronIndex,
209-
layerIndex,
210-
} = networkState.getNeuronAndLayerIndexes(index);
211-
const note = this.grid[layerIndex][neuronIndex - 1];
212-
213207
let color;
214208
if (isSelected) {
215209
color = this.settings.colorByState.neuronSelected;
@@ -221,6 +215,21 @@ selectorDevice.setNeuronLight = function(options: SetNeuronOptions): void {
221215
color = this.settings.colorByState.neuronOn;
222216
}
223217

218+
const {
219+
neuronIndex,
220+
layerIndex,
221+
} = networkState.getNeuronAndLayerIndexes(index);
222+
223+
if (networkState.isOutputNode(options.index)) {
224+
this.playNote({
225+
note: this.settings.functionKeys.lastColumn[0],
226+
color,
227+
});
228+
return;
229+
}
230+
231+
const note = this.grid[layerIndex][neuronIndex - 1];
232+
224233
this.playNote({
225234
note,
226235
color,
@@ -288,6 +297,7 @@ selectorDevice.getGridFlatIndex = function(note: number): number {
288297
*/
289298
selectorDevice.attachNavigation = function(): void {
290299
this.attachPlayPauseButton();
300+
this.attachOutputButton();
291301
};
292302

293303
selectorDevice.attachPlayPauseButton = function() {
@@ -324,6 +334,27 @@ selectorDevice.attachPlayPauseButton = function() {
324334
});
325335
};
326336

337+
selectorDevice.attachOutputButton = function() {
338+
const note = this.settings.functionKeys.lastColumn[0];
339+
const color = this.settings.colorByState.neuronOn;
340+
const outputNode = networkState.getOutputNode();
341+
const id = parseInt(outputNode.id);
342+
const callback = () => {
343+
if (playgroundFacade.selectedNodes.indexOf(id) === -1) {
344+
networkUi.toggleNodeSelection(id, true);
345+
}
346+
else {
347+
networkUi.toggleNodeSelection(id, false);
348+
}
349+
};
350+
351+
this.addNoteListener_NEW({
352+
note,
353+
color,
354+
callback,
355+
});
356+
};
357+
327358
/**
328359
* Attach layer buttons
329360
*/

src/app/state/network.state.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,3 +444,11 @@ networkState.setLayer = function(index: number) {
444444
networkState.resetLayerSelection = function() {
445445
this.selectedLayerIndex = null;
446446
};
447+
448+
networkState.getOutputNode = function() {
449+
return this.nodes[this.nodes.length - 1][0];
450+
};
451+
452+
networkState.isOutputNode = function(index) {
453+
return index === parseInt(networkState.nodes[networkState.nodes.length - 1][0].id);
454+
};

src/app/ui/network.ui.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,21 @@ networkUi.toggleNodeSelection = function(nodeIndex: number, isSelected: boolean)
7171
playgroundFacade.unselectNode(nodeIndex);
7272
}
7373

74-
// class
75-
const canvas = d3.select(`#canvas-${nodeIndex}`);
76-
canvas.classed('selected', isSelected);
74+
// styling
75+
if (networkState.isOutputNode(nodeIndex)) {
76+
const canvas = document.querySelector('#heatmap').children[0].children[0] as HTMLCanvasElement;
77+
78+
if (isSelected) {
79+
canvas.style.border = '2px solid cyan';
80+
}
81+
else {
82+
canvas.style.border = null;
83+
}
84+
}
85+
else {
86+
const canvas = d3.select(`#canvas-${nodeIndex}`);
87+
canvas.classed('selected', isSelected);
88+
}
7789

7890
selectCardUi.updateCard();
7991

src/app/ui/select-card.ui.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,14 @@ selectCardUi.updateCard = function() {
9797
this.rows.forEach((row, index) => {
9898
// single selection
9999
if (selectedNodes.length === 1) {
100-
const link = networkState.getNeuron(selectedNodes[0]).neuron.inputLinks[index];
100+
let link;
101+
102+
if (networkState.isOutputNode(selectedNodes[0])) {
103+
link = networkState.getOutputNode().inputLinks[index];
104+
}
105+
else {
106+
link = networkState.getNeuron(selectedNodes[0]).neuron.inputLinks[index];
107+
}
101108

102109
if (typeof link === 'undefined') {
103110
this.updateSourceWeight(index);

0 commit comments

Comments
 (0)