This repository has been archived by the owner on Jul 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* heatmaps * updated flutter version * flutter downgrade
- Loading branch information
Showing
13 changed files
with
194 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import 'dart:ui'; | ||
|
||
import 'heatcolor_interpolation.dart'; | ||
|
||
/// Defines the color of each pixel based on its density value in a heatmap | ||
class Heatcolor { | ||
final HeatcolorInterpolation interpolation; | ||
final Map<double, Color> densityColors; | ||
|
||
Heatcolor({required this.interpolation, required this.densityColors}); | ||
|
||
String toProperty() { | ||
final density = densityColors.keys.map((density) { | ||
final color = densityColors[density]!.toProperty(); | ||
return '$density,"$color"'; | ||
}).join(','); | ||
return '["interpolate",${interpolation.toProperty()},["heatmap-density"],$density]'; | ||
} | ||
} | ||
|
||
extension ColorProperty on Color { | ||
String toProperty() => 'rgba($red,$green,$blue,$alpha)'; | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/atlas/lib/src/heatmap/heatcolor_interpolation.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/// Produces continuous, smooth results by interpolating between pairs of input and output value | ||
abstract class HeatcolorInterpolation { | ||
String toProperty(); | ||
} | ||
|
||
class LinearInterpolation extends HeatcolorInterpolation { | ||
@override | ||
String toProperty() => '["linear"]'; | ||
} | ||
|
||
class ExponentialInterpolation extends HeatcolorInterpolation { | ||
final double base; | ||
ExponentialInterpolation(this.base); | ||
@override | ||
String toProperty() => '["exponential", $base]'; | ||
} | ||
|
||
class CubitInterpolation extends HeatcolorInterpolation { | ||
final double x1; | ||
final double y1; | ||
final double x2; | ||
final double y2; | ||
CubitInterpolation(this.x1, this.y1, this.x2, this.y2); | ||
@override | ||
String toProperty() => '["cubic-bezier"], $x1, $y1, $x2, $y2]'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import 'package:atlas/src/heatmap/heatcolor.dart'; | ||
|
||
import 'heatpoint.dart'; | ||
|
||
/// Visualization to depict the intensity of data at geographical points. | ||
class Heatmap { | ||
final Set<Heatpoint> heatpoints; | ||
final Heatcolor? heatcolor; | ||
final bool showCounter; | ||
|
||
const Heatmap({required this.heatpoints, this.heatcolor, this.showCounter = false}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import 'package:atlas/src/lat_lng.dart'; | ||
|
||
/// The points where to build the heatmaps | ||
class Heatpoint { | ||
final String id; | ||
final LatLng position; | ||
final int counter; | ||
|
||
const Heatpoint({required this.id, required this.position, required this.counter}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/atlas/test/heatmap/heatcolor_interpolation_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:atlas/src/heatmap/heatcolor_interpolation.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('HeatcolorInterpolation Tests', () { | ||
test('LinearInterpolation returns correct property', () { | ||
final interpolation = LinearInterpolation(); | ||
expect(interpolation.toProperty(), '["linear"]'); | ||
}); | ||
|
||
test('ExponentialInterpolation returns correct property', () { | ||
final base = 2.0; | ||
final interpolation = ExponentialInterpolation(base); | ||
expect(interpolation.toProperty(), '["exponential", $base]'); | ||
}); | ||
|
||
test('CubitInterpolation returns correct property', () { | ||
final x1 = 0.42; | ||
final y1 = 0.0; | ||
final x2 = 0.58; | ||
final y2 = 1.0; | ||
final interpolation = CubitInterpolation(x1, y1, x2, y2); | ||
expect(interpolation.toProperty(), '["cubic-bezier"], $x1, $y1, $x2, $y2]'); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'dart:ui'; | ||
|
||
import 'package:atlas/src/heatmap/heatcolor.dart'; | ||
import 'package:atlas/src/heatmap/heatcolor_interpolation.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('Heatcolor Tests', () { | ||
test('Heatcolor returns correct property string', () { | ||
final interpolation = LinearInterpolation(); | ||
final densityColors = { | ||
0.0: Color.fromARGB(255, 255, 0, 0), // Red | ||
0.5: Color.fromARGB(255, 0, 255, 0), // Green | ||
1.0: Color.fromARGB(255, 0, 0, 255), // Blue | ||
}; | ||
final heatcolor = Heatcolor(interpolation: interpolation, densityColors: densityColors); | ||
final expectedString = '["interpolate",["linear"],["heatmap-density"],' | ||
'0.0,"rgba(255,0,0,255)",' | ||
'0.5,"rgba(0,255,0,255)",' | ||
'1.0,"rgba(0,0,255,255)"]'; | ||
|
||
expect(heatcolor.toProperty(), expectedString); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import 'package:atlas/atlas.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('Heatmap Tests', () { | ||
test('Heatmap is correctly instantiated with default values', () { | ||
final heatpoints = <Heatpoint>{ | ||
Heatpoint(id: '1', position: LatLng(latitude: 37.7749, longitude: -122.4194), counter: 10), | ||
Heatpoint(id: '2', position: LatLng(latitude: 34.0522, longitude: -118.2437), counter: 20), | ||
}; | ||
final heatmap = Heatmap(heatpoints: heatpoints); | ||
|
||
expect(heatmap.heatpoints, equals(heatpoints)); | ||
expect(heatmap.heatcolor, isNull); | ||
expect(heatmap.showCounter, isFalse); | ||
}); | ||
|
||
test('Heatmap correctly assigns non-default values', () { | ||
final heatpoints = <Heatpoint>{ | ||
Heatpoint(id: '1', position: LatLng(latitude: 37.7749, longitude: -122.4194), counter: 10), | ||
Heatpoint(id: '2', position: LatLng(latitude: 34.0522, longitude: -118.2437), counter: 20), | ||
}; | ||
final heatcolor = Heatcolor( | ||
interpolation: LinearInterpolation(), | ||
densityColors: {0.0: Colors.red, 0.5: Colors.green, 1.0: Colors.blue}, | ||
); | ||
final heatmap = Heatmap(heatpoints: heatpoints, heatcolor: heatcolor, showCounter: true); | ||
|
||
expect(heatmap.heatpoints, equals(heatpoints)); | ||
expect(heatmap.heatcolor, equals(heatcolor)); | ||
expect(heatmap.showCounter, isTrue); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'package:atlas/atlas.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('Heatpoint Tests', () { | ||
test('Heatpoint properties are correctly assigned', () { | ||
final position = LatLng(latitude: 37.7749, longitude: -122.4194); | ||
final id = 'testId'; | ||
final counter = 42; | ||
|
||
final heatpoint = Heatpoint(id: id, position: position, counter: counter); | ||
|
||
expect(heatpoint.id, id); | ||
expect(heatpoint.position, position); | ||
expect(heatpoint.counter, counter); | ||
}); | ||
}); | ||
} |