Identical constraints on identical images, different behaviour? - ios

I'm using the same image inside different imageviews, with the same constraints, yet somehow, last 2 images don't keep aspect ratios, despite constraints.
Here's the constraint code.
PS: all of them have the following 2 lines. (I just removed those lines from each group to avoid wall of code).
.contentMode = .scaleAspectFit
.translatesAutoresizingMaskIntoConstraints = false
ImageLineEvents.topAnchor.constraint(equalTo: LabelTitleEvents.bottomAnchor, constant:UI_SPACING_SCROLL).isActive = true
ImageLineEvents.centerXAnchor.constraint(equalTo: ScrollView.centerXAnchor).isActive = true
ImageLineEvents.widthAnchor.constraint(equalTo: VC_UserProfile.view.widthAnchor).isActive = true
ImageLineEvents.widthAnchor.constraint(equalTo: ImageLineEvents.heightAnchor, multiplier: (ImageLineEvents.image?.size.width)! / (ImageLineEvents.image?.size.height)!).isActive = true
ImageLineUpdates.topAnchor.constraint(equalTo: LabelTitleUpdates.bottomAnchor, constant:UI_SPACING_SCROLL).isActive = true
ImageLineUpdates.centerXAnchor.constraint(equalTo: ScrollView.centerXAnchor).isActive = true
ImageLineUpdates.widthAnchor.constraint(equalTo: VC_UserProfile.view.widthAnchor).isActive = true
ImageLineUpdates.widthAnchor.constraint(equalTo: ImageLineUpdates.heightAnchor, multiplier: (ImageLineUpdates.image?.size.width)! / (ImageLineUpdates.image?.size.height)!).isActive = true
ImageLineSoon.topAnchor.constraint(equalTo: LabelTitleSoon.bottomAnchor, constant:UI_SPACING_SCROLL).isActive = true
ImageLineSoon.centerXAnchor.constraint(equalTo: ScrollView.centerXAnchor).isActive = true
ImageLineSoon.widthAnchor.constraint(equalTo: VC_UserProfile.view.widthAnchor).isActive = true
ImageLineSoon.widthAnchor.constraint(equalTo: ImageLineSoon.heightAnchor, multiplier: (ImageLineSoon.image?.size.width)! / (ImageLineSoon.image?.size.height)!).isActive = true
ImageLineToday.topAnchor.constraint(equalTo: LabelTitleToday.bottomAnchor, constant:UI_SPACING_SCROLL).isActive = true
ImageLineToday.centerXAnchor.constraint(equalTo: ScrollView.centerXAnchor).isActive = true
ImageLineToday.widthAnchor.constraint(equalTo: VC_UserProfile.view.widthAnchor).isActive = true
ImageLineToday.widthAnchor.constraint(equalTo: ImageLineToday.heightAnchor, multiplier: (ImageLineToday.image?.size.width)! / (ImageLineToday.image?.size.height)!).isActive = true
Everything is fine in portait mode, but when I turn to landscape, somehow last 2 images do not keep aspect ratios. I have logs from each orientation.
print("ar = \(Float((ImageLineEvents.image?.size.width)!) / Float((ImageLineEvents.image?.size.height)!))")
print("ar = \(Float((ImageLineUpdates.image?.size.width)!) / Float((ImageLineUpdates.image?.size.height)!))")
print("ar = \(Float((ImageLineSoon.image?.size.width)!) / Float((ImageLineSoon.image?.size.height)!))")
print("ar = \(Float((ImageLineToday.image?.size.width)!) / Float((ImageLineToday.image?.size.height)!))")
print("w = \(ImageLineEvents.frame.width)")
print("w = \(ImageLineUpdates.frame.width)")
print("w = \(ImageLineSoon.frame.width)")
print("w = \(ImageLineToday.frame.width)")
print("h = \(ImageLineEvents.frame.height)")
print("h = \(ImageLineUpdates.frame.height)")
print("h = \(ImageLineSoon.frame.height)")
print("h = \(ImageLineToday.frame.height)")
These are from portrait and everything is as expected.
ar = 162.5
ar = 162.5
ar = 162.5
ar = 162.5
w = 335.0
w = 335.0
w = 335.0
w = 335.0
h = 2.0
h = 2.0
h = 2.0
h = 2.0
Yet if I turn to landscape, last 2 have different results.
ar = 162.5
ar = 162.5
ar = 162.5
ar = 162.5
w = 684.0
w = 684.0
w = 684.0
w = 684.0
h = 4.33333333333333
h = 4.33333333333333
h = 4.0 (Why is this not 4.33 ???)
h = 4.0 (Why is this not 4.33 ???)
I looked millions of times but I still can't figure out what's wrong with this. There are no constraint errors. Visually, last 2 images do not go all over the edges, because they keep aspect ratios, yet somehow the height is lower. They are all inside a ScrollView, but I don't see how that can matter. Any help ?
EDIT:
I've added the visual result. First 2 constraints are the first image, last 2 are the last image. As you can see, their widths are not the same in landscape. The image in question is the line just below the title and it should spread from title leading to dot image trailing. All of them behave well on portrait, yet on landscape, last 2 behave differently.
Correct Behaviour
Wrong Behaviour

