1

I have the following Swift code from SciChat Tutorial07 on annotations. I am looking for functionally equivalent code in Objective C. Unfortunately i could not find any relevant examples. Could anyone from the SciChart community please help. Thanks!

let totalCapacity = 500.0
// annotation collection property, used to store all annotations
let annotationGroup = SCIAnnotationCollection()

if (i%100 == 0){

        let customAnnotation = SCICustomAnnotation()
        let customAnnotationContentView = UILabel(frame: CGRect.init(x: 0, y: 0, width: 10, height: 10))
        customAnnotationContentView.text = "Y"
        customAnnotationContentView.backgroundColor = UIColor.lightGray

        customAnnotation.contentView = customAnnotationContentView
        customAnnotation.x1 = SCIGeneric(i)
        customAnnotation.y1 = SCIGeneric(0.5)
        customAnnotation.coordinateMode = .relativeY

        // adding new custom annotation into the annotationGroup property
        annotationGroup.add(customAnnotation)

        // removing annotations that are out of visible range
        let customAn = annotationGroup.item(at: 0) as! SCICustomAnnotation

        if(SCIGenericDouble(customAn.x1) < Double(i) - totalCapacity){
            // since the contentView is UIView element - we have to call removeFromSuperView method to remove it from screen
            customAn.contentView.removeFromSuperview()
            annotationGroup.remove(customAn)
        }
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Val Nenov
  • 63
  • 8

1 Answers1

2

Looks like you need the equivalent Objective-C constants.

From the documentation, your enum options for a coordinateMode are:

SCIAnnotationCoordinate_Absolute
SCIAnnotationCoordinate_Relative
SCIAnnotationCoordinate_RelativeX
SCIAnnotationCoordinate_RelativeY

You probably want SCIAnnotationCoordinate_RelativeY.

cbutton9
  • 148
  • 6
  • Thank you for your feedback. The problem which I am facing is that it appears that there are no "add" and "remove" annotation methods in Objective-c that are corresponding to annotationGroup.add(customAnnotation) and annotationGroup.remove(customAn). I could not find any - or am I blind:-) – Val Nenov May 08 '18 at 15:00
  • SCIAnnotationCollection seems to have 'add' and 'remove' methods in Objective-C just like in Swift, such as in this example: https://www.scichart.com/documentation/ios/v2.x/Combining%20Multiple%20Annotations.html – cbutton9 May 08 '18 at 18:46
  • Maybe you could post your attempt at implementing this in Objective-C, and share what's not working? – cbutton9 May 08 '18 at 18:46
  • Thank you for your feedback. Both 'add' and 'remove' are working fine. I was lacking the correct syntax which I found in your example code. Thanks! – Val Nenov May 09 '18 at 21:51
  • I have only one more issue. When adding text annotations with: SCITextAnnotation * annotation1 = [SCITextAnnotation new]; annotation1.text = @"myText"; [self.surface.annotations add:annotation1]; Instead of 'myText' i get the text 'SciChart' on the surface. I see this behavior both in my trial and purchased versions of SciChart for iOS. I have NO assignment of annotation1.text = @"SciChart"; in my code. Why is this happening? – Val Nenov May 09 '18 at 21:55
  • CLARIFICATION: I have 2 surfaces. The code above shows "myText" fine on Surface1 but shows "SciChart" on Surface2. I have defined separately annotation1 and annotation2. – Val Nenov May 09 '18 at 22:27
  • False alarm:-( I had the test assignment for annotation2 buried in IF statements and apparently never got executed. I assume that if the assignment is not done correctly the text value to @"SciChart". My mistake. Sorry to bother the community. – Val Nenov May 09 '18 at 23:44