raphael4gwt

62 views
Skip to first unread message

Sebastian Gurin

unread,
Jul 30, 2013, 11:20:17 PM7/30/13
to rapha...@googlegroups.com
Hi Geoff, I'm the author of raphael4gwt a library that takes a different approach to port raphaeljs to GWT. It is focused only in a 100% raphaeljs native API using GWT overlays. No dependency on Gwt Widgets, only with gwt.dom.client.

As I understand yours raphaelgwt is focused on integrating raphaeljs shapes with GWT Widgets and uses an internal native API to GWT based on overlay types and raphaeljs 1.x.

Want to tell you two things:

1) feel free to use mine raphael4gwt native API / JavaScriptObjects in your project for supporting latest raphaeljs API

2) one thing to share with you. For graphael that accepts arrays of numbers as parameters, for that to work in GWT I needed to implement the following rphaeljs extensions:


/*
 * These are some fixes that can be done with extensions - this is the only required extension for compliance with GWT (arrays of data in bar charts won't work.)
 * R.is() fix for arrays:     https://github.com/DmitryBaranovskiy/raphael/issues/564
 */
(function() {   
   
    // sgurin: types utils for knowing js types
    Raphael._sg_typesutils = {};
    /**
     * Best guess if object is an array.
     */
    Raphael._sg_typesutils.isArray = function(obj) {
        // do an instanceof check first
        if (obj instanceof Array) {
            return true;
        }
        // then check for obvious falses
        if (typeof obj !== 'object') {
            return false;
        }
        if (Raphael._sg_typesutils.type(obj) === 'array') {
            return true;
        }
        return false;
    };
    /**
     * Attempt to ascertain actual object type.
     */
    Raphael._sg_typesutils.type = function(obj) {
        if (obj === null || typeof obj === 'undefined') {
            return String(obj);
        }
        return Object.prototype.toString.call(obj).replace(
                /\[object ([a-zA-Z]+)\]/, '$1').toLowerCase();
    };

    //names from raphael.js
    var objectToString = Object.prototype.toString,
        lowerCase=String.prototype.toLowerCase,
        isnan = {"NaN": 1, "Infinity": 1, "-Infinity": 1},
        has = "hasOwnProperty";
       
    Raphael.is = function(o, type) {
        type = lowerCase.call(type);
        if (type == "finite") {
            return !isnan[has](+o);
        }
        if (type == "array") {
            // return o instanceof Array;
            return Raphael._sg_typesutils.isArray(o); // sgurin fix
        }
        return (type == "null" && o === null)
                || (type == typeof o && o !== null)
                || (type == "object" && o === Object(o))
                || (type == "array" && Array.isArray && Array.isArray(o))
                || objectToString.call(o).slice(8, -1).toLowerCase() == type;
    };   
})();


Well hope that this can help you. Regards.
Reply all
Reply to author
Forward
0 new messages