Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose chartYMin and chartYMax to rendererDelegates #64

Closed
AlBirdie opened this issue May 4, 2015 · 12 comments
Closed

Expose chartYMin and chartYMax to rendererDelegates #64

AlBirdie opened this issue May 4, 2015 · 12 comments

Comments

@AlBirdie
Copy link
Contributor

AlBirdie commented May 4, 2015

Like in the Android version, yMin and yMax values of any given chart should be accessible using the corresponding renderer's delegate.

For instance, in BarChartRendererDelegate we need to add;

func barChartRendererChartYMin(renderer:BarChartRenderer) -> Float;
func barChartRendererChartYMax(renderer:BarChartRenderer) -> Float;
@danielgindi
Copy link
Collaborator

There are delegates for all the values the this renderer requires

@AlBirdie
Copy link
Contributor Author

AlBirdie commented May 5, 2015

Exactly, the values THIS renderer requires. However, for people like me who need to adapt this library heavily (in this case subclassing the BarChartRenderer), it would be nice to have ALL the delegate methods we have in the Android version as well. Given that this library is a port of MPAndroidCharts, keeping the APIs as close together as possible should really be a priority in order to make it as versatile as the Android version.

@danielgindi
Copy link
Collaborator

Okay, I agree :)

The APIs are kept close, but in android there's the interface which is
generic, and in iOS the convention is delegates, so I wrote only what was
required. I will add all the delegates functions soon

‏בתאריך יום שלישי, 5 במאי 2015, AlBirdie notifications@github.com כתב:

Exactly, the values THIS renderer requires. However, for people like me
who need to adapt this library heavily (in this case subclassing the
BarChartRenderer), it would be nice to have ALL the delegate methods we
have in the Android version as well. Given that this library is a port of
MPAndroidCharts, keeping the APIs as close together as possible should
really be a priority in order to make it as versatile as the Android version


Reply to this email directly or view it on GitHub
#64 (comment)
.

@AlBirdie
Copy link
Contributor Author

AlBirdie commented May 5, 2015

Yes, I've seen the differences in the implementations and adding the "missing" delegate methods is quite a lot to write, so I appreciate your work here!

On a side note, how do you feel about a pull request regarding an Open-High-Low-Close, and a step chart (both are very common finance chart types)? I've made such a request on MPAndroidCharts a couple of weeks ago but since it hasn't been pulled yet (not sure if Philipp is even considering it), I'm not sure if it would make sense to include it into iOSCharts.

@danielgindi
Copy link
Collaborator

It takes time to review PRs, make sure they match with code styling,
conventions, performance, and test with viewports and animations etc... So
I dont't blame him :)

i have no objections to PRs, and the moment I get to review it and possibly
make neccessary adjustments- we'll work on having the same code and
functionality on both platforms!

‏בתאריך יום שלישי, 5 במאי 2015, AlBirdie notifications@github.com כתב:

Yes, I've seen the differences in the implementations and adding the
"missing" delegate methods is quite a lot to write, so I appreciate your
work here!

On a side note, how do you feel about a pull request regarding an
Open-High-Low-Close, and a step chart (both are very common finance chart
types)? I've made such a request on MPAndroidCharts a couple of weeks ago
but since it hasn't been pulled yet (not sure if Philipp is even
considering it), I'm not sure if it would make sense to include it into
iOSCharts.


Reply to this email directly or view it on GitHub
#64 (comment)
.

@AlBirdie
Copy link
Contributor Author

AlBirdie commented May 5, 2015

I don't blame him either (not the slightest bit).
Ok then, I'll make a pull request in the next couple of weeks and we'll just go from there. :)
Thanks Daniel.

@danielgindi
Copy link
Collaborator

Anyway, it's done!

@AlBirdie
Copy link
Contributor Author

AlBirdie commented May 5, 2015

Perfect. Thanks a lot Daniel!

@danielgindi
Copy link
Collaborator

:-)

@winsonlim
Copy link

Hey @AlBirdie,

How's the pull request for the OHLC chart coming? Looking forward to it in ios-charts.
I tried your OHLCRenderer in MPAndroidCharts. It's great! Thanks for the contribution.

@AlBirdie
Copy link
Contributor Author

Sorry @winsonlim, currently don't have the time to create a pull request for this, but if you want to give it a try, this is the rendering code for the OHLC renderer. The remaining stuff is pretty much identical to the CandleStick renderer.

internal func drawDataSet(#context: CGContext, dataSet: OHLCChartDataSet)
{
var ohlcData = delegate!.ohlcChartRendererOHLCData(self);

    var trans = delegate!.ohlcChartRenderer(self, transformerForAxis: dataSet.axisDependency);

    var phaseX = _animator.phaseX;
    var phaseY = _animator.phaseY;
    var bodySpace = dataSet.bodySpace;

    var dataSetIndex = ohlcData.indexOfDataSet(dataSet);

    var entries = dataSet.yVals as! [CandleChartDataEntry];

    var entryFrom = dataSet.entryForXIndex(_minX);
    var entryTo = dataSet.entryForXIndex(_maxX);

    var minx = max(dataSet.entryIndex(entry: entryFrom!, isEqual: true), 0);
    var maxx = min(dataSet.entryIndex(entry: entryTo!, isEqual: true) + 1, entries.count);

    CGContextSaveGState(context);

    CGContextSetLineWidth(context, dataSet.shadowWidth);

    for (var j = minx, count = Int(ceil(CGFloat(maxx - minx) * phaseX + CGFloat(minx))); j < count; j++)
    {
        // get the entry
        var e = entries[j];

        if (e.xIndex < _minX || e.xIndex > _maxX)
        {
            continue;
        }

        // calculate the vertical line
        _lineSegments[0].x = CGFloat(e.xIndex);
        _lineSegments[0].y = CGFloat(e.high) * phaseY;
        _lineSegments[1].x = CGFloat(e.xIndex);
        _lineSegments[1].y = CGFloat(e.low) * phaseY;

        // calculate the open line
        _lineSegments[2].x = CGFloat(e.xIndex) - 0.5 + bodySpace;
        _lineSegments[2].y = CGFloat(e.open);
        _lineSegments[3].x = CGFloat(e.xIndex);
        _lineSegments[3].y = CGFloat(e.open);

        // calculate the close line
        _lineSegments[4].x = CGFloat(e.xIndex) + 0.5 - bodySpace;
        _lineSegments[4].y = CGFloat(e.close);
        _lineSegments[5].x = CGFloat(e.xIndex);
        _lineSegments[5].y = CGFloat(e.close);

        trans.pointValuesToPixel(&_lineSegments);

        // draw the lines

        if (e.open >= e.close) {
            CGContextSetStrokeColorWithColor(context, dataSet.decreasingColor?.CGColor);
        } else if(e.open < e.close) {
            CGContextSetStrokeColorWithColor(context, dataSet.increasingColor?.CGColor);
        } else {
            CGContextSetStrokeColorWithColor(context, dataSet.shadowColor?.CGColor);
        }

        CGContextStrokeLineSegments(context, _lineSegments, 6);
    }

    CGContextRestoreGState(context);
}

@IshuPhogat
Copy link

IshuPhogat commented Dec 23, 2016

hi @danielgindi ,
firstly thanks for making this great library. This is great.

But at this time I am facing a problem and want to your suggestion/help.
I have an app in which your chart's library has been implemented. This app is in Obj-C language.
Now client want to OHLC and many more chart view. This is my first project on chart and I made most of charts in it using @danielgindi charts . but i couldn't understand, How to make OHLC chart in it.

Please give me any suggestion.

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants