Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1d955a8
Add a basic heatmap
karwa Dec 6, 2019
6c9575c
SVG text-width calculation now skips non-ascii characters, rather tha…
karwa Dec 6, 2019
a1e64d5
Updated heatmap, added Interpolator and loosened generic requirements…
karwa Dec 6, 2019
3cdffbb
- Dropped the Comparable requirement down in to a comparator function…
karwa Dec 6, 2019
a8e00dc
Added ColorMap, and some popular maps from matplotlib (which their li…
karwa Dec 7, 2019
f9ea3b6
Added heatmap slicing convenience for generating a heatmap with a par…
karwa Dec 7, 2019
c074449
Added Equatable, Hashable to Pair, Size and Rect.
karwa Dec 10, 2019
1066fc3
Added todo
karwa Dec 7, 2019
5c0d5d2
Snap the plot rect to integer coordinates.
karwa Dec 7, 2019
0abb40b
Round markers (and hence gridlines) to integer coordinates. This resu…
karwa Dec 7, 2019
725ba00
Heatmap: round the item size to an integer value. This removes the al…
karwa Dec 7, 2019
f20d2d1
Added a heatmap function for all Collections. It requires an O(n) sca…
karwa Dec 7, 2019
556db93
- Namespace the Sequence heatmap APIs
karwa Dec 7, 2019
3d8f95f
Added more advanced ColorMap with multi-stop linear gradients and som…
karwa Dec 10, 2019
31b4ea9
GraphLayout Improvements:
karwa Dec 10, 2019
8bb2c56
Better text height estimation for AGG and... slightly better for Quartz.
karwa Dec 10, 2019
840d7ef
GraphLayout should adjust its title location if the plot size changes
karwa Dec 10, 2019
a197a9f
Heatmap improvements:
karwa Dec 10, 2019
7db05ec
Stuff
karwa Jan 25, 2020
ce77ac3
More work on PlotElements. Still to do are:
karwa Jan 27, 2020
9a58f3f
Some cleanup and documentation. PlotElement rects are now calculated …
karwa Jan 29, 2020
be2d516
Remove CopyOnWriteValue
karwa Jan 29, 2020
538b688
- Revert unintentional change to QuartzRenderer (rebase error? idk)
karwa Jan 29, 2020
941986e
Added some docs and utilities for ColorMap, provenance info for Color…
karwa Jan 29, 2020
9fe90a7
Rename Interpolator -> Adapters.Heatmap
karwa Jan 31, 2020
f396b2f
Rename file
karwa Jan 31, 2020
9a7b8d0
Renaming:
karwa Jan 31, 2020
28f4984
- Split LayoutComponents off in to its own file
karwa Jan 31, 2020
449d9be
- Moved EdgeComponents to its own file
karwa Jan 31, 2020
c421069
Rename "GraphLayout.Results" -> "GraphLayout.LayoutPlan"
karwa Jan 31, 2020
b399644
Fix some layout issues in GraphLayout after analysing test regressions.
karwa Feb 2, 2020
b4fab4c
Split padding/fixedspace layout components in to own file
karwa Feb 2, 2020
543acac
Update linuxmain
karwa Feb 3, 2020
34db69e
Add .swift-format file
karwa Feb 4, 2020
0be8104
swift-format files created in this PR
karwa Feb 4, 2020
5562eb7
Remove GraphLayout.roundMarkers (NFC)
karwa Feb 4, 2020
c44bb2f
- Fix bug in AGG text sizing
karwa Feb 4, 2020
b91dfc7
Clean up debugging flags in GraphLayout
karwa Feb 4, 2020
c5cf66d
Updated reference images
karwa Feb 4, 2020
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
14 changes: 14 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": 1,
"lineLength": 100,
"indentation": {
"spaces": 4
},
"maximumBlankLines": 1,
"respectsExistingLineBreaks": true,
"blankLineBetweenMembers": {
"ignoreSingleLineProperties": true
},
"lineBreakBeforeControlFlowKeywords": false,
"lineBreakBeforeEachArgument": false
}
11 changes: 6 additions & 5 deletions Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,9 @@ namespace CPPAGGRenderer{
void get_text_size(const char *s, float size, float* outW, float* outH){
font_width = font_height = size;
m_contour.width(-font_weight*font_height*0.05);
float x = 0;
float y = 0;
float x = 0;
float maxY = 0;
float minY = 0;
// set rotation of font engine to zero before calculating text width
agg::trans_affine matrix;
matrix *= agg::trans_affine_rotation(agg::deg2rad(0));
Expand All @@ -496,16 +497,16 @@ namespace CPPAGGRenderer{
const agg::glyph_cache* glyph = m_fman.glyph(*s);
if(glyph){
x+=glyph->advance_x;
float height = glyph->bounds.y2 - glyph->bounds.y1;
y = max(y, height);
maxY = max(maxY, (float)glyph->bounds.y2);
minY = min(minY, (float)glyph->bounds.y1);
}
++s;
}
}
if (outW)
*outW = x;
if (outH)
*outH = y;
*outH = abs(maxY - minY);
}

