JsInterop wrapping of D3 js

71 views
Skip to first unread message

Tim Macpherson

unread,
Dec 4, 2025, 2:29:05 PM (5 days ago) Dec 4
to GWT Users
There was one but d3 requires following the js samples.
I am having to use typescript to make sense of my extensive D3 js code. 
I'm now thinking seems like TS is coercing  new writers of js to write more like Java because the old style 'duck typing' chaining methods can't be typed by TS

(written on phone, sorry about typos)

Vassilis Virvilis

unread,
Dec 4, 2025, 2:54:53 PM (5 days ago) Dec 4
to google-we...@googlegroups.com
I have a ~750 LOC file that maps the subset my application uses of an older version (3.5.x) of D3 to jsinterop.

I managed to write Java in a very javascript way with this. Chaining was also working. If you return a Selection object everything works as expected. Transforming the JS examples was very straightforward with minimal changes.

I have even filed a bug report when I had hit GWT limitations... https://github.com/gwtproject/gwt/issues/9675

I always wanted to clean it up, update it to the latest D3 and post it as OpenSource in Github but I never found the time...

    Vassilis

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-tool...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/google-web-toolkit/575562369.7270741.1764876458368%40mail.yahoo.com.


--
Vassilis Virvilis

Tim Macpherson

unread,
Dec 4, 2025, 3:09:44 PM (5 days ago) Dec 4
to google-we...@googlegroups.com
For you the chaining patterns are ok in  java ? I have several thousand lines of D3 js code, all written in Java patterns with little chaining. Converting it to TS is tedious but every step makes the codebase easier in the ide.
AI told me the d3 lib by Bostock can't be  in TS if anyone wants to edit it, we just get TS types from it

Vassilis Virvilis

unread,
Dec 4, 2025, 3:22:58 PM (5 days ago) Dec 4
to google-we...@googlegroups.com
To be honest not really no.

I didn't like the chaining pattern when I saw it initially. If there was a jfreechart (https://www.jfree.org/jfreechart/) like library back then I would use it. Now it looks like there is one: https://github.com/jfree/jsfreechart Wow!

But...

D3 is built around the selection object - exactly like jQuery. This presents some interesting capabilities.

For example you can have a big table and D3 will read the data from there. There is no need to duplicate the data, to sync them etc.

Furthermore the possibility to transform any random js example on the web in GWT java quickly, was a productivity boost.

That approach really paid off also for debugging. Consider the following case. D3 java does not work. What's the problem? Is it the bindings? Let's create a small example in js and run it natively. If it works it's the binding's fault. If it doesn't work then it is the way we use D3 or worse a D3 bug.

So I believe it was a pragmatic approach. We could use D3 docs, D3 examples etc.

Hope that helps.

   Vassilis











--
Vassilis Virvilis

Tim Macpherson

unread,
Dec 4, 2025, 3:42:37 PM (5 days ago) Dec 4
to google-we...@googlegroups.com
off subject for the group maybe, I have to use d3 in TS for  new projects,  no problem just wondering why the d3 lib is not released in TS ? because it's impossible to type probably, too old fashioned js.
On Thu, Dec 4, 2025 at 8:22 PM, Vassilis Virvilis

Tim Macpherson

unread,
Dec 5, 2025, 1:13:18 PM (5 days ago) Dec 5
to google-we...@googlegroups.com
Question  possibly of interest is how GWT stands against Typescript which seems to be now established as a  front end standard. 
Observations so far: 
1) refactoring in vscode with TS built in or eclipse with the TS plugin: is very poor compared to GWT in eclipse. 
2) Typing in TS ... 
On Thu, Dec 4, 2025 at 8:41 PM, 'Tim Macpherson' via GWT Users

RobW

unread,
Dec 6, 2025, 4:42:49 AM (4 days ago) Dec 6
to GWT Users
Question  possibly of interest is how GWT stands against Typescript which seems to be now established as a  front end standard. 

I'm really not sure why Typescript is relevant - if I were coding front-end in JS or TS, then yes I'd think about which syntax and features (type checking etc) were better. But in GWT I'm coding in Java. I don't really care what the compiles down to as long as it works. OK, when debugging I do see the JS output, but I'm never mod'ing that directly. On occasion, to use a lib, I'll quickly craft some JSNI bindings for the methods I need. But that's as close as I go to the JS layer. 

Tim Macpherson

unread,
Dec 6, 2025, 2:13:13 PM (3 days ago) Dec 6
to google-we...@googlegroups.com
I'm using GWT and TS together, both involve static typing and ide support around that. Basic question is: does anyone else do this (I assume yes) and how do they compare?

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-tool...@googlegroups.com.
To view this discussion visit

Craig Mitchell

unread,
Dec 8, 2025, 6:46:43 PM (2 days ago) Dec 8
to GWT Users
I'm not sure I understand the question.  I've used TS in one project, and GWT in another.  Never in the same project.  As far as static typing goes, Java (GWT) wins hands down, as it is a native to the language.

Tim Macpherson

unread,
Dec 9, 2025, 1:07:55 PM (13 hours ago) Dec 9
to google-we...@googlegroups.com
As a  GWT user also using TS when necessary:
refactoring: WWD in eclipse for TS,  vs  VScode, no noticeable difference  ? essentially nothing useful in either ?
Typing - all must be done manually, syntax is  back to front: name then type.

Why did Google drop GWT for it to be superceded by this?
About the same time they were trying to launch Dart but that went nowhere afaik

Craig Mitchell

unread,
Dec 9, 2025, 6:46:54 PM (7 hours ago) Dec 9
to GWT Users
Re: Why did Google drop GWT for it to be superceded by this?

My 2 cents worth of guessing is that because GWT protects developers from learning all about JS, developers might not get the most out of JS.  Eg: A Java developer sees no issue using integers, but JS doesn't support them, so GWT adds complexity in JS to simulate them.  Companies that want the bleeding edge performance might not like this.

But, as I said, I'm only guessing here, I've never worked at Google.

Colin Alworth

unread,
Dec 9, 2025, 9:59:40 PM (4 hours ago) Dec 9
to GWT Users
It is probably worth noting that while Google did drop GWT the compiler and runtime, they continue to ship GWT's JRE emulation in Google Sheets and Gmail (via J2CL and Closure Compiler) in decently large JS files, with a lot of other code that plausibly looks like it shares (1000+ classes each). Java's distinctive Object.toString() behavior makes it pretty easy to find in compiled JS. As Google has described in the past, this lets them write the core runtime for an app in a single language, Java, and translate to build the UI in the most appropriate language for the platform they are deploying to.

I'm not aware of many GWT apps that are being used like that, but there are some. For one of them, we built and open sourced https://github.com/Vertispan/jsinterop-ts-defs/ to do the opposite of what you're discussing with d3.js - take Java types with some JsInterop annotations, and generate .d.ts files from them. This way, JS/TS developers can import those types and get rich type information about the Java we compiled to JS. There are a few custom annotations that we've found helpful to add on, but for the most part this tool works with any GWT app using JsInterop to expose some classes/functions as a library.

I don't think that is what Google is doing - mostly because they've historically resisted efforts to generate externs from JsInterop, preferring to read Closure-annotated JS and generate Java from it. It has worked well for us though, as there aren't a lot of JS/TS projects outside of Google that are suitable to being passed through Closure on their way to production.
Reply all
Reply to author
Forward
0 new messages