SVG in 4D v11.3
[These are notes from 4D Summit 2008 - pictures to follow later.]
Presenter: Tom Fitch, 4D Inc.
Demoed a database with interactive SVG areas. Click on an area on the graphic (a seating chart for an arena) and it maps it to the appropriate data elements and lets you take action on that element (buying a ticket for a particular seat). Likewise the image is data driven, so the seating chart updates automatically as things change.
SVG is completely Scalable, 'cause it's Vector Graphics... That means no jaggies or blurred images. Also generally smaller.
The cool part is that you can do mouse events on a scalable area, which is really difficult without SVG.
Shapes and gradients are perfect for SVG. But complex images can be larger. However, SVG are uncompressed images, so if you're using gzip on the web it can dramatically reduce the file size making it more competitive with small raster images.
Labels and descriptions in the image mean they're searchable. Active events and triggers are possible, as is animation (in part or the entire image). To animate ECMAScript and SML(?) are used, but animation is not supported by all browsers (not supported by Safari or Netscape).
IE only supports SVG if you have the Adobe plugin for SVG.
SVG is a text-based open standard for images developed by W3C with the help of Adobe. It's also an XML specification.
Basic SVG shapes (more are possible):
- <rect>
- <circle>
- <ellipse>
- <line>
- <polyline>
- <polygon>
- <path>
<path> is extremely useful since it can draw non-standard shapes. It draws by specifying the points... d="M 100 100 L 300 100 L 200 300 z" - the first one is the starting point, then L draws a line to each new area and z takes you back to the starting point.
SVG can go into any picture area just like other image type. If you put your charts in a picture area 4D will write it as SVG. You can also build by writing xml with the DOM commands. DOM EXPORT TO PICTURE writes the xml to an SVG picture.
One thing to realize is that the stroke width goes on the outside of the area, not the inside.
To get On Clicked events you have to set an ID attribute. Then you need to GET MOUSE coordinates and then pass those to SVG Find element ID by coordinates, but make sure you subtract the position of the picture area from the values you get from GET MOUSE since you need the position inside the picture area, not the position inside the window. You can get the coordinates of the picture area with GET OBJECT RECT. You can also group objects in an SVG area and when you click on them they return the ID for the group, not the particular object.
One word of warning - you'll need to use keyboard shortcuts when tracing an On Clicked event until you hit GET MOUSE since the mouse position at the time of GET MOUSE is critical.
You can have raster objects in the SVG area.
Converting to PDF right now only on Mac because Windows doesn't have native support for PDFs.
Tags: 4D Summit 2008, 4D-v11, SVG
Categories: 4D
October 9th, 2008 at 7:55 am
Hello,
You said : “To get On Clicked events you have to set an ID attribute. Then you need to GET MOUSE coordinates and then pass those to SVG Find element ID by coordinates….”
No, since the 11.3, you pass the system variables “MouseX” and “MouseY” as parameters to the command. You don’t need “GET MOUSE” and substraction. “MouseX” and “MouseY” are always availables on rollover or clic events. (except for replicated picture of course). It’s magic!
A Component (4D SVG) will be available, free, at the same time that the 4D 11.3. This component gives more than 100 macro-commands to generate SVG pictures.
October 22nd, 2008 at 1:52 am
I am very interested in using the SVG component for 4D in a GIS Project that I am working on. However, the component I found on the 4D Forum is compilied so I cannot really see how it was done. Do you have an example database that you could send me (interpreted) like the “seating chart for an arena” that you mentioned above?
Are drag and drop also supported in an SVG area? For example dragging an element from a ListBox onto a polygon in the SVG area.
I highly appreciate your comments!
Best Regards
Dan Röthlisberger
October 22nd, 2008 at 7:00 am
Not sure on the drag and drop, but I suspect so since it’s not a special area.
I’m not sure what the copyright issues are on the Summit databases. You might try calling your 4D sales rep and see if it’s OK to get it from an attendee.
March 2nd, 2009 at 12:12 pm
First : a SVG Zone is a picture.
Second : Yes you can drop something on it. You must use the event On Begin Drag Over in the listbox to fill the d&d container and On Mouse Move (to get the id of the object SVG) and On Drop (to read into the d&d container) for the picture area.