提交 d4e68ab5 编写于 作者: C Collin Jackson

Add weight chart to fitness app

上级 bc30e0e5
...@@ -173,28 +173,59 @@ class FeedFragment extends StatefulComponent { ...@@ -173,28 +173,59 @@ class FeedFragment extends StatefulComponent {
}); });
} }
Widget buildChart() {
double startX;
double endX;
double startY;
double endY;
List<Point> dataSet = new List<Point>();
for (FitnessItem item in userData) {
if (item is Measurement) {
double x = item.when.millisecondsSinceEpoch.toDouble();
double y = item.weight;
if (startX == null)
startX = x;
endX = x;
if (startY == null || startY > y)
startY = y;
if (endY == null || endY < y)
endY = y;
dataSet.add(new Point(x, y));
}
}
playfair.ChartData data = new playfair.ChartData(
startX: startX,
startY: startY,
endX: endX,
endY: endY,
dataSet: dataSet
);
return new playfair.Chart(data: data);
}
Widget buildBody() { Widget buildBody() {
TextStyle style = Theme.of(this).text.title; TextStyle style = Theme.of(this).text.title;
if (userData.length == 0)
return new Material(
type: MaterialType.canvas,
child: new Flex(
[new Text("No data yet.\nAdd some!", style: style)],
justifyContent: FlexJustifyContent.center
)
);
switch (_fitnessMode) { switch (_fitnessMode) {
case FitnessMode.feed: case FitnessMode.feed:
if (userData.length > 0) return new FitnessItemList(
return new FitnessItemList( items: userData,
items: userData, onDismissed: _handleItemDismissed
onDismissed: _handleItemDismissed
);
return new Material(
type: MaterialType.canvas,
child: new Flex(
[new Text("No data yet.\nAdd some!", style: style)],
justifyContent: FlexJustifyContent.center
)
); );
case FitnessMode.chart: case FitnessMode.chart:
return new Material( return new Material(
type: MaterialType.canvas, type: MaterialType.canvas,
child: new Flex([ child: new Container(
new Text("Charts are coming soon!", style: style) padding: const EdgeDims.all(20.0),
], justifyContent: FlexJustifyContent.center) child: buildChart()
)
); );
} }
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
library fitness; library fitness;
import 'package:playfair/playfair.dart' as playfair;
import 'package:sky/editing/input.dart'; import 'package:sky/editing/input.dart';
import 'package:sky/painting/text_style.dart'; import 'package:sky/painting/text_style.dart';
import 'package:sky/theme/colors.dart' as colors; import 'package:sky/theme/colors.dart' as colors;
......
...@@ -2,6 +2,7 @@ name: fitness ...@@ -2,6 +2,7 @@ name: fitness
dependencies: dependencies:
sky: any sky: any
sky_tools: any sky_tools: any
playfair: any
path: "^1.3.6" path: "^1.3.6"
dependency_overrides: dependency_overrides:
material_design_icons: material_design_icons:
......
...@@ -464,6 +464,8 @@ sky_core_files = [ ...@@ -464,6 +464,8 @@ sky_core_files = [
"painting/Size.cpp", "painting/Size.cpp",
"painting/Size.h", "painting/Size.h",
"painting/TransferMode.h", "painting/TransferMode.h",
"painting/Typeface.cpp",
"painting/Typeface.h",
"rendering/BidiRun.h", "rendering/BidiRun.h",
"rendering/BidiRunForLine.cpp", "rendering/BidiRunForLine.cpp",
"rendering/BidiRunForLine.h", "rendering/BidiRunForLine.h",
...@@ -682,6 +684,7 @@ core_idl_files = get_path_info([ ...@@ -682,6 +684,7 @@ core_idl_files = get_path_info([
"painting/PictureRecorder.idl", "painting/PictureRecorder.idl",
"painting/RRect.idl", "painting/RRect.idl",
"painting/Shader.idl", "painting/Shader.idl",
"painting/Typeface.idl",
"view/EventCallback.idl", "view/EventCallback.idl",
"view/FrameCallback.idl", "view/FrameCallback.idl",
"view/View.idl", "view/View.idl",
......
...@@ -264,6 +264,14 @@ void Canvas::drawPaintingNode(PaintingNode* paintingNode, const Point& p) ...@@ -264,6 +264,14 @@ void Canvas::drawPaintingNode(PaintingNode* paintingNode, const Point& p)
translate(-p.sk_point.x(), -p.sk_point.y()); translate(-p.sk_point.x(), -p.sk_point.y());
} }
void Canvas::drawText(const String& text, const Point& p, const Paint& paint)
{
if (!m_canvas)
return;
ASSERT(text);
m_canvas->drawText(text.utf8().data(), text.length(), p.sk_point.x(), p.sk_point.y(), paint.sk_paint);
}
void Canvas::drawAtlas(CanvasImage* atlas, void Canvas::drawAtlas(CanvasImage* atlas,
const Vector<RSTransform>& transforms, const Vector<Rect>& rects, const Vector<RSTransform>& transforms, const Vector<Rect>& rects,
const Vector<SkColor>& colors, SkXfermode::Mode mode, const Vector<SkColor>& colors, SkXfermode::Mode mode,
......
...@@ -91,6 +91,7 @@ public: ...@@ -91,6 +91,7 @@ public:
void drawPicture(Picture* picture); void drawPicture(Picture* picture);
void drawDrawable(Drawable* drawable); void drawDrawable(Drawable* drawable);
void drawPaintingNode(PaintingNode* paintingNode, const Point& p); void drawPaintingNode(PaintingNode* paintingNode, const Point& p);
void drawText(const String& text, const Point& p, const Paint& paint);
void drawAtlas(CanvasImage* atlas, void drawAtlas(CanvasImage* atlas,
const Vector<RSTransform>& transforms, const Vector<Rect>& rects, const Vector<RSTransform>& transforms, const Vector<Rect>& rects,
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
void drawPicture(Picture picture); void drawPicture(Picture picture);
void drawDrawable(Drawable drawable); void drawDrawable(Drawable drawable);
void drawPaintingNode(PaintingNode paintingNode, Point p); void drawPaintingNode(PaintingNode paintingNode, Point p);
void drawText(DOMString text, Point p, Paint paint);
// TODO(eseidel): Paint should be optional, but optional doesn't work. // TODO(eseidel): Paint should be optional, but optional doesn't work.
[RaisesException] void drawAtlas(Image image, [RaisesException] void drawAtlas(Image image,
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "sky/engine/core/painting/PaintingStyle.h" #include "sky/engine/core/painting/PaintingStyle.h"
#include "sky/engine/core/painting/Shader.h" #include "sky/engine/core/painting/Shader.h"
#include "sky/engine/core/painting/TransferMode.h" #include "sky/engine/core/painting/TransferMode.h"
#include "sky/engine/core/painting/Typeface.h"
#include "sky/engine/core/script/dom_dart_state.h" #include "sky/engine/core/script/dom_dart_state.h"
#include "sky/engine/wtf/text/StringBuilder.h" #include "sky/engine/wtf/text/StringBuilder.h"
#include "third_party/skia/include/core/SkColorFilter.h" #include "third_party/skia/include/core/SkColorFilter.h"
...@@ -35,6 +36,7 @@ enum PaintFields { ...@@ -35,6 +36,7 @@ enum PaintFields {
kShader, kShader,
kStyle, kStyle,
kTransferMode, kTransferMode,
kTypeface,
// kNumberOfPaintFields must be last. // kNumberOfPaintFields must be last.
kNumberOfPaintFields, kNumberOfPaintFields,
...@@ -82,6 +84,8 @@ Paint DartConverter<Paint>::FromDart(Dart_Handle dart_paint) { ...@@ -82,6 +84,8 @@ Paint DartConverter<Paint>::FromDart(Dart_Handle dart_paint) {
paint.setStyle(DartConverter<PaintingStyle>::FromDart(values[kStyle])); paint.setStyle(DartConverter<PaintingStyle>::FromDart(values[kStyle]));
if (!Dart_IsNull(values[kTransferMode])) if (!Dart_IsNull(values[kTransferMode]))
paint.setXfermodeMode(DartConverter<TransferMode>::FromDart(values[kTransferMode])); paint.setXfermodeMode(DartConverter<TransferMode>::FromDart(values[kTransferMode]));
if (!Dart_IsNull(values[kTypeface]))
paint.setTypeface(DartConverter<Typeface*>::FromDart(values[kTypeface])->typeface());
result.is_null = false; result.is_null = false;
return result; return result;
......
...@@ -43,6 +43,7 @@ class Paint { ...@@ -43,6 +43,7 @@ class Paint {
Shader _shader; Shader _shader;
PaintingStyle _style; PaintingStyle _style;
TransferMode _transferMode; TransferMode _transferMode;
Typeface typeface;
// Must match PaintFields enum in Paint.cpp. // Must match PaintFields enum in Paint.cpp.
List<dynamic> get _value { List<dynamic> get _value {
...@@ -57,6 +58,7 @@ class Paint { ...@@ -57,6 +58,7 @@ class Paint {
_shader, _shader,
_style, _style,
_transferMode, _transferMode,
typeface
]; ];
} }
...@@ -71,6 +73,8 @@ class Paint { ...@@ -71,6 +73,8 @@ class Paint {
// TODO(mpcomplete): Figure out how to show a drawLooper. // TODO(mpcomplete): Figure out how to show a drawLooper.
if (_drawLooper != null) if (_drawLooper != null)
result += ', drawLooper:true'; result += ', drawLooper:true';
if (typeface != null)
result += ', typeface: $_typeface';
result += ')'; result += ')';
return result; return result;
} }
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/core/painting/Typeface.h"
namespace blink {
Typeface::Typeface(PassRefPtr<SkTypeface> typeface)
: typeface_(typeface) {
}
Typeface::~Typeface()
{
}
} // namespace blink
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_ENGINE_CORE_PAINTING_TYPEFACE_H_
#define SKY_ENGINE_CORE_PAINTING_TYPEFACE_H_
#include "sky/engine/tonic/dart_wrappable.h"
#include "sky/engine/wtf/PassRefPtr.h"
#include "sky/engine/wtf/RefCounted.h"
#include "third_party/skia/include/core/SkTypeface.h"
namespace blink {
class Typeface : public RefCounted<Typeface>, public DartWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
~Typeface() override;
SkTypeface* typeface() { return typeface_.get(); }
void set_typeface(PassRefPtr<SkTypeface> typeface) { typeface_ = typeface; }
protected:
Typeface(PassRefPtr<SkTypeface> typeface);
private:
RefPtr<SkTypeface> typeface_;
};
} // namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_TYPEFACE_H_
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
interface Typeface {
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册