Wednesday, May 25, 2011

pv.scale.Ordinal & splitBanded function


pv.scale.Ordinal represents an ordinal scale. An ordinal scale represents a pairwise mapping from n discrete values in the input domain to n discrete values in the output range.

pv.Scale.ordinal generate a pair mapping function from input domain to output range
splitBanded(min, max, band) function

Sets the range from the given continuous interval. The interval [min, max] is subdivided into n equispaced bands, where n is the number of (unique) values in the domain. The first and last band are offset from the edge of the range by the distance between bands.

The band width argument, band, is typically in the range [0, 1] and defaults to 1. This fraction corresponds to the amount of space in the range to allocate to the bands, as opposed to padding. A value of 0.5 means that the band width will be equal to the padding width. The computed absolute band width can be retrieved from the range as scale.range().band.

If the band width argument is negative, this method will allocate bands of a fixed width -band, rather than a relative fraction of the available space.

Tip: to inset the bands by a fixed amount p, specify a minimum value of min + p (or simply p, if min is 0). Then set the mark width to scale.range().band - p.

This method must be called after the domain is set.


pv.Scale.ordinal("ABCDE".split("")).splitBanded(0, 500, 0.8)


Sample Code :

<html>
<head>
<script type="text/javascript"  src="protovis-r3.2.js"></script>
<title>pv.Scale.ordinal</title>
</head>
<body>
<div id="pesan">
</div>
<script type="text/javascript+protovis"
    var ordinalidx = "ABCDE".split("");
    var x = pv.Scale.ordinal(ordinalidx).splitBanded(05000.8);

    document.getElementById("pesan").innerHTML 
        += "ordinalidx = " + ordinalidx + "<BR />";
    document.getElementById("pesan").innerHTML 
        += "band width = " + x.range().band + "<BR />";

    document.getElementById("pesan").innerHTML 
        += "x['A'] = " + x('A') + "<BR />";
    document.getElementById("pesan").innerHTML 
        += "x['B'] = " + x('B') + "<BR />";
    document.getElementById("pesan").innerHTML 
        += "x['C'] = " + x('C') + "<BR />";
    document.getElementById("pesan").innerHTML 
        += "x['D'] = " + x('D') + "<BR />";
    document.getElementById("pesan").innerHTML 
        += "x['E'] = " + x('E') + "<BR />";
    /*
    */

</script>
</body>
</html>


Result :

ordinalidx = A,B,C,D,E
band width = 88.23529411764707
x['A'] = 9.80392156862745
x['B'] = 107.84313725490196
x['C'] = 205.8823529411765
x['D'] = 303.921568627451
x['E'] = 401.9607843137255

No comments:

Post a Comment