Git Product home page Git Product logo

visual-town-budget's Introduction

Budget Visualization Framework

Our 2017 WordPress plugin is available here: https://github.com/goinvo/visualbudget

screenshot Open-source budget visualization framework.

Requirements

  • PHP-enabled webserver
  • SCSS compiler

Setup

Clone this repository to your local machine and point your webserver root to src/httpdocs, the application should work out of the box, this repository contains some sample data that can be used for testing.

Localized Variables

Set the variables in the localized_variables.php file to your municipality's information. These are global variables used throughout the Visual Budget instance. The file can be found in /src/httpdocs/includes.

Components

Cards

Report statical information about selected entry (src/httpdocs/js/cards.js).

card-img

Chart

Shows data change over time (src/httpdocs/js/chart.js).

chart-img

Treemap

Used as the main navigation component (src/httpdocs/js/treemap.js).

treemap-img

Table

Alternative navigation technique to a treemap (src/httpdocs/js/tables.js).

table-img

Component Interface

Each component implements a common interface of 3 calls:

  • Initialize: called only once, prepares the component to show data
  • Open: opens a data object and displays its contents using the specified component
  • Update: refreshes component data (useful when year changes and new values need to be plotted)

Directory Structure

  • /config: Compass configuration files
  • /src/httpdocs: Application root directory
    • css: compiled SCSS and libraries (bootstrap, introJs)
    • data: CSV and JSON data files
      • processing: temporary directory for data conversion
        • processCSV.py: converts CSV file to nested JSON structure
        • update.php: Interface for data update
    • img: image assets
    • includes: templates and HTML assets
      • localized_variables.php: A collection of global variables specific to a municipaltiy.
      • imports.php: CSS and JS assets imports
      • datafiles.php: json datafiles loaded in each instance (AJAX can be used as an alternative)
      • home.php: homescreen html
      • navbar.php: navigation bar html
      • templates.php: contains Mustache templates (eg. table row templates, cards...)
    • js: Javascript assets
      • avb.js: helper functions and initialization routines
      • cards.js: cards component routines
      • chart.js: chart component routines
      • home.js: homescreen routines and introJs based tutorials code
      • statistics.js: functions used to generate statistical info and number formatting functions
      • table.js: table component routines
      • treemap.js: treemap component routines
  • /src/scss: SCSS files
    • print.scss: SCSS applied when printing a Visual Budget page
    • global.scss: main SCSS file (imports all the partials defined below)
    • partials: SCSS assets
      • _avb.scss: section styles
      • _base.scss: html, body styles, colors and font variables
      • _cards.scss: styles for card component
      • _chart.scss: styles for chart component
      • _home.scss: styles for homescreen
      • _navbar.scss: styles for top navigation bar
      • _table.scss: styles for tabular view
      • _treemap.scss: styles for treemap component

Required Libraries

  • Bootstrap (grid layout, dropdowns..)
  • D3 (visualizations)
  • Jquery Cookie
  • DetectMobileBrowser
  • Jquery
  • Mustache (templates)
  • IntroJS (required for tutorials)

Sample Datasets

Sample Expenses.json, Revenues.json and Funds.json from Arlington, MA in src/httpdocs/data.

Budget data is kept in JSON and CSV format. The JSON format is actively used for computation while the CSV format is kept for reference and data download.

Data structure

The base data unit is an object with the following fields:

  • key {string}: entry name
  • src {url string}: link to data source from where entry data was extracted (optional)
  • hash {string}: entry id (can be arbitrary)
  • sub {array of other entries}: subsections that make up current entry
  • descr {string} : entry description (optional)
  • values {array of value objects} : entry values over time

A simple value object is defined by:

  • year : year of value
  • val : value

This data structure could be changed should it be considered not ideal for future uses.

Data structure sample

The data sample below is partial section of src/httpdocs/data/funds.json.

{
   "key":"Funds",
   "src":"http://www.arlingtonma.gov/",
   "hash":"d42b2bb7",
   "sub":[
      {
         "key":"Tip Fee Stabilization Fund",
         "src":"www.arlin",
         "hash":"68a317f0",
         "sub":[],
         "descr":"The Town of Arlington participated in a regional solid waste consortium, and upon leaving the consortium in September 2005, the Town was entitled to revenue derived from the regional agreement.",
         "url":"",
         "values":[
            {
               "val":1885012.0,
               "year":2010
            },
            {
               "val":1010675.0,
               "year":2011
            },
            {
               "val":562906.0,
               "year":2012
            },
            {
               "val":164000.0,
               "year":2013
            }
         ]
      },
      {
         "key":"Override Stabilization Fund",
         "src":"",
         "hash":"cc5b3ad1",
         "sub":[],
         "descr":"This Fund was created as a result of the 2005 Proposition 2 1/2 override. The Town makes annual appropriations to the fund until the time in which it is necessary to make withdrawals for the purposes of balancing the general fund budget.",
         "url":"",
         "values":[
            {
               "val":1584330.0,
               "year":2010
            },
            {
               "val":0.0,
               "year":2011
            },
            {
               "val":3986819.0,
               "year":2012
            },
            {
               "val":7886125.0,
               "year":2013
            }
         ]
      },
      {
         "key":"Stabilization Fund",
         "src":"",
         "hash":"22772b4f",
         "sub":[],
         "descr":"In accordance with M.G.L. Ch. 40 S. 5B, the Town may appropriate in any year an amount not exceeding, in the aggregate, 10% of the amount raised in the preceding fiscal year's tax levy.",
         "url":"",
         "values":[
            {
               "val":2541858.0,
               "year":2010
            },
            {
               "val":2551951.0,
               "year":2011
            },
            {
               "val":2558551.0,
               "year":2012
            },
            {
               "val":2667328.0,
               "year":2013
            }
         ]
      }
   ],
   "descr":"All accounts which hold money from year to year. For more information, see the Glossary.",
   "url":"",
   "values":[
      {
         "val":8538240.0,
         "year":2010
      },
      {
         "val":5089098.0,
         "year":2011
      },
      {
         "val":8423147.0,
         "year":2012
      },
      {
         "val":18398926.0,
         "year":2013
      }
   ]
}

