Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita9f72cd

Browse files
committed
fix: fixed line and bar charts title labels
1 parent69ccc54 commita9f72cd

File tree

3 files changed

+37
-24
lines changed

3 files changed

+37
-24
lines changed

‎Kit/Widgets/BarChart.swift

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public class BarChart: WidgetWrapper {
2525
privatevarboxSettingsView:NSSwitch?=nil
2626
privatevarframeSettingsView:NSSwitch?=nil
2727

28+
publicvarNSLabelCharts:[NSAttributedString]=[]
29+
2830
publicinit(title:String, config:NSDictionary?, preview:Bool=false){
2931
varwidgetTitle:String= title
3032

@@ -83,6 +85,19 @@ public class BarChart: WidgetWrapper {
8385
self.invalidateIntrinsicContentSize()
8486
self.display()
8587
}
88+
89+
letstyle=NSMutableParagraphStyle()
90+
style.alignment=.center
91+
letstringAttributes=[
92+
NSAttributedString.Key.font:NSFont.systemFont(ofSize:7, weight:.regular),
93+
NSAttributedString.Key.foregroundColor:NSColor.textColor,
94+
NSAttributedString.Key.paragraphStyle: style
95+
]
96+
97+
forcharinString(self.title.prefix(3)).uppercased().reversed(){
98+
letstr=NSAttributedString.init(string:"\(char)", attributes: stringAttributes)
99+
self.NSLabelCharts.append(str)
100+
}
86101
}
87102

88103
requiredinit?(coder:NSCoder){
@@ -131,22 +146,13 @@ public class BarChart: WidgetWrapper {
131146
}
132147

133148
ifself.labelState{
134-
letstyle=NSMutableParagraphStyle()
135-
style.alignment=.center
136-
letstringAttributes=[
137-
NSAttributedString.Key.font:NSFont.systemFont(ofSize:7, weight:.regular),
138-
NSAttributedString.Key.foregroundColor:NSColor.textColor,
139-
NSAttributedString.Key.paragraphStyle: style
140-
]
141-
142149
letletterHeight=self.frame.height/3
143150
letletterWidth:CGFloat=6.0
144151

145152
varyMargin:CGFloat=0
146-
forcharinString(self.title.prefix(3)).uppercased().reversed(){
153+
forcharinself.NSLabelCharts{
147154
letrect=CGRect(x: x, y: yMargin, width: letterWidth, height: letterHeight)
148-
letstr=NSAttributedString.init(string:"\(char)", attributes: stringAttributes)
149-
str.draw(with: rect)
155+
char.draw(with: rect)
150156
yMargin+= letterHeight
151157
}
152158

‎Kit/Widgets/LineChart.swift

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public class LineChart: WidgetWrapper {
5757
privatevarboxSettingsView:NSSwitch?=nil
5858
privatevarframeSettingsView:NSSwitch?=nil
5959

60+
publicvarNSLabelCharts:[NSAttributedString]=[]
61+
6062
publicinit(title:String, config:NSDictionary?, preview:Bool=false){
6163
varwidgetTitle:String= title
6264
if config!=nil{
@@ -117,6 +119,19 @@ public class LineChart: WidgetWrapper {
117119
self.chart.points= list
118120
self._value=0.38
119121
}
122+
123+
letstyle=NSMutableParagraphStyle()
124+
style.alignment=.center
125+
letstringAttributes=[
126+
NSAttributedString.Key.font:NSFont.systemFont(ofSize:7, weight:.regular),
127+
NSAttributedString.Key.foregroundColor:NSColor.textColor,
128+
NSAttributedString.Key.paragraphStyle: style
129+
]
130+
131+
forcharinString(self.title.prefix(3)).uppercased().reversed(){
132+
letstr=NSAttributedString.init(string:"\(char)", attributes: stringAttributes)
133+
self.NSLabelCharts.append(str)
134+
}
120135
}
121136

122137
requiredinit?(coder:NSCoder){
@@ -156,24 +171,16 @@ public class LineChart: WidgetWrapper {
156171
}
157172

158173
ifself.labelState{
159-
letstyle=NSMutableParagraphStyle()
160-
style.alignment=.center
161-
letstringAttributes=[
162-
NSAttributedString.Key.font:NSFont.systemFont(ofSize:7, weight:.regular),
163-
NSAttributedString.Key.foregroundColor:NSColor.textColor,
164-
NSAttributedString.Key.paragraphStyle: style
165-
]
166-
167174
letletterHeight=self.frame.height/3
168175
letletterWidth:CGFloat=6.0
169176

170177
varyMargin:CGFloat=0
171-
forcharinString(self.title.prefix(3)).uppercased().reversed(){
178+
forcharinself.NSLabelCharts{
172179
letrect=CGRect(x: x, y: yMargin, width: letterWidth, height: letterHeight)
173-
letstr=NSAttributedString.init(string:"\(char)", attributes: stringAttributes)
174-
str.draw(with: rect)
180+
char.draw(with: rect)
175181
yMargin+= letterHeight
176182
}
183+
177184
width+= letterWidth+ Constants.Widget.spacing
178185
x= letterWidth+ Constants.Widget.spacing
179186
}

‎Kit/helpers.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -807,12 +807,12 @@ internal class WidgetLabelView: NSView {
807807
NSAttributedString.Key.paragraphStyle: style
808808
]
809809

810-
lettitle=self.title.prefix(3)
810+
lettitle=String(self.title.prefix(3)).uppercased().reversed()
811811
letletterHeight=self.frame.height/3
812812
letletterWidth:CGFloat=self.frame.height/ CGFloat(title.count)
813813

814814
varyMargin:CGFloat=0
815-
forcharin title.uppercased().reversed(){
815+
forcharin title{
816816
letrect=CGRect(x:0, y: yMargin, width: letterWidth, height: letterHeight-1)
817817
letstr=NSAttributedString.init(string:"\(char)", attributes: stringAttributes)
818818
str.draw(with: rect)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp