GithubHelp home page GithubHelp logo

thecoder066 / trademap Goto Github PK

View Code? Open in Web Editor NEW

This project forked from uk-bis-analysis/trademap

0.0 0.0 0.0 19.59 MB

International Trade in Goods Visualization based on UN Comtrade data

Home Page: http://comtrade.un.org/labs/BIS-trade-in-goods/

Shell 0.05% JavaScript 88.37% PHP 0.22% CoffeeScript 0.55% Dart 0.42% CSS 1.89% Makefile 0.05% HTML 8.45% Roff 0.01%

trademap's Introduction

Note: this project has been further developed in this fork: https://github.com/mjs2020/trademap

Trade Map Visualization

Quick details

Libraries, frameworks and tools used:

Frontend:

Development tools:

  • Bower.io: To manage library dependencies
  • Grunt: To package and minify the application

Both are command line tools and depend on NodeJS and NPM being installed on a system. See nodejs.org for installation instructions.

Technical overview

The application is a single page HTML5, CSS, JS application. The entire app logic is in Javascript and therefore run in the browser. There is no server backend required. Data is pulled by the browser from the Comtrade API.

The point of entry for the application is the index.html file which includes all necessary CSS and JS assets.

RequireJS allows breaking up an application into modules and defining dependencies of each module on other modules (AKA dependency injection). The scripts/main.js file is the main file that boots the application and includes all the different modules, initializing them.

The scripts/helpers folder contains modules for different components of the visualization:

  • data.js: This module handles interaction with the Comtrade API as well as managing Crossfilter which we use as a local database. The setup function of the module loads all necessary JSON and CSV data (see the data/sources/sources.md file). The query function runs API queries ensuring throttling (no more than 1 query fired per second) as well as avoiding duplicate queries. It also stores the retrieved data into crossfilter avoiding duplicate records. The getData function queries the crossfilter and the combineData function merges import and export records adding balance and bilateral trade info.
  • controls.js: Sets up and handles the behaviours associated with the main controls (reporter, partner, commodity, flow, year). It also fires events, alerting charts if filters are changed so that they can update accordingly. The file also manages the changes to the URL location bar ensuring that a persistent URL is used, enabling users to copy links to specific views of the data.
  • gui.js: Sets up and manages the behaviours of other GUI components (drop down menus, page scrolling, PNG, SVG and CSV downloading etc.)
  • charts.js: Triggers the setup of each of the charts on the page, defines some common properties like colours and also injects CSS code into the SVG elements to make the SVG exports behave better.
  • embed.js: The module is used instead of the charts one and only triggers the rendering of one chart hiding all other markup. It is used to render the embedded chart view and is triggered by having an &embed=yearChart query parameter.
  • charts/*.js: Each file contains specific logic for each of the different charts.
  • rowchart.js: Contains re-usable logic to draw each of the row charts and is invoked from the modules inside the charts folder.
  • intro.js: Contains the logic and steps for the introduction slideshow.

Build process: packaging and optimization

The source code of the application is optimized and minified for production use unsing Grunt based on the Gruntfile.js script. To run the optimization and generate production code make sure you have all dependencies installed by running (you only need to do this once on your system):

npm install

You can then generate production code simply by running:

grunt

The following files are generated:

  • index.html is generated from index.dev.html replacing javascript dependencies with the compiled and minified versions.
  • assets/libs.min.css is generated from all the CSS files of the libraries used (Bootstrap, Select2...)
  • assets/libs.min.js is generated compiling and minifying all JS files of library dependencies (d3, crossfileter, jquery, bootstrap...)
  • assets/main.min.css is a minified version of styles/main.css which contain custom style information for the app.
  • assets/main.min.js is generated compiling the custom scripts or specific app logic. It uses requirejs to compile.

Sources and API information:

More details about the sources and the API can be found in the data/sources/sources.md file.

Code style, notes & other practices

  • Normally external libraries would be excluded from the repository and be retrieved upon install using bower. However to make the visualization more portable, even on systems that do not have npm and bower installed they are included in this git repo.
  • Remember to modify the index.dev.html file instead of the index.html file in development.
  • Variables are preferably named using camelCase
  • Indenting is 2 spaces (no tabs)

Credits

Coding by Francesco Merletti.

Contacts:

trademap's People

Contributors

mjs2020 avatar

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.