Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions ChartsDemo-macOS/ChartsDemo-macOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
65B3F6421C73B4F5000983D0 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65B3F6411C73B4F5000983D0 /* AppDelegate.swift */; };
65B3F6461C73B4F5000983D0 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 65B3F6451C73B4F5000983D0 /* Assets.xcassets */; };
65B3F6491C73B4F5000983D0 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65B3F6471C73B4F5000983D0 /* Main.storyboard */; };
9406FF8D29C4AF1800AC466A /* RadarMarkerViewMac.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9406FF8C29C4AF1800AC466A /* RadarMarkerViewMac.swift */; };
9406FF9129C4AF5900AC466A /* RadarMarkerViewMac.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9406FF9029C4AF5900AC466A /* RadarMarkerViewMac.xib */; };
9406FF9429C4B1C300AC466A /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 9406FF9329C4B1C300AC466A /* [email protected] */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -68,6 +71,9 @@
65B3F6451C73B4F5000983D0 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
65B3F6481C73B4F5000983D0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
65B3F64A1C73B4F5000983D0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9406FF8C29C4AF1800AC466A /* RadarMarkerViewMac.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RadarMarkerViewMac.swift; sourceTree = "<group>"; };
9406FF9029C4AF5900AC466A /* RadarMarkerViewMac.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = RadarMarkerViewMac.xib; sourceTree = "<group>"; };
9406FF9329C4B1C300AC466A /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -98,6 +104,7 @@
5B9A0C3B1C83AB2100ED8ED8 /* LineDemoViewController.swift */,
5B9A0C3D1C83AB2B00ED8ED8 /* RadarDemoViewController.swift */,
5B9A0C3F1C83AB3400ED8ED8 /* PieDemoViewController.swift */,
9406FF9229C4B1C300AC466A /* Resources */,
);
path = Demos;
sourceTree = "<group>";
Expand All @@ -123,6 +130,8 @@
65B3F6401C73B4F5000983D0 /* ChartsDemo-macOS */ = {
isa = PBXGroup;
children = (
9406FF8B29C4AEE800AC466A /* Components */,
9406FF8929C4AEC900AC466A /* XIBs */,
5B9A0C381C83AB0600ED8ED8 /* Demos */,
65B3F6411C73B4F5000983D0 /* AppDelegate.swift */,
65B3F6451C73B4F5000983D0 /* Assets.xcassets */,
Expand All @@ -132,6 +141,31 @@
path = "ChartsDemo-macOS";
sourceTree = "<group>";
};
9406FF8929C4AEC900AC466A /* XIBs */ = {
isa = PBXGroup;
children = (
9406FF9029C4AF5900AC466A /* RadarMarkerViewMac.xib */,
);
path = XIBs;
sourceTree = "<group>";
};
9406FF8B29C4AEE800AC466A /* Components */ = {
isa = PBXGroup;
children = (
9406FF8C29C4AF1800AC466A /* RadarMarkerViewMac.swift */,
);
path = Components;
sourceTree = "<group>";
};
9406FF9229C4B1C300AC466A /* Resources */ = {
isa = PBXGroup;
children = (
9406FF9329C4B1C300AC466A /* [email protected] */,
);
name = Resources;
path = "ChartsDemo-macOS/Resources";
sourceTree = SOURCE_ROOT;
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -217,8 +251,10 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
9406FF9429C4B1C300AC466A /* [email protected] in Resources */,
65B3F6461C73B4F5000983D0 /* Assets.xcassets in Resources */,
65B3F6491C73B4F5000983D0 /* Main.storyboard in Resources */,
9406FF9129C4AF5900AC466A /* RadarMarkerViewMac.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -232,6 +268,7 @@
65B3F6421C73B4F5000983D0 /* AppDelegate.swift in Sources */,
5B9A0C3E1C83AB2B00ED8ED8 /* RadarDemoViewController.swift in Sources */,
5B9A0C3A1C83AB1800ED8ED8 /* BarDemoViewController.swift in Sources */,
9406FF8D29C4AF1800AC466A /* RadarMarkerViewMac.swift in Sources */,
5B9A0C401C83AB3400ED8ED8 /* PieDemoViewController.swift in Sources */,
5B9A0C3C1C83AB2100ED8ED8 /* LineDemoViewController.swift in Sources */,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// RadarMarkerViewMac.swift
// ChartsDemo-OSX
//
// Copyright 2015 Daniel Cohen Gindi & Philipp Jahoda
// A port of MPAndroidChart for iOS
// Licensed under Apache License 2.0
//
// https://github.com/danielgindi/Charts
//

import Foundation
import Charts
#if canImport(AppKit)
import AppKit
#endif

public class RadarMarkerViewMac: MarkerView {
@IBOutlet var label: NSTextField!

public override func awakeFromNib() {
self.offset.x = -self.frame.size.width / 2.0
self.offset.y = -self.frame.size.height - 7.0
}

public override func refreshContent(entry: ChartDataEntry, highlight: Highlight) {
label.stringValue = String.init(format: "%.1f %%", (entry.y * 100))
needsLayout = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ open class RadarDemoViewController: NSViewController
self.radarChartView.data = data
self.radarChartView.chartDescription.text = "Radarchart Demo"

let marker = RadarMarkerViewMac.viewFromXib()!
marker.chartView = radarChartView
radarChartView.marker = marker
}

override open func viewWillAppear()
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 52 additions & 0 deletions ChartsDemo-macOS/ChartsDemo-macOS/XIBs/RadarMarkerViewMac.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21507" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21507"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner"/>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="c22-O7-iKe" customClass="RadarMarkerViewMac" customModule="ChartsDemo_macOS" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="66" height="50"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="qno-uW-aGa">
<rect key="frame" x="0.0" y="0.0" width="66" height="50"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="5xS-KG-ver"/>
<constraint firstAttribute="width" constant="66" id="eUf-yN-9Lu"/>
</constraints>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="radar_marker" id="xEh-v8-ETH"/>
</imageView>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="UtZ-Pb-cdS">
<rect key="frame" x="14" y="30" width="39" height="15"/>
<textFieldCell key="cell" lineBreakMode="clipping" alignment="center" title="Label" id="VlJ-pa-R8z">
<font key="font" textStyle="callout" name=".SFNS-Regular"/>
<color key="textColor" name="selectedMenuItemTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<constraints>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="UtZ-Pb-cdS" secondAttribute="trailing" constant="5" id="8kA-mr-vr7"/>
<constraint firstAttribute="trailing" secondItem="qno-uW-aGa" secondAttribute="trailing" id="Cv6-ko-UlE"/>
<constraint firstItem="UtZ-Pb-cdS" firstAttribute="centerY" secondItem="c22-O7-iKe" secondAttribute="centerY" constant="-12" id="K05-rt-EcT"/>
<constraint firstItem="UtZ-Pb-cdS" firstAttribute="centerX" secondItem="c22-O7-iKe" secondAttribute="centerX" id="LzM-gV-oOy"/>
<constraint firstAttribute="bottom" secondItem="qno-uW-aGa" secondAttribute="bottom" id="Thg-yL-erI"/>
<constraint firstItem="qno-uW-aGa" firstAttribute="top" secondItem="c22-O7-iKe" secondAttribute="top" id="rzT-HX-Nl3"/>
<constraint firstItem="UtZ-Pb-cdS" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="c22-O7-iKe" secondAttribute="leading" constant="5" id="uyW-0c-JHA"/>
<constraint firstItem="qno-uW-aGa" firstAttribute="leading" secondItem="c22-O7-iKe" secondAttribute="leading" id="zZG-0K-tr4"/>
</constraints>
<connections>
<outlet property="label" destination="UtZ-Pb-cdS" id="XNw-5o-L9d"/>
</connections>
<point key="canvasLocation" x="-281" y="29"/>
</customView>
</objects>
<resources>
<image name="radar_marker" width="133.33332824707031" height="100"/>
</resources>
</document>
42 changes: 37 additions & 5 deletions Source/Charts/Components/MarkerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ open class MarkerView: NSUIView, Marker
{
open var offset: CGPoint = CGPoint()

@objc open weak var chartView: ChartViewBase?
@objc open weak var chartView: ChartViewBase? {
didSet {
didAddToChart(chartView)
}
}

open func offsetForDrawing(atPoint point: CGPoint) -> CGPoint
{
Expand Down Expand Up @@ -72,28 +76,56 @@ open class MarkerView: NSUIView, Marker
}

@objc
open class func viewFromXib(in bundle: Bundle = .main) -> MarkerView?
open class func viewFromXib(in bundle: Bundle = .main) -> Self?
{
#if !os(OSX)

return bundle.loadNibNamed(
String(describing: self),
owner: nil,
options: nil)?[0] as? MarkerView
options: nil)?
.compactMap { $0 as? Self }
.first
#else

var loadedObjects: NSArray? = NSArray()

if bundle.loadNibNamed(
NSNib.Name(String(describing: self)),
owner: nil,
topLevelObjects: &loadedObjects)
topLevelObjects: &loadedObjects),
let view = loadedObjects?.compactMap({ $0 as? Self }).first
{
return loadedObjects?[0] as? MarkerView
view.wantsLayer = true
return view
}

return nil
#endif
}

@objc
open func didAddToChart(_ chartView: ChartViewBase?) {
#if os(OSX)
removeFromSuperview()

// Need to add MarkerView to a view in order to allow it to render out of visible area
guard let chartView else { return }

var parentView: NSView = chartView
while let grandparentView = parentView.superview {
parentView = grandparentView
}
parentView.addSubview(self)

// Constrain MarkerView to off-screen, since it's only being used to render in `draw()` function
// and not to display directly as NSView
translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
leadingAnchor.constraint(equalTo: parentView.trailingAnchor, constant: 100.0),
topAnchor.constraint(equalTo: parentView.bottomAnchor, constant: 100.0)
])

#endif
}
}