Vertical text inside table headers using a JavaScript-based SVG library

前端 未结 2 1808

I use jqGrid with many columns containing boolean information, which are displayed as checkboxes inside the table (see http://www.ok-soft-gmbh.com/VerticalHeaders/TestFixedO

相关标签:
2条回答
  • 2020-12-10 07:07

    Here's a working jsfiddle that does it. It should work in IE 6, I only used jquery and raphael js. I made static sizes for the raphael drawing area and the text, but you can certainly do a little math to figure out dynamic sizes:

    http://jsfiddle.net/UYj58/9/

    Code looks like this if you include jquery and raphael:

    $(document).ready(function(){
        var font = {font: '12px Helvetica, Arial'};
        var fill = {fill: "hsb(120deg, .5, 1)"}
        $('tr th div').each(function (index, div){
            R = Raphael($(div).attr('id'), 20, 100);
            R.text(4, 50, $(div).find('span').text())
                .attr(font)
                .attr(fill)
                .rotate(-90, true);
            $(div).find('span').hide();
        });
    });
    

    And the HTML looks like this:

    <table>
        <thead>
            <tr>
                <th><div id="columnOne"><span>heading one</span></div></th>
                <th><div id="columnTwo"><span>heading two</span></div></th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>1</td>
                <td>2</td>
            </tr>
            <tr>
                <td>4</td>
                <td>5</td>
            </tr>
        </tbody>
    </table>
    

    Oh, and I used this as my example: http://raphaeljs.com/text-rotation.html

    0 讨论(0)
  • 2020-12-10 07:30

    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>
    

    0 讨论(0)
提交回复
热议问题