Giter VIP home page Giter VIP logo

abc's Introduction

Angular Bound Charts v 0.4.6

DEPRECATED: This library is no longer maintained

Customisable SVG charts with live data & settings, completely bound to AngularJS with no other dependencies

This release is compatible with all modern browsers [Chrome, Firefox, Safari, IE, Opera]

This is a reasonably new project (with only myself working on it currently), but I plan on keeping it updated, improving performance & will be adding tests & extensive documentation shortly.

Feel free to fork or give suggestions for features. Constructive criticism is welcome.

Getting started

These instructions apply to an application setup using Yeoman but can easily be adjusted to your needs.

  1. First you'll have to add ABC to your bower.json, I'd suggest pinning a specific version using =. The version at the time of writing this is 0.3.0.

     "dependencies": {
         ...
         "angular-abc": "=0.3.0"
         ...
     }
    
  2. You'll need to reference the main ABC javascript file in your index.html like so:

     <script src="bower_components/angular-abc/scripts/abc.js"></script>
    
  3. This will also need referencing in your main javascript file (e.g. app.js)

     angular.module('myApp', [
         ...
         'angularAbc'
         ...
     ])
    
  4. Now we have to adjust our gruntfile.js to copy the views (e.g. abc.html) to a location where they can be loaded after your application has been built & deployed. In my application it looks something like this:

     copy: {
         abc: {
             files: [{
                 expand: true,
                 cwd: '<%= yeoman.app %>/bower_components/angular-abc/views/',
                 dest: '<%= yeoman.dist %>/bower_components/angular-abc/views/',
                 src: '*.html',
             flatten: true
             }]
         }
     }
    
  5. I then call copy:abc in my build task just after copy:dist

     grunt.registerTask('build', [
         ...
         'copy:dist',
         'copy:abc',
         ...
     ]);
    
  6. If you plan on running any tests using karma you'll have to include ABC in your karma.conf.js file

     files: [
       ...
       'bower_components/angular-abc/scripts/abc.js',
       ...
     ],
    

Implementation

  1. Prepare your data to use with ABC. I'd recommend using the ABC service to transform your data.

     app.controller('MainCtrl', ['$scope', 'ABC', function ($scope, ABC) {
    
         ...
    
         $scope.myChart = {
             data: ABC.transformData($scope.data),
             headers: ABC.transformHeaders($scope.data)
         }
    
         ...
    
     });
    
  2. Add the ABC element with a data attribute linking to your transformed data / ABC settings.

     <abc data="myChart"></abc>
    
  3. Tune the settings to your liking. The following settings are all optional.

     $scope.myChart = {
    
         // Classes for styling
         class: 'abc-chart',
         focusClass: 'abc-focus',
         nofocusClass 'abc-nofocus',
    
         // These hovering indices are used to focus on data from outside ABC
         hovering: {
             x: -1,
             y: -1
         },
    
         // Size settings
         width: 800,
         height: 200,
         resize: {
             width: true,
             height: false
         },
    
         // Element styling
         margin: 12,
         lineWidth: 2,
         axisLineWidth: 1,
         axisTickWidth: 1,
         axisTickSize: 4,
         pointSize: 2.5,
         pointHoverSize: 4,
    
         // Axis options
         xAxisLabelOffset: 0.5, // Offset by 0.5 ticks
         xAxisLabelCulling: true, // Automatically hides some axis labels when needed
    
         // Chart colors
         colors: ['#d24949', '#e59648', '#4f8f47', '#316e93', '#684c8a'],
    
         // Regions
         regions: [
           {
             start: 0,
             end: 1,
             color: 'red',
             title: 'Region 1',
             size: 12,
             titleY: 'top', // 'top', 'center', 'bottom', or number e.g. 0.5 (half) or 0.75 (3 quarters)
             opacity: 0.2 // Set highlight opacity of region, defaults to 0.2
           }
         ],
    
         // Bands
         bands: [
           {
             start: 0, // Start & end can be exact values
             end: 'bottom', // Start & End can be 'top' or 'bottom'
             color: 'red',
             title: 'Lower band',
             size: 10
           }
         ],
    
         // Text transforms
         transforms: {
             yLabels: function,
             xLabels: function,
             popupLabels: function,
             popupValues: function,
             popupHeaders: function
         }
    
         // Title settings
         title: {
             content: 'My Chart',
             size: 12,
             margin: 4,
             align: 'center' // center, left or right
         },
    
         // Transformed data & headers
         data: ABC.transformData($scope.data),
         headers: ABC.transformHeaders($scope.data)
     }
    

abc's People

Contributors

jakesidsmith avatar

Stargazers

timelyportfolio avatar Jurek avatar Bilgehan Zeki ÖZAYTAÇ avatar

Watchers

Bilgehan Zeki ÖZAYTAÇ avatar timelyportfolio avatar James Cloos avatar Chris Evans avatar  avatar RiccardoTonini avatar Jurek avatar

abc's Issues

Individual margins

Allow top, right, bottom & left margins to be set individually.

margin: {
top: 0,
left: 10,
right: 10,
bottom: 5
}

Custom opacity on regions & bands

regions: [
  {
    opacity: 0.2 // 0.2 = default
  }
]

Ensure falsy values do not default to 0.2
e.g. opacity: 0 should set the opacity to zero
whereas opacity: undefined should default to 0.2

Settings can be falsy

Having the title as an empty string, or it's size set to 0 is ignore because abc thinks it is false.

Will need to find out what other settings may be falsy.

Danger zone

Like bands, but only one can be added & instead of having a faint overlay in the background it filters any lines / bars that cross into it, but is otherwise invisible.

Same settings as bands (but not an array)

Chart bands

Like regions, but horizontal

e.g. Highlight the area between 0 & 100
or the entire area below 0

bands: [
  {
    start: 0,
    end: 'bottom'
    color: 'red',
    title: 'Danger zone'
  }
]

Highlight sections

Add ability to highlight sections of chart e.g. [{start: 2, end: 5}]
Make sure to account for negative values / negative highlighting e.g. [{start: 5, end: 2}]

Chart margins

  • Add settings to adjust chart margins (within axes)
  • Start with only left / right margins

X-axis label culling

Only display every other (or every other 2, etc, etc) label if there is not enough room.

Transform values

Add ability for custom transform functions on x / y axis & popup headers / values.

Y-ticks bug in Safari

"[$interpolate:interr] Can't interpolate: {{0 - settings.axisTickSize*1.5 - abc.yTickTextLength($index)}}
TypeError: 'undefined' is not an object (evaluating 'c[a].getComputedTextLength')

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.