Help overriding function

49 views
Skip to first unread message

Simon Johnson

unread,
Jul 24, 2015, 1:40:45 PM7/24/15
to dc-js user group
Hi,

I want to tweak dc.leaflet.js so that the rendering accepts an existing leaflet map object for the chart creation rather than creating a new one.

I am attempting this by trying to override the chart's render function to now include the generated map object.  This works if I substitute _chart variable for the chart.  At the moment I'm commenting out other variables such as _listeners and _legend to get it working.  I'm not sure how to reference these as they are out of scope and they are not in the chart object.  Any pointers on how to reference them?  


    whereChart.render = function () {
        console.log(this);
        //_listeners.preRender(_chart);

        //if (whereChart._mandatoryAttributes)
        //    whereChart._mandatoryAttributes.forEach(checkForMandatoryAttributes);

        var result = whereChart._doRender(mapObject);

        //if (_legend) _legend.render();

        whereChart._activateRenderlets("postRender");

        return result;
    };

Gordon Woodhull

unread,
Jul 24, 2015, 2:15:18 PM7/24/15
to dc.js user group
Hi Simon,

It can get hard to replace methods when they access private variables.

As it happens, I just updated the dc.js community fork of dc.leaflet.js today, to make it more modular and to encorporate @monostop's fixes to make it work with dc.js 2.0. 

And I added a createLeaflet customization point, so you can replace the method which starts leaflet.

Would you please try it out? The differences are that it now requires dc.js 2.0+, and that the namespace is now dc_leaflet (dc_leaflet.choroplethChart, etc.).


Cheers,
Gordon



--
You received this message because you are subscribed to the Google Groups "dc-js user group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dc-js-user-gro...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dc-js-user-group/7493811d-95c8-4617-96a7-d49e818d1724%40googlegroups.com.

Simon Johnson

unread,
Jul 27, 2015, 5:37:40 AM7/27/15
to dc-js user group, gor...@woodhull.com
Hi Gordon,

This is fantastic timing.  Thank you.  I will try to implement this version into my dashboard this week.  Thanks again for the work you are putting in.  DC.js is getting quite popular and good usage in the humanitarian sector now!

Simon

Simon Johnson

unread,
Jul 30, 2015, 11:46:53 AM7/30/15
to dc-js user group, gor...@woodhull.com, simonb...@gmail.com
Hi Gordon,

I haven't had a chance to try this particular version of the extension as I used my tweaked version as under time pressure.  I did, however, use the same method of createLeaflet customization point.  My feedback on this is that it needs to include the creation/adding of tiles and setting the zoom as these could already be set when the map has been created before DC is used.

I'll try to use the community fork next week and make a PR if you want.

Thanks

Simon

Gordon Woodhull

unread,
Jul 30, 2015, 12:21:09 PM7/30/15
to Simon Johnson, dc.js user group
Thanks Simon, a PR would be very helpful.

If you have any humanitarian examples for the wiki, that would be awesome.

anmol koul

unread,
Aug 10, 2015, 10:08:17 AM8/10/15
to dc-js user group, simonb...@gmail.com
Hey Gordon,

There was a dc-leaflet integration by Yurukov. Any chance that will be integrated sometime?
Just curious.

Cheers,
Anmol

anmol koul

unread,
Aug 10, 2015, 10:11:19 AM8/10/15
to dc-js user group, simonb...@gmail.com
Hey Gordon,

More like is that the best dc-leaflet integration that we have till now?
I have been out of touch for some time now. Need to start building geo-charts and looking for a dc based leaflet integration.

Cheers,
Anmol

On Thursday, July 30, 2015 at 9:51:09 PM UTC+5:30, Gordon Woodhull wrote:

Gordon Woodhull

unread,
Aug 10, 2015, 11:02:44 AM8/10/15
to dc.js user group, simonb...@gmail.com
Yes, as mentioned below, I've started a community fork of the project, here:


It is fully updated for dc.js 2.0 (beta). 

It will remain a separate project because of the extra dependency.


Gordon Woodhull

unread,
Aug 10, 2015, 11:03:56 AM8/10/15
to dc.js user group, simonb...@gmail.com
I'm sure you can find other features out there on the web, since doing this integration isn't terribly difficult. What features in particular are you looking for?


anmol koul

unread,
Aug 17, 2015, 3:10:39 PM8/17/15
to dc-js user group, simonb...@gmail.com
Just the standard aggregations, Gordon. Essentially rolling sum and averages. The markers at the map level should show aggregated values rather than individual data points. I think this version takes care of that. :)
Reply all
Reply to author
Forward
0 new messages