The onTapGesture in SWiftUI doesn't work reliably. This example shows the problem, which is that sometimes when you tap on a cell, the background changes to grey as it should, and another time an adjacent cell changes and at other time nothing happens at all. Any ideas why?
struct ContentView: View {
#State var cellFg: [[Color]] = [
[.clear, .clear, .clear, .clear, .clear, .clear, .clear, .clear, .clear],
[.clear, .clear, .clear, .clear, .clear, .clear, .clear, .clear, .clear],
[.clear, .clear, .clear, .clear, .clear, .clear, .clear, .clear, .clear],
[.clear, .clear, .clear, .clear, .clear, .clear, .clear, .clear, .clear],
[.clear, .clear, .clear, .clear, .clear, .clear, .clear, .clear, .clear],
[.clear, .clear, .clear, .clear, .clear, .clear, .clear, .clear, .clear],
[.clear, .clear, .clear, .clear, .clear, .clear, .clear, .clear, .clear],
[.clear, .clear, .clear, .clear, .clear, .clear, .clear, .clear, .clear],
[.clear, .clear, .clear, .clear, .clear, .clear, .clear, .clear, .clear]
]
var body: some View {
VStack {
Spacer()
ForEach(0..<9) { row in
HStack {
Spacer()
ForEach(0..<9) { column in
Rectangle()
.foregroundColor(cellFg[row][column])
.border(Color.gray, width: 1)
// When you tap, it sometimes works, sometimes selects
// an adjacent cell and sometimes does nothing
.onTapGesture {
print("Row \(row) - Column\(column)")
cellFg[row][column] = .gray
}
}
Spacer()
}
}
Spacer()
}
}
}
Rectangle here is transparent but gesture requires content to be opaque.
Here is a fix (tested with Xcode 11.4 / iOS 13.4)
Rectangle()
.foregroundColor(self.cellFg[row][column])
.border(Color.gray, width: 1)
.contentShape(Rectangle()) // << here !!
the .contentShape make hit-testable entire frame independently of transparency.
Add an extension to fix this problem
private struct ExpandAreaTap: ViewModifier {
func body(content: Content) -> some View {
ZStack {
Rectangle()
.foregroundColor(Color.white)
.contentShape(Rectangle())
content
}
}
}
extension View {
func expandTap(tap: #escaping () -> ()) -> some View {
self.modifier(ExpandAreaTap()).onTapGesture(perform: tap)
}
}
Related
I want to make area chart with smooth line. and I have tried curveType : "function" and intervals : { "style" : "area", "color" : "#D49464" } but both are not working in my case here is my code -
var options = {
chartArea: { top: -10, height: '90%', width: '90%' },
height: 40,
width: 100,
legend: 'none',
curveType: 'function',
intervals: { 'style': 'area', 'color': '#D49464' },
hAxis: {
textPosition: 'none',
minValue: 0,
},
vAxis: {
minValue: 0,
textPosition: 'none',
gridlines: { count: 0 },
baselineColor: '#FFF',
},
areaOpacity: 0.1,
isStacked: true
};
i have an issue with ordering, combining and positioning of my solid shapes and text
the task is simple enough, but while im completely newbie in swfitui i cannot do it for my self
task: place solid shapes with zstack relative by their parrent using coordinates (including text of each shape) and apply isometric/perpective modifier
i will be glad for explanations and hints
this is what i have done for now
works without modifiers
and no with isometric modifier
struct ContentView: View {
#ObservedObject var datas = ReadData()
//MagnificationState
//DragState
//#GestureState
//#State viewMagnificationState
//#GestureState
//#State viewDragState
//magnificationScale
//translationOffset
//#State popoverState
//#State selectedShape
var body: some View {
//magnificationGesture
//dragGesture
//magnificationGesture.simultaneously
GeometryReader { geometry in
ZStack(alignment: .topLeading) {
MainShape(showingPopover: $popoverState,
setCurrentShape: $selectedShape,
alldatas: datas.pokedex)
}
.scaleEffect(magnificationScale)
.offset(translationOffset)
//.position(x: geometry.size.width / 2, y: geometry.size.height / 2)
//.gesture(both)
//popover
}
.edgesIgnoringSafeArea(.all)
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
struct MainShape: View {
let alldatas: [PokedexElement]
var body: some View {
ForEach(alldatas, id: \.id) { shape in
ZStack(alignment: .topLeading) {
Text(shape.metaProperties.name)
.font(.system(size: 20))
.zIndex(2)
.offset(x: shape.metaProperties.offset.x, y: shape.metaProperties.offset.y)
Rectangle()
.cornerRadius(shape.id == 1 ? 55 : 10)
.foregroundColor(chooseColor(shape.metaProperties.color))
.offset(x: shape.metaProperties.offset.x, y: shape.metaProperties.offset.y)
.frame(
width: shape.metaProperties.size.width,
height: shape.metaProperties.size.height
)
.isometric()
.zIndex(1)
.onTapGesture {
self.showingPopover = true
self.setCurrentShape = shape.id
}
}
}
}
}
data:
[
{
"id": 1,
"parentId": 0,
"baseProperties": {
"name": "",
"descr": "",
"contacts": ""
},
"metaProperties": {
"name": "root",
"status": true,
"type": "plain",
"size": {
"width": 350,
"height": 350
},
"offset": {
"x": 0,
"y": 0
},
"color": "blue"
}
},
{
"id": 2,
"parentId": 1,
"baseProperties": {
"name": "object 1",
"descr": "",
"contacts": ""
},
"metaProperties": {
"name": "child 1",
"status": true,
"type": "imobject",
"size": {
"width": 50,
"height": 50
},
"offset": {
"x": 50,
"y": 50
},
"color": "red"
}
},
{
"id": 3,
"parentId": 1,
"baseProperties": {
"name": "object 1",
"descr": "",
"contacts": ""
},
"metaProperties": {
"name": "child 2",
"status": true,
"type": "imobject",
"size": {
"width": 100,
"height": 50
},
"offset": {
"x": 100,
"y": 50
},
"color": "green"
}
}
]
and modifiers…
extension View {
func chooseColor(_ name: String) -> Color {
switch name {
case "red":
return Color.red
case "blue":
return Color.blue
case "brown":
return Color.brown
case "green":
return Color.green
case "yellow":
return Color.yellow
case "white":
return Color.white
default :
return Color.black
}
}
func perspective() -> some View {
self
.rotation3DEffect(.degrees(45), axis: (x: 1, y: 0, z: 0))
}
func isometric() -> some View {
self
.rotationEffect(Angle.init(degrees: 45))
.scaleEffect(y: 0.5)
}
}
task was easy, instead of using regular solid shapes with "magic methods from black box" do it all manually
convert decart to iso and place it whatever you want together with text or anything else and offset will be fine
family of programmers. I'm new to programming, I'm having a hard time transferring data from a screen to a list, where the user can review the messages sent. Sorry for this one with a silly question like that, but I already tried it in the library, videos and etc. But I did not find the solution, please, could someone help me with this? Thanks! (I've been stuck on this issue for days).
My code:
import 'dart:io';
import 'package:flutter/services.dart';
import 'package:animated_text_kit/animated_text_kit.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:animated_button/animated_button.dart';
import 'package:giffy_dialog/giffy_dialog.dart';
import 'package:mailer/mailer.dart';
import 'package:mailer/smtp_server/gmail.dart';
import 'package:ouvidoria_mvl/main.dart';
// ignore: must_be_immutable
class PaginadeBoasVindasAN extends StatelessWidget {
String _localAn;
String _problemaAn;
File _imagemAn;
File _imagemGaleriaAn;
PaginadeBoasVindasAN(
this._localAn,
this._problemaAn,
this._imagemAn,
this._imagemGaleriaAn,
);
final _formKey = GlobalKey<FormState>();
// Aqui vamos criar o e-mail - smtp
enviarMensagem() async {
String username = '#gmail.com';
String password = '4#';
final smtpServer = gmail(username, password);
// Use the SmtpServer class to configure an SMTP server:
// final smtpServer = SmtpServer('smtp.domain.com');
// See the named arguments of SmtpServer for further configuration
// options.
// Create our message.
final message = Message()
..from = Address('', '')
..recipients.add('#gmail.com')
..ccRecipients.addAll(['destCc1#gmail.com', 'destCc1#gmail.com'])
..bccRecipients.add(Address('destCc1#gmail.com'))
..subject = '$_localAn :: ${DateTime.now()}'
..text = 'LOCAL DA OCORRÊNCIA: $_localAn,n\ OCORRÊNCIA: $_problemaAn';
if ((_imagemAn != null) && (_imagemAn != ""))
message.attachments.add(FileAttachment(_imagemAn,));
if ((_imagemGaleriaAn!= null) && (_imagemGaleriaAn!= ""))
message.attachments.add(FileAttachment(_imagemGaleriaAn,));
try {
final sendReport = await send(message, smtpServer);
print('Mensagem enviada: ' + sendReport.toString());
} on MailerException catch (e) {
print('Mensagem não enviada.');
for (var p in e.problems) {
print('Problema: ${p.code}: ${p.msg}');
}
}
var connection = PersistentConnection(smtpServer);
await connection.send(message);
await connection.close();
}
// HERE THE APP CONFIGURATION IS ENDED
// The Function below blocks the screen rotation, thus allowing the app to stay in vertical mode
void blockgiro() {
SystemChrome.setPreferredOrientations(
[DeviceOrientation.portraitDown, DeviceOrientation.portraitUp]);
}
#override
Widget build(BuildContext context) {
blockgiro();
return Stack(children: <Widget>[
Scaffold(
backgroundColor: Colors.white,
body: SingleChildScrollView(
padding: EdgeInsets.only(bottom: 20),
child: Container(
margin: EdgeInsets.all(10),
color: Colors.transparent,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
margin: EdgeInsets.only(
left: 1,
bottom: 10,
top: 10,
),
padding: EdgeInsets.all(10),
height: 200,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
blurRadius: 0,
color: Colors.white,
offset: Offset(0, 0))
],
borderRadius: BorderRadius.circular(13),
color: Colors.white),
child:
Image.asset("Assets/image/enviando-loading.gif")),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
padding: EdgeInsets.only(
bottom: 30, right: 1, left: 1, top: 20),
),
Container(
margin: EdgeInsets.only(
left: 1,
bottom: 10,
top: 5,
),
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
blurRadius: 2,
color: Colors.black54,
offset: Offset(1, 1))
],
borderRadius: BorderRadius.circular(13),
color: Colors.white),
child: Align(
alignment: Alignment.topLeft,
child: SizedBox(
width: 250.0,
child: TypewriterAnimatedTextKit(
pause: Duration(minutes: 10),
speed: Duration(milliseconds: 100),
onTap: () {
print("Tap Event");
},
text: ['The location is this: $_localAn'],
textStyle: TextStyle(
color: Colors.black,
fontSize: 20.0,
fontFamily: "Agne"),
textAlign: TextAlign.start,
),
),
),
),
Container(
margin: EdgeInsets.only(
left: 1,
bottom: 10,
top: 10,
),
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
blurRadius: 4,
color: Colors.black54,
offset: Offset(2, 2))
],
borderRadius: BorderRadius.circular(13),
color: Colors.white),
child: Align(
alignment: Alignment.topLeft,
child: SizedBox(
width: 1000.0,
child: TypewriterAnimatedTextKit(
pause: Duration(minutes: 10),
onTap: () {
print("Tap Event");
},
text: [
'Its occurrence: $_problemaAn',
],
textStyle: TextStyle(
color: Colors.black,
fontSize: 20.0,
fontFamily: "Agne"),
textAlign: TextAlign.justify,
curve: Curves.linear),
),
)),
Container(
margin: EdgeInsets.all(10),
padding: EdgeInsets.all(10),
child: _imagemAn != null
? Image.file(
_imagemAn,
fit: BoxFit.scaleDown,
)
: Center(
child: Text(
'',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w400),
),
),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
blurRadius: 1,
color: Colors.transparent,
offset: Offset(1, 1))
],
borderRadius: BorderRadius.circular(30),
color: Colors.transparent),
),Container(
margin: EdgeInsets.all(10),
padding: EdgeInsets.all(10),
child: _imagemGaleriaAn != null
? Image.file(
_imagemGaleriaAn,
fit: BoxFit.scaleDown,
)
: Center(
child: Text(
'Capture a photo',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w400),
),
),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
blurRadius: 1,
color: Colors.transparent,
offset: Offset(1, 1))
],
borderRadius: BorderRadius.circular(30),
color: Colors.transparent),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TypewriterAnimatedTextKit(
pause: Duration(minutes: 10),
onTap: () {
print("Select below");
},
text: [
'Need to edit your message?',
],
textStyle: TextStyle(
fontWeight: FontWeight.w600,
color: Colors.lightBlueAccent,
fontSize: 20.0,
fontFamily: "Agne"),
textAlign: TextAlign.center,
curve: Curves.linear),
],
),
//INICIO DOS BOTOES SIM E NAO
Container(
padding: EdgeInsets.only(bottom: 50),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
margin: EdgeInsets.only(
bottom: 2, top: 2, right: 55),
alignment: Alignment.centerLeft,
child: AnimatedButton(
shape: BoxShape.rectangle,
child: Text(
'Edit',
style: TextStyle(
fontSize: 15,
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
onPressed: () {
Navigator.pop(context);
},
width: 70,
height: 40,
color: Theme.of(context).primaryColor,
shadowDegree: ShadowDegree.dark,
enabled: true,
),
),
//ACIMA SIM, ABAIXO NÃO
Container(
margin: EdgeInsets.only(
bottom: 2, top: 2, left: 55),
alignment: Alignment.centerRight,
child: AnimatedButton(
child: const Text(
'Send',
style: TextStyle(
fontSize: 19,
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
onPressed: () {
enviarMensagem();
showDialog(
context: context,
builder: (_) => AssetGiffyDialog(
image: Image.asset(
'Assets/image/Correta.gif'),
title: Text(
'Success',
style: TextStyle(
fontSize: 22.0,
fontWeight:
FontWeight.w600),
),
description: Text(
'Hi, we received your message',
style: TextStyle(),
),
entryAnimation:
EntryAnimation.BOTTOM_RIGHT,
onlyCancelButton: false,
onOkButtonPressed: () async {
final result =
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
splashScreen()));
},
onlyOkButton: true,
));
},
width: 70,
height: 40,
color: Theme.of(context).primaryColor,
shadowDegree: ShadowDegree.dark,
enabled: true,
),
)
],
),
],
),
Container(
padding: EdgeInsets.only(bottom: 50),
),
]))),
)
]);
}
}
I have this apexcharts definition and when i've got more than e.g. 300 datasamples for my series things are overlapping on the xAxis like this
i would rather see something like this though
The option "hideOverlapLabels" does not work since it only works with timeseries from what i've read.
I know i can reduce the ticks but i want the chart to be zoomable and have all data in it.
Is there a way how i can prevent the labels to overlap?
var options_apex = {
series: null,
colors: [ '#0054ff', '#FF0000' ,'#FF0000'],
chart: {
height: 450,
type: 'line',
zoom: {
enabled: true
},
animations: {
enabled: false
}
},
stroke: {
width: [3, 3, 3],
curve: 'straight'
},
labels: null,
title: {
text: "Serial Data",
align: 'center',
margin: 10,
offsetX: 0,
offsetY: 0,
floating: false,
style: {
fontSize: '14px',
fontWeight: 'bold',
fontFamily: undefined,
color: '#263238'
},
},
subtitle: {
text: "the reckoning",
align: 'center',
margin: 10,
offsetX: 0,
offsetY: 20,
floating: true,
style: {
fontSize: '12px',
fontWeight: 'normal',
fontFamily: undefined,
color: '#9699a2'
},
},
xaxis: {
type:"category",
labels: {
rotate: -90,
rotateAlways: true,
hideOverlappingLabels: true,
style: {
colors: [],
fontSize: '7px',
fontFamily: 'Roboto',
fontWeight: 100,
cssClass: 'apexcharts-xaxis-label',
}
},
axisTicks: {
show: true,
borderType: 'solid',
color: '#78909C',
height: 6,
offsetX: 0,
offsetY: 0
},
tickAmount: undefined,
title: {
text: "STEP ID",
offsetX: 0,
offsetY: 0,
style: {
color: "#0000ff",
fontSize: '12px',
fontFamily: 'Helvetica, Arial, sans-serif',
fontWeight: 600,
cssClass: 'apexcharts-xaxis-title',
},
}
},
};
i used: tickAmount:15 , and work for my , this show 15 values and hide anothers, also you can try applied formatt and if condicional, to xaxis with:
formatter: function (value) {
if(value && ((value.split(':')[1][1] === '0') || (value.split(':')[1][1] === '5'))){
return (value);
}else{
value='';
return('');
}
}
I think i found the solution
xaxis: {
type:"category",
tooltip: {
enabled: false,
formatter: undefined,
offsetY: 0,
style: {
fontSize: 0,
fontFamily: 0,
},
},
labels: {
rotate: -45,
rotateAlways: true,
hideOverlappingLabels: true,
style: {
colors: [],
fontSize: '6px',
fontFamily: 'Roboto',
fontWeight: 80,
//cssClass: 'apexcharts-xaxis-label',
},
axisTicks: {
show: true,
borderType: 'solid',
color: '#78909C',
height: 6,
offsetX: 0,
offsetY: 0
},
},
With this setup and setting not the Labels but Categories with
options_apex.xaxis.categories = labels;
things seem to work without overlapping.
I want the annotations above columns to always BE ABOVE columns. I set annotations.alwaysOutside to true, but whenever a column reaches the roof of the chart, it will position the annotation within the column. If you run the code on JSFiddle you'll see what I mean.
So, how can I force annotations to ALWAYS display above columns?
https://jsfiddle.net/y7ootfoo/
<link href='https://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load("current", {
packages: ['corechart']
});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
["Mana Cost", "Cards"],
["0", 1],
["1", 2],
["2", 3],
["3", 4],
["4", 4],
["5", 3],
["6", 2],
["7+", 1],
]);
var view = new google.visualization.DataView(data);
view.setColumns([0, 1, {
calc: "stringify",
sourceColumn: 1,
type: "string",
role: "annotation",
}, ]);
var options = {
title: "Cards/Mana Cost",
width: '750',
height: '375',
backgroundColor: "#FFF",
enableInteractivity: false,
bar: {
groupWidth: "90%"
},
legend: {
position: "none"
},
annotations: {
alwaysOutside: true,
stem: {
color: "transparent"
},
textStyle: {
fontName: 'Lato',
fontSize: 18.75,
bold: true,
italic: false,
auraColor: 'transparent',
color: "#000"
}
},
chartArea: {
backgroundColor: "#FFF"
},
titleTextStyle: {
color: "#000",
fontName: "Lato",
fontSize: 25,
bold: true,
italic: false
},
vAxis: {
gridlines: {
color: 'transparent'
},
textPosition: "none"
},
hAxis: {
textStyle: {
color: "#000",
fontName: "Lato",
fontSize: 18.75,
bold: true,
italic: false
}
}
};
var chart = new google.visualization.ColumnChart(document.getElementById("columnchart_values"));
chart.draw(view, options);
}
</script>
<div id="columnchart_values" style="width: 900px; height: 300px;"></div>
set
var options = {
vAxis: {
viewWindow:{
max: maxV, //maximum value of annotations + 1
},
}}
I also add
chartArea: {
width: '95%',
}
https://jsfiddle.net/damiantt/y7ootfoo/1/
complete code:
<link href='https://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load("current", {
packages: ['corechart']
});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
["Mana Cost", "Cards"],
["0", 1],
["1", 2],
["2", 3],
["3", 4],
["4", 4],
["5", 3],
["6", 2],
["7+", 1],
]);
var maxV = 0;
for (var i = 0; i < data.getNumberOfRows(); i++) {
if(data.getValue(i, 1) > maxV) {
maxV = data.getValue(i, 1);
}
}
maxV++;
var view = new google.visualization.DataView(data);
view.setColumns([0, 1, {
calc: "stringify",
sourceColumn: 1,
type: "string",
role: "annotation",
}, ]);
var options = {
title: "Cards/Mana Cost",
width: '750',
height: '375',
backgroundColor: "#FFF",
enableInteractivity: false,
bar: {
groupWidth: "90%"
},
legend: {
position: "none"
},
annotations: {
alwaysOutside: true,
stem: {
color: "transparent"
},
textStyle: {
fontName: 'Lato',
fontSize: 18.75,
bold: true,
italic: false,
auraColor: 'transparent',
color: "#000"
}
},
chartArea: {
width: '95%',
backgroundColor: "#FFF"
},
titleTextStyle: {
color: "#000",
fontName: "Lato",
fontSize: 25,
bold: true,
italic: false
},
vAxis: {
viewWindow:{
max:maxV,
},
gridlines: {
color: 'transparent'
},
textPosition: "none"
},
hAxis: {
textStyle: {
color: "#000",
fontName: "Lato",
fontSize: 18.75,
bold: true,
italic: false
}
}
};
var chart = new google.visualization.ColumnChart(document.getElementById("columnchart_values"));
chart.draw(view, options);
}
</script>
<div id="columnchart_values" style="width: 900px; height: 300px;"></div>