ssdesign
ssdesign

Reputation: 2821

How so create complex SVG shapes using D3JS?

I am trying to customize one of the D3 JS samples but am stuck on how to add complex graphics to it.

This is the script I am trying to modify: http://bl.ocks.org/jmgimeno/1665141

I want to add better graphics for the handler at the bottom. Something like how the iPhone video edit control looks like: http://bit.ly/ZDjnOq

Now, I guess, the only option to do that would be to use complex SVG graphics. So I created a SVG file for a graphics control that looks similar to iPhone control.

My SVG file looks like this:

    <?xml version="1.0" encoding="iso-8859-1"?>
<!-- Generator: Adobe Illustrator 16.0.4, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="37.5px"
     height="20.25px" viewBox="0 0 37.5 20.25" enable-background="new 0 0 37.5 20.25" xml:space="preserve">
<g id="Layer_2">
</g>
<g id="Layer_1">
    <path fill="none" stroke="#F28A1A" stroke-miterlimit="10" d="M34.442,15.665c0,1.565-1.27,2.835-2.835,2.835H5.594
        c-1.565,0-2.835-1.27-2.835-2.835V3.834C2.759,2.269,4.028,1,5.594,1h26.014c1.565,0,2.835,1.269,2.835,2.834V15.665z"/>
    <g>
        <path fill="#FFFFFF" stroke="#626161" stroke-width="0.25" stroke-miterlimit="10" d="M4.342,12.298
            c0,0.874-0.709,1.583-1.584,1.583l0,0c-0.874,0-1.583-0.709-1.583-1.583V7.131c0-0.874,0.709-1.583,1.583-1.583l0,0
            c0.875,0,1.584,0.709,1.584,1.583V12.298z"/>
        <line fill="none" stroke="#626161" stroke-width="0.25" stroke-miterlimit="10" x1="1.883" y1="9.715" x2="3.466" y2="9.715"/>

            <line id="XMLID_16_" fill="none" stroke="#626161" stroke-width="0.25" stroke-miterlimit="10" x1="1.883" y1="8.976" x2="3.466" y2="8.976"/>

            <line id="XMLID_15_" fill="none" stroke="#626161" stroke-width="0.25" stroke-miterlimit="10" x1="1.883" y1="10.369" x2="3.466" y2="10.369"/>
    </g>
    <g>
        <path fill="#FFFFFF" stroke="#626161" stroke-width="0.25" stroke-miterlimit="10" d="M36.025,12.298
            c0,0.874-0.709,1.583-1.584,1.583l0,0c-0.874,0-1.583-0.709-1.583-1.583V7.131c0-0.874,0.709-1.583,1.583-1.583l0,0
            c0.875,0,1.584,0.709,1.584,1.583V12.298z"/>
        <line fill="none" stroke="#626161" stroke-width="0.25" stroke-miterlimit="10" x1="33.566" y1="9.715" x2="35.149" y2="9.715"/>

            <line id="XMLID_14_" fill="none" stroke="#626161" stroke-width="0.25" stroke-miterlimit="10" x1="33.566" y1="8.976" x2="35.149" y2="8.976"/>

            <line id="XMLID_13_" fill="none" stroke="#626161" stroke-width="0.25" stroke-miterlimit="10" x1="33.566" y1="10.369" x2="35.149" y2="10.369"/>
    </g>
</g>
</svg>

Somehow, I am not able to see the SVG graphics when I use the above code.

Do I need some simpler form of the SVG? or is there something more to it.

Upvotes: 2

Views: 1930

Answers (1)

Andrew Staroscik
Andrew Staroscik

Reputation: 2704

The complex paths can be rendered by putting the svg element information into arrays that d3 can use as data:

http://bl.ocks.org/AndrewStaroscik/5220771

Upvotes: 2

Related Questions