Skip to content

Commit

Permalink
resolve merge confligt
Browse files Browse the repository at this point in the history
  • Loading branch information
o-bagge committed Nov 15, 2024
2 parents 9ed2340 + 5eb46dc commit 0d2b568
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 4 deletions.
45 changes: 44 additions & 1 deletion open_earable/lib/sensor_data_tab/sensor_chart.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'package:open_earable/sensor_data_tab/sensor_html_chart.dart';
import 'package:open_earable/shared/earable_not_connected_warning.dart';
import 'package:open_earable_flutter/open_earable_flutter.dart';
import 'package:flutter/material.dart';
Expand All @@ -9,6 +10,7 @@ import 'package:simple_kalman/simple_kalman.dart';
import 'package:collection/collection.dart';
import 'dart:math';
import 'dart:core';
import 'package:flutter/foundation.dart';

class EarableDataChart extends StatefulWidget {
final OpenEarable openEarable;
Expand Down Expand Up @@ -151,6 +153,7 @@ class _EarableDataChartState extends State<EarableDataChart> {
late int _maxX = 0;
late List<String> colors;
List<charts.Series<dynamic, num>> seriesList = [];
List<ChartSeries> webSeriesList = [];
late double _minY;
late double _maxY;
final errorMeasure = {"ACC": 5.0, "GYRO": 10.0, "MAG": 25.0};
Expand Down Expand Up @@ -384,6 +387,32 @@ class _EarableDataChartState extends State<EarableDataChart> {
data: _data,
),
];
webSeriesList = [
ChartSeries(
id: 'X${_data.isNotEmpty ? " (${_units[widget.sensorName]})" : ""}',
label: 'X${_data.isNotEmpty ? " (${_units[widget.sensorName]})" : ""}',
getDomainFn: (SensorData data, _) => data.timestamp,
getMeasureFn: (SensorData data, _) => data.values[0],
getColorFn: (_, __) => colors[0],
data: _data,
),
ChartSeries(
id: 'Y${_data.isNotEmpty ? " (${_units[widget.sensorName]})" : ""}',
label: 'Y${_data.isNotEmpty ? " (${_units[widget.sensorName]})" : ""}',
getDomainFn: (SensorData data, _) => data.timestamp,
getMeasureFn: (SensorData data, _) => data.values[1],
getColorFn: (_, __) => colors[1],
data: _data,
),
ChartSeries(
id: 'Z${_data.isNotEmpty ? " (${_units[widget.sensorName]})" : ""}',
label: 'Z${_data.isNotEmpty ? " (${_units[widget.sensorName]})" : ""}',
getDomainFn: (SensorData data, _) => data.timestamp,
getMeasureFn: (SensorData data, _) => data.values[2],
getColorFn: (_, __) => colors[2],
data: _data,
),
];
} else if (widget.sensorName == "PPG") {
seriesList = [
charts.Series<SensorData, int>(
Expand Down Expand Up @@ -411,8 +440,20 @@ class _EarableDataChartState extends State<EarableDataChart> {
data: _data,
),
];
webSeriesList = [
ChartSeries(
id: '${widget.chartTitle}${_data.isNotEmpty ? " (${_units[widget.sensorName]})" : ""}',
label: '${widget.chartTitle}${_data.isNotEmpty ? " (${_units[widget.sensorName]})" : ""}',
getDomainFn: (SensorData data, _) => data.timestamp,
getMeasureFn: (SensorData data, _) => data.values[0],
getColorFn: (_, __) => colors[0],
data: _data,
),
];
}

print("Created series list for ${widget.sensorName}: $webSeriesList");

return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expand All @@ -426,7 +467,9 @@ class _EarableDataChartState extends State<EarableDataChart> {
Expanded(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: charts.LineChart(
child: kIsWeb
? ChartJsWidget(chartType: 'line', seriesList: webSeriesList, title: widget.sensorName)
: charts.LineChart(
seriesList,
animate: false,
behaviors: [
Expand Down
81 changes: 81 additions & 0 deletions open_earable/lib/sensor_data_tab/sensor_html_chart.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import 'dart:convert';
import 'dart:js' as js;
import 'dart:html' as html;
import 'dart:ui_web';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:open_earable/sensor_data_tab/sensor_chart.dart';

class ChartSeries {
final String id;
final String label;
final Function(SensorData, int?) getDomainFn;
final Function(SensorData, int?) getMeasureFn;
final Function(SensorData, String?) getColorFn;

final List<SensorData> data;

ChartSeries({
required this.id,
required this.label,
required this.getDomainFn,
required this.getMeasureFn,
required this.getColorFn,
required this.data,
});
}


class ChartJsWidget extends StatelessWidget {
final String chartType;
final List<ChartSeries> seriesList;

final String title;

const ChartJsWidget({super.key,
required this.chartType,
required this.seriesList,
required this.title,
});

@override
Widget build(BuildContext context) {
if (!kIsWeb) {
return Center(
child: Text("Chart.js is only supported on Flutter Web."),
);
}

// Generate a unique chart ID
final String chartId = 'chart-$title';

// Register a view for the HTML element (CanvasElement)
platformViewRegistry.registerViewFactory(
chartId,
(int viewId) => html.CanvasElement()..id = chartId,
);

// Extract labels and datasets after the widget has been built
WidgetsBinding.instance.addPostFrameCallback((_) {
final labels = seriesList[0].data.map((data) => seriesList[0].getDomainFn(data, null).toString()).toList();
final datasets = seriesList.map((series) {
return {
'label': series.label,
'data': series.data.map((data) => series.getMeasureFn(data, null)).toList(),
'borderColor': series.getColorFn(series.data[0], null), // Use colorFn for color
'backgroundColor': series.getColorFn(series.data[0], null) + '33', // With transparency
};
}).toList();

// Call the JavaScript function to render the Chart.js chart
js.context.callMethod('renderChartJS', [
chartId,
chartType,
jsonEncode(labels),
jsonEncode(datasets),
]);
});

return HtmlElementView(viewType: chartId);
}
}
4 changes: 4 additions & 0 deletions open_earable/linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@

#include "generated_plugin_registrant.h"

#include <open_file_linux/open_file_linux_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) open_file_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "OpenFileLinuxPlugin");
open_file_linux_plugin_register_with_registrar(open_file_linux_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
Expand Down
1 change: 1 addition & 0 deletions open_earable/linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
open_file_linux
url_launcher_linux
)

Expand Down
6 changes: 6 additions & 0 deletions open_earable/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ import FlutterMacOS
import Foundation

import flutter_inappwebview_macos
import open_file_mac
import path_provider_foundation
import shared_preferences_foundation
import universal_ble
import url_launcher_macos
import webview_flutter_wkwebview

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
InAppWebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "InAppWebViewFlutterPlugin"))
OpenFilePlugin.register(with: registry.registrar(forPlugin: "OpenFilePlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
UniversalBlePlugin.register(with: registry.registrar(forPlugin: "UniversalBlePlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
FLTWebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "FLTWebViewFlutterPlugin"))
}
16 changes: 13 additions & 3 deletions open_earable/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@ packages:
description:
name: cli_util
sha256: ff6785f7e9e3c38ac98b2fb035701789de90154024a75b6cb926445e83197d1c
sha256: ff6785f7e9e3c38ac98b2fb035701789de90154024a75b6cb926445e83197d1c
url: "https://pub.dev"
source: hosted
version: "0.4.2"
version: "0.4.2"
clock:
dependency: transitive
description:
Expand Down Expand Up @@ -330,9 +332,11 @@ packages:
description:
name: html
sha256: "1fc58edeaec4307368c60d59b7e15b9d658b57d7f3125098b6294153c75337ec"
sha256: "1fc58edeaec4307368c60d59b7e15b9d658b57d7f3125098b6294153c75337ec"
url: "https://pub.dev"
source: hosted
version: "0.15.5"
version: "0.15.5"
image:
dependency: transitive
description:
Expand Down Expand Up @@ -453,7 +457,7 @@ packages:
resolved-ref: "9c21f1bb268260f6150435f7757bc8578dd64e26"
url: "https://github.com/OpenEarable/open_earable_flutter.git"
source: git
version: "0.0.4"
version: "0.0.5"
open_file:
dependency: "direct main"
description:
Expand Down Expand Up @@ -531,9 +535,11 @@ packages:
description:
name: path_provider
sha256: "50c5dd5b6e1aaf6fb3a78b33f6aa3afca52bf903a8a5298f53101fdaee55bbcd"
sha256: "50c5dd5b6e1aaf6fb3a78b33f6aa3afca52bf903a8a5298f53101fdaee55bbcd"
url: "https://pub.dev"
source: hosted
version: "2.1.5"
version: "2.1.5"
path_provider_android:
dependency: transitive
description:
Expand Down Expand Up @@ -659,9 +665,11 @@ packages:
description:
name: shared_preferences
sha256: "95f9997ca1fb9799d494d0cb2a780fd7be075818d59f00c43832ed112b158a82"
sha256: "95f9997ca1fb9799d494d0cb2a780fd7be075818d59f00c43832ed112b158a82"
url: "https://pub.dev"
source: hosted
version: "2.3.3"
version: "2.3.3"
shared_preferences_android:
dependency: transitive
description:
Expand Down Expand Up @@ -808,9 +816,11 @@ packages:
description:
name: url_launcher_android
sha256: "6fc2f56536ee873eeb867ad176ae15f304ccccc357848b351f6f0d8d4a40d193"
sha256: "6fc2f56536ee873eeb867ad176ae15f304ccccc357848b351f6f0d8d4a40d193"
url: "https://pub.dev"
source: hosted
version: "6.3.14"
version: "6.3.14"
url_launcher_ios:
dependency: transitive
description:
Expand All @@ -823,10 +833,10 @@ packages:
dependency: transitive
description:
name: url_launcher_linux
sha256: e2b9622b4007f97f504cd64c0128309dfb978ae66adbe944125ed9e1750f06af
sha256: "4e9ba368772369e3e08f231d2301b4ef72b9ff87c31192ef471b380ef29a4935"
url: "https://pub.dev"
source: hosted
version: "3.2.0"
version: "3.2.1"
url_launcher_macos:
dependency: transitive
description:
Expand Down
46 changes: 46 additions & 0 deletions open_earable/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,52 @@
<link rel="stylesheet" type="text/css" href="splash/style.css">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">
<script src="splash/splash.js"></script>

<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
function renderChartJS(chartId, chartType, labelsString, datasetsString) {
const canvas = document.getElementById(chartId);
const ctx = canvas.getContext('2d');

console.log('Rendering chart ' + chartId + ' with type: ' + chartType);

var labels = JSON.parse(labelsString);
var datasets = JSON.parse(datasetsString);

if (!datasets || !labels) {
console.error('Datasets or labels are null');
return;
}

datasets.forEach(dataset => {
dataset.pointStyle =false;
});

if (canvas.chartInitialized === true) {
console.log('Updating existing chart');
// Update the existing chart
canvas.chart.data.labels = labels;
canvas.chart.data.datasets = datasets;
canvas.chart.update();
} else {
console.log('Creating new chart');
canvas.chart = new Chart(ctx, {
type: chartType,
data: {
labels: labels,
datasets: datasets,
},
options: {
responsive: true,
animation: {
duration: 0,
},
},
});
canvas.chartInitialized = true;
}
}
</script>
</head>
<body>
<script>
Expand Down
6 changes: 6 additions & 0 deletions open_earable/windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@

#include "generated_plugin_registrant.h"

#include <flutter_inappwebview_windows/flutter_inappwebview_windows_plugin_c_api.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <universal_ble/universal_ble_plugin_c_api.h>
#include <url_launcher_windows/url_launcher_windows.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
FlutterInappwebviewWindowsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterInappwebviewWindowsPluginCApi"));
PermissionHandlerWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
UniversalBlePluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UniversalBlePluginCApi"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}
2 changes: 2 additions & 0 deletions open_earable/windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
flutter_inappwebview_windows
permission_handler_windows
universal_ble
url_launcher_windows
)

Expand Down

0 comments on commit 0d2b568

Please sign in to comment.