Question Robert Harris · May 6, 2017

Using SVG in ZEN

Hi all,

Does anyone know how to bind data and display it on

    %ZEN.SVGComponent.sprite

class objects?

The only example I could find in the documentation was:


http://localhost:57777/csp/samples/ZENTest.SVGSpriteTest.cls

where I could only statically display a label. Anyone have any have any experience here?

Thanks,

Bob Harris

Comments

Pravin Barton · May 8, 2017

Hi Bob,

I've done databindings on other SVG components like charts and meters. Unfortunately, sprites don't extend the %ZEN.Component.dataView class and don't have any built-in way to function as view components in Zen MVC. You'll have to set the values programmatically using the getDataByName() and setDataByName() functions of the data controller (documentation).

0
Robert Harris · May 11, 2017

Hi Pravin,

When I checked out the documentation, it said I would have to use the dataBag API. Do you know if there is any place that has a couple of lines of Cache related code using the dataBag API? If the dataBag API is completely outside of Cache, is this API relevantly explored in Ruby or Chef documentation?

Thanks,

Bob Harris

0
Pravin Barton  May 11, 2017 to Robert Harris

Hi Bob,

The databag API is what the Zen MVC uses internally, you shouldn't have to worry about it.

Here's some sample code modifying the ZENTest.SVGSpriteTest sample page to display data from a datacontroller:

ClientMethod initializeCanvas() [ Language = javascript ]
{
var canvas zenPage.getComponentById('svgCanvas');
if ((!canvas) || !canvas.document) {
// ensure we don't execute code before the SVG document has been fully loaded
setTimeout('zenPage.initializeCanvas();',10);
return;
}
var inspector this.getComponentById('objectInspector');
inspector.setCurrObject(canvas);
var controller zenPage.getComponentById('spriteController');
controller.setModelId(1);
// create initial set of sprites & connectors
var sprite new Array();
sprite[0] canvas.createSprite('sprite',200,100);
sprite[0].setProperty('onclick','zenPage.selectSprite(zenThis);');
sprite[0].setProperty('caption', controller.getDataByName("sprite1"));
sprite[1] canvas.createSprite('sprite',200,300);
sprite[1].setProperty('caption', controller.getDataByName("sprite2"));
sprite[2] canvas.createSprite('sprite',400,100);
sprite[2].setProperty('caption', controller.getDataByName("sprite3"));
sprite[3] canvas.createSprite('sprite',400,300);
sprite[3].setProperty('caption', controller.getDataByName("sprite4"));
var connect canvas.createConnector('connector');
connect.addOutput(sprite[0],1);
//connect.addOutput(sprite[2],1);
connect.addInput(sprite[1],0);
//connect.addInput(sprite[3],0);
// turn off layout; turn on edit mode
canvas.setProperty('layout','');
canvas.setProperty('editMode','drag');
}

0
Robert Harris · May 12, 2017

Hi Pravin,

Thanks for your example code.

For some reason I'm haven't been getting all of the community posts, so that's why the delay in my responses. I'm looking forward to checking this out this weekend.

Best,

Bob Harris

0
Robert Harris · May 12, 2017

Hi Pravin,

When I tried:

I got the following error msg:

The controller seems to be defined. Any thoughts?

Thanks.

Best,

Bob Harris

0
Pravin Barton  May 12, 2017 to Robert Harris

Hi Bob,

For this to work you also need to define the data controller element in the page contents. For example, you could add the following element to the XData:

<dataController id="spriteController" modelClass="User.SpriteDataModel" modelId="1"/> 

If you have a data model class defined called "User.SpriteDataModel".

I recommend taking a look at the "ZENMVC.MVCForm" class in the SAMPLES namespace if you'd like an example of defining a data controller and data model.

0
Robert Harris · May 17, 2017

Hi Pravin,

Thanks for your help.

I got the code working and can print out a single line caption on a sprite.

My last question: Do you happen to know if it is possible to print out more than one line of text on a sprite? I've been looking into displaying multiple lines of text in a <svgFrame> and multiple data fields, but I'm not sure how extensively Cache supports the <text> tab from the svg specifications in Zen, at this time, even in a custom component.

I know how to reformat text to fit a given space, but getting the <svgFrame> to auto-expand...if you happen to already know of some ways to do this, that would be great, but you've already been quite helpful, so thanks.

Best,

Bob Harris

0