1- import { lightningChart , emptyFill , DataPatterns , Point , UILayoutBuilders , UIBackgrounds , UIOrigins , UIDraggingModes , SolidFill , ColorHEX , emptyLine , UIElementBuilders , Themes , UIRectangle , UIElementColumn , UITextBox , UICheckBox } from "@arction/lcjs"
1+ import { lightningChart , emptyFill , Point , UILayoutBuilders , UIBackgrounds , UIOrigins , UIDraggingModes , SolidFill , emptyLine , UIElementBuilders , Themes , UIRectangle , UIElementColumn , UITextBox , UICheckBox } from "@arction/lcjs"
22import { createProgressiveTraceGenerator } from "@arction/xydata"
33
44// Use theme if provided
@@ -11,28 +11,28 @@ let dataAmount = 1 * 1000 * 1000
1111
1212// Generate random data using 'xydata' library.
1313let data : Point [ ]
14- const generateData = ( amount : number , after : ( ) => void ) => {
14+ const generateData = ( amount : number , after : ( ) => void ) => {
1515 createProgressiveTraceGenerator ( )
16- . setNumberOfPoints ( amount + 1 )
16+ . setNumberOfPoints ( amount + 1 )
1717 . generate ( )
1818 . toPromise ( )
1919 . then ( ( generatedData ) => {
2020 data = generatedData
2121 after ( )
2222 } )
2323}
24- generateData ( dataAmount , ( ) => {
24+ generateData ( dataAmount , ( ) => {
2525 measureRenderingSpeed ( )
26- } )
26+ } )
2727
28- const container = document . getElementById ( 'chart-container' ) as HTMLDivElement
28+ const container = document . getElementById ( 'chart-container' ) as HTMLDivElement
2929// Create Chart.
3030const chart = lightningChart ( ) . ChartXY ( {
3131 theme,
3232 container
3333} )
3434 // Hide title.
35- . setTitleFillStyle ( emptyFill )
35+ . setTitleFillStyle ( emptyFill )
3636 // Minimize paddings.
3737 . setPadding ( { left : 0 , bottom : 0 , right : 30 , top : 10 } )
3838
@@ -41,13 +41,15 @@ container.style.width = '0'
4141
4242// Disable scrolling animations to view loaded data instantly.
4343const axisX = chart . getDefaultAxisX ( )
44- . setAnimationScroll ( undefined )
44+ . setAnimationScroll ( undefined )
4545const axisY = chart . getDefaultAxisY ( )
46- . setAnimationScroll ( undefined )
46+ . setAnimationScroll ( undefined )
4747
4848const series = chart . addLineSeries ( {
4949 // Specifying progressive DataPattern enables some otherwise unusable optimizations.
50- dataPattern : DataPatterns . horizontalProgressive
50+ dataPattern : {
51+ pattern : 'ProgressiveX'
52+ }
5153} )
5254
5355const measureRenderingSpeed = ( ) => {
@@ -59,9 +61,9 @@ const measureRenderingSpeed = () => {
5961
6062 // Measure time required to render supplied data.
6163 const tStart = window . performance . now ( )
62-
63- series . add ( data )
64-
64+
65+ series . add ( data )
66+
6567 // Subscribe to next animation frame to know how long it took to render.
6668 requestAnimationFrame ( ( ) => {
6769 const tNow = window . performance . now ( )
@@ -75,47 +77,47 @@ const measureRenderingSpeed = () => {
7577// Create indicator for displaying rendering speed.
7678const indicatorLayout = chart . addUIElement < UIElementColumn < UIRectangle > > (
7779 UILayoutBuilders . Column
78- . setBackground ( UIBackgrounds . Rectangle ) ,
80+ . setBackground ( UIBackgrounds . Rectangle ) ,
7981 // Position UIElement with Axis coordinates.
8082 {
81- x : axisX . scale ,
82- y : axisY . scale
83+ x : axisX ,
84+ y : axisY
8385 }
8486)
85- . setOrigin ( UIOrigins . LeftTop )
86- . setDraggingMode ( UIDraggingModes . notDraggable )
87+ . setOrigin ( UIOrigins . LeftTop )
88+ . setDraggingMode ( UIDraggingModes . notDraggable )
8789 // Set dark, tinted Background style.
88- . setBackground ( ( background ) => background
89- . setFillStyle ( new SolidFill ( { color : theme . chartBackgroundFillStyle . get ( 'color' ) . setA ( 150 ) } ) )
90- . setStrokeStyle ( emptyLine )
90+ . setBackground ( ( background ) => background
91+ . setFillStyle ( new SolidFill ( { color : theme . seriesBackgroundFillStyle . get ( 'color' ) . setA ( 150 ) } ) )
92+ . setStrokeStyle ( emptyLine )
9193 )
9294// Reposition indicators whenever Axis scale is changed (to keep position static).
9395const repositionIndicator = ( ) =>
94- indicatorLayout . setPosition ( { x : axisX . scale . getInnerStart ( ) , y : axisY . scale . getInnerEnd ( ) } )
96+ indicatorLayout . setPosition ( { x : axisX . getInterval ( ) . start , y : axisY . getInterval ( ) . end } )
9597repositionIndicator ( )
96- axisX . onScaleChange ( repositionIndicator )
97- axisY . onScaleChange ( repositionIndicator )
98+ axisX . onScaleChange ( repositionIndicator )
99+ axisY . onScaleChange ( repositionIndicator )
98100// Rendering speed indicator.
99- const indicatorRenderingSpeed = indicatorLayout . addElement < UITextBox < UIRectangle > > ( UIElementBuilders . TextBox )
100- . setText ( 'Rendering ...' )
101- . setFont ( ( font ) => font
102- . setWeight ( 'bold' )
101+ const indicatorRenderingSpeed = indicatorLayout . addElement < UITextBox < UIRectangle > > ( UIElementBuilders . TextBox )
102+ . setText ( 'Rendering ...' )
103+ . setTextFont ( ( font ) => font
104+ . setWeight ( 'bold' )
103105 )
104106
105107// Create button for rendering and measuring again.
106108const reRender = ( ) => {
107109 series
108110 . clear ( )
109111 indicatorRenderingSpeed
110- . setText ( 'Rendering ...' )
112+ . setText ( 'Rendering ...' )
111113
112114 measureRenderingSpeed ( )
113115}
114- const buttonRerender = indicatorLayout . addElement < UICheckBox < UIRectangle > > ( UIElementBuilders . ButtonBox )
115- . setText ( 'Render again' )
116+ const buttonRerender = indicatorLayout . addElement < UICheckBox < UIRectangle > > ( UIElementBuilders . ButtonBox )
117+ . setText ( 'Render again' )
116118 . setMargin ( { left : 10 } )
117119buttonRerender . onSwitch ( ( _ , state ) => {
118- if ( state ) {
120+ if ( state ) {
119121 reRender ( )
120122 }
121123} )
0 commit comments