@@ -12,47 +12,50 @@ import {Margin, Rect} from "math/Rect";
12
12
import { Renderer } from "core/rendering/Renderer" ;
13
13
import { Style } from "core/rendering/Style" ;
14
14
15
+ import { Line } from "core/rendering/shapes/Line" ;
15
16
import { Rectangle } from "core/rendering/shapes/Rectangle" ;
16
17
17
18
import { AnalogCircuitInfo } from "analog/utils/AnalogCircuitInfo" ;
18
19
19
20
import { Oscilloscope } from "analog/models/eeobjects" ;
20
21
21
22
22
- const GRAPH_LINE_WIDTH = 1 ;
23
+ const GRAPH_LINE_WIDTH = 0.02 ;
24
+ const AXIS_LINE_WIDTH = 0.02 ;
25
+ const GRID_LINE_WIDTH = 0.01 ;
23
26
24
- const DISPLAY_PADDING = Margin ( 15 , 15 ) ;
27
+ const DISPLAY_PADDING = Margin ( 0.3 , 0.3 ) ;
25
28
26
- const AXIS_PTS = 5 / 400 ; // 5 pts / 400 units of size
27
- const AXIS_MARK_FONT_SIZE = 12 ;
28
- const AXIS_LABEL_FONT_SIZE = 15 ;
29
+ const AXIS_PTS = 5 / 8 ; // 5 pts / 8 units of size
30
+ const AXIS_MARK_FONT_SIZE = 0.25 ;
31
+ const AXIS_LABEL_FONT_SIZE = 0.3 ;
29
32
30
- const AXIS_MARK_LENGTH = 8 ;
33
+ const AXIS_MARK_LENGTH = 0.16 ;
31
34
32
35
const AXIS_MARK_FONT = `lighter ${ AXIS_MARK_FONT_SIZE } px arial` ;
33
36
const AXIS_LABEL_FONT = `lighter ${ AXIS_LABEL_FONT_SIZE } px arial` ;
34
- const AXIS_TEXT_OFFSET = AXIS_MARK_LENGTH / 2 + 4 ;
37
+ const AXIS_TEXT_OFFSET = AXIS_MARK_LENGTH / 2 + 0.08 ;
35
38
36
39
const AXES_INFO_MARGIN = Margin (
37
- 12 + AXIS_LABEL_FONT_SIZE * 2 + AXIS_MARK_FONT_SIZE ,
40
+ 0.24 + AXIS_LABEL_FONT_SIZE * 2 + AXIS_MARK_FONT_SIZE ,
38
41
0 ,
39
- 12 + AXIS_LABEL_FONT_SIZE + AXIS_MARK_FONT_SIZE ,
42
+ 0.24 + AXIS_LABEL_FONT_SIZE + AXIS_MARK_FONT_SIZE ,
40
43
0 ,
41
44
) ;
42
45
const AXES_MARGIN = Margin (
43
- AXIS_MARK_LENGTH / 2 + 4 ,
44
- 10 ,
45
- AXIS_MARK_LENGTH / 2 + 4 ,
46
- 10 ,
46
+ AXIS_MARK_LENGTH / 2 + 0.08 ,
47
+ 0.2 ,
48
+ AXIS_MARK_LENGTH / 2 + 0.08 ,
49
+ 0.2 ,
47
50
) ;
48
51
49
52
50
53
const GRID_PTS = 2 ; // (N+1) grid points / 1 axis pt
51
54
52
- const LEGEND_AREA = 100 ;
53
- const LEGEND_PADDING = Margin ( 10 , 10 , 0 , 0 ) ;
54
- const LEGEND_TITLE_FONT_SIZE = 15 ;
55
- const LEGEND_ENTRY_FONT_SIZE = 10 ;
55
+ const LEGEND_AREA = 2 ;
56
+ const LEGEND_PADDING = Margin ( 0.2 , 0.2 , 0 , 0 ) ;
57
+ const LEGEND_TITLE_FONT_SIZE = 0.3 ;
58
+ const LEGEND_ENTRY_FONT_SIZE = 0.2 ;
56
59
const LEGEND_TITLE_FONT = `normal ${ LEGEND_TITLE_FONT_SIZE } px arial` ;
57
60
const LEGEND_ENTRY_FONT = `lighter ${ LEGEND_ENTRY_FONT_SIZE } px arial` ;
58
61
@@ -118,7 +121,7 @@ export const OscilloscopeRenderer = ({
118
121
// axesGridRect: => Area just for axes + grid + plot
119
122
// plotRect : => Area just for the plot
120
123
// legendRect : => Area for the legend
121
- const baseRect = new Rect ( V ( 0 , 0 ) , size , false ) ;
124
+ const baseRect = new Rect ( V ( 0 , 0 ) , size ) ;
122
125
const innerRect = baseRect . subMargin ( DISPLAY_PADDING ) ;
123
126
const axesInfoRect = innerRect . subMargin ( ( showLegend ? { right : LEGEND_AREA } : { } ) ) ;
124
127
const axesGridRect = axesInfoRect . subMargin ( ( showAxes ? AXES_INFO_MARGIN : { } ) ) ;
@@ -127,12 +130,12 @@ export const OscilloscopeRenderer = ({
127
130
128
131
// Debug drawing
129
132
if ( info . debugOptions . debugSelectionBounds ) {
130
- renderer . draw ( toShape ( baseRect ) , new Style ( "#999999" , "#000000" , 1 ) ) ;
131
- renderer . draw ( toShape ( innerRect ) , new Style ( "#ff0000" , "#000000" , 1 ) ) ;
132
- renderer . draw ( toShape ( axesInfoRect ) , new Style ( "#00ff00" , "#000000" , 1 ) ) ;
133
- renderer . draw ( toShape ( axesGridRect ) , new Style ( "#0000ff" , "#000000" , 1 ) ) ;
134
- renderer . draw ( toShape ( plotRect ) , new Style ( "#ff00ff" , "#000000" , 1 ) ) ;
135
- renderer . draw ( toShape ( legendRect ) , new Style ( "#00ffff" , "#000000" , 1 ) ) ;
133
+ renderer . draw ( toShape ( baseRect ) , new Style ( "#999999" , "#000000" , 0.02 ) ) ;
134
+ renderer . draw ( toShape ( innerRect ) , new Style ( "#ff0000" , "#000000" , 0.02 ) ) ;
135
+ renderer . draw ( toShape ( axesInfoRect ) , new Style ( "#00ff00" , "#000000" , 0.02 ) ) ;
136
+ renderer . draw ( toShape ( axesGridRect ) , new Style ( "#0000ff" , "#000000" , 0.02 ) ) ;
137
+ renderer . draw ( toShape ( plotRect ) , new Style ( "#ff00ff" , "#000000" , 0.02 ) ) ;
138
+ renderer . draw ( toShape ( legendRect ) , new Style ( "#00ffff" , "#000000" , 0.02 ) ) ;
136
139
}
137
140
138
141
if ( showGrid )
@@ -148,8 +151,8 @@ export const OscilloscopeRenderer = ({
148
151
149
152
function getMarks ( bounds : Rect ) {
150
153
const num = V (
151
- Math . max ( 5 , Math . ceil ( AXIS_PTS * size . x ) ) ,
152
- Math . max ( 5 , Math . ceil ( AXIS_PTS * size . y ) )
154
+ Math . max ( 0.1 , Math . ceil ( AXIS_PTS * size . x ) ) ,
155
+ Math . max ( 0.1 , Math . ceil ( AXIS_PTS * size . y ) )
153
156
) ;
154
157
return {
155
158
xs : linspace ( bounds . left , bounds . right , num . x ) ,
@@ -162,7 +165,7 @@ export const OscilloscopeRenderer = ({
162
165
function drawGrid ( bounds : Rect , innerBounds : Rect ) {
163
166
renderer . save ( ) ;
164
167
renderer . setPathStyle ( { lineCap : "square" } ) ;
165
- renderer . setStyle ( new Style ( undefined , GRID_LINE_COLOR , 0.5 ) , 0.5 ) ;
168
+ renderer . setStyle ( new Style ( undefined , GRID_LINE_COLOR , GRID_LINE_WIDTH ) , 0.5 ) ;
166
169
167
170
const marks = getMarks ( innerBounds ) ;
168
171
@@ -183,7 +186,7 @@ export const OscilloscopeRenderer = ({
183
186
function drawAxes ( outerBounds : Rect , bounds : Rect , innerBounds : Rect ) {
184
187
renderer . save ( ) ;
185
188
renderer . setPathStyle ( { lineCap : "square" } ) ;
186
- renderer . setStyle ( new Style ( undefined , "#000000" , 1 ) ) ;
189
+ renderer . setStyle ( new Style ( undefined , "#000000" , AXIS_LINE_WIDTH ) ) ;
187
190
188
191
// Draw each axis
189
192
renderer . strokePath ( [ bounds . topLeft , bounds . bottomLeft , bounds . bottomRight ] ) ;
@@ -196,7 +199,7 @@ export const OscilloscopeRenderer = ({
196
199
197
200
// Draw axis mark text
198
201
marks . xVals . forEach ( ( text , i ) => {
199
- const pos = V ( marks . xs [ i ] , bounds . bottom + AXIS_TEXT_OFFSET ) ;
202
+ const pos = V ( marks . xs [ i ] , bounds . bottom - AXIS_TEXT_OFFSET ) ;
200
203
renderer . text ( text , pos , "center" , "#000000" , AXIS_MARK_FONT , "top" ) ;
201
204
} ) ;
202
205
marks . yVals . forEach ( ( text , i ) => {
@@ -218,10 +221,10 @@ export const OscilloscopeRenderer = ({
218
221
219
222
renderer . text ( "Legend" , V ( bounds . left , bounds . top ) , "left" , "#000000" , LEGEND_TITLE_FONT , "top" ) ;
220
223
221
- const boxSize = 10 ;
224
+ const boxSize = 0.2 ;
222
225
enabledVecIDs . forEach ( ( id , i ) => {
223
226
const color = vecs [ id ] . color ;
224
- const y = bounds . top + 20 + i * ( boxSize + 5 ) ;
227
+ const y = bounds . top - i * ( boxSize + 0.1 ) - 0.7 ;
225
228
226
229
// Draw box
227
230
const box = Rect . From ( {
@@ -233,7 +236,7 @@ export const OscilloscopeRenderer = ({
233
236
renderer . draw ( toShape ( box ) , new Style ( color ) , 1 ) ;
234
237
235
238
// Draw text
236
- renderer . text ( id , V ( box . right + 5 , box . y ) , "left" , "#000000" , LEGEND_ENTRY_FONT , "middle" ) ;
239
+ renderer . text ( id , V ( box . right + 0.1 , box . y ) , "left" , "#000000" , LEGEND_ENTRY_FONT , "middle" ) ;
237
240
} ) ;
238
241
239
242
renderer . restore ( ) ;
@@ -244,14 +247,14 @@ export const OscilloscopeRenderer = ({
244
247
renderer . setPathStyle ( { lineCap : "round" } ) ;
245
248
246
249
// Get data bounds as a rectangle
247
- const dataBounds = Rect . From ( { left : minX , right : maxX , bottom : minVal , top : maxVal } , false ) ;
250
+ const dataBounds = Rect . From ( { left : minX , right : maxX , bottom : minVal , top : maxVal } ) ;
248
251
249
252
const scale = V ( bounds . width / dataBounds . width , bounds . height / dataBounds . height ) ;
250
253
251
254
sampledData . forEach ( ( data , i ) => {
252
255
// Calculate position for each data point
253
256
const positions = data . map (
254
- ( s , i ) => V ( xData [ i ] , - s )
257
+ ( s , i ) => V ( xData [ i ] , s )
255
258
. sub ( dataBounds . center )
256
259
. scale ( scale )
257
260
. add ( bounds . center )
0 commit comments