unsigned save_image(const char *s, const char** errorDesc){
Expand Down
3 changes: 2 additions & 1 deletion Sources/QuartzRenderer/QuartzRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,8 @@ public class QuartzRenderer: Renderer {
#endif
let string = NSAttributedString(string: "\(text)", attributes: attributes)
let size = string.size()
return Size(width: Float(size.width), height: Float(size.height))
// FIXME: 'size.height' is always too big and misaligns text.
return Size(width: Float(size.width), height: s)
}

enum WritePNGError: Error {
Expand Down
11 changes: 4 additions & 7 deletions Sources/SVGRenderer/SVGRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,11 @@ public class SVGRenderer: Renderer{
}

public func getTextLayoutSize(text: String, textSize size: Float) -> Size {
var width: Float = 0
let scaleFactor = size/100.0

for i in 0..<text.count {
let index = text.index(text.startIndex, offsetBy: i)
width = width + Float(Self.LCARS_CHAR_SIZE_ARRAY[Int(text[index].ascii!)])
let width = text.reduce(into: Float(0)) { width, character in
guard let asciiVal = character.ascii else { return }
width += Float(Self.LCARS_CHAR_SIZE_ARRAY[Int(asciiVal)])
}

let scaleFactor = size/100.0
return Size(width: width*scaleFactor + 25, height: size)
}

Expand Down
2 changes: 2 additions & 0 deletions Sources/SwiftPlot/AdaptersNamespace.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

public enum Mapping {}
56 changes: 0 additions & 56 deletions Sources/SwiftPlot/Color.swift

This file was deleted.

100 changes: 100 additions & 0 deletions Sources/SwiftPlot/Color/Color.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
public struct Color {
public var r: Float
public var g: Float
public var b: Float
public var a: Float
public init(_ r: Float, _ g: Float, _ b: Float, _ a: Float) {
self.r = r
self.g = g
self.b = b
self.a = a
}
public static let transparent = Color(0, 0, 0, 0)
public static let black: Color = Color(0.0, 0.0, 0.0, 1.0)
public static let white: Color = Color(1.0, 1.0, 1.0, 1.0)
public static let transluscentWhite: Color = Color(1.0, 1.0, 1.0, 0.7)
public static let purple: Color = Color(0.5, 0.0, 0.5, 1.0)
public static let lightBlue: Color = Color(0.529, 0.808, 0.922, 1.0)
public static let blue: Color = Color(0.0, 0.0, 1.0, 1.0)
public static let darkBlue: Color = Color(0.0, 0.0, 0.54, 1.0)
public static let green: Color = Color(0.0, 0.5, 0.0, 1.0)
public static let darkGreen: Color = Color(0.0, 0.39, 0.0, 1.0)
public static let yellow: Color = Color(1.0, 1.0, 0.0, 1.0)
public static let gold: Color = Color(1.0, 0.84, 0.0, 1.0)
public static let orange: Color = Color(1.0, 0.647, 0.0, 1.0)
public static let red: Color = Color(1.0, 0.0, 0.0, 1.0)
public static let darkRed: Color = Color(0.54, 0.0, 0.0, 1.0)
public static let brown: Color = Color(0.54, 0.27, 0.1, 1.0)
public static let pink: Color = Color(1.0, 0.75, 0.79, 1.0)
public static let gray: Color = Color(0.5, 0.5, 0.5, 1.0)
public static let darkGray: Color = Color(0.66, 0.66, 0.66, 1.0)
}

extension Color {

/// Returns a `Color` whose RBGA components are generated by the given `RandomNumberGenerator`.
///
public static func random<RNG: RandomNumberGenerator>(using generator: inout RNG) -> Color {
return Color(
.random(in: 0...1.0, using: &generator),
.random(in: 0...1.0, using: &generator),
.random(in: 0...1.0, using: &generator),
.random(in: 0...1.0, using: &generator))
}

/// Returns a `Color` whose RBGA components are generated by the system's default `RandomNumberGenerator`.
///
public static func random() -> Color {
var generator = SystemRandomNumberGenerator()
return Color.random(using: &generator)
}

/// Returns a `Color` whose RGB components are given by this color, and whose alpha component is `alpha`.
///
public func withAlpha(_ alpha: Float) -> Color {
var color = self
color.a = alpha
return color
}

/// Returns a `Color` whose components are a distance `offset` between this and another color.
///
/// - parameters:
/// - other: The color to blend with.
/// - offset: The fractional distance between this color and `other`, between 0 and 1.
/// A value of 0 always returns this color, and a value of 1 always returns `other`.
///
public func linearBlend(with other: Color, offset: Float) -> Color {
return Color(
(other.r - r) * offset + r,
(other.g - g) * offset + g,
(other.b - b) * offset + b,
(other.a - a) * offset + a)
}
}

#if canImport(CoreGraphics)
import CoreGraphics

fileprivate let RGBColorSpace = CGColorSpaceCreateDeviceRGB()

public extension Color {
@available(tvOS 13.0, watchOS 6.0, *)
var cgColor: CGColor {
if #available(OSX 10.15, iOS 13.0, *) {
return CGColor(
srgbRed: CGFloat(r),
green: CGFloat(g),
blue: CGFloat(b),
alpha: CGFloat(a))
} else {
var tuple = (CGFloat(r), CGFloat(g), CGFloat(b), CGFloat(a))
return withUnsafePointer(to: &tuple) { tupPtr in
return tupPtr.withMemoryRebound(to: CGFloat.self, capacity: 4) { floatPtr in
return CGColor(colorSpace: RGBColorSpace, components: floatPtr)!
}
}
}
}
}
#endif
Loading