Data pipeline

Town representatives are likely to be proficient in editing spreadsheets. The Visual Budget application currently uses a pipeline that converts CSV files (created with Microsoft Excel) to nested JSON files used for computation.

A python script src/httpdocs/data/processing/processCSV.py converts a flat CSV file into the nested JSON structure listed above. A php script src/httpdocs/data/processing/update.php orchestrates the entire data update procedure.

For more information about CSV data formats or update procedures check docs/data.

Future upgrades

  • Decoupling town related assets (budget sections, links, logos, data..) from core visualization techniques
  • Changing data sections (eg. Replace 'revenues' with 'Town Departments') requires to manually change links (navbar.php), homepage data (home.php), initialization javascripts (avb.js) and update routines (processCSV.py, update.php). This process should be simplified to allow a simpler migration between different types of data.
  • Grid space. As of now, although each viz component implements a common interface, each visualization is tied to specific div (or html section), the creation of a 'grid' space that allows any visualization to be 'attached' to any area of the screen and would greatly enhance the customization and upgradability of the application.

Core Contributors

GoInvo (Design and Coding)

Town of Arlington (Data Collection and Testing)

License

Visual Town Budget is licensed under the Apache-2.0 open source license. You can find more information on the Apache-2.0 license at http://www.apache.org/licenses/LICENSE-2.0

For guidance integrating Visual Town Budget for your town, contact us at [email protected].

visual-town-budget's People

Contributors

benjaminlistwon avatar craigmcginley avatar ericbenwa avatar iddl avatar jsonin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

visual-town-budget's Issues

Modify distro contents to make updating simpler

Remove the data files (csv & json) from /data & /data/processing. Rename /includes/localized_variables.php to localized_variables_template.php. The intent is to allow updating a site by simply overwriting with all the files in the distro, without overwriting the data and localization. Sample data files could be packaged separately for the initial installation.

Trendline Slider Enhancements

  • First year on graph says '100%' increase from last year. Maybe put in prior year's values without drawing them?
  • Values for years change in-between year tick marks (changing on fiscal year?)

Treemap scaling for small data values

Small entries for data are nearly impossible to see sometimes at the bottom of the tree map. Especially if drawn as a small thin line rather than a square.

Internet Explorer problems

IE8 and earlier, doesn't work at all, Just see the header and footer with no map or graph.

IE9&10 shows Labels but missing the money totals on the tree map. (Ex on Revenues screen. Shows "Property Tax" but missing "79M"

IE11 Missing all labels on tree map, can't click through map. Graph works.

python import script - compatible with levels?

trying to use 'processCSV.py' with a csv file (first two lines below). getting the following error:

@expenses
list index out of range
Error reconstructing tree at node: <main.entry instance at 0x7f9edeafccb0>

==========CSV Example=================================
LEVEL1,LEVEL2,LEVEL3,LEVEL4,LEVEL5,TOOLTIP,SOURCE,SOURCE URL,2010,2011,2012,2013,2014,2015,2016,2017,2018,LEVEL
General Fund,Administration,SALARIES AND WAGES,,,,,,104357.00,111563.00,179844.00,115976.00,222554.00,160906.00,,,,3

Various Enhancements/Oddities

  • Why is 'Funds' the landing page?
  • Keep tabular/map view when switching between Revenue/Expenses/Funds?
  • Transitions on tour not lined up. Div gets highlighted before transition
  • Not all pop-overs have descriptions
  • When you dive in a parent that has one child, you first view the parent zoomed in, then you click again and view the child, but the data is exactly the same because there is only one child holding any data for the parent. This middle zone should be bypassed. (E.g. Revenues > Other Revenues)
  • No highway maintenance salaires in 2010?

City/Town switch

Use "town" or "city" in various text strings, e.g. "City/Town budget visualized", "how much money does the city/town spend on schools", "Education is an important factor in City/Town expenses". Could be a separate field in localized_variables.php, or just parse $longName.

Tabular View Enhancements

  • How are these sorted, if any? Should sort by columns (name/$/etc.)?
  • Pop-overs block highlighting new tabs
  • Can click through pop-overs to toggle display on parent tabs
  • Some graph lines draw below their allotted tab
  • Triangles should transition when opening/closing parent tabs

Are you adjusting for inflation when comparing over time?

When showing fiscal budgets over time, its a good idea to adjust for inflation to ensure apples to apples comparisons of spending. I looked through your code and didn't see any evidence that you were doing so.

A straightforward way to do this is to take the Consumer Price Index (CPI) and multiply your data by it for each year.

Here's a table of CPI: ftp://ftp.bls.gov/pub/time.series/cu/cu.data.4.AsizeNorthCentral
Here's an R script we use to do the calculation: https://github.com/open-city/hows-business/blob/master/import/taxes.R

Make Localized Variables

Make a variable file so new instances of VTB can more easily be spun up with the proper data. Replace hard coded data with these variables.

IE popovers show wrong text

IE popovers show block title, should show "Your contribution is $XXX" for Expenses, tooltip field for Funds & Revenues.

Tree Map Pop-Overs

Pop-overs sometimes don't disappear when transitioning, and get permanently stuck on page.

Text Card Enhancements

  • Left/Right swap buttons do not line up on swapping
  • 'Town of Arlington' link should open in new tab

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.