Giter Club home page Giter Club logo

icov-interactive-concernschema's People

Contributors

awana1 avatar imkarin avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

devign-it

icov-interactive-concernschema's Issues

Avoid putting function declarations in .then()

Example

d3.xml(data).then((document) => {
   ...

    node = node.data(nodes).enter().append("circle")
      .attr("r", 20)
      .attr("fill", nodeColor)
      .on("mouseover", function(d) {
        div.transition()
            .duration(100)
            .style("opacity", .9);
        div.html( "<h1>Div Title</h1>"... )
            .style("left", (d3.event.pageX) + "px")
            .style("top", (d3.event.pageY - 50) + "px");
      })

Why is this an issue?

There are several anonymous functions written in .then(), after the d3.xml promise. This is bad practice for several reasons:

  • Using inline, anonymous functions make your code hard to read and understand for others.

  • These function declarations now depend on the d3.xml promise. In other words: if the XML-data somehow fails to be loaded, these functions won't be declared either. If you have other code depending on these functions, this code won't work anymore.

  • It's better to turn anonymous functions into named functions, so they can be re-used later without having to copy code. DRY coding is happy coding! ๐Ÿ˜‰

What's a better option?

Use named functions that you can reuse. Declare these functions in the destined section of the code, and call them by their name when you need them anywhere else in your code.

d3.xml(data).then((document) => {
   ...

    node = node.data(nodes).enter().append("circle")
      .attr("r", 20)
      .attr("fill", nodeColor)
      .on("mouseover", showDetailsPopup)
}

// Functions declarations
function showDetailsPopup() {
    div.transition()
        .duration(100)
        .style("opacity", .9);
    div.html( "<h1>Div Title</h1>"... )
        .style("left", (d3.event.pageX) + "px")
        .style("top", (d3.event.pageY - 50) + "px");
}

DataViz: look into D3js for timelines

  • Find examples of timelines on D3js.
  • See what kind of data (structure) is needed for these libraries.
  • Create fake time/event data.
  • Create branch for timeline.
  • Try out timeline library with newly made fake data.

DataViz: extract more data from XML

  • Check what other attributes exist in the XML file (link info, cards?)
  • Extract attributes from XML, insert them into JS objects.

Next up: use these new details in the detail popup, or when hovering over links.

CS: make Datasection-loading code modular.

Move the ComponentDidMount() code in the Datasection to a separate file. See if there are possibilities to break this code up into smaller pieces and make those modular too.

UI: filter interactions smoother

  • Click on node -> add "bigger" class to node + label
  • Not-clicked nodes -> add "faded_out" class to nodes + label

.bigger class

  • radius bigger
  • opacity 1

.faded_out class

  • opacity .3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.