Repository Public
1import Foundation2import SheetCore34/// A data bar to draw inside a cell. Positions are fractions of the cell width, 0 = left edge.5public struct DataBarEffect: Sendable, Hashable {6 /// Left end of the bar.7 public var start: Double8 /// Right end of the bar.9 public var end: Double10 /// Position of the zero axis: 0 when every bound is ≥ 0, 1 when every bound is ≤ 0,11 /// −min/(max − min) when the bounds straddle zero.12 public var axis: Double13 public var color: RGBA14 /// True for a negative value (the bar extends leftwards from the axis).15 public var isNegative: Bool16 /// Length of the bar as a fraction of the cell width.17 public var fraction: Double { end - start }18}1920/// An icon of an icon set. Index 0 is the icon of the lowest bucket (for "3Arrows": the down arrow).21public struct IconEffect: Sendable, Hashable {22 /// Icon set name as stored in the rule, e.g. "3TrafficLights1".23 public var set: String24 public var index: Int25 /// Number of icons in the set.26 public var count: Int27 /// Stable identifier: set name + "#" + index, e.g. "3Arrows#2".28 public var id: String { "\(set)#\(index)" }29}3031/// Everything conditional formatting contributes to one cell.32public struct ConditionalEffect: Sendable, Hashable {33 /// Style overrides of the matching rules, merged property by property (the rule with the34 /// highest priority wins each property).35 public var style: DiffStyle?36 /// Background from the first applicable colour scale.37 public var scaleFill: RGBA?38 public var dataBar: DataBarEffect?39 public var icon: IconEffect?40 /// Indexes into `SheetMeta.conditionalFormats` of the rules that applied, in evaluation order.41 public var matchedRules: [Int] = []4243 public init() {}4445 /// The fill to paint: the rules' explicit fill if any, else the colour-scale fill.46 public var effectiveFill: RGBA? { style?.fill ?? scaleFill }4748 var isEmpty: Bool { matchedRules.isEmpty }4950 mutating func merge(_ s: DiffStyle) {51 guard var cur = style else { style = s; return }52 if cur.bold == nil { cur.bold = s.bold }53 if cur.italic == nil { cur.italic = s.italic }54 if cur.strikethrough == nil { cur.strikethrough = s.strikethrough }55 if cur.textColor == nil { cur.textColor = s.textColor }56 if cur.fill == nil { cur.fill = s.fill }57 if cur.numberFormat == nil { cur.numberFormat = s.numberFormat }58 style = cur59 }60}61