Skip to content

Commit

Permalink
update chart
Browse files Browse the repository at this point in the history
  • Loading branch information
wutsi committed Dec 25, 2022
1 parent 4e10089 commit c657b10
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CHANGELOG

## [0.1.184] 2022-12-24
## [0.1.190] 2022-12-24

- ADD: Add chart component

Expand Down
43 changes: 34 additions & 9 deletions lib/src/chart.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import 'package:flutter/cupertino.dart';
import 'package:sdui/src/logger.dart';
import 'package:sdui/src/widget.dart';
import 'package:syncfusion_flutter_charts/charts.dart';

/// Class for handling the analytics.
/// This class does nothing. It's up the the application using this library
/// to provide it's own implementation and set the global variable [sduiAnalytics].
class SDUIChart extends SDUIWidget {
final _logger = LoggerFactory.create("SDUIChart");
String? _title;
final List<List<ChartData>> _series = [];

Expand All @@ -14,14 +16,25 @@ class SDUIChart extends SDUIWidget {
_title = json?["title"];

var series = json?["series"];

if (series is List<dynamic>) {
List<ChartData> list = [];
for (var element in series) {
if (element is Map<String, dynamic>) {
list.add(ChartData.fromJson(element));
if (element is List<dynamic>) {
List<ChartData> serie = [];

for (var data in element) {
if (data is Map<String, dynamic>) {
_logger.i('Adding data: $data');
serie.add(ChartData.fromJson(data));
} else {
_logger.i('Not data: $data');
}
}

_logger.i('serie= $serie');
_series.add(serie);
}
}
_series.add(list);
}
return super.fromJson(json);
}
Expand All @@ -31,11 +44,20 @@ class SDUIChart extends SDUIWidget {
return SfCartesianChart(
title: _title == null ? null : ChartTitle(text: _title!),
primaryXAxis: CategoryAxis(),
series: _series.map((e) => LineSeries<ChartData, String>(
dataSource: e,
xValueMapper: (ChartData data, _) => data.x,
yValueMapper: (ChartData data, _) => data.y,
)));
series: _toSeries());
}

List<LineSeries> _toSeries() {
var result = <LineSeries>[];
for (var element in _series) {
result.add(LineSeries<ChartData, String>(
dataSource: element,
xValueMapper: (ChartData data, _) => data.x,
yValueMapper: (ChartData data, _) => data.y,
));
}

return result;
}
}

Expand All @@ -50,4 +72,7 @@ class ChartData {

return data;
}

@override
String toString() => "ChartData($x = $y)";
}
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ description: SDUI make it easy to implement Server Driven UI pattern on flutter.
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 0.1.184
version: 0.1.190

environment:
sdk: ">=2.12.0 <3.0.0"

# Dependencies specify other packages that your package needs in order to work.
# Dependencies specify othe9r packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
Expand Down

0 comments on commit c657b10

Please sign in to comment.