Sign In/My Account | View Cart  
advertisement


Listen Print Discuss

Many interfaces on the web are just lists of elements. You click one, and you are taken to a subsequent "card" page with the properties of the item. Simple enough, right? Well...not always. While this approach works for web pages on your 21-inch monitor, it is less effective on a cell phone, where both navigation and real estate are more limited.

In this article we explore an alternative SVG-based interface for displaying summary lists and detail pages.

The Goal

Our goal is to combine the context provided by summary lists with the detail provided by a "properties" view. The main issues we will have to tackle are screen size and limited navigation. In other words, our goal is to be able to read a UBL invoice in a small cell phone screen, while we have one hand on the wheel.

Important Considerations

Some important considerations that influenced the design are worth mentioning:

  • Invoices and other documents have deeply-nested representations on XML, but as humans we don't need to think of them (or represent them) deeply nested.

  • Numbered lists and breadcrumbs are the bread and butter of context-keeping in web interfaces, but they need not be the only way. A particularly good mechanism for keeping a sense of position within the list is to keep collapsed titles of items before and after the "expanded" item. That is the essential mechanism we use in this article.

  • While you can just point and click on a web list, you have to sequentially go through the items on your cell phone before you get to the one you want. This emphasizes the need to be able to get back to the original point after you explore an item. Coming back just to the list (as we do on the web) is not acceptable.

  • Finally, a disclaimer: In this article I concentrate on explaining the SVG and JavaScript of the interface, assuming we already have blocks of SVG text with the right data to display. We will not deal with where the data comes from now; maybe we'll do that in the next article.

Arranging and Rotating Items

The way we achieve the effect of items moving up and down through an arc is by placing them around a circle. We control the effect by varying the diameter and center of the circle as well as the separation angle between items.

circle
Figure 4. Impact of diameter/position/separation angle

The code for moving an item around in a circle with JavaScript is conceptually simple:

  • Get the element using getElementByID

  • Calculate the next intermediate position by modifying the angle at which the item is standing

  • Translate the object to the next intermediate position

  • Sleep for a while and repeat the process until the element reaches the final desired angle

The actual code is a little more complicated because of JavaScript idosyncrasies, such as having to implement the wait with a recursive call to setTimeOut(circle(),10) instead of the more Java-like Thread.sleep(10);. In any case, the code (Listing 1) is simple enough.

// Get the SVG element to rotate around
summaries[0] = root.getElementById("summary_1");

var angle = 0;

circle(360);

function circle (degreesLeft) 
{
    if (degreesLeft-- == 0) 
	return;

   angle += 1; 
   var matrix = target.getCTM();
   offset.x = center.x + radius*Math.cos(angle*Math.PI/180);
   offset.y = center.y + radius*Math.sin(angle*Math.PI/180);
   target.setAttribute('transform', 
	  	      'translate(' + offset.x + ',' + offset.y + ')');
   window.setTimeout("circle("+ --iterations +")",10);
}

Listing 1. Rotate around a circle

By the way, in this article I'm sticking to JavaScript for the animations, but they can certainly be done declaratively with SVG. An example of how to do an equivalent rotation declaratively can be found on the color wheel example of my SVG and Type article.

Moving Items Up and Down

To move items up and down, we just have to loop through each one of them, changing their angles. The next version of our circle function looks like Listing 2. Note that we've added a clockwise argument to control the direction of the spin.

function circle(iterations,clockwise) 
{
    if (iterations == 0)
	return;

    angle = angle + (clockwise ? stepSize : -stepSize);

    for(var i=0; i <= 5; i++)
    {
	var matrix = summaries[i].getCTM();
	var itemAngle = angle + separation*i;
offset.x =center.x + radius*Math.cos(itemAngle*Math.PI/180);
offset.y =center.y + radius*Math.sin(itemAngle*Math.PI/180);

	moveSVGItemTo(summaries[i],offset.x,offset.y);
    }
    window.setTimeout("circle("+ --iterations +","+
		      clockwise+")",10);
}

