From 10c51c5a0d381e95006e1f33b4a043e838673513 Mon Sep 17 00:00:00 2001 From: Alexandr Nevyantsev Date: Thu, 25 Feb 2021 20:34:17 +0300 Subject: [PATCH 1/8] add seriesType method --- Example/Podfile.lock | 4 ++-- .../Classes/LightweightChartsModels/SeriesType.swift | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 LightweightCharts/Classes/LightweightChartsModels/SeriesType.swift diff --git a/Example/Podfile.lock b/Example/Podfile.lock index e8a4c98..67c2057 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -1,5 +1,5 @@ PODS: - - LightweightCharts (3.2.0) + - LightweightCharts (3.3.0) DEPENDENCIES: - LightweightCharts (from `../`) @@ -9,7 +9,7 @@ EXTERNAL SOURCES: :path: "../" SPEC CHECKSUMS: - LightweightCharts: 04cf1c18f24019889976b0de40bef2329916e020 + LightweightCharts: 05a4b19200513eb5a063ff81b09b8e18aee3997e PODFILE CHECKSUM: 10aa45b030d82b96cfc0e4e3b143c5488576107b diff --git a/LightweightCharts/Classes/LightweightChartsModels/SeriesType.swift b/LightweightCharts/Classes/LightweightChartsModels/SeriesType.swift new file mode 100644 index 0000000..91ef66f --- /dev/null +++ b/LightweightCharts/Classes/LightweightChartsModels/SeriesType.swift @@ -0,0 +1,8 @@ +// +// SeriesType.swift +// LightweightCharts +// +// Created by Alexandr on 25.02.2021. +// + +import Foundation From 77ef129a9343da092625ff2279f486aa69564c9c Mon Sep 17 00:00:00 2001 From: Alexandr Nevyantsev Date: Thu, 25 Feb 2021 20:37:23 +0300 Subject: [PATCH 2/8] add SeriesType enum --- LightweightCharts.podspec | 6 ++--- .../API/Series/SeriesApi+Extension.swift | 6 +++++ .../LightweightChartsModels/SeriesType.swift | 24 +++++++++++++------ .../Classes/Protocols/SeriesApi.swift | 1 + 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/LightweightCharts.podspec b/LightweightCharts.podspec index c9810dd..49b5952 100644 --- a/LightweightCharts.podspec +++ b/LightweightCharts.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'LightweightCharts' - s.version = '3.2.0' + s.version = '3.3.0' s.summary = 'LightweightCharts for iOS.' s.description = 'LightweightCharts pod. Swift wrapper above JavaScript library.' s.homepage = 'https://tradingview.com' @@ -19,9 +19,9 @@ Pod::Spec.new do |s| :script => 'LIBRARY=${TEMP_DIR}/lightweight-charts.js if [ "${CONFIGURATION}" = "Release" ]; then - curl -o $LIBRARY https://unpkg.com/lightweight-charts@3.2.0/dist/lightweight-charts.standalone.production.js + curl -o $LIBRARY https://unpkg.com/lightweight-charts@3.3.0/dist/lightweight-charts.standalone.production.js else - curl -o $LIBRARY https://unpkg.com/lightweight-charts@3.2.0/dist/lightweight-charts.standalone.development.js + curl -o $LIBRARY https://unpkg.com/lightweight-charts@3.3.0/dist/lightweight-charts.standalone.development.js fi cp -f $LIBRARY ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/lightweight-charts.js' diff --git a/LightweightCharts/Classes/Implementations/API/Series/SeriesApi+Extension.swift b/LightweightCharts/Classes/Implementations/API/Series/SeriesApi+Extension.swift index faa1295..fdf2254 100644 --- a/LightweightCharts/Classes/Implementations/API/Series/SeriesApi+Extension.swift +++ b/LightweightCharts/Classes/Implementations/API/Series/SeriesApi+Extension.swift @@ -93,6 +93,11 @@ public extension SeriesApi where Self: SeriesObject { context.evaluateScript(script, completion: nil) } + func seriesType(completion: @escaping (SeriesType?) -> Void) { + let script = "\(jsName).seriesType();" + context.decodedResult(forScript: script, completion: completion) + } + private func setSeriesData(_ data: [T]) { let script = "\(jsName).setData(\(data.jsonString));" context.evaluateScript(script, completion: nil) @@ -103,4 +108,5 @@ public extension SeriesApi where Self: SeriesObject { context.evaluateScript(script, completion: nil) } + } diff --git a/LightweightCharts/Classes/LightweightChartsModels/SeriesType.swift b/LightweightCharts/Classes/LightweightChartsModels/SeriesType.swift index 91ef66f..aa8026d 100644 --- a/LightweightCharts/Classes/LightweightChartsModels/SeriesType.swift +++ b/LightweightCharts/Classes/LightweightChartsModels/SeriesType.swift @@ -1,8 +1,18 @@ -// -// SeriesType.swift -// LightweightCharts -// -// Created by Alexandr on 25.02.2021. -// - import Foundation + + +public enum SeriesType: String { + case line = "Line" + case area = "Area" + case candlestick = "Candlestick" + case bar = "Bar" + case histogram = "Histogram" + case none +} + +extension SeriesType: Decodable { + public init(from decoder: Decoder) throws { + let type = try decoder.singleValueContainer().decode(String.self) + self = SeriesType(rawValue: type) ?? .none + } +} diff --git a/LightweightCharts/Classes/Protocols/SeriesApi.swift b/LightweightCharts/Classes/Protocols/SeriesApi.swift index 9618417..d7394e5 100644 --- a/LightweightCharts/Classes/Protocols/SeriesApi.swift +++ b/LightweightCharts/Classes/Protocols/SeriesApi.swift @@ -121,4 +121,5 @@ public protocol SeriesApi: class { */ func removePriceLine(line: PriceLine) + func seriesType(completion: @escaping (SeriesType?) -> Void) } From eaed715909afdeb25c6a208542daf6e6c155dca3 Mon Sep 17 00:00:00 2001 From: Alexandr Nevyantsev Date: Thu, 25 Feb 2021 20:47:28 +0300 Subject: [PATCH 3/8] Add crosshair colors --- .../Example/CustomPriceFormatterViewController.swift | 4 +++- .../Options/SeriesOptions/Options/AreaSeriesOptions.swift | 8 +++++++- .../Options/SeriesOptions/Options/LineSeriesOptions.swift | 8 +++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Example/LightweightCharts/Example/CustomPriceFormatterViewController.swift b/Example/LightweightCharts/Example/CustomPriceFormatterViewController.swift index d009716..f961d18 100644 --- a/Example/LightweightCharts/Example/CustomPriceFormatterViewController.swift +++ b/Example/LightweightCharts/Example/CustomPriceFormatterViewController.swift @@ -143,7 +143,9 @@ class CustomPriceFormatterViewController: UIViewController { topColor: "rgba(21, 101, 192, 0.5)", bottomColor: "rgba(21, 101, 192, 0.5)", lineColor: "rgba(255, 255, 255, 0.8)", - lineWidth: .two + lineWidth: .two, + crosshairMarkerBorderColor: "rgba(255, 255, 255, 1)", + crosshairMarkerBackgroundColor: "rgba(100, 50, 20, 1)" ) let series = chart.addAreaSeries(options: options) let data = [ diff --git a/LightweightCharts/Classes/LightweightChartsModels/Options/SeriesOptions/Options/AreaSeriesOptions.swift b/LightweightCharts/Classes/LightweightChartsModels/Options/SeriesOptions/Options/AreaSeriesOptions.swift index 1d6bfe9..e01a6be 100644 --- a/LightweightCharts/Classes/LightweightChartsModels/Options/SeriesOptions/Options/AreaSeriesOptions.swift +++ b/LightweightCharts/Classes/LightweightChartsModels/Options/SeriesOptions/Options/AreaSeriesOptions.swift @@ -25,6 +25,8 @@ public struct AreaSeriesOptions: SeriesOptionsCommon { public var lineWidth: LineWidth? public var crosshairMarkerVisible: Bool? public var crosshairMarkerRadius: Double? + public var crosshairMarkerBorderColor: ChartColor? + public var crosshairMarkerBackgroundColor: ChartColor? public init(lastValueVisible: Bool? = nil, title: String? = nil, @@ -47,7 +49,9 @@ public struct AreaSeriesOptions: SeriesOptionsCommon { lineStyle: LineStyle? = nil, lineWidth: LineWidth? = nil, crosshairMarkerVisible: Bool? = nil, - crosshairMarkerRadius: Double? = nil) { + crosshairMarkerRadius: Double? = nil, + crosshairMarkerBorderColor: ChartColor? = nil, + crosshairMarkerBackgroundColor: ChartColor? = nil) { self.lastValueVisible = lastValueVisible self.title = title self.priceScaleId = priceScaleId @@ -70,6 +74,8 @@ public struct AreaSeriesOptions: SeriesOptionsCommon { self.lineWidth = lineWidth self.crosshairMarkerVisible = crosshairMarkerVisible self.crosshairMarkerRadius = crosshairMarkerRadius + self.crosshairMarkerBorderColor = crosshairMarkerBorderColor + self.crosshairMarkerBackgroundColor = crosshairMarkerBackgroundColor } } diff --git a/LightweightCharts/Classes/LightweightChartsModels/Options/SeriesOptions/Options/LineSeriesOptions.swift b/LightweightCharts/Classes/LightweightChartsModels/Options/SeriesOptions/Options/LineSeriesOptions.swift index b9ce63e..b6540bd 100644 --- a/LightweightCharts/Classes/LightweightChartsModels/Options/SeriesOptions/Options/LineSeriesOptions.swift +++ b/LightweightCharts/Classes/LightweightChartsModels/Options/SeriesOptions/Options/LineSeriesOptions.swift @@ -24,6 +24,8 @@ public struct LineSeriesOptions: SeriesOptionsCommon { public var lineType: LineType? public var crosshairMarkerVisible: Bool? public var crosshairMarkerRadius: Double? + public var crosshairMarkerBorderColor: ChartColor? + public var crosshairMarkerBackgroundColor: ChartColor? public init(lastValueVisible: Bool? = nil, title: String? = nil, @@ -45,7 +47,9 @@ public struct LineSeriesOptions: SeriesOptionsCommon { lineWidth: LineWidth? = nil, lineType: LineType? = nil, crosshairMarkerVisible: Bool? = nil, - crosshairMarkerRadius: Double? = nil) { + crosshairMarkerRadius: Double? = nil, + crosshairMarkerBorderColor: ChartColor? = nil, + crosshairMarkerBackgroundColor: ChartColor? = nil) { self.lastValueVisible = lastValueVisible self.title = title self.priceScaleId = priceScaleId @@ -67,6 +71,8 @@ public struct LineSeriesOptions: SeriesOptionsCommon { self.lineType = lineType self.crosshairMarkerVisible = crosshairMarkerVisible self.crosshairMarkerRadius = crosshairMarkerRadius + self.crosshairMarkerBorderColor = crosshairMarkerBorderColor + self.crosshairMarkerBackgroundColor = crosshairMarkerBackgroundColor } } From 15edff4d58361d4cc73c77d5413a61f3f2184212 Mon Sep 17 00:00:00 2001 From: Alexandr Nevyantsev Date: Thu, 25 Feb 2021 21:08:31 +0300 Subject: [PATCH 4/8] add shiftVisibleRangeOnNewBar to TimeScaleOptions --- .../Options/Basics/TimeScaleOptions.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/LightweightCharts/Classes/LightweightChartsModels/Options/Basics/TimeScaleOptions.swift b/LightweightCharts/Classes/LightweightChartsModels/Options/Basics/TimeScaleOptions.swift index 8c3c849..9c82289 100644 --- a/LightweightCharts/Classes/LightweightChartsModels/Options/Basics/TimeScaleOptions.swift +++ b/LightweightCharts/Classes/LightweightChartsModels/Options/Basics/TimeScaleOptions.swift @@ -12,6 +12,7 @@ public struct TimeScaleOptions { public var visible: Bool? public var timeVisible: Bool? public var secondsVisible: Bool? + public var shiftVisibleRangeOnNewBar: Bool? public var tickMarkFormatter: JavaScriptMethod? { get { @@ -33,6 +34,7 @@ public struct TimeScaleOptions { visible: Bool? = nil, timeVisible: Bool? = nil, secondsVisible: Bool? = nil, + shiftVisibleRangeOnNewBar: Bool? = nil, tickMarkFormatter: JavaScriptMethod? = nil) { self.rightOffset = rightOffset self.barSpacing = barSpacing @@ -44,6 +46,7 @@ public struct TimeScaleOptions { self.visible = visible self.timeVisible = timeVisible self.secondsVisible = secondsVisible + self.shiftVisibleRangeOnNewBar = shiftVisibleRangeOnNewBar self.tickMarkFormatter = tickMarkFormatter } @@ -63,6 +66,7 @@ extension TimeScaleOptions: Codable { case visible case timeVisible case secondsVisible + case shiftVisibleRangeOnNewBar } } From ca0e5b724ed478744753a0fe1ca6146a8b31114a Mon Sep 17 00:00:00 2001 From: Alexandr Nevyantsev Date: Thu, 25 Feb 2021 21:09:52 +0300 Subject: [PATCH 5/8] Bump version of example project --- Example/LightweightCharts.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Example/LightweightCharts.xcodeproj/project.pbxproj b/Example/LightweightCharts.xcodeproj/project.pbxproj index 4b551ac..d561777 100644 --- a/Example/LightweightCharts.xcodeproj/project.pbxproj +++ b/Example/LightweightCharts.xcodeproj/project.pbxproj @@ -620,7 +620,7 @@ INFOPLIST_FILE = LightweightCharts/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MARKETING_VERSION = 3.2.0; + MARKETING_VERSION = 3.3.0; MODULE_NAME = ExampleApp; PRODUCT_BUNDLE_IDENTIFIER = "tradingview.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -638,7 +638,7 @@ INFOPLIST_FILE = LightweightCharts/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MARKETING_VERSION = 3.2.0; + MARKETING_VERSION = 3.3.0; MODULE_NAME = ExampleApp; PRODUCT_BUNDLE_IDENTIFIER = "tradingview.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; From c6b9923ffa2ede5b187b1134edb0cf769b141059 Mon Sep 17 00:00:00 2001 From: Alexandr Nevyantsev Date: Thu, 25 Feb 2021 21:13:49 +0300 Subject: [PATCH 6/8] Add docs --- LightweightCharts/Classes/Protocols/SeriesApi.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/LightweightCharts/Classes/Protocols/SeriesApi.swift b/LightweightCharts/Classes/Protocols/SeriesApi.swift index d7394e5..385ec78 100644 --- a/LightweightCharts/Classes/Protocols/SeriesApi.swift +++ b/LightweightCharts/Classes/Protocols/SeriesApi.swift @@ -121,5 +121,9 @@ public protocol SeriesApi: class { */ func removePriceLine(line: PriceLine) + /** + * Returns the type of this series + * - Parameter completion: this SeriesType + */ func seriesType(completion: @escaping (SeriesType?) -> Void) } From bfc5a1566ba38442cf5b48b0429397935dc5fcbf Mon Sep 17 00:00:00 2001 From: Alexandr Nevyantsev Date: Tue, 2 Mar 2021 20:52:05 +0300 Subject: [PATCH 7/8] Remove custom decoding from SeriesType & remove case none in SeriesType --- .../Classes/LightweightChartsModels/SeriesType.swift | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/LightweightCharts/Classes/LightweightChartsModels/SeriesType.swift b/LightweightCharts/Classes/LightweightChartsModels/SeriesType.swift index aa8026d..a692a6f 100644 --- a/LightweightCharts/Classes/LightweightChartsModels/SeriesType.swift +++ b/LightweightCharts/Classes/LightweightChartsModels/SeriesType.swift @@ -1,18 +1,10 @@ import Foundation -public enum SeriesType: String { +public enum SeriesType: String, Decodable { case line = "Line" case area = "Area" case candlestick = "Candlestick" case bar = "Bar" case histogram = "Histogram" - case none -} - -extension SeriesType: Decodable { - public init(from decoder: Decoder) throws { - let type = try decoder.singleValueContainer().decode(String.self) - self = SeriesType(rawValue: type) ?? .none - } } From f0cd8a5c7b57777c154670385b91aa791a2679b2 Mon Sep 17 00:00:00 2001 From: Alexandr Nevyantsev Date: Tue, 2 Mar 2021 20:52:38 +0300 Subject: [PATCH 8/8] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7a838b2..edf27ea 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ LightweightCharts is available through [CocoaPods](https://cocoapods.org). To in it, just simply add the following line to your Podfile: ```ruby -pod 'LightweightCharts', '~> 3.2.0' +pod 'LightweightCharts', '~> 3.3.0' ``` ## Usage