rn-native-ios-charts 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -59,10 +59,11 @@ their axes.
59
59
  - **Bar chart enhancements.** Two new fields on `bar` marks (and
60
60
  the matching `<BarChart>` props):
61
61
  - `position: "auto" | "stacked" | "grouped"` — multi-series
62
- positioning. `"stacked"` applies SwiftUI's
63
- `positionAdjustment(.stacking)`; `"grouped"` applies
64
- `position(by: .value("Series", category))` so bars sit
65
- side-by-side.
62
+ positioning. SwiftUI Charts already stacks `BarMark`s that
63
+ share an X value, so `"auto"` and `"stacked"` are equivalent
64
+ (both lean on the framework default). `"grouped"` adds
65
+ `position(by: .value("Series", category))` so the bars sit
66
+ side-by-side, one column per series.
66
67
  - `horizontal: boolean` — swaps the X and Y axes for `bar`
67
68
  marks. Use for Top-N lists and ranked leaderboards.
68
69
 
package/README.md CHANGED
@@ -333,8 +333,8 @@ extra fields for multi-series layouts:
333
333
 
334
334
  | Prop | Effect |
335
335
  | ------------ | ---------------------------------------------------------------------- |
336
- | `position: "auto"` | SwiftUI's default. |
337
- | `position: "stacked"` | Applies `.positionAdjustment(.stacking)`. |
336
+ | `position: "auto"` | SwiftUI's default — multiple bars at the same X stack. |
337
+ | `position: "stacked"` | Same as `"auto"`. SwiftUI Charts already stacks by default — this label is an explicit alias for readability. |
338
338
  | `position: "grouped"` | Applies `.position(by: .value("Series", category))`. |
339
339
  | `horizontal: true` | Swaps X and Y on `BarMark` — labels on the Y axis. |
340
340
 
@@ -762,22 +762,32 @@ private extension View {
762
762
  /// Builds the Text view shown for a single axis tick. Routes through
763
763
  /// the active `valueFormat` and applies prefix/suffix. String values
764
764
  /// pass through unchanged; Double values get a NumberFormatter or a
765
- /// FormatStyle depending on the requested format.
765
+ /// FormatStyle depending on the requested format. Returns a single
766
+ /// `Text` (not `@ViewBuilder` content) so the caller can apply
767
+ /// `.font` and `.foregroundColor` directly to it.
766
768
  @available(iOS 17.0, *)
767
- @ViewBuilder
768
769
  private func axisLabelText(
769
770
  for axisValue: AxisValue,
770
771
  config: ChartAxisConfig
771
772
  ) -> Text {
773
+ return Text(axisLabelString(for: axisValue, config: config))
774
+ }
775
+
776
+ @available(iOS 17.0, *)
777
+ private func axisLabelString(
778
+ for axisValue: AxisValue,
779
+ config: ChartAxisConfig
780
+ ) -> String {
772
781
  if let v = axisValue.as(Double.self) {
773
- Text(formatAxisValue(v, config: config))
774
- } else if let v = axisValue.as(Int.self) {
775
- Text(formatAxisValue(Double(v), config: config))
776
- } else if let s = axisValue.as(String.self) {
777
- Text("\(config.valuePrefix)\(s)\(config.valueSuffix)")
778
- } else {
779
- Text("")
782
+ return formatAxisValue(v, config: config)
783
+ }
784
+ if let v = axisValue.as(Int.self) {
785
+ return formatAxisValue(Double(v), config: config)
786
+ }
787
+ if let s = axisValue.as(String.self) {
788
+ return "\(config.valuePrefix)\(s)\(config.valueSuffix)"
780
789
  }
790
+ return ""
781
791
  }
782
792
 
783
793
  @available(iOS 17.0, *)
@@ -848,10 +858,14 @@ private extension View {
848
858
  /// Trading-chart X mode: 0pt plot-dimension padding so the first
849
859
  /// and last data points sit flush against the chart's edges. Use
850
860
  /// when the axis is hidden and you want the line to bleed.
861
+ /// `plotDimension` takes separate `startPadding` / `endPadding` —
862
+ /// there's no single `padding:` form on this API.
851
863
  @ViewBuilder
852
864
  func conditionalTightX(enabled: Bool) -> some View {
853
865
  if enabled {
854
- self.chartXScale(range: .plotDimension(padding: 0))
866
+ self.chartXScale(
867
+ range: .plotDimension(startPadding: 0, endPadding: 0)
868
+ )
855
869
  } else {
856
870
  self
857
871
  }
@@ -957,14 +971,17 @@ private struct CalloutPositioner: ViewModifier {
957
971
  }
958
972
  }
959
973
 
960
- /// Per-bar position adjustment. SwiftUI's default behavior with
961
- /// multiple BarMarks at the same X is implementation-defined; this
962
- /// extension makes the intent explicit:
963
- /// - "stacked" `positionAdjustment(.stacking)`
964
- /// - "grouped" → `position(by: .value("Series", category))` so
965
- /// bars sit side-by-side, one column per series. Falls back to
966
- /// "auto" when no category is set.
967
- /// - anything else → leave the mark alone.
974
+ /// Per-bar position adjustment. SwiftUI Charts already stacks
975
+ /// multiple `BarMark`s that share an X value by default — that's
976
+ /// the framework's built-in behavior, no modifier needed. To opt
977
+ /// OUT of stacking and lay bars side-by-side, we add
978
+ /// `.position(by: .value("Series", category))`.
979
+ ///
980
+ /// So this helper:
981
+ /// - "stacked" / "auto" / anything else → leave the mark alone
982
+ /// (stacking is the default)
983
+ /// - "grouped" → apply `position(by:)` using the point's
984
+ /// `category`. Falls back to no-op if `category` is missing.
968
985
  @available(iOS 17.0, *)
969
986
  private extension ChartContent {
970
987
  @ChartContentBuilder
@@ -972,16 +989,9 @@ private extension ChartContent {
972
989
  kind: String,
973
990
  category: String?
974
991
  ) -> some ChartContent {
975
- switch kind {
976
- case "stacked":
977
- self.positionAdjustment(.stacking)
978
- case "grouped":
979
- if let cat = category, !cat.isEmpty {
980
- self.position(by: .value("Series", cat))
981
- } else {
982
- self
983
- }
984
- default:
992
+ if kind == "grouped", let cat = category, !cat.isEmpty {
993
+ self.position(by: .value("Series", cat))
994
+ } else {
985
995
  self
986
996
  }
987
997
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rn-native-ios-charts",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Native SwiftUI Charts for React Native / Expo. iOS-only, zero-compromise charts that bypass the limitations of cross-platform chart libraries.",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -47,4 +47,4 @@
47
47
  "scripts": {
48
48
  "test": "echo \"Error: no test specified\" && exit 1"
49
49
  }
50
- }
50
+ }