Generic JavaScript View Code Improvement ( how to load and retrive variables arrays with loops)

Hi everybody.

Maybe someone could help me on this.

I’m working in this workflow. Inside there is a Generic JavaScript node, that i have been successfully coded (the results are what is expected, but i think it can be better coded.

For example:

To get the information from the previews node, we used:

var h1= knimeDataTable.getColumn(1);
var h2= knimeDataTable.getColumn(2);
var h3= knimeDataTable.getColumn(3);
var h4= knimeDataTable.getColumn(4);
var h5= knimeDataTable.getColumn(5);
.
.
.
var h55= knimeDataTable.getColumn(55);
var h56= knimeDataTable.getColumn(56);
var h57= knimeDataTable.getColumn(57);
var h58= knimeDataTable.getColumn(58);
var h59= knimeDataTable.getColumn(59);
var h60= knimeDataTable.getColumn(60);

Then, we substitute all of previews code for this next one:

for (var i = 1; i < 61; i++) {
this[“h”+i] = knimeDataTable.getColumn(i);
}

And is working right !.

We want to do the same with the next part of the code:
steps: [
{label: n[1], method: ‘animate’, args: [[n[1]], { mode: ‘immediate’, frame: {redraw: false, duration: 500}, transition: {duration: 500} }]},
{label: n[2], method: ‘animate’, args: [[n[2]], { mode: ‘immediate’, frame: {redraw: false, duration: 500}, transition: {duration: 500} }]},
{label: n[3], method: ‘animate’, args: [[n[3]], { mode: ‘immediate’, frame: {redraw: false, duration: 500}, transition: {duration: 500} }]},
{label: n[4], method: ‘animate’, args: [[n[4]], { mode: ‘immediate’, frame: {redraw: false, duration: 500}, transition: {duration: 500} }]},
{label: n[5], method: ‘animate’, args: [[n[5]], { mode: ‘immediate’, frame: {redraw: false, duration: 500}, transition: {duration: 500} }]},
.
.
.
{label: n[55], method: ‘animate’, args: [[n[55]], { mode: ‘immediate’, frame: {redraw: false, duration: 500}, transition: {duration: 500} }]},
{label: n[56], method: ‘animate’, args: [[n[56]], { mode: ‘immediate’, frame: {redraw: false, duration: 500}, transition: {duration: 500} }]},
{label: n[57], method: ‘animate’, args: [[n[57]], { mode: ‘immediate’, frame: {redraw: false, duration: 500}, transition: {duration: 500} }]},
{label: n[58], method: ‘animate’, args: [[n[58]], { mode: ‘immediate’, frame: {redraw: false, duration: 500}, transition: {duration: 500} }]},
{label: n[59], method: ‘animate’, args: [[n[59]], { mode: ‘immediate’, frame: {redraw: false, duration: 500}, transition: {duration: 500} }]},
{label: n[60], method: ‘animate’, args: [[n[60]], { mode: ‘immediate’, frame: {redraw: false, duration: 500}, transition: {duration: 500} }]},
]

and this part of the code:

frames:[
{name: n[1], data: [{ y: h1, marker: {color: c1, size: s0}}]},
{name: n[2], data: [{ y: h2, marker: {color: c2, size: s0}}]},
{name: n[3], data: [{ y: h3, marker: {color: c3, size: s0}}]},
{name: n[4], data: [{ y: h4, marker: {color: c4, size: s0}}]},
{name: n[5], data: [{ y: h5, marker: {color: c5, size: s0}}]},
.
.
.
{name: n[55], data: [{ y: h55, marker: {color: c55, size: s0}}]},
{name: n[56], data: [{ y: h56, marker: {color: c56, size: s0}}]},
{name: n[57], data: [{ y: h57, marker: {color: c57, size: s0}}]},
{name: n[58], data: [{ y: h58, marker: {color: c58, size: s0}}]},
{name: n[59], data: [{ y: h59, marker: {color: c59, size: s0}}]},
{name: n[60], data: [{ y: h60, marker: {color: c60, size: s0}}]},
]

we thought that something like the following code would work, but not:

for (var i = 1; i < 61; i++) {
{name: n[i], data: [{ y: h[i], marker: {color: c[1], size: s0}}]},
}

or:

for (var i = 1; i < 61; i++) {
{label: n[i], method: ‘animate’, args: [[n[i]], { mode: ‘immediate’, frame: {redraw: false, duration: 500}, transition: {duration: 500} }]},
}

The workflow is this one. Please check it and help me,


Schedule.knwf (9.9 KB)