< Return to Video

Data Visualizations and Maps with JavaScript - TalkJS

  • 0:00 - 0:11
    slides now yes can see the slice so
  • 0:08 - 0:15
    let's start the talk now
  • 0:11 - 0:15
    thank you okay
  • 0:15 - 0:21
    hi I'm William I'm a software developer
  • 0:19 - 0:24
    and today I'm gonna be talking about
  • 0:21 - 0:36
    data visualizations and maps with
  • 0:24 - 0:43
    JavaScript so I'm going to show you
  • 0:36 - 0:49
    something similar to this today it's
  • 0:43 - 0:51
    it's blurry and but I'll show the real
  • 0:49 - 0:58
    thing later and there are problems with
  • 0:51 - 1:12
    mine I'm not sure if I can you can see
  • 0:58 - 1:15
    oh gosh I don't know if can you see we
  • 1:12 - 1:22
    still see the cuz the slide with the
  • 1:15 - 1:22
    market after with the smack manually
  • 1:24 - 1:27
    [Music]
  • 1:44 - 1:51
    honest I think that's better so I can
  • 1:47 - 2:00
    yes I can I can now switch now you can
  • 1:51 - 2:02
    see so if you look like on one map fuck
  • 2:00 - 2:05
    you see I'm not sure I've done something
  • 2:02 - 2:15
    wrong or that box does this like the D
  • 2:05 - 2:18
    is cut off in New Zealand I'm sorry
  • 2:15 - 2:21
    about this like write down some notes
  • 2:18 - 2:23
    inside my slides it's because this talk
  • 2:21 - 2:27
    has been postponed quite a few times I
  • 2:23 - 2:30
    might forget I might forget what I want
  • 2:27 - 2:32
    to say in the presentation
  • 2:30 - 2:38
    [Music]
  • 2:32 - 2:43
    here's another another interesting thing
  • 2:38 - 2:44
    to look at if you can't see it it's fine
  • 2:43 - 2:48
    [Music]
  • 2:44 - 2:53
    here it is zoomed in there's there's a
  • 2:48 - 3:01
    problem here with a data visualization
  • 2:53 - 3:01
    given by Channel NewsAsia like this
  • 3:04 - 3:10
    there's supposed to be something here
  • 3:07 - 3:12
    but there's none and I think it's it's
  • 3:10 - 3:15
    just a mistake I think I mean they
  • 3:12 - 3:19
    probably didn't really care about it I
  • 3:15 - 3:21
    guess so
  • 3:19 - 3:24
    what I want to say is that every
  • 3:21 - 3:27
    everybody makes mistakes and I'll be I
  • 3:24 - 3:30
    guess this was done using d3 I could I
  • 3:27 - 3:35
    could check now but I have to but I
  • 3:30 - 3:44
    guess it's done I'll talk about d3 again
  • 3:35 - 3:46
    later here is where a lot of these
  • 3:44 - 3:47
    realizations you see now are taken from
  • 3:46 - 3:51
    [Music]
  • 3:47 - 3:54
    this repository and just want to note
  • 3:51 - 4:04
    that this and this notice that there's
  • 3:54 - 4:08
    only one repository and I'm also really
  • 4:04 - 4:14
    grateful for the work and that you can
  • 4:08 - 4:16
    see in this repository although this
  • 4:14 - 4:19
    slides these these slides are going to
  • 4:16 - 4:22
    be up on github later on so you can look
  • 4:19 - 4:28
    at you can look at this after after my
  • 4:22 - 4:36
    job here's the sources that this
  • 4:28 - 4:41
    repository takes from and I I wanted to
  • 4:36 - 4:45
    show this this source this this part of
  • 4:41 - 4:52
    the repository because this is the data
  • 4:45 - 4:59
    that I used in late March and just
  • 4:52 - 5:04
    notice that oh gosh so big
  • 4:59 - 5:08
    late March that you get province and
  • 5:04 - 5:10
    state country-region you know last time
  • 5:08 - 5:13
    they are all these are these are all
  • 5:10 - 5:16
    these these headings and this is your
  • 5:13 - 5:22
    this is your raw data but then on
  • 5:16 - 5:22
    [Music]
  • 5:24 - 5:38
    but then on I think this was one week
  • 5:34 - 5:43
    ago and I'm just guessing that it's the
  • 5:38 - 5:45
    same now the headings have changed and
  • 5:43 - 5:47
    the raw data that you that I pulled from
  • 5:45 - 5:49
    it was different
  • 5:47 - 5:51
    actually a lot of other people pull cool
  • 5:49 - 5:53
    from this data and they create a api's
  • 5:51 - 5:54
    and I've been gonna talk about them
  • 5:53 - 5:57
    later
  • 5:54 - 6:04
    [Music]
  • 5:57 - 6:10
    here's something interesting which oh I
  • 6:04 - 6:14
    think yeah I'll talk about I'll talk
  • 6:10 - 6:17
    about pulling from this from this source
  • 6:14 - 6:23
    later here's this here's this something
  • 6:17 - 6:30
    interesting that I found that I think it
  • 6:23 - 6:36
    looks nice so when you build Maps in
  • 6:30 - 6:41
    JavaScript I I think you look at these
  • 6:36 - 6:47
    map libraries at first so leaflet
  • 6:41 - 6:50
    popularise and later I'm gonna show
  • 6:47 - 6:53
    where I got stuck while using open
  • 6:50 - 6:55
    layers so I ended up using leaflet for
  • 6:53 - 7:01
    speed and it looks like what I wanted to
  • 6:55 - 7:05
    get in the end you'll probably use these
  • 7:01 - 7:05
    map fbi's as well if you working on maps
  • 7:06 - 7:10
    [Music]
  • 7:08 - 7:17
    some some things that you might consider
  • 7:10 - 7:20
    is like pricing so for format box I'm
  • 7:17 - 7:23
    quite scared so for Google Maps you can
  • 7:20 - 7:30
    set daily quotas to protect against
  • 7:23 - 7:32
    unexpected increases so you don't want
  • 7:30 - 7:35
    your billing to suddenly increase
  • 7:32 - 7:35
    without you knowing
  • 7:39 - 7:45
    which which I aced when using map box so
  • 7:43 - 7:47
    it's important to pick the right tool
  • 7:45 - 7:50
    for the right job and don't be like me
  • 7:47 - 7:53
    if you can avoid it I only pick me flirt
  • 7:50 - 7:55
    because I only ended up using leaflet
  • 7:53 - 7:58
    because it works nicely with Matt box
  • 7:55 - 8:05
    and it just got close to results I
  • 7:58 - 8:07
    wanted to get so for security you might
  • 8:05 - 8:12
    want to look at that too like how it
  • 8:07 - 8:16
    deals with tokens and how how each of
  • 8:12 - 8:18
    these map ups deal with security and and
  • 8:16 - 8:24
    how good their documentation is for
  • 8:18 - 8:31
    security so you can link leaflet to
  • 8:24 - 8:34
    Google Maps by using plugins you can
  • 8:31 - 8:40
    also have a look at these are the these
  • 8:34 - 8:48
    are the plugins as well when Apple's map
  • 8:40 - 8:50
    is marketeers in maps like there's
  • 8:48 - 8:54
    comparisons usually between google maps
  • 8:50 - 8:56
    and maps and other map map api is I'm
  • 8:54 - 9:01
    not going to go through that in this
  • 8:56 - 9:04
    talk this talk is just meant for a like
  • 9:01 - 9:14
    things specific to mine to what I wanted
  • 9:04 - 9:17
    to to get if also if there's a plan like
  • 9:14 - 9:20
    this if there's a better API that that
  • 9:17 - 9:21
    um can help with open source projects
  • 9:20 - 9:24
    like what I what I did that would be
  • 9:21 - 9:30
    that would be they'll be best because um
  • 9:24 - 9:32
    I don't want to worry about billing and
  • 9:30 - 9:35
    things like that when I'm doing
  • 9:32 - 9:36
    client-side small small projects open
  • 9:35 - 9:40
    source
  • 9:36 - 9:40
    [Music]
  • 9:40 - 9:46
    so before the demo I just want to say
  • 9:42 - 9:50
    again that if you take data from a
  • 9:46 - 9:51
    repository or Fei be prepared for the
  • 9:50 - 9:55
    data format to change and break your
  • 9:51 - 10:00
    entire app this will tend to happen if
  • 9:55 - 10:00
    you automate pulling fetching the data
  • 10:01 - 10:09
    and not something I consider was like
  • 10:06 - 10:12
    automating the whole process to get the
  • 10:09 - 10:20
    latest to show the latest map and the
  • 10:12 - 10:24
    latest data but after a while I I
  • 10:20 - 10:31
    realized that if you pull from a dynamic
  • 10:24 - 10:35
    API your your app might break it might
  • 10:31 - 10:40
    be inaccurate which is not what not not
  • 10:35 - 10:43
    good for you your users so so if I'll
  • 10:40 - 10:49
    talk about this later in the next slide
  • 10:43 - 10:54
    or now it should also have two changes
  • 10:49 - 10:56
    every day or at shorter intervals if you
  • 10:54 - 10:59
    intend to work a news organization
  • 10:56 - 11:02
    Americans Newton this might be helpful
  • 10:59 - 11:09
    for you this is also helpful for
  • 11:02 - 11:12
    databases in general so something I
  • 11:09 - 11:14
    thought would be nice to have I think
  • 11:12 - 11:19
    it'd be nice to have if you do any of
  • 11:14 - 11:24
    this database in the future is you
  • 11:19 - 11:33
    should let let your users choose the
  • 11:24 - 11:35
    primary location because you look here
  • 11:33 - 11:38
    and and what I want to see is like in
  • 11:35 - 11:43
    the around Singapore just and I get you
  • 11:38 - 11:46
    know this and I feel like slow down get
  • 11:43 - 11:55
    to that at the end it
  • 11:46 - 12:00
    takes time also there are enough
  • 11:55 - 12:04
    existing visualizations online on coca
  • 12:00 - 12:06
    Dorothy please don't add more unless you
  • 12:04 - 12:08
    can maintain it well that's what that's
  • 12:06 - 12:13
    why I'm reluctant to make it to add more
  • 12:08 - 12:16
    to this this this whole thing I'm doing
  • 12:13 - 12:18
    is just a learning tool and it's not
  • 12:16 - 12:40
    well you can use it to deploy something
  • 12:18 - 12:44
    but just maintain it and so when I
  • 12:40 - 12:47
    started off I start off with open I
  • 12:44 - 12:53
    tried I I try to do I try to use both
  • 12:47 - 12:58
    open layers and leaflet this is just to
  • 12:53 - 13:01
    do a comparison for them and I think I
  • 12:58 - 13:04
    tried I tried them both around the same
  • 13:01 - 13:11
    time but what I got for open layers was
  • 13:04 - 13:16
    this what I got in the end what I did
  • 13:11 - 13:18
    was I followed their documentation and I
  • 13:16 - 13:21
    for some reason I did service I would
  • 13:18 - 13:26
    just know not what I wanted and then I
  • 13:21 - 13:30
    did did their client-side thing and that
  • 13:26 - 13:36
    is that's what you get when you get when
  • 13:30 - 13:37
    you use some open open layers yeah
  • 13:36 - 13:42
    that's what you get when you use open
  • 13:37 - 13:47
    layers and open layers compared to
  • 13:42 - 13:53
    leaflet it's nice because like for
  • 13:47 - 13:59
    instance if you want it it localizes the
  • 13:53 - 14:04
    language of locations automatically
  • 13:59 - 14:09
    it gives you if that part of the box for
  • 14:04 - 14:15
    all the different places in the world
  • 14:09 - 14:20
    but the thing is for openlayers I got
  • 14:15 - 14:22
    stuck I got stuck here and like I didn't
  • 14:20 - 14:25
    want to move further because it's just
  • 14:22 - 14:31
    more complicated because I wanted to get
  • 14:25 - 14:31
    something similarly similar to this
  • 14:31 - 14:40
    you're just shown in Channel NewsAsia
  • 14:35 - 14:42
    and I don't I don't mind it looking like
  • 14:40 - 14:44
    this but to get the markers on it's
  • 14:42 - 14:55
    quite difficult I think it was quite
  • 14:44 - 15:02
    difficult so so that's it for open
  • 14:55 - 15:05
    layers so I tried leaflet and oh it's
  • 15:02 - 15:10
    gonna show mm I was gonna show the real
  • 15:05 - 15:13
    like like what I was trying to recreate
  • 15:10 - 15:13
    and it's this this thing that's on
  • 15:13 - 15:21
    channel is it
  • 15:13 - 15:32
    Channel NewsAsia and this mmm kind of
  • 15:21 - 15:36
    kept lucky yeah this is mine it's what I
  • 15:32 - 15:39
    got when I usually flip so
  • 15:36 - 15:48
    when you zoom in you get well you get
  • 15:39 - 15:53
    like the darker red areas are places
  • 15:48 - 15:56
    where it's more affected I guess and
  • 15:53 - 16:00
    then when you zoom in you get a similar
  • 15:56 - 16:00
    thing where you can see for each
  • 16:01 - 16:14
    each country like their current
  • 16:05 - 16:17
    situation and this is March 21st so I'm
  • 16:14 - 16:19
    gonna go through how you can build
  • 16:17 - 16:33
    something like this
  • 16:19 - 16:40
    five time HTML is here
  • 16:33 - 16:44
    I'd leaflet add another thing for
  • 16:40 - 16:48
    leaflet think you see this in the
  • 16:44 - 16:54
    documentation is quite nice and I joined
  • 16:48 - 16:56
    oh I'm not sure if I've time well I
  • 16:54 - 16:59
    joined I joined both chart yes and
  • 16:56 - 17:02
    leaflet into the same into the same half
  • 16:59 - 17:06
    machine so what I mean by truck is is
  • 17:02 - 17:15
    like you can view the you can view the
  • 17:06 - 17:23
    case is left as well on the same I just
  • 17:15 - 17:28
    put it all together so that's what char
  • 17:23 - 17:32
    CSS does then all you have to do for
  • 17:28 - 17:38
    leaflet is add this all you have to do
  • 17:32 - 17:42
    for charge is inside that and notice I
  • 17:38 - 17:45
    don't use d3.js and I use short guess
  • 17:42 - 17:48
    and I'm if I have time I'll go through
  • 17:45 - 17:56
    that well I know why I try to avoid
  • 17:48 - 17:56
    using d3 now that's this buttons to
  • 17:58 - 18:04
    access token here which I'm not gonna
  • 18:01 - 18:07
    show but the whole things of a source
  • 18:04 - 18:11
    but I had removed the access token in my
  • 18:07 - 18:11
    the public repository
  • 18:12 - 18:25
    the data this is the data from John
  • 18:21 - 18:40
    Hopkins I think that's that's the data
  • 18:25 - 18:44
    and then script for leaflet is here and
  • 18:40 - 18:56
    just that's that's all it takes to do
  • 18:44 - 19:01
    like all that so I think set the you set
  • 18:56 - 19:07
    the bounds of a map here Oh Southwest
  • 19:01 - 19:10
    North East then you said when you first
  • 19:07 - 19:18
    load the page you set the center here
  • 19:10 - 19:22
    and set the view here and I I think I'm
  • 19:18 - 19:22
    not sure what country it's that 244
  • 19:23 - 19:36
    against the London or something then had
  • 19:30 - 19:39
    the tiles so so for for mapping in
  • 19:36 - 19:45
    general on the web I think everything
  • 19:39 - 19:47
    has to use tiles 512 pixels I guess I
  • 19:45 - 19:47
    think so
  • 19:50 - 20:08
    everything is made of tiles that are
  • 19:56 - 20:11
    this this size set the markers which are
  • 20:08 - 20:11
    [Music]
  • 20:12 - 20:20
    the markers are the blue these blue
  • 20:15 - 20:26
    things where the pop-up comes from is
  • 20:20 - 20:32
    patched the circles are the circles are
  • 20:26 - 21:01
    the circles the red circles add them
  • 20:32 - 21:03
    here I'll just go through this like for
  • 21:01 - 21:06
    each for each data set for each data
  • 21:03 - 21:10
    point you add a marker here and then
  • 21:06 - 21:14
    it's pop-up and then you add the pop-up
  • 21:10 - 21:27
    to the position latitude/longitude on
  • 21:14 - 21:30
    the map you add the circle as well then
  • 21:27 - 21:32
    you add the marker layer the layer of
  • 21:30 - 21:34
    markers all all the markers which is all
  • 21:32 - 21:36
    the blue points onto the map and then
  • 21:34 - 21:39
    you add all the circles onto the map and
  • 21:36 - 21:46
    then you think you you think you've
  • 21:39 - 21:49
    added all the all the markers already
  • 21:46 - 21:52
    but what you what do you have to do I'll
  • 21:49 - 21:52
    tell you later
  • 21:53 - 21:57
    so all the blue blue points
  • 21:59 - 22:41
    I think gosh I think all the markers are
  • 22:25 - 23:00
    pushed here but not sure remember what
  • 22:41 - 23:12
    that that does because I wanted to add
  • 23:00 - 23:26
    comments on to this but I thought I'd be
  • 23:12 - 23:28
    able to remember anyway anyway you have
  • 23:26 - 23:38
    to add like I've added all the markers
  • 23:28 - 23:41
    already but I have to add it again
  • 23:38 - 23:49
    I don't know I don't know why I have to
  • 23:41 - 23:51
    do that for leaflet and then I I want to
  • 23:49 - 23:53
    remove them I think I think I have to
  • 23:51 - 23:53
    clear
  • 23:58 - 24:06
    I have to clear them every time you zoom
  • 24:01 - 24:08
    in and at a certain point after delete
  • 24:06 - 24:12
    these blue markers and a sort of zoom
  • 24:08 - 24:14
    point and the thing is actually I
  • 24:12 - 24:16
    shouldn't shouldn't even gone through
  • 24:14 - 24:21
    the code like what I what I tried to do
  • 24:16 - 24:24
    was I just want to show this but what
  • 24:21 - 24:28
    what you might firstly do is it'll show
  • 24:24 - 24:30
    it will show this all of this but what
  • 24:28 - 24:33
    happens is that the whole map is shown
  • 24:30 - 24:35
    it shows all the markers it shows all
  • 24:33 - 24:37
    the markers and all the puppets for the
  • 24:35 - 24:41
    entire map even though it's not in the
  • 24:37 - 24:47
    view it even even if it's not in the
  • 24:41 - 24:49
    view right now so in my code here which
  • 24:47 - 24:51
    is public it which is open source you
  • 24:49 - 24:57
    can find out how I did that
  • 24:51 - 25:00
    and it's these few lines only but what
  • 24:57 - 25:02
    what that what it does out of the box is
  • 25:00 - 25:07
    that it shows you all the popups outside
  • 25:02 - 25:10
    of this view and it lags a lot it
  • 25:07 - 25:13
    there's a very huge performance hit
  • 25:10 - 25:16
    because all these things are dumb all
  • 25:13 - 25:19
    these things are built using the Dom the
  • 25:16 - 25:19
    popups are all Dom I think I guess the
  • 25:19 - 25:21
    markers
  • 25:19 - 25:27
    I think the markers are images it is not
  • 25:21 - 25:34
    really no idea so okay I think I've gone
  • 25:27 - 25:37
    over time but okay which is really no
  • 25:34 - 25:39
    idea so I I got around that made it
  • 25:37 - 25:41
    quite perfect made the performance quite
  • 25:39 - 25:45
    quite good I think it performs better
  • 25:41 - 25:45
    than performance better than this
  • 25:49 - 25:57
    yeah which which you can't even really
  • 25:51 - 26:03
    load and also something about this I've
  • 25:57 - 26:06
    missed out I started I fixed for this I
  • 26:03 - 26:11
    fixed their this this great thing you
  • 26:06 - 26:21
    get when you drag to the top or to the
  • 26:11 - 26:23
    bottom okay okay how about where do
  • 26:21 - 26:29
    people get the project from if they want
  • 26:23 - 26:32
    to try your code out I think this it's
  • 26:29 - 26:35
    on my it's on my github boots oh it's
  • 26:32 - 26:38
    not you can't find this type in like the
  • 26:35 - 26:41
    search for did a search for data
  • 26:38 - 27:01
    visualizations and maps your github is
  • 26:41 - 27:03
    WL WL - is it and it's this you just
  • 27:01 - 27:07
    search for this repository and all you
  • 27:03 - 27:12
    have to do is all you have to do is add
  • 27:07 - 27:16
    the private key for a leaflet for map
  • 27:12 - 27:18
    box in this
  • 27:16 - 27:22
    [Music]
  • 27:18 - 27:25
    all right in this in this string here
  • 27:22 - 27:31
    and then you can get the whole thing and
  • 27:25 - 27:32
    I view the whole thing again thanks a
  • 27:31 - 27:36
    lot
  • 27:32 - 27:39
    very interesting we're gonna ask some
  • 27:36 - 27:42
    open it up for questions now I think
  • 27:39 - 27:44
    Eric's could have a mutant everyone in
  • 27:42 - 27:47
    case in all monster house questions I
  • 27:44 - 27:49
    don't know if Cheyenne can help you with
  • 27:47 - 27:52
    the UM with the billing because I know
  • 27:49 - 28:05
    he's had trouble with animating in the
  • 27:52 - 28:07
    past I have one questions for you did
  • 28:05 - 28:09
    you did you try making these circles
  • 28:07 - 28:12
    because you made them darker when there
  • 28:09 - 28:16
    were more cases
  • 28:12 - 28:18
    did you try making them larger well but
  • 28:16 - 28:23
    by the number of cases changing the size
  • 28:18 - 28:25
    I think and I tried not to do that
  • 28:23 - 28:28
    because I knew that that would take
  • 28:25 - 28:30
    quite a long time so I avoided doing
  • 28:28 - 28:30
    that
  • 28:31 - 28:38
    it takes a considerable amount of time
  • 28:34 - 28:39
    compared to how like how I got all this
  • 28:38 - 28:42
    set up
  • 28:39 - 28:46
    it was quite quick and I and I finished
  • 28:42 - 28:50
    this like like within one or two days I
  • 28:46 - 28:52
    think okay sometime in March so and I
  • 28:50 - 28:54
    think joining getting those large
  • 28:52 - 28:56
    circles and doing it like channels in
  • 28:54 - 28:59
    News Asia there's also a maybe
  • 28:56 - 29:01
    performance problems then you might have
  • 28:59 - 29:04
    to deal with as well once you get that
  • 29:01 - 29:13
    off maybe we can never know about
  • 29:04 - 29:49
    performance until we try you try anyone
  • 29:13 - 29:51
    else have questions for William I have
  • 29:49 - 29:54
    got a question for I I don't know if I'm
  • 29:51 - 29:57
    allowed to ask yeah go ahead
  • 29:54 - 29:57
    like like
  • 29:58 - 30:04
    Oh actually actually it's difficult to
  • 30:01 - 30:06
    ask like like in this in in zoom but I
  • 30:04 - 30:14
    was wondering how many people still use
  • 30:06 - 30:17
    d3 for their database yeah okay yeah I
  • 30:14 - 30:20
    guess done online
  • 30:17 - 30:20
    [Music]
  • 30:20 - 30:26
    I think everyone can click on the path
  • 30:23 - 30:34
    on this difference but then I would
  • 30:26 - 30:36
    wanna and then like yes or no I mean
  • 30:34 - 30:37
    everyone can say like yes or no one and
  • 30:36 - 30:46
    then I see it
  • 30:37 - 30:49
    yep and yes means d3 right yeah how many
  • 30:46 - 31:00
    people still use d3 for all the means
  • 30:49 - 31:02
    something else no I still use it but I'm
  • 31:00 - 31:04
    just wondering how you still use it and
  • 31:02 - 31:08
    actually the follow-up question would be
  • 31:04 - 31:12
    have you found anything better because
  • 31:08 - 31:15
    it's causing its costs problems for me
  • 31:12 - 31:18
    like for some work
  • 31:15 - 31:38
    and it happens again and I ended up
  • 31:18 - 31:42
    using charges I used to use d3 now we're
  • 31:38 - 31:44
    using victory charts for react which
  • 31:42 - 31:47
    seemed a little bit easier to get going
  • 31:44 - 31:48
    with but I couldn't really say which
  • 31:47 - 31:49
    one's best
  • 31:48 - 31:54
    I think d3 would give us more
  • 31:49 - 31:56
    flexibility but victory was very simple
  • 31:54 - 32:06
    to just put the data and get some charts
  • 31:56 - 32:08
    and some interactive okay maybe at the
  • 32:06 - 32:13
    end you can have more chests after the
  • 32:08 - 32:13
    end of the meter and and heater
Title:
Data Visualizations and Maps with JavaScript - TalkJS
Description:

more » « less
Duration:
32:12

English subtitles

Revisions