@@ -9,6 +9,16 @@ import { colorPicker } from "../ColorPicker";
9
9
import { canvasHelper } from "../CanvasHelper" ;
10
10
import { Stage } from "../Stage" ;
11
11
import { BaseChart , BaseChartOptions , KeyGener } from "./BaseChart" ;
12
+
13
+ interface BarChartOptions extends BaseChartOptions {
14
+ itemCount ?: number ;
15
+ barPadding ?: number ;
16
+ barGap ?: number ;
17
+ barInfoFormat ?: KeyGener ;
18
+ dataLabelSize ?: number ;
19
+ showDateLabel ?: boolean ;
20
+ }
21
+
12
22
interface BarOptions {
13
23
id : string ;
14
24
data : any ;
@@ -20,14 +30,21 @@ interface BarOptions {
20
30
alpha : number ;
21
31
image ?: string ;
22
32
}
23
-
24
- interface BarChartOptions extends BaseChartOptions {
25
- itemCount ?: number ;
26
- barPadding ?: number ;
27
- barGap ?: number ;
28
- barInfoFormat ?: KeyGener ;
29
- }
30
33
export class BarChart extends BaseChart {
34
+ constructor ( options ?: BarChartOptions ) {
35
+ super ( options ) ;
36
+ if ( ! options ) return ;
37
+ if ( options . itemCount ) this . itemCount = options . itemCount ;
38
+ if ( options . barPadding !== undefined ) this . barPadding = options . barPadding ;
39
+ if ( options . barGap !== undefined ) this . barGap = options . barGap ;
40
+ if ( options . barInfoFormat !== undefined )
41
+ this . barInfoFormat = options . barInfoFormat ;
42
+ if ( options . dataLabelSize !== undefined )
43
+ this . dataLabelSize = options . dataLabelSize ;
44
+ if ( options . showDateLabel !== undefined )
45
+ this . showDateLabel = options . showDateLabel ;
46
+ }
47
+
31
48
itemCount = 20 ;
32
49
33
50
barPadding = 8 ;
@@ -36,6 +53,8 @@ export class BarChart extends BaseChart {
36
53
lastValue = new Map < string , number > ( ) ;
37
54
labelPlaceholder : number ;
38
55
valuePlaceholder : number ;
56
+ dataLabelSize : number = 60 ;
57
+ showDateLabel : boolean = true ;
39
58
40
59
get sampling ( ) {
41
60
if ( this . stage ) {
@@ -55,13 +74,6 @@ export class BarChart extends BaseChart {
55
74
56
75
historyIndex : Map < any , any > ;
57
76
ids : string [ ] ;
58
- constructor ( options ?: BarChartOptions ) {
59
- super ( options ) ;
60
- if ( ! options ) return ;
61
- if ( options . itemCount ) this . itemCount = options . itemCount ;
62
- if ( options . barPadding !== undefined ) this . barPadding = options . barPadding ;
63
- if ( options . barGap !== undefined ) this . barGap = options . barGap ;
64
- }
65
77
setup ( stage : Stage ) {
66
78
super . setup ( stage ) ;
67
79
this . ids = [ ...this . dataScales . keys ( ) ] ;
@@ -167,20 +179,22 @@ export class BarChart extends BaseChart {
167
179
}
168
180
} ) ;
169
181
170
- const dateLabel = new Text ( {
171
- text : d3 . timeFormat ( this . dateFormat ) ( this . secToDate ( sec ) ) ,
172
- font : "Sarasa Mono Slab SC" ,
173
- fontSize : 45 ,
174
- fillStyle : "#777" ,
175
- textAlign : "right" ,
176
- fontWeight : "bolder" ,
177
- textBaseline : "bottom" ,
178
- position : {
179
- x : this . shape . width - this . margin . right ,
180
- y : this . shape . height - this . margin . bottom ,
181
- } ,
182
- } ) ;
183
- res . children . push ( dateLabel ) ;
182
+ if ( this . showDateLabel ) {
183
+ const dateLabel = new Text ( {
184
+ text : d3 . timeFormat ( this . dateFormat ) ( this . secToDate ( sec ) ) ,
185
+ font : "Sarasa Mono Slab SC" ,
186
+ fontSize : this . dataLabelSize ,
187
+ fillStyle : "#777" ,
188
+ textAlign : "right" ,
189
+ fontWeight : "bolder" ,
190
+ textBaseline : "bottom" ,
191
+ position : {
192
+ x : this . shape . width - this . margin . right ,
193
+ y : this . shape . height - this . margin . bottom ,
194
+ } ,
195
+ } ) ;
196
+ res . children . push ( dateLabel ) ;
197
+ }
184
198
return res ;
185
199
}
186
200
private get barHeight ( ) {
0 commit comments