From the very page on MDN that you linked to:

Warning: SVG 2 replaced the SVGMatrix interface by the more general DOMMatrix and DOMMatrixReadOnly interfaces.


The APIs are not exactly the same, but do appear similar so should probably be able to achieve the same result. Maybe. As SVG 2 is new and not exactly a popular target for the browsers vendors, however, I would stick with SVGMatrix for better support - it may be deprecated, but it's unlikely to be completely removed for quite some time to come.

Of course, if you can be certain that the transform attribute will only ever contain a single translate(), you could just do some simple string manipulation instead:

screw.getAttribute("transform").slice(10,-1).split(",");


I'm sure there are caveats about coordinate systems that mean this won't work in the general case, but it might be worth a try.


Mark


On Thu, May 25, 2017 at 11:55 AM, Steve Litt <slitt@...2357...> wrote:
Hi all,

I have a bunch of groups of class "screw", each comprised of a circle
screwhead and a smaller square in the center called a screwsquare. In
every instance of "screw", screwhead and screwsquare have identical x,
y, height, width and r dimensions. Each screw's position is determined
by the screw group's transform=translate(xadjust, yadjust). This is
done automatically by Inkscape, and furthermore, it's easy to set
manually with:

myElement.setAttribute('transform','translate(xadjust,yadjust)');

The trouble comes in when you want to *get* that transform. Getting the
transform is necessary when you want to move element whatever2 in
relation to the location of screw1. Getting the translation is one of
the worst documented things I've seen, but the concensus seems to be
something like the following (for my screw case where the group has the
transform):

===============================================================
function screw_coords(screw){
        matrix = screw.transform.baseVal.getItem(0).matrix;
        var coords = [];
        shead = screw.querySelector('.screwhead');
        coords[0] = shead.cx.animVal.value + matrix.e;
        coords[1] = shead.cy.animVal.value + matrix.f;
        return(coords);
}
===============================================================

The preceding is ugly and fragile for a whole number of reasons, it's
inobvious and horribly undocumented. But the real problem is it appears
to be deprecated:

https://developer.mozilla.org/en-US/docs/Web/API/SVGMatrix

The preceding article says not to use SVGMatrix, and to update code as
soon as possible, but remains mute on what you use instead. How the
hell do you read a translation? It's a mystery.

The following article gives a crazy train regex kludge method to read a
translate:

https://stackoverflow.com/questions/10349811/how-to-manipulate-translate-transforms-on-a-svg-element-with-javascript-in-chrom

If anybody knows the proper secret handshake to read a translate in a
non-deprecated, browser independent, non-kludgificent way, please let
me know, perhaps with some URLs of docs for such a functionality.

Thanks,

SteveT

Steve Litt
May 2017 featured book: Twenty Eight Tales of Troubleshooting
http://www.troubleshooters.com/28



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Inkscape-user mailing list
Inkscape-user@...3230...9...sourceforge.net
https://lists.sourceforge.net/lists/listinfo/inkscape-user