Skip to content

Commit ab60f02

Browse files
committed
Update to lcjs 3.0
1 parent 75f7ecd commit ab60f02

File tree

3 files changed

+44
-36
lines changed

3 files changed

+44
-36
lines changed

package-lock.json

Lines changed: 9 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"webpack-dev-server": "^3.11.0"
2525
},
2626
"dependencies": {
27-
"@arction/lcjs": "^2.2.0",
27+
"@arction/lcjs": "^3.0.0",
2828
"@arction/xydata": "^1.4.0"
2929
}
3030
}

src/app.ts

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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"
22
import { 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.
1313
let 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.
3030
const 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.
4343
const axisX = chart.getDefaultAxisX()
44-
.setAnimationScroll( undefined )
44+
.setAnimationScroll(undefined)
4545
const axisY = chart.getDefaultAxisY()
46-
.setAnimationScroll( undefined )
46+
.setAnimationScroll(undefined)
4747

4848
const series = chart.addLineSeries({
4949
// Specifying progressive DataPattern enables some otherwise unusable optimizations.
50-
dataPattern: DataPatterns.horizontalProgressive
50+
dataPattern: {
51+
pattern: 'ProgressiveX'
52+
}
5153
})
5254

5355
const 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.
7678
const 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).
9395
const repositionIndicator = () =>
94-
indicatorLayout.setPosition({ x: axisX.scale.getInnerStart(), y: axisY.scale.getInnerEnd() })
96+
indicatorLayout.setPosition({ x: axisX.getInterval().start, y: axisY.getInterval().end })
9597
repositionIndicator()
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.
106108
const 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 })
117119
buttonRerender.onSwitch((_, state) => {
118-
if ( state ) {
120+
if (state) {
119121
reRender()
120122
}
121123
})

0 commit comments

Comments
 (0)