mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Merge pull request #568 from collinjackson/playfair
Add support for charts to fitness app
This commit is contained in:
commit
480ea65989
@ -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() {
|
||||
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) {
|
||||
case FitnessMode.feed:
|
||||
if (userData.length > 0)
|
||||
return new FitnessItemList(
|
||||
items: userData,
|
||||
onDismissed: _handleItemDismissed
|
||||
);
|
||||
return new Material(
|
||||
type: MaterialType.canvas,
|
||||
child: new Flex(
|
||||
[new Text("No data yet.\nAdd some!", style: style)],
|
||||
justifyContent: FlexJustifyContent.center
|
||||
)
|
||||
return new FitnessItemList(
|
||||
items: userData,
|
||||
onDismissed: _handleItemDismissed
|
||||
);
|
||||
case FitnessMode.chart:
|
||||
return new Material(
|
||||
type: MaterialType.canvas,
|
||||
child: new Flex([
|
||||
new Text("Charts are coming soon!", style: style)
|
||||
], justifyContent: FlexJustifyContent.center)
|
||||
child: new Container(
|
||||
padding: const EdgeDims.all(20.0),
|
||||
child: buildChart()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
|
||||
library fitness;
|
||||
|
||||
import 'package:playfair/playfair.dart' as playfair;
|
||||
import 'package:sky/editing/input.dart';
|
||||
import 'package:sky/painting/text_style.dart';
|
||||
import 'package:sky/theme/colors.dart' as colors;
|
||||
|
||||
@ -2,6 +2,7 @@ name: fitness
|
||||
dependencies:
|
||||
sky: any
|
||||
sky_tools: any
|
||||
playfair: any
|
||||
path: "^1.3.6"
|
||||
dependency_overrides:
|
||||
material_design_icons:
|
||||
|
||||
@ -464,6 +464,8 @@ sky_core_files = [
|
||||
"painting/Size.cpp",
|
||||
"painting/Size.h",
|
||||
"painting/TransferMode.h",
|
||||
"painting/Typeface.cpp",
|
||||
"painting/Typeface.h",
|
||||
"rendering/BidiRun.h",
|
||||
"rendering/BidiRunForLine.cpp",
|
||||
"rendering/BidiRunForLine.h",
|
||||
@ -682,6 +684,7 @@ core_idl_files = get_path_info([
|
||||
"painting/PictureRecorder.idl",
|
||||
"painting/RRect.idl",
|
||||
"painting/Shader.idl",
|
||||
"painting/Typeface.idl",
|
||||
"view/EventCallback.idl",
|
||||
"view/FrameCallback.idl",
|
||||
"view/View.idl",
|
||||
|
||||
@ -264,6 +264,14 @@ void Canvas::drawPaintingNode(PaintingNode* paintingNode, const Point& p)
|
||||
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,
|
||||
const Vector<RSTransform>& transforms, const Vector<Rect>& rects,
|
||||
const Vector<SkColor>& colors, SkXfermode::Mode mode,
|
||||
|
||||
@ -91,6 +91,7 @@ public:
|
||||
void drawPicture(Picture* picture);
|
||||
void drawDrawable(Drawable* drawable);
|
||||
void drawPaintingNode(PaintingNode* paintingNode, const Point& p);
|
||||
void drawText(const String& text, const Point& p, const Paint& paint);
|
||||
|
||||
void drawAtlas(CanvasImage* atlas,
|
||||
const Vector<RSTransform>& transforms, const Vector<Rect>& rects,
|
||||
|
||||
@ -39,6 +39,7 @@
|
||||
void drawPicture(Picture picture);
|
||||
void drawDrawable(Drawable drawable);
|
||||
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.
|
||||
[RaisesException] void drawAtlas(Image image,
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
#include "sky/engine/core/painting/PaintingStyle.h"
|
||||
#include "sky/engine/core/painting/Shader.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/wtf/text/StringBuilder.h"
|
||||
#include "third_party/skia/include/core/SkColorFilter.h"
|
||||
@ -35,6 +36,7 @@ enum PaintFields {
|
||||
kShader,
|
||||
kStyle,
|
||||
kTransferMode,
|
||||
kTypeface,
|
||||
|
||||
// kNumberOfPaintFields must be last.
|
||||
kNumberOfPaintFields,
|
||||
@ -82,6 +84,8 @@ Paint DartConverter<Paint>::FromDart(Dart_Handle dart_paint) {
|
||||
paint.setStyle(DartConverter<PaintingStyle>::FromDart(values[kStyle]));
|
||||
if (!Dart_IsNull(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;
|
||||
return result;
|
||||
|
||||
@ -43,6 +43,7 @@ class Paint {
|
||||
Shader _shader;
|
||||
PaintingStyle _style;
|
||||
TransferMode _transferMode;
|
||||
Typeface typeface;
|
||||
|
||||
// Must match PaintFields enum in Paint.cpp.
|
||||
List<dynamic> get _value {
|
||||
@ -57,6 +58,7 @@ class Paint {
|
||||
_shader,
|
||||
_style,
|
||||
_transferMode,
|
||||
typeface
|
||||
];
|
||||
}
|
||||
|
||||
@ -71,6 +73,8 @@ class Paint {
|
||||
// TODO(mpcomplete): Figure out how to show a drawLooper.
|
||||
if (_drawLooper != null)
|
||||
result += ', drawLooper:true';
|
||||
if (typeface != null)
|
||||
result += ', typeface: $_typeface';
|
||||
result += ')';
|
||||
return result;
|
||||
}
|
||||
|
||||
17
sky/engine/core/painting/Typeface.cpp
Normal file
17
sky/engine/core/painting/Typeface.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
// 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
|
||||
32
sky/engine/core/painting/Typeface.h
Normal file
32
sky/engine/core/painting/Typeface.h
Normal file
@ -0,0 +1,32 @@
|
||||
// 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_
|
||||
6
sky/engine/core/painting/Typeface.idl
Normal file
6
sky/engine/core/painting/Typeface.idl
Normal file
@ -0,0 +1,6 @@
|
||||
// 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 {
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user