Giter VIP home page Giter VIP logo

efcalendargraph's Introduction

EFCalendarGraph

Demo

This code:

- (void)viewDidLoad
{
	EFCalendarGraph *calendarGraph = [[EFCalendarGraph alloc] initWithEndDate:[NSDate new]];
	self.calendarGraph.dataSource = self;
	[self.view addSubview:calendarGraph];
	self.calendarGraph.frame = CGRectMake(20, CGRectGetHeight(self.view.bounds)/2 - 60, CGRectGetWidth(self.view.bounds) - 40, 120);
	
	[self.calendarGraph reloadData];
}

- (NSUInteger)numberOfDataPointsInCalendarGraph:(EFCalendarGraph *)calendarGraph
{
    return 14;
}

-(id)calendarGraph:(EFCalendarGraph *)calendarGraph
      valueForDate:(NSDate *)date
daysAfterStartDate:(NSUInteger)daysAfterStartDate
 daysBeforeEndDate:(NSUInteger)daysBeforeEndDate
{
    return arc4random() % 2 == 0 ? @0 : @(arc4random() % 5;
}

will produce this:

14 Days Calendar Graph

or with 365 days:

365 Days Calendar Graph

Also, note that I am uploading this on a Monday. Since we are setting this up with an end date initWithEndDate..., you'll see the last box is the second from the top. The days start with Sunday at the top and each day follows normally. This will be configurable in the future.

Installation

Until the first CocoaPods release, clone the project and copy the EFCalendarGraph/NSDate+Utilities.{h,m} files into your project.

Important Methods

It's important to note that after changing any of the options or your data, you should call [calendarGraph reloadData].

DataSource

The EFCalendarGraphDataSource protocol defines 2 required methods that allow it to present your data:

- (NSUInteger)numberOfDataPointsInCalendarGraph:(EFCalendarGraph *)calendarGraph

This is very self explanatory, just return the number of squares that you want to show. This is important because it is how the view decides how big the boxes can be and still fit inside its bounds.

- (id)calendarGraph:(EFCalendarGraph *)calendarGraph
       valueForDate:(NSDate *)date
 daysAfterStartDate:(NSUInteger)daysAfterStartDate
  daysBeforeEndDate:(NSUInteger)daysBeforeEndDate;

This is the method where you will return the data points for each square when requested. The return type says id, but is currently only accepting NSNumber. In the future, I would like to support accepting any id and optinally delegating to the user to determine the denomination.

Options

###Properties (default)

####EFCalendarGraphSquareModifier squareModifier (EFCalendarGraphSquareModifierAlpha)

Currently the only value, setting this to EFCalendarGraphSquareModifierAlpha will cause variance in value to change the alpha of each of the boxes.

####NSArray *modifierDenominations (@[@.3, @.4, @.5, @.6, @.7, @.9])

Seemingly random, but this set of numbers seems to work fairly well for most data sets that I've encountered so far. You can set this array to any set of numbers between 0 and 1. It does not have to be 6 numbers either, you can have as many or as few as you want.

####UIColor *baseColor ([UIColor greenColor])

This is the color that will fill the squares.

####UIColor *zeroColor ([UIColor colorWithRed:.9 green:.9 blue:.9 alpha:.5])

This is the color that the boxes will be when the value for the box is 0.

License (MIT)

Copyright (c) 2015 Eliot Fowler

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

efcalendargraph's People

Contributors

eliotfowler avatar

Stargazers

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

Watchers

 avatar  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.