ItemArray updating problem


I’m working on a project for a client, which strongly builds up on your exmaple ‘seatingChart’. I’m writing a custom ResizingTool, where the tables can be resized and the amount of seats will be calculated automatically.

Here is my template:
GO(go.Node, "Spot", { name: 'TABLEGROUP' }, { background: "transparent", locationObjectName: "TABLESHAPE", locationSpot: go.Spot.Center, rotatable: true, resizable: true, resizeObjectName: "TABLESHAPE", layerName: "Background", selectionAdornmentTemplate: adornmentTemplate, resizeAdornmentTemplate: adornmentTemplate }, new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify), new go.Binding("angle").makeTwoWay(), GO(go.Panel, "Spot", GO(go.Shape, { name: "TABLESHAPE", desiredSize: new go.Size(160, 80), fill: '#877866', stroke: null, portId: "TABLESHAPE" }, new go.Binding("figure", "shape"), new go.Binding("angle", "angle"), new go.Binding("desiredSize", "size", go.Size.parse).makeTwoWay(go.Size.stringify), new go.Binding("fill")), GO(go.TextBlock, { editable: true, font: "bold 11pt Arial, sans-serif", stroke: 'white' }, new go.Binding("text", "name").makeTwoWay(), new go.Binding("angle", "angle", n => { return -n; })) ), new go.Binding("itemArray", "seats"), { itemTemplate: GO(go.Panel, "Spot", new go.Binding("alignment", "loc", go.Spot.parse).makeTwoWay(go.Spot.stringify), new go.Binding("alignmentFocus", "focus", go.Spot.parse).makeTwoWay(go.Spot.stringify), GO(go.Shape, "Circle", { name: "SEATSHAPE", desiredSize: new go.Size(40, 40), fill: style.unseatedBgColor, stroke: "white", strokeWidth: 2 }, new go.Binding("fill")), GO(go.TextBlock, new go.Binding("text", "name"), { font: "10pt Arial, sans-serif", stroke: style.unseatedFontColor }, new go.Binding("angle", "angle", n => { return -n; })) ) } );

In every update I clear first the ‘seats’ from the selected table with diagram.model.setDataProperty(, 'seats', []); Then I create a new Array with all seat objects like this:
{ "name": "1", "loc": "0.2 0", "focus": "0.5 1" }

After the calcualtion I set the new ItemArray again with diagram.model.setDataProperty(, 'seats', newItemsArray);. Unfortunately the seats are positioned wrong, they irgnore the main table shape.

I also used diagram.model.insertArrayItem(part.itemArray, i, element); but it also gives me same results without the main table. I tried many ways put nothing seems to work, maybe I miss some NodeData update, DataBinding or something. I would really appreciate some help on this, because I stuck with this problem.

Is your table data’s size.height zero?

What seat data did you use for “7”, for example?

By the way, it is not necessary to set data.seats to [] before setting it to the Array that you want.

Thank you very much, you pointed me in the right direction and I was able to solve the problem. I had a typo in the location calculation.