Listing 2. Rotate all items

Gathering Elements

As you may have noticed in Listing 2, we are now getting the SVG elements from an array called summaries. This array depends on the SVG document that contains elements like Listing 3:

<g id="summary_0">
  <text x="0" y="0">
    <tspan style="fill:#888888;">Invoice #</tspan>
    00645</text>
</g>
<g id="summary_1">
  <text x="0" y="0">
    <tspan style="fill:#888888;">Buyer</tspan>
  Samuel Fisher</text>
</g>
<g id="summary_2">
  <text x="0" y="0">
   <tspan style="fill:#888888;">Seller</tspan>
  HBO Store</text>
</g>
<g id="summary_3">
  <text x="0" y="0">
    <tspan style="fill:#888888;">Transport</tspan>
UPS Ground</text>
</g>

Listing 3. SVG declaration for summaries

Here is what we do to populate the summaries array:

var listSize  = 10;
var summaries = new Array(listSize);
var contents  = new Array(listSize);

for(i=0;i < listSize;i++)
{
  summaries[i] = root.getElementById("summary_"+i);
  window.status = i;
  contents[i]  = root.getElementById("content_"+i);
}

Listing 4. Gathering all elements

Expanding and Collapsing

To expand an item we need, first, to make room for it by rotating up all of items before it by 30 degrees, or whatever our desired degree of separation is, and rotating all of the items after it down.

We can easily achieve this by adding two more parameters to the circle function, telling it the range of items to rotate. Then we can make two calls to achieve the effect:

circle(30,            // angle
          0,          // index in summaries[] of the first
                      // element to move
          itemIndex-1,// index in summaries[] of the last
                      // element to move
          false       // counter-clockwise
          );

   circle(30,itemIndex+1,listSize-1,true);

Listing 5. Rotate all items

Showing the Expanded Item

To show the expanded item, we just set its visibility to "visible" while hiding the summary. Since we are doing this from JavaScript, the syntax can be a little inelegant, but it's still understandable:

 function moveSVGItemTo(element,x,y)
{
   element.setAttribute("transform", 
                          "translate(" + x + "," + y + ")");
}

function SVGItemVisible(element,visible)
{
   element.setAttribute("style", visible ?
                "visibility:visible" : "visibility:hidden");
}
 
Listing 6. Altering the attributes of an element from JavaScript

Polishing and Refactoring

At this point we have all the building blocks of our strategy: we can rotate items up and down, we can expand and collapse, and we can show/hide the elements. From here on, the changes in the code (Listing 7) are mainly checks on boundaries, and a little polishing with helper functions. You can see the complete code for the SVG here and the complete code for the JavaScript here.

function oneClickDown()
{
    if(centralItem == lastItem)
	return;

    var wasExpanded = expanded;
    collapse();

    rotateItems(0,lastItem,false);	

    startAngle -= separation;
    centralItem++;
}


function rotateItems(start,end,clockwise)
{
    circle(separation/stepSize, start, end, clockwise,
                                            startAngle, 10);
}


function expand()
{
    if(expanded)
	return;

    if(centralItem > 0)
      circle(separation/stepSize, 0, centralItem-1, false,
                                 startAngle-separation, 10);
								 
    if(centralItem < lastItem)
      circle(separation/stepSize, centralItem+1,lastItem,
                           true, startAngle+separation, 10);

    SVGItemVisible(summaries[centralItem],false);
    SVGItemVisible(contents[centralItem],true);

    expanded = true;
}


