Unable to resize tickLabel using sChart:alterTickMark:beforeAddingToAxis: in latest Shinobi


#1

We’ve just updated our project to Shinobi Charts Premium 2.8.1 and our y axis tick label adjustments are no longer working.

We’re were using the following code to move the tick mark labels and resize them so that the label text wraps on to two lines.

It’s worth noting that the tick labels are themed to display vertically, Shinobi applies a transform to achive this. Using Reveal.app I notice that the transfoms are now using floating point values with long precission whereas before [0, -1, 1, 0, 0, 0] is now [-1.8369701987210297e-16, -1, 1, -1.8369701987210297e-16, 0, 0].

 

- (void)sChart:(ShinobiChart *)chart alterTickMark:(SChartTickMark *)tickMark beforeAddingToAxis:(SChartAxis *)axis
{
        if (axis == chart.yAxis) {
            
            // if landscape then adjust tick labels so that the wrap and display on two lines.
            if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {
                
                CGFloat height = axis.axisFrame.size.height / ((SChartCategoryAxis *)axis).categories.count;
                CGRect frame = tickMark.tickLabel.frame;
                frame.size.height = height - 10.0f;
                frame.size.width = 25.0f;
                frame.origin.x = 0;
                tickMark.tickLabel.frame = CGRectIntegral(frame);
                tickMark.tickLabel.lineBreakMode = NSLineBreakByWordWrapping;
                tickMark.tickLabel.numberOfLines = 2;
                tickMark.tickLabel.textAlignment = NSTextAlignmentLeft;
                
            } else {
                CGFloat height = axis.axisFrame.size.height / ((SChartCategoryAxis *)axis).categories.count;
                CGRect frame = tickMark.tickLabel.frame;
                frame.size.height = height - 10.0f;
                tickMark.tickLabel.frame = CGRectIntegral(frame);
                tickMark.tickLabel.numberOfLines = 1;
                tickMark.tickLabel.textAlignment = NSTextAlignmentLeft;
            }
        }
}

This no longer seems to work in the latest version.

Here is how it used to look (and should look like):

After installing the latest version 2.8.1 ** of Shinobi it now looks like:**

It appears the adjustments to the frame i.e. width and height I had made are now being overridden and changed after this method has been called.

Maybe someone could shed some light on this, it feels like a change behind the scenes as changed the way tick labels are rendered which as broken our layout. Is there a better way I could achive my goal of multi-line y axis labels?

Many thanks,


#2

Does anyone have any idea on this one, it seems to be a change in the way Shinobi works. Was hoping from a reply from someone at Shinobi?


#3

Hi camsoft,

We’re not currently aware of any tick label regressions, and there were major changes to the ticklabels during our recent release which brought major speed improvements to the chart rendering. It certainly looks like a bug - would you be able to share your axis configuration too? - it looks like you’ve set the y-axis’ tick label orientation to vertical and I just wanted to confirm this, as well as any other setup you may have.

Thanks!

Rob


#4

Hi Rob,

Yes I had change the tick labels to vertical at the theme level.

Creation of y axis:

SChartCategoryAxis *yAxis = [[SChartCategoryAxis alloc] init];
yAxis.axisPositionValue = @0;
yAxis.axisLabelsAreFixed = YES;
shinobiChart.yAxis = yAxis;

Theme setting for chart:

self.yAxisStyle.lineWidth = @1.5;
self.yAxisStyle.lineColor = [UIColor standardTextColor];
self.yAxisStyle.majorTickStyle.labelFont = font;
self.yAxisStyle.majorTickStyle.labelColor = [UIColor colorWithHex:0x333333];
self.yAxisStyle.majorTickStyle.tickLabelOrientation = TickLabelOrientationVertical;
self.yAxisStyle.majorTickStyle.tickGap = @100;

It seems that where I used to be able to adjust the frame of the labels using this Delegate method what ever I now do is overridden and the labels are reset back to frames that match their content.


#5

Hi Camsoft,

Apologies, this seems to be something that we missed whilst refactoring our tick label generation codebase.

We have fixed this locally and it should be available in our next release.

In the meantime, I believe you could be able to work around this if you wish by having a property that stores the tickmarks (of type NSMutableSet/Array) and something like the following:

- (void)sChart:(ShinobiChart *)chart alterTickMark:(SChartTickMark *)tickMark beforeAddingToAxis:(SChartAxis *)axis {
    [tickMarks addObject:tickMark];
}

- (void)sChartRenderFinished:(ShinobiChart *)chart {

    for (SChartTickMark *tm in tickMarks) {
        // Edit the frame e.t.c
        tm.tickLabel.frame = CGRectInset(tm.tickLabel.frame, 0, -10);
    }
}

- (void)sChartRenderStarted:(ShinobiChart *)chart withFullRedraw:(BOOL)fullRedraw {
    // Remove tick labels as they will go stale at some point... easier to add new tickmarks than relying on the the tickmark objects sticking around 
    [tickMarks removeAllObjects];
}

I hope that’s of some help. Additionally, I’ll add a note to update this ticket when the fix goes out.

Thanks,

Sam


#6

Hi Sam,

Phew I’m glad that was not something I had broken! I’m also glad that it will be fixed in the next release, do you have any idea when that next release might be?

Many thanks,

Cameron.


#7

Hi Cameron,

I’m afraid I don’t have a firm date but it should be some time in the next few weeks.

In the meantime, if you implement the workaround and experience any issues please let me know and I’ll try to help  smiley grin

Thanks,

Sam


#8

Hi Sam,

Any news on the update?


#9

Any news on this please, even if it’s a no?


#10

Hi camsoft,

We may be able to get a version of the framework to you with this fixed. If you could send an email to info@shinobicontrols.com quoting this forum post that would be great.

Sam