Archives

All posts for the month March, 2014

Screenshot from 2014-03-27 14:23:55

Recently we started dumping some data from the database into a shared spreadsheet on Google Docs.  With all of this data it would be helpful to visualize it in some way.  After searching the net it seems there isn’t really a good way to create a chart that is dynamic with what data is in the spreadsheet.  What I want is to have my graph update every time a new row is added to the sheet without having to edit the graph directly.  The solution was to write a custom Google Apps Script to do just that.

To add a Google Apps Script to a document open the document and click Tools -> Script editor…  This opens up a page for editing scripts.  If a prompt appears for what type of script you want to do just select Blank.  Now you just need to paste in this code below.

To make this work for you just change the tabName variable to whatever your tab is that you want to use the graph in, change the start row and start column of where your data begins and what column to end reading.  You don’t need to specify an endRow because we will just be reading all of the data until there is no more.  After that you can customize where the graph will be located, how wide it is, and the titles of the axis.

You’ll see that this method will get called anytime the document is edited or opened by someone who can edit.  Viewers who cannot edit will not trigger the event even on open.  That’s all there is to it.  dynamic Google spreadsheet graphs are now just a click away and once you have it set up you’ll never have to touch it again.

If you have any other Google Apps Scripts tips leave them below in the comments.

send-file-iconupload-files-icon-ts7tteez

I have never found a good list of the default styles that ReportLab gives you when you run getSampleStyleSheet() so I wrote a method to spit them out and what they look like.  Below is that list along with the PDF output of each of the styles.  They are grouped into two categories, byAlias and byName.  Normally I just use the name but you can use either.

  • byAlias
    • ‘title’: <ParagraphStyle ‘Title’>
    • ‘h1’: <ParagraphStyle ‘Heading1’>
    • ‘h2’: <ParagraphStyle ‘Heading2’>
    • ‘h3’: <ParagraphStyle ‘Heading3’>
    • ‘h4’: <ParagraphStyle ‘Heading4’>
    • ‘h5’: <ParagraphStyle ‘Heading5’>
    • ‘h6’: <ParagraphStyle ‘Heading6’>
    • ‘bu’: <ParagraphStyle ‘Bullet’>
    • ‘df’: <ParagraphStyle ‘Definition’>
  • byName
    • ‘Title’: <ParagraphStyle ‘Title’>
    • ‘Heading1’: <ParagraphStyle ‘Heading1’>
    • ‘Heading2’: <ParagraphStyle ‘Heading2’>
    • ‘Heading3’: <ParagraphStyle ‘Heading3’>
    • ‘Heading4’: <ParagraphStyle ‘Heading4’>
    • ‘Heading5’: <ParagraphStyle ‘Heading5’>
    • ‘Heading6’: <ParagraphStyle ‘Heading6’>
    • ‘Bullet’: <ParagraphStyle ‘Bullet’>
    • ‘Definition’: <ParagraphStyle ‘Definition’>
    • ‘Normal’: <ParagraphStyle ‘Normal’>
    • ‘Italic’: <ParagraphStyle ‘Italic’>
    • ‘BodyText’: <ParagraphStyle ‘BodyText’>
    • ‘Code’: <ParagraphStyle ‘Code’>

Screenshot from 2014-03-26 12:07:45

square

AngularJS has a ton of built in directives and functions to make your app come alive very quickly.  One thing I noticed it was lacking was a built in on-enter event.  For example, if a user is in an input field when they hit enter I want it to do something, maybe not necessarily submit the form.  Luckily, AngularJS gives you the ability to create your own directives and add them into your app.  Below is a simple directive that you can add to your app that allows you to add ng-enter to elements in your partials.  Pass it a function and watch as you hit enter and that function is executed flawlessly.

That’s it.  Now just add ng-enter="myFunction()" to any element in your partial that detects keystrokes. This has helped me a ton and added a lot of easy functionality to an already great AngularJS system.  If you have any other great directives or AngularJS tips please leave them below in the comments.

afire-logo

Firebase is a great way to connect applications to a database that will sync data in realtime.  Tying this in with AngularJS allows you to create a single page application that updates dynamically and as data changes without page refreshes.  This allows you to create applications that can give your users access to data the moment it is updated and changed.  They have a great binding called AngularFire that links the two services together nicely.

One thing that I had problems with was filtering data returned by Firebase with the great AngularJS filter method.  Because AngularFire returns a dictionary with methods and elements the AngularJS filter has problems filtering the data correctly.  The AngularJS template rendering can render the data just fine but the filter does not work.  To fix that you’ll need to employ the AngularFire method orderByPriority before your AngularJS filter.  Here is an example.

In my Controller I access the list of stores using Firebase and $firebase.  At this point my $scope has the list of stores with some methods used by AngularFire to update data.  The partial above will render the list just fine but without orderByPriority the search filter would not work.  The orderByPriority converts an object returned by $firebase into an array.  This array will work with any normal AnguarJS filter.

Here is the definition from the API of AngularFire.

The orderByPriority filter is provided by AngularFire to convert an object returned by $firebase into an array. The objects in the array are ordered by priority (as defined in Firebase). Additionally, each object in the array will have a$id property defined on it, which will correspond to the key name for that object.

That’s all there is to it.  I hope this helps someone else figure out this problem as I spent a long time trying to get my filter to work with Firebase objects.