Related

How to assign one conditional label per stacked bar (not per stack) on time series ggplot in facet grid

I would love to have your input how to solve this issues.
I have a time series (x=date) ggplot with bars (y=cmass1), and my bars are on position="stack" using a factor (polymer) to display polymer types for each sample.
Each bar represents another sampling station (factor sample), and I would like to identify which bar is which station (factor "sample" in my data frame) and add the label above each bar.
I've come so far that I can show the "sample" labels, but then there appear multiple replicated labels (one for each data point in the stacked parts of the bar). But I need only one per bar!
Can someone help, how I can create one label per bar (above each bar) that identifies which sample it is (without manual annotation)?
Additional date display problem:
Also, on one date (11 November) I have two samples, and in this plot they are cumulated, but I would need them next to each - so two as stacked bars on one date (like with besides=TRUE, but that doesn't seem to work with stacked bars). Any help here?
I hope it is clear, and thanks so much for any help!
Cleo
The plot, where S1, S2 etc should be above each bar as a label
Dataframe view_partial
ggplot(Merg1[!(is.na(Merg1$campaign)),] ,
aes(date,y=cmass1,group_by(sample1), fill=polymer))+
geom_col(show.legend = T, alpha = 0.8, position="stack",
stat="identity")+
xlab("July 2021 November 2021 February 2022 July 2022") +
facet_grid(.~campaign, scales = "free_x",space = "free_x" )+
geom_point(aes(y=montsouris_mm*20 ),color="#A3009F",size=2.5, position="dodge")+
geom_point(aes(y=melun_mm*20 ),color="#558C8C",size=2.5, position="dodge")+
geom_point(aes(y=fauville_mm*20 ),color="#E8DB7D",size=2.5, position="dodge")+
scale_y_continuous(expand = c(0,0),limits=c(0, 1000), breaks = seq(0, 1000, by = 100),
sec.axis = sec_axis(~./20, name = "Precipitation (mm)",
breaks = seq(0, 50, by = 10))) +
scale_x_date(date_breaks = "1 day", labels = date_format("%d"))+
ylab(expression(bold(paste(~C[mass]~ (µg ~L^{-1}))))) +
theme(axis.text.x=element_text(color="black", size=12, angle=0, vjust=0.5),
axis.text.y=element_text(color="black", size=12, angle=0, vjust=0.5),
axis.ticks.x=element_blank(),
axis.title.x = element_text(size = 12,
color = "black",
face = "bold"),
strip.background = element_rect(color="white", fill="white", size=0.5,
linetype="solid"),
legend.text = element_text(color = "black",size = 12),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_rect(size = 0.5,colour="#D4CDCB",
fill="white" ,linetype = 'solid'),
legend.key.height= unit(0.2, 'cm'),
legend.key.width= unit(0.4, 'cm'))+
scale_fill_manual(name = "", values = MPcol, breaks = c("abs","acrylic", "acrylic paints", "alkyd","epoxy", "pa", "pan_acrylic fibre", "pe", "polyester", "pp", "ps", "pu", "pvac", "pvc", "sbr", "vinyl copolymer"),
labels=c("Acrylonitrile butadiene styrene (ABS)","Acrylic", "Acrylic paint", "Alkyd", "Epoxy", "Polyamide (PA)", "Pan acrylic fibre", "Polyethylene (PE)", "Polyester (PET)", "Polypropylene (PP)", "Polystyrene (PS)", "Polyurethane (PU)", "Polyvinyl acetate (PVAC)", "Poly vinyl chloride (PVC)", "Styrene butadiene rubber (SBR)", "Vinyl copolymere"))+
theme(legend.position = "bottom",
legend.background = element_rect(fill = "#FFFCFB", # Background
colour = 1),
legend.title = element_text(family = "sans",
color = "black",
size = 10,
face = 2)) +
theme(panel.grid.minor = element_line(color = "#D4CDCB",
size = 0.15,
linetype = 2))+
theme(strip.text.x = element_text(size=14, face="bold",
vjust = 2, color="black")) +
#geom_text( label = label1, vjust = -1, position = position_dodge(0.90), size = 3, hjust=-0.5)+
labs(title = "Microplastics",
subtitle = "Mass Concentrations by Polymer Types",
caption = "Still missing S4 repeated samples and M1 in Campaign D. S4 in Campaign C cumulated repetaed samples. MPs >300µm are excluded, also natural particles are excluded.",
tag = "Fig. 5-1") +
theme(plot.title = element_text(family = "serif", # Font family
face = "bold", # Font face
color = 1, # Font color
size = 16, # Font size
hjust = 1, # Horizontal adjustment
vjust = 1, # Vertical adjustment
angle = 0, # Font angle
lineheight = 1, # Line spacing
margin = margin(5, 0, 0, 0)), # Margins (t, r, b, l)
plot.subtitle = element_text(family = "serif",
hjust = 1, size=14), # Subtitle customization
plot.caption = element_text(hjust = 0.25, size =11,
family = "serif",face = "italic"), # Caption customization
plot.tag = element_text(face = "italic"), # Tag customization
plot.title.position = "plot", # Title and subtitle position ("plot" or "panel")
plot.caption.position = "panel", # Caption position ("plot" or "panel")
plot.tag.position = "top") # Tag position

how to show all x label charts ios?

I make a custom numbering label, everything works great. the problem is when the number of entries is less than X-axis maximum, the chart doesn't show any lines.
lineChart.data = data
let leftAxis = lineChart.leftAxis
//set constant label range
leftAxis.forceLabelsEnabled = true
leftAxis.labelCount = 4
leftAxis.axisMinimum = 0
leftAxis.axisMaximum = 4.5
leftAxis.granularity = 1
leftAxis.axisLineWidth = 0
leftAxis.valueFormatter = YAxisData()
//x axis label
let bottomAxis = lineChart.xAxis
bottomAxis.axisMinimum = 1
bottomAxis.axisMaximum = 7.0
bottomAxis.labelCount = 7
bottomAxis.forceLabelsEnabled = true
bottomAxis.granularity = 1
bottomAxis.axisLineWidth = 0
bottomAxis.valueFormatter = XAxisData()
bottomAxis.labelHeight = 30
if I changed the number of entries to 7, it works fine.
I want a way to show all x labels even if the number of entries is less than 7!

Changing Chart Number Labels to Text not working (iOS Charts)

I'm plotting sunrise/sunset against time, so time goes along the X axis with iOS Charts (Daniel Gindi).
If I display the x labels as numbers they manifest correctly: If I swap them over to text (Jan - Dec) only Jan shows up???
Associated iOS Chart code:
// Setup X Axis
lineChartView.xAxis.axisMinimum = 0
lineChartView.xAxis.axisMaximum = 366
lineChartView.xAxis.granularityEnabled = true
lineChartView.xAxis.granularity = 30
lineChartView.xAxis.labelCount = 12
lineChartView.xAxis.axisLineWidth = 2
lineChartView.xAxis.axisLineColor = .black
lineChartView.xAxis.centerAxisLabelsEnabled = true
If I swap it over to literals then I only get Jan. All the values are populated. Any ideas?
Code: (n.b. putting labelCount before IndexAxisValueFormatter(values:months) makes no difference.)
// Setup X Axis
let months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sept","Oct","Nov","Dec"]
lineChartView.xAxis.axisMinimum = 0
lineChartView.xAxis.axisMaximum = 366
lineChartView.xAxis.granularityEnabled = true
lineChartView.xAxis.granularity = 30
lineChartView.xAxis.labelCount = 12
lineChartView.xAxis.valueFormatter = IndexAxisValueFormatter(values:months)
lineChartView.xAxis.axisLineWidth = 2
lineChartView.xAxis.axisLineColor = .black
lineChartView.xAxis.centerAxisLabelsEnabled = true

Roblox, how to make something only tween in one direction?

I tried doing
local fakeRightArm = Instance.new("Part")
fakeRightArm.BottomSurface = Enum.SurfaceType.Smooth
fakeRightArm.CanCollide = false
fakeRightArm.Massless = true
fakeRightArm.Material = Enum.Material.Plastic
fakeRightArm.BrickColor = RightArm.BrickColor
fakeRightArm.Size = RightArm.Size
fakeRightArm.CFrame = RightArm.CFrame
fakeRightArm.Parent = character
fakeRightArm.Name = "fakeRightArm"
local weld = Instance.new("WeldConstraint")
weld.Part0 = RightArm
weld.Part1 = fakeRightArm
weld.Parent = character
weld.Name = "FakeArmWeld"
tweenService:Create(fakeRightArm, TweenInfo.new(0.3, Enum.EasingStyle.Quad), {Size = fakeRightArm.Size + Vector3.new(0, 50, 0), CFrame = fakeRightArm.CFrame * CFrame.new(0,0,-50)}):Play()
but that seems to not work. It's probably because of the weld.
I want it so it tweens the arm forward.
DevForum post (maybe more detailed): https://devforum.roblox.com/t/how-to-only-tween-in-one-direction/841408/42
Thank you!
don't think you need the tween function just to position it
https://developer.roblox.com/en-us/api-reference/datatype/CFrame
start with the right arm position, then rotate its coordinate frame.
local fakeRightArm = Instance.new("Part")
fakeRightArm.BottomSurface = Enum.SurfaceType.Smooth
fakeRightArm.CanCollide = false
fakeRightArm.Massless = true
fakeRightArm.Material = Enum.Material.Plastic
fakeRightArm.BrickColor = RightArm.BrickColor
fakeRightArm.Size = RightArm.Size
fakeRightArm.Parent = character
fakeRightArm.Anchored = true
fakeRightArm.Name = "fakeRightArm"
-- you pick which angle to make it face
local Xdir = math.rad( 0 ) -- twist palm up, palm down
local Ydir = math.rad( 90 ) -- lift up / down
local Zdir = math.rad( 15 ) -- swing left / right
fakeRightArm.CFrame = RightArm.Position *CFrame.Angles( Xdir, Ydir, Zdir )

in LUA....Corona SDK... My new score is Overlapping without erasing old score?

in code below it displays "SCORE: 100" or whatever however as the score / points change
the totals are over lapping one on top of the other and you cant read them ...
i want the old score erased / removed before displaying new score/points
ANY THOUGHTS HOW TO FIX this...this is LUA and using CORONA SDK
during my test i have sent print statements to try to troubleshoot sections
--Points is being calculated in another location
--UPDATE SCORE POINTS
local function updateScore(Points)
if WTF == 1 then
print ("SCORE: -->",Points)
--PointsText:removeSelf(PointsText)
PointsText = display.newText(Points,0,0,native.sytemFont,42)
PointsText.text = Points
PointsText.xscale = 0.5; PointsText.yscale = 0.5
PointsText:setTextColor(155,155,225)
PointsText.x = centerX * 1
PointsText.y = centerY - 150
ScoreTxt = display.newText("Score: ",0,0,native.systemFont,40)
ScoreTxt:setTextColor(220,50,50)
ScoreTxt.x = display.contentCenterX
ScoreTxt.y = display.contentCenterY-100
end
end
Every time you call updateScore you're creating a new text object. This code ensures you only create the text once.
local function updateScore(Points)
if PointsText == nil then
PointsText = display.newText(Points,0,0,native.sytemFont,42)
end
PointsText.text = Points
PointsText.xscale = 0.5; PointsText.yscale = 0.5
PointsText:setTextColor(155,155,225)
PointsText.x = centerX * 1
PointsText.y = centerY - 150
ScoreTxt = display.newText("Score: ",0,0,native.systemFont,40)
ScoreTxt:setTextColor(220,50,50)
ScoreTxt.x = display.contentCenterX
ScoreTxt.y = display.contentCenterY-100
end
You could also do:
local function updateScore(Points)
if PointsText then
PointsText:removeSelf()
end
PointsText = display.newText(Points,0,0,native.systemFont,42)
PointsText.text = Points
PointsText.xscale = 0.5; PointsText.yscale = 0.5
PointsText:setTextColor(155,155,225)
PointsText.x = centerX * 1
PointsText.y = centerY - 150
ScoreTxt = display.newText("Score: ",0,0,native.systemFont,40)
ScoreTxt:setTextColor(220,50,50)
ScoreTxt.x = display.contentCenterX
ScoreTxt.y = display.contentCenterY-100
end

Resources