1
- import { ChartDetail , chartTypes } from "./chart" ;
2
- import { ChartJsType , chartJsTypes } from "./chartJs" ;
3
-
4
- export interface StatementSettings {
5
- chart ?: ChartJsType ;
6
- title ?: string ;
7
- y ?: string ;
8
- hideStatement ?: string ;
9
- [ key : string ] : string
10
- } ;
11
-
12
- export function getStatementDetail ( content : string , eol : string ) {
13
- let chartDetail : ChartDetail = { } ;
14
- let settings : StatementSettings = { } ;
15
-
16
- // Strip out starting comments
17
- if ( content . startsWith ( `--` ) ) {
18
- const lines = content . split ( eol ) ;
19
- const firstNonCommentLine = lines . findIndex ( line => ! line . startsWith ( `--` ) ) ;
20
-
21
- const startingComments = lines . slice ( 0 , firstNonCommentLine ) . map ( line => line . substring ( 2 ) . trim ( ) ) ;
22
- content = lines . slice ( firstNonCommentLine ) . join ( eol ) ;
23
-
24
- for ( let comment of startingComments ) {
25
- const sep = comment . indexOf ( `:` ) ;
26
- const key = comment . substring ( 0 , sep ) . trim ( ) ;
27
- const value = comment . substring ( sep + 1 ) . trim ( ) ;
28
- settings [ key ] = value ;
29
- }
30
-
31
- // Chart settings defined by comments
32
- if ( settings [ `chart` ] && chartJsTypes . includes ( settings [ `chart` ] ) ) {
33
- chartDetail . type = settings [ `chart` ] ;
34
- }
35
-
36
- if ( settings [ `title` ] ) {
37
- chartDetail . title = settings [ `title` ] ;
38
- }
39
-
40
- if ( settings [ `y` ] ) {
41
- chartDetail . y = settings [ `y` ] ;
42
- }
43
- }
44
-
45
- // Remove trailing semicolon. The Service Component doesn't like it.
46
- if ( content . endsWith ( `;` ) ) {
47
- content = content . substring ( 0 , content . length - 1 ) ;
48
- }
49
-
50
- // Perhaps the chart type is defined by the statement prefix
51
- const chartType : ChartJsType | undefined = chartTypes . find ( type => content . startsWith ( `${ type } :` ) ) ;
52
- if ( chartType ) {
53
- chartDetail . type = chartType ;
54
- content = content . substring ( chartType . length + 1 ) ;
55
- }
56
- return { chartDetail, content, settings } ;
1
+ import { ChartDetail , chartTypes } from "./chart" ;
2
+ import { ChartJsType , chartJsTypes } from "./chartJs" ;
3
+
4
+ export interface StatementSettings {
5
+ chart ?: ChartJsType ;
6
+ title ?: string ;
7
+ y ?: string ;
8
+ hideStatement ?: string ;
9
+ [ key : string ] : string
10
+ } ;
11
+
12
+ export function getStatementDetail ( content : string , eol : string ) {
13
+ let chartDetail : ChartDetail = { } ;
14
+ let settings : StatementSettings = { } ;
15
+
16
+ // Strip out starting comments
17
+ if ( content . startsWith ( `--` ) ) {
18
+ const lines = content . split ( eol ) ;
19
+ const firstNonCommentLine = lines . findIndex ( line => ! line . startsWith ( `--` ) ) ;
20
+
21
+ const startingCommentLines = firstNonCommentLine === - 1 ? lines : lines . slice ( 0 , firstNonCommentLine ) ;
22
+ const startingComments = startingCommentLines . map ( line => line . substring ( 2 ) . trim ( ) ) ;
23
+ content = lines . slice ( firstNonCommentLine ) . join ( eol ) ;
24
+
25
+ for ( let comment of startingComments ) {
26
+ const sep = comment . indexOf ( `:` ) ;
27
+ const key = comment . substring ( 0 , sep ) . trim ( ) ;
28
+ const value = comment . substring ( sep + 1 ) . trim ( ) ;
29
+ settings [ key ] = value ;
30
+ }
31
+
32
+ // Chart settings defined by comments
33
+ if ( settings [ `chart` ] && chartJsTypes . includes ( settings [ `chart` ] ) ) {
34
+ chartDetail . type = settings [ `chart` ] ;
35
+ }
36
+
37
+ if ( settings [ `title` ] ) {
38
+ chartDetail . title = settings [ `title` ] ;
39
+ }
40
+
41
+ if ( settings [ `y` ] ) {
42
+ chartDetail . y = settings [ `y` ] ;
43
+ }
44
+ }
45
+
46
+ // Remove trailing semicolon. The Service Component doesn't like it.
47
+ if ( content . endsWith ( `;` ) ) {
48
+ content = content . substring ( 0 , content . length - 1 ) ;
49
+ }
50
+
51
+ // Perhaps the chart type is defined by the statement prefix
52
+ const chartType : ChartJsType | undefined = chartTypes . find ( type => content . startsWith ( `${ type } :` ) ) ;
53
+ if ( chartType ) {
54
+ chartDetail . type = chartType ;
55
+ content = content . substring ( chartType . length + 1 ) ;
56
+ }
57
+ return { chartDetail, content, settings } ;
57
58
}
0 commit comments