GithubHelp home page GithubHelp logo

azu / arsscale Goto Github PK

View Code? Open in Web Editor NEW
7.0 7.0 0.0 356 KB

[Objective-C] Porting D3.js Scales concepts to iOS.

License: BSD 3-Clause "New" or "Revised" License

Ruby 3.67% Objective-C 96.33%

arsscale's Introduction

ArsScale Build Status

Objective-C port of D3.js Scales.

  • Support Linear scale.

Installation

pod 'ArsScale'

Usage

NSArray *dataArray = @[@1, @5, @10, @18, @22, @44, @55, @114];
ArsScaleLinear *scaleLinear = [[ArsScaleLinear alloc] init];
CGSize canvasSize = CGSizeMake(320, 480);
scaleLinear.domain = @[ArsMin(dataArray), ArsMax(dataArray)];
scaleLinear.range = @[@0, @(canvasSize.width)];
scaleLinear.clamp = YES;
scaleLinear.niceByStep([dataArray count]);
for (NSNumber *value in dataArray) {
    NSLog(@"Value:%@ , Scaled: %@", value, [scaleLinear scale:value]);
}
/*
Value:1 , Scaled: 2.666666666666667
Value:5 , Scaled: 13.33333333333333
Value:10 , Scaled: 26.66666666666666
Value:18 , Scaled: 48
Value:22 , Scaled: 58.66666666666666
Value:44 , Scaled: 117.3333333333333
Value:55 , Scaled: 146.6666666666667
Value:114 , Scaled: 304
*/
[linear ticks:10];
/* e.g) use for axis label
(
    0,
    10,
    20,
    30,
    40,
    50,
    60,
    70,
    80,
    90,
    100,
    110,
    120
)
*/

API

@interface ArsScaleLinear : ArsScale
// extend the scale domain to nice round numbers.
// @see https://github.com/mbostock/d3/wiki/Quantitative-Scales#wiki-linear_nice
// @example `linear.nice()`
- (void (^)(void))nice;

// @example `linear.niceByStep(10)`
- (void (^)(NSUInteger))niceByStep;

// enable or disable clamping of the output range.
// @see https://github.com/mbostock/d3/wiki/Quantitative-Scales#wiki-linear_clamp
@property(nonatomic, getter=isClamp) BOOL clamp;
#pragma mark - block
@property(nonatomic, copy) ArsInterpolate interpolate;
@property(nonatomic, copy) ArsUninterpolate uninterpolate;
#pragma mark - produce

- (NSNumber *)scale:(NSNumber *) number;

// invert scale
- (NSNumber *)invert:(NSNumber *) number;

#pragma mark - ticks
// returns approximately count representative values from the scale's input domain.
// @see https://github.com/mbostock/d3/wiki/Quantitative-Scales#wiki-linear_ticks
- (NSArray *)ticks:(NSUInteger)count;
@end

More Info

Very Nice article about D3.scale.

D3.js API Reference

Example

Dependence

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

3-clause BSD license

Acknowledgment

D3.js
https://github.com/mbostock/d3
Copyright (c) 2010-2014, Michael Bostock

arsscale's People

Contributors

azu avatar

Stargazers

 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.