11import React from 'react' ;
2+ import { loremIpsum } from 'lorem-ipsum' ;
23
34import {
45 Axis ,
@@ -9,88 +10,129 @@ import {
910 Position ,
1011 ScaleType ,
1112 Settings ,
12- LineSeries ,
13+ AreaSeries ,
14+ mergeWithDefaultTheme ,
1315} from '../src' ;
1416import { KIBANA_METRICS } from '../src/utils/data_samples/test_dataset_kibana' ;
15- import { CursorEvent } from '../src/specs/settings' ;
16- import { CursorUpdateListener } from '../src/chart_types/xy_chart/store/chart_state' ;
1717
1818export class Playground extends React . Component {
19- ref1 = React . createRef < Chart > ( ) ;
20- ref2 = React . createRef < Chart > ( ) ;
21- ref3 = React . createRef < Chart > ( ) ;
22-
23- onCursorUpdate : CursorUpdateListener = ( event ?: CursorEvent ) => {
24- this . ref1 . current ! . dispatchExternalCursorEvent ( event ) ;
25- this . ref2 . current ! . dispatchExternalCursorEvent ( event ) ;
26- this . ref3 . current ! . dispatchExternalCursorEvent ( event ) ;
27- } ;
28-
2919 render ( ) {
30- return (
31- < >
32- { renderChart (
33- '1' ,
34- this . ref1 ,
35- KIBANA_METRICS . metrics . kibana_os_load [ 0 ] . data . slice ( 0 , 15 ) ,
36- this . onCursorUpdate ,
37- true ,
38- ) }
39- { renderChart (
40- '2' ,
41- this . ref2 ,
42- KIBANA_METRICS . metrics . kibana_os_load [ 1 ] . data . slice ( 0 , 15 ) ,
43- this . onCursorUpdate ,
44- true ,
45- ) }
46- { renderChart ( '2' , this . ref3 , KIBANA_METRICS . metrics . kibana_os_load [ 1 ] . data . slice ( 15 , 30 ) , this . onCursorUpdate ) }
47- </ >
48- ) ;
20+ return < > { this . renderChart ( Position . Bottom ) } </ > ;
4921 }
50- }
51-
52- function renderChart (
53- key : string ,
54- ref : React . RefObject < Chart > ,
55- data : any ,
56- onCursorUpdate ?: CursorUpdateListener ,
57- timeSeries : boolean = false ,
58- ) {
59- return (
60- < div key = { key } className = "chart" >
61- < Chart ref = { ref } >
62- < Settings tooltip = { { type : 'vertical' } } debug = { false } showLegend = { true } onCursorUpdate = { onCursorUpdate } />
63- < Axis
64- id = { getAxisId ( 'timestamp' ) }
65- title = "timestamp"
66- position = { Position . Bottom }
67- tickFormat = { niceTimeFormatter ( [ 1555819200000 , 1555905600000 ] ) }
68- />
69- < Axis id = { getAxisId ( 'count' ) } title = "count" position = { Position . Left } tickFormat = { ( d ) => d . toFixed ( 2 ) } />
70- < LineSeries
71- id = { getSpecId ( 'dataset A with long title' ) }
72- xScaleType = { timeSeries ? ScaleType . Time : ScaleType . Linear }
22+ renderChart ( legendPosition : Position ) {
23+ const renderMore = ( ) => {
24+ const random = Math . floor ( Math . random ( ) * 3 ) + 1 ;
25+ const id = loremIpsum ( { count : random , units : 'words' } ) ;
26+ return (
27+ < AreaSeries
28+ id = { getSpecId ( id ) }
29+ xScaleType = { ScaleType . Time }
7330 yScaleType = { ScaleType . Linear }
74- data = { data }
31+ data = { KIBANA_METRICS . metrics . kibana_os_load [ 0 ] . data . slice ( 0 , 15 ) }
7532 xAccessor = { 0 }
76- lineSeriesStyle = { {
33+ areaSeriesStyle = { {
34+ point : {
35+ visible : true ,
36+ strokeWidth : 3 ,
37+ radius : 10 ,
38+ } ,
7739 line : {
78- stroke : 'red' ,
79- opacity : 1 ,
40+ strokeWidth : 10 ,
8041 } ,
8142 } }
8243 yAccessors = { [ 1 ] }
8344 />
84- < LineSeries
85- id = { getSpecId ( 'dataset B' ) }
86- xScaleType = { ScaleType . Time }
87- yScaleType = { ScaleType . Linear }
88- data = { KIBANA_METRICS . metrics . kibana_os_load [ 1 ] . data . slice ( 0 , 15 ) }
89- xAccessor = { 0 }
90- yAccessors = { [ 1 ] }
91- stackAccessors = { [ 0 ] }
92- />
93- </ Chart >
94- </ div >
95- ) ;
45+ ) ;
46+ } ;
47+ const theme = mergeWithDefaultTheme ( {
48+ lineSeriesStyle : {
49+ line : {
50+ stroke : 'violet' ,
51+ strokeWidth : 4 ,
52+ } ,
53+ point : {
54+ fill : 'yellow' ,
55+ stroke : 'black' ,
56+ strokeWidth : 2 ,
57+ radius : 6 ,
58+ } ,
59+ } ,
60+ } ) ;
61+ return (
62+ < div className = "chart" >
63+ < Chart >
64+ < Settings debug = { false } showLegend = { true } legendPosition = { legendPosition } rotation = { 0 } theme = { theme } />
65+ < Axis
66+ id = { getAxisId ( 'timestamp' ) }
67+ title = "timestamp"
68+ position = { Position . Bottom }
69+ tickFormat = { niceTimeFormatter ( [ 1555819200000 , 1555905600000 ] ) }
70+ />
71+ < Axis id = { getAxisId ( 'count' ) } title = "count" position = { Position . Left } tickFormat = { ( d ) => d . toFixed ( 2 ) } />
72+
73+ < AreaSeries
74+ id = { getSpecId ( 'dataset B' ) }
75+ xScaleType = { ScaleType . Time }
76+ yScaleType = { ScaleType . Linear }
77+ data = { KIBANA_METRICS . metrics . kibana_os_load [ 1 ] . data . slice ( 0 , 15 ) }
78+ xAccessor = { 0 }
79+ yAccessors = { [ 1 ] }
80+ stackAccessors = { [ 0 ] }
81+ areaSeriesStyle = { {
82+ line : {
83+ // opacity:1,
84+ strokeWidth : 10 ,
85+ } ,
86+ point : {
87+ visible : true ,
88+ strokeWidth : 3 ,
89+ radius : 10 ,
90+ } ,
91+ } }
92+ />
93+ < AreaSeries
94+ id = { getSpecId ( 'dataset C' ) }
95+ xScaleType = { ScaleType . Time }
96+ yScaleType = { ScaleType . Linear }
97+ data = { KIBANA_METRICS . metrics . kibana_os_load [ 1 ] . data . slice ( 0 , 15 ) }
98+ xAccessor = { 0 }
99+ yAccessors = { [ 1 ] }
100+ stackAccessors = { [ 0 ] }
101+ areaSeriesStyle = { {
102+ line : {
103+ // opacity:1,
104+ strokeWidth : 10 ,
105+ } ,
106+ point : {
107+ visible : true ,
108+ strokeWidth : 3 ,
109+ radius : 10 ,
110+ } ,
111+ } }
112+ />
113+ < AreaSeries
114+ id = { getSpecId ( 'dataset A' ) }
115+ xScaleType = { ScaleType . Time }
116+ yScaleType = { ScaleType . Linear }
117+ data = { KIBANA_METRICS . metrics . kibana_os_load [ 0 ] . data . slice ( 0 , 15 ) }
118+ xAccessor = { 0 }
119+ areaSeriesStyle = { {
120+ point : {
121+ visible : true ,
122+ strokeWidth : 3 ,
123+ radius : 10 ,
124+ } ,
125+ line : {
126+ strokeWidth : 10 ,
127+ } ,
128+ } }
129+ yAccessors = { [ 1 ] }
130+ />
131+ { Array ( 10 )
132+ . fill ( null )
133+ . map ( renderMore ) }
134+ </ Chart >
135+ </ div >
136+ ) ;
137+ }
96138}
0 commit comments