function circle(iterations,startIndex,endIndex,clockwise,
                                              angle,timeout) 
{
    if (iterations == 0)
    {
	working = false;
	return;
    }

    working = true;
    angle = angle + (clockwise ? stepSize : -stepSize);

    for(var i=startIndex; i <= endIndex; i++)
    {
	var matrix = summaries[i].getCTM();
	var itemAngle = angle + separation*i;
	offset.x= center.x+radius*Math.cos(itemAngle*Math.PI/180);
  offset.y= center.y+radius*Math.sin(itemAngle*Math.PI/180);

	moveSVGItemTo(summaries[i],offset.x,offset.y);
    }
    window.setTimeout("circle("+ --iterations +","+
	              startIndex+","+
		      endIndex+","+
		      clockwise+","+	
		      angle+","+
		      timeout+")",timeout);
}

Listing 7. Final versions of circle and helper functions

Finally, we have an interesting result where detail and context can coexist in a small space.

The (Bittersweet) Icing on the Cake

The ideal icing on the cake would be mapping the keys on the numeric keyboard so we capture the event (note that this only works if the mouse is over the SVG window,) and simulate the whole phone experience instead of doing point-and-click on the "phone keys."

The problem is that the keys on the numeric keyboard are "flipped" compared with those of a phone. So, I will provide the code (Listing 8) but you will have to provide the suspension of disbelief and press 8 while thinking you are pressing 2.

 function getKey(evt) 
{
   var keyCode = evt.getCharCode();
   switch(keyCode)
   {
      case 56:
        oneClickUp();
	break;
      case 50:
        oneClickDown();
	break;
      case 52:
        collapse();
	break;
      case 54:
        expand();
	break;
   }
   var keyString=String.fromCharCode(keyCode).toLowerCase();
   window.status = keyCode;
}

Listing 8. Altering the attributes of an element from JavaScript

Also in Sacré SVG

SVG At the Movies

Mobile SVG

SVG and Typography: Animation

Going Mobile With SVG: Standards

SVG and Typography: Bells and Whistles

SVG Essentials

Related Reading

SVG Essentials
By J. David Eisenberg


Comment on this articleShare your experience in our forums.
(* You must be a
member of XML.com to use this feature.)
Comment on this Article


Titles Only Full Threads Newest First
  • christmas lights installation los angeles 310-925-1720
    2008-11-20 12:32:32 orellytos [Reply]

    christmas lights installation los angeles 310-925-1720
    http://www.christmaslightinstallationlosangeles.blogspot.com/
    (Lets lights, light up your Christmas)


    Use a combination of candles and lights for Christmas decor.Lighting has almost taken over Christmas candles as they burn for longer periods of time and are comparably safer for decoration purposes. Especially Christmas trees have turned more charming, sparkling and magical with light strands illuminating them. With time, the art of installing Christmas lights has evolved to the level where it has become an art in itself. Lets see how to choose the color or combination of color of lights, check for the load of electricity that you can safely use, the different patterns in which to arrange the strings of light and how to install Christmas lights.



    (These types of Innovative lights will definetly add to your Christmas decor)



    Here are the tips to use:



    The most common color combinations appropriate for the Christmas season include red, green and copper lights that denote festivity; blue and green lights for more subdued arrangements; novelty combinations such as blue and red lights; and mauve, blue and copper lights.
    While you can use a combo of as many as five colors for coniferous trees, use not more than three colors for deciduous trees.
    Any color of light used with white does not show itself well, so if are planning to use white lights, stick to the monochromatic scheme.
    Use low watt bulbs for strings and indoor light decoration but you will need high watt bulbs for outdoor decorations and lights that will be viewed from a distance.
    Dip the socket end of the light bulb in petroleum jelly before fitting it into the socket string. This will prevent corrosion in the socket and will make it easier to pull out the bulb from it later.
    Tape all connections well with electrical tape to avoid short-circuits.
    Lights installed on the trees to keep up with its growth look quite graceful.
    Do not try to climb the branches of the tree you want to decorate. Use stepladder instead.
    Work on the tree from top to bottom and from inside to outside for ease of work and safety purposes.


    The best advice when it comes to Christmas decorating is "plan ahead". Decide whether you plan to use Christmas decors both indoors and outdoors, how many you'll need and where you'll place them. Decide whether each room will have a unique decor theme or if one theme will carry from room to room. As you can see there is a lot to consider when it comes to Christmas decorating. While some people love the spontaneous approach, others hate it. If you're one of the latter, make a detailed plan. This is especially true if you have a sophisticated theme in mind for your Christmas decors. Everyone has driven past lawns with the most beautifully laid out decor. Do you think they just threw those decor up? Probably not. They were probably working from a rough floor plan.



    (Lights add new dimensions to outdoor christmas decor)



    You Can’t Go Wrong



    If, however, you're a spontaneous decorator, simply go where your imagination takes you. Does the stairway need some garland? Sure, why not! How about a mantle full of nutcracker dolls? Maybe some Christmas candles on that table would look great. When it comes to Christmas decorations, there is no right or wrong way to approach it. Christmas is a rich holiday full of many diverse traditions. Express it in the way that is uniquely you; use any or as many Christmas decor as you want



    Do post your comments and shre your ideas . If you have any special query feel free to mail me. Look out for these Special Christmas blogs



    Christmas tree decoration
    Christmas Crafts
    Themes for Christmas Party


    Hope these Christmas lights light up your Christmas and your life.
    Welcome: Holiday lights Christmas lights (also sometimes called fairy lights, twinkle lights or holiday lights in the United States) are strands of electric lights used to decorate homes, public/commercial buildings and Christmas trees during the Christmas season. Christmas lights come in a dazzling array of configurations and colors. The small "midget" bulbs commonly known as fairy lights are also called Italian lights in some parts of the U.S.,


    Experience pays off! Our experience can save you hundreds, if not thousands, of dollars by determining the best combination of services to meet your needs — that means every project we build is customized for you, not all home Christmas lights decorations project are identical.


    We are known for our reliability, superior workmanship & impeccable service. Using only quality materials, our standards of excellence provide you the most return for your investment. Over the years, we have developed a deep respect for the importance of individual expression in home Christmas lights decor. Right from the start of every project, we strive to fully understand and incorporate your individuality into every phase of planning, design and Christmas lights Sale and decorations.


    We offer the following Products and Services:
    Christmas Lighting New inside / outside christmas planter that lights up


    Christmas tree sale and decoration


    Full service sales and installation departments


    Custom pole-mounted banner sales and installation


    Large animated holiday displays


    Custom holiday displays


    Leasing and rental programs


    In house graphic arts department


    Knowledgeable and helpful year round staff
    Lvhsystems
    full-service approach begins with the assignment of a project manager, engineer, and draftsman who work closely with you throughout the process to ensure a design reflective of your aesthetic preferences, programming that meets your control requirements, and an Christmas Lighting installation that is efficient and trouble-free. This level of client commitment and systems expertise allows Lvhsystems to stand apart as a premier integrator of design home Christmas lights decoration and solutions throughout the southern California communities of Los Angeles, Santa Monica, Beverly Hills, Calabasas, Agoura Hills, Woodland Hills, Pasadena, Burbank, Glandale and Sherman Oaks.


    To learn more about Lvhsystems complete line of home automation products and services,call 1-818-386-1022
    http://christmaslightinginstall.blogspot.com/

  • Carpet Cleaners los angeles 1-818-386-1022
    2008-09-28 15:43:45 0 [Reply]

    Carpet Cleaners los angeles 1-818-386-1022
    Los Angeles Carpet Cleaning services is the place for carpet cleaning, upholstery cleaning and air duct cleaning needs. Come see the experts at carpet cleaning, Spot and Stain Removal Pet Stain and Odor Removal, upholstery cleaning, tile and grout cleaning and stain removal. Learn about our two-step process and satisfaction guarantee. We have expert carpet cleaners, upholstery cleaners and air duct cleaners standing by! call 1-818-386-1022