Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
dart_pdf
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
David PHAM-VAN
2021-04-24 07:34:36 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d07c16a36f7686751c30a7313b87cd8c84f4dc33
d07c16a3
1 parent
4cdf1f79
Improve PieChart default colors
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
11 deletions
demo/lib/examples/invoice.dart
demo/lib/examples/report.dart
pdf/CHANGELOG.md
pdf/lib/src/pdf/color.dart
pdf/lib/src/widgets/chart/pie_chart.dart
demo/lib/examples/invoice.dart
View file @
d07c16a
...
...
@@ -83,11 +83,9 @@ class Invoice {
static
const
_darkColor
=
PdfColors
.
blueGrey800
;
static
const
_lightColor
=
PdfColors
.
white
;
PdfColor
get
_baseTextColor
=>
baseColor
.
luminance
<
0.5
?
_lightColor
:
_darkColor
;
PdfColor
get
_baseTextColor
=>
baseColor
.
isLight
?
_lightColor
:
_darkColor
;
PdfColor
get
_accentTextColor
=>
baseColor
.
luminance
<
0.5
?
_lightColor
:
_darkColor
;
PdfColor
get
_accentTextColor
=>
baseColor
.
isLight
?
_lightColor
:
_darkColor
;
double
get
_total
=>
products
.
map
<
double
>((
p
)
=>
p
.
total
).
reduce
((
a
,
b
)
=>
a
+
b
);
...
...
demo/lib/examples/report.dart
View file @
d07c16a
...
...
@@ -282,17 +282,13 @@ Future<Uint8List> generateReport(
datasets:
List
<
pw
.
Dataset
>.
generate
(
dataTable
.
length
,
(
index
)
{
final
data
=
dataTable
[
index
];
final
color
=
chartColors
[
index
%
chartColors
.
length
];
final
textColor
=
color
.
luminance
<
0.2
?
PdfColors
.
white
:
PdfColors
.
black
;
final
value
=
(
data
[
2
]
as
num
).
toDouble
();
final
pct
=
(
value
/
expense
*
100
).
round
();
return
pw
.
PieDataSet
(
legend:
'
${data[0]}
\n
$pct
%'
,
value:
value
,
color:
color
,
legendStyle:
pw
.
TextStyle
(
fontSize:
10
,
color:
textColor
),
legendStyle:
pw
.
TextStyle
(
fontSize:
10
),
);
}),
),
...
...
pdf/CHANGELOG.md
View file @
d07c16a
...
...
@@ -13,6 +13,7 @@
-
Passthrough SpanningWidget on SingleChildWidget and StatelessWidget
-
Improve TextOverflow support
-
Fix Table horizontalInside borders
-
Improve PieChart default colors
## 3.2.0
...
...
pdf/lib/src/pdf/color.dart
View file @
d07c16a
...
...
@@ -180,6 +180,16 @@ class PdfColor {
return
math
.
pow
((
component
+
0.055
)
/
1.055
,
2.4
).
toDouble
();
}
/// Determines whether the given [PdfColor] is light.
bool
get
isLight
=>
!
isDark
;
/// Determines whether the given [PdfColor] is dark.
bool
get
isDark
{
final
relativeLuminance
=
luminance
;
const
kThreshold
=
0.15
;
return
(
relativeLuminance
+
0.05
)
*
(
relativeLuminance
+
0.05
)
>
kThreshold
;
}
/// Get the luminance
double
get
luminance
{
final
R
=
_linearizeColorComponent
(
red
);
...
...
@@ -240,6 +250,12 @@ class PdfColor {
int
get
hashCode
=>
toInt
();
}
class
PdfColorGrey
extends
PdfColor
{
/// Create a grey color
const
PdfColorGrey
(
double
color
,
[
double
alpha
=
1.0
])
:
super
(
color
,
color
,
color
,
alpha
);
}
/// Represents an CMYK color
class
PdfColorCmyk
extends
PdfColor
{
/// Creates a CMYK color
...
...
pdf/lib/src/widgets/chart/pie_chart.dart
View file @
d07c16a
...
...
@@ -126,13 +126,14 @@ class PieDataSet extends Dataset {
this
.
legendAlign
,
this
.
legendPosition
=
PieLegendPosition
.
auto
,
this
.
legendLineWidth
=
1.0
,
this
.
legendLineColor
=
PdfColors
.
black
,
PdfColor
?
legendLineColor
,
Widget
?
legendWidget
,
this
.
legendOffset
=
20
,
})
:
drawBorder
=
drawBorder
??
borderColor
!=
null
&&
color
!=
borderColor
,
assert
((
drawBorder
??
borderColor
!=
null
&&
color
!=
borderColor
)
||
drawSurface
),
_legendWidget
=
legendWidget
,
legendLineColor
=
legendLineColor
??
color
,
super
(
legend:
legend
,
color:
color
,
...
...
@@ -201,7 +202,18 @@ class PieDataSet extends Dataset {
_legendWidget
??=
legend
==
null
?
null
:
Text
(
legend
!,
style:
legendStyle
,
textAlign:
_legendAlign
);
:
RichText
(
text:
TextSpan
(
children:
[
TextSpan
(
text:
legend
!,
style:
legendStyle
)],
style:
TextStyle
(
color:
lp
==
PieLegendPosition
.
inside
?
color
!.
isLight
?
PdfColors
.
white
:
PdfColors
.
black
:
null
),
),
textAlign:
_legendAlign
,
);
if
(
_legendWidget
!=
null
)
{
_legendWidget
!.
layout
(
context
,
...
...
Please
register
or
login
to post a comment