views:

164

answers:

1

I use jqGrid with many columns contains Boolean information, which are displayed as checkboxes inside of table (see http://www.ok-soft-gmbh.com/VerticalHeaders/TestFixedO.htm as an example). To display information more compact I use vertical column headers. It works very well and works in jqGrid in all browsers (see my discussion with Tony Tomov in jqGrid forum http://www.trirand.com/blog/?page_id=393/feature-request/headers-with-vertical-orientation/), but in IE vertical texts are blur and look not nice enough (open the link above in IE and you will see exactly what I mean). I was asked from users why the texted displayed so strange. So I think about using a JavaScript based SVG library like SVG Web ( http://code.google.com/p/svgweb/ ) or Raphaël ( http://raphaeljs.com/ ). SVG is very powerful and it is difficult to find a good example is not very easy. I need only display vertical texts (-90 grad, from bottom to up) and use if possible without working in mode of absolute position.

So one more times my question: I need have a possibility to display vertical texts (-90 grad rotation) inside of <td> element of table header. I want use a JavaScript based SVG library like SVG Web or Raphaël. The solution must support on IE6. Have somebody a good reference to example which could help me to do this? If somebody post a whole solution of the problem I would be happy.

To be exact here is my current solution: I define

.rotate 
{
    -webkit-transform: rotate(-90deg);    /* Safari 3.1+, Chrome */
    -moz-transform: rotate(-90deg);    /* Firefox 3.5+ */
    -o-transform: rotate(-90deg); /* Opera starting with 10.50 */
    /* Internet Explorer: */
    filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3); /* IE6, IE7 */
   -ms-filter: "progid:DXImageTransform.Microsoft.BasicImage(rotation=3)" /* IE8 */;
}

define RotateCheckboxColumnHeaders function

var RotateCheckboxColumnHeaders = function (grid, headerHeight) {
    // we use grid as context (if one have more as one table on tnhe page)
    var trHead = $("thead:first tr", grid.hdiv);
    var cm = grid.getGridParam("colModel");
    $("thead:first tr th").height(headerHeight);
    headerHeight = $("thead:first tr th").height();

    for (var iCol = 0; iCol < cm.length; iCol++) {
        var cmi = cm[iCol];
        if (cmi.formatter === 'checkbox') {
            // we must set width of column header div BEFOR adding class "rotate" to
            // prevent text cutting based on the current column width
            var headDiv = $("th:eq(" + iCol + ") div", trHead);
            headDiv.width(headerHeight).addClass("rotate");
            if (!$.browser.msie) {
                if ($.browser.mozilla) {
                    headDiv.css("left", (cmi.width - headerHeight) / 2 + 3).css("bottom", 7);
                }
                else {
                    headDiv.css("left", (cmi.width - headerHeight) / 2);
                }
            }
            else {
                var ieVer = jQuery.browser.version.substr(0, 3);
                // Internet Explorer
                if (ieVer !== "6.0" && ieVer !== "7.0") {
                    headDiv.css("left", cmi.width / 2 - 4).css("bottom", headerHeight / 2);
                    $("span", headDiv).css("left", 0);
                }
                else {
                    headDiv.css("left", 3);
                }
            }
        }
    }
};

And include a call like RotateCheckboxColumnHeaders(grid, 110); after creating jqGrid.

A: 

Canvas text transformations example

            <!--[if IE]><script type="text/javascript" src="../excanvas.js"></script><![endif]-->
<script type="text/javascript" src="../canvas.text.js"></script>
<script type="text/javascript" src="../faces/dejavu_sans-normal-normal.js"></script>
<script type="text/javascript" src="../faces/dejavu_sans-bold-normal.js"></script>
    </head>
    <body>
            <canvas width="500" height="300" id="test-canvas" style="font-size: 16px;"></canvas>

            <script type="text/javascript">
                function initCanvas(canvas) {
                    if (window.G_vmlCanvasManager && window.attachEvent && !window.opera) {
                        canvas = window.G_vmlCanvasManager.initElement(canvas);
                    }
                    return canvas;
                }

                window.onload = function() {
                    var canvas = initCanvas(document.getElementById("test-canvas")),
                                ctx = canvas.getContext('2d');

                    ctx.strokeStyle = "rgba(255,0,0,1)";
                    ctx.fillStyle = "rgba(0,0,0,1)";
                    ctx.lineWidth = 1;
                    ctx.font = "20pt Verdana, sans-serif";
                    ctx.strokeStyle = "#000";
                    ctx.rotate(Math.PI / 2);
                    ctx.fillText('Vertical', 0, 0);
                    ctx.restore();
                }
            </script>
    </body>

XGreen
I know that the problem which I asked for can be solved. You suggest HTML5 technique. It looks close to using JavaScript based SVG library, but your links are too general. I need at least an example of usage this technique for rotated textes. Could you give me more exact reference? Is it works for IE6?
Oleg
updated now with code sample
XGreen
find more information on http://code.google.com/p/canvas-text/
XGreen
Thank you for the example, but I am a little disappointed from canvas. 1) in this example font size is fixed 16px and look like bad after scaling with Ctrl+'+' (my old solution can be perfect scaled in all browsers excepted IE). It is the most important disadvantage. 2) I wrote that I need -90 grad rotation and not 90 grad. Changing from Math.PI/2 to -Math.PI/2 or 3*Math.PI/2 not works. 3) All coordinates seems be ABSOLUTE and not relative, which makes placing the text inside of table header more complex. Perfect for me is if I could use in my CSS "transform: rotate(-90deg);" from CSS3, but...
Oleg