@@ -47,10 +47,15 @@ class ImageObject {
47
47
}
48
48
49
49
// D3.js用のデータを生成
50
- const createCurvePathData = ( startGraphX , endGraphX ) => {
50
+ const createCurvePathData = ( startGraphX , endGraphX , velocity = false ) => {
51
51
const n = config . curveResolution ;
52
- let data = [ ]
53
- const yArray = graphEditor . getCurveValueArray ( config . editMode , startGraphX , 0 , endGraphX , 1 , n ) ;
52
+ let data = [ ] ;
53
+ let yArray ;
54
+ if ( velocity ) {
55
+ yArray = graphEditor . getCurveVelocityArray ( config . editMode , startGraphX , 0 , endGraphX , 1 , n ) ;
56
+ } else {
57
+ yArray = graphEditor . getCurveValueArray ( config . editMode , startGraphX , 0 , endGraphX , 1 , n ) ;
58
+ }
54
59
for ( let i = 0 ; i < n ; i ++ ) {
55
60
const x = startGraphX + ( endGraphX - startGraphX ) / ( n - 1 ) * i ;
56
61
data . push ( {
@@ -62,25 +67,42 @@ const createCurvePathData = (startGraphX, endGraphX) => {
62
67
}
63
68
64
69
// 描画するカーブの内容を更新
65
- const updateCurvePath = ( t = null ) => {
66
- const startGraphX = Math . max ( 0 , currentScaleX . invert ( 0 ) ) ;
67
- const endGraphX = Math . min ( 1 , currentScaleX . invert ( width ) ) ;
70
+ const updateCurvePath = ( t = null , zoom = false ) => {
71
+ const startGraphX = Math . max ( 0 , currentScaleX . invert ( zoom ? - 200 : 0 ) ) ;
72
+ const endGraphX = Math . min ( 1 , currentScaleX . invert ( width + ( zoom ? 200 : 0 ) ) ) ;
68
73
69
- path . datum ( createCurvePathData ( startGraphX , endGraphX ) ) ;
70
- ( t ? path . transition ( t ) : path ) . attr ( 'd' , d3 . line ( )
74
+ curvePath . datum ( createCurvePathData ( startGraphX , endGraphX ) ) ;
75
+ ( t ? curvePath . transition ( t ) : curvePath ) . attr ( 'd' , d3 . line ( )
71
76
. x ( d => originalScaleX ( d . x ) )
72
77
. y ( d => originalScaleY ( d . y ) )
73
78
. curve ( curve ) ) ;
74
79
75
- const editMode = config . editMode ;
76
- if ( editMode == 2 || editMode == 3 || editMode == 4 ) {
77
- window . top . postMessage ( {
78
- to : 'panel-editor' ,
79
- command : 'updateParam'
80
- } ) ;
80
+ if ( ! zoom ) {
81
+ const editMode = config . editMode ;
82
+ if ( editMode == 2 || editMode == 3 || editMode == 4 ) {
83
+ window . top . postMessage ( {
84
+ to : 'panel-editor' ,
85
+ command : 'updateParam'
86
+ } ) ;
87
+ }
81
88
}
82
89
}
83
90
91
+ // 描画するカーブの内容を更新
92
+ const updateVelocityPath = ( t = null ) => {
93
+ if ( ! config . showVelocityGraph ) {
94
+ return ;
95
+ }
96
+ const startGraphX = Math . max ( 0 , currentScaleX . invert ( 0 ) ) ;
97
+ const endGraphX = Math . min ( 1 , currentScaleX . invert ( width ) ) ;
98
+
99
+ velocityPath . datum ( createCurvePathData ( startGraphX , endGraphX , true ) ) ;
100
+ ( t ? velocityPath . transition ( t ) : velocityPath ) . attr ( 'd' , d3 . line ( )
101
+ . x ( d => originalScaleX ( d . x ) )
102
+ . y ( d => originalScaleY ( d . y ) )
103
+ . curve ( curve ) ) ;
104
+ }
105
+
84
106
const updateHandles = ( ) => {
85
107
handles . remove ( ) ;
86
108
handles = createHandles ( getCurrentCurve ( ) , g , currentScaleX , currentScaleY ) ;
@@ -90,33 +112,43 @@ const updateHandleVisibility = () => {
90
112
$ ( '.anchor, .handle, .handle-line' ) . css ( 'visibility' , config . showHandle ? 'visible' : 'hidden' ) ;
91
113
}
92
114
115
+ const updateVelocityGraphVisibility = ( ) => {
116
+ velocityPath . style ( 'visibility' , config . showVelocityGraph ? 'visible' : 'hidden' ) ;
117
+ updateVelocityPath ( ) ;
118
+ }
119
+
93
120
window . addEventListener ( 'message' , function ( event ) {
94
121
switch ( event . data . command ) {
95
122
case 'changeId' :
96
123
updateCurvePath ( ) ;
124
+ updateVelocityPath ( ) ;
97
125
fit ( 0 ) ;
98
126
updateHandles ( ) ;
99
127
break ;
100
128
101
129
case 'updateCurvePath' :
102
130
updateCurvePath ( ) ;
131
+ updateVelocityPath ( ) ;
103
132
break ;
104
133
105
134
case 'updateHandles' :
106
135
updateHandles ( ) ;
107
136
updateCurvePath ( ) ;
137
+ updateVelocityPath ( ) ;
108
138
break ;
109
139
110
140
case 'updateHandlePos' :
111
141
if ( handles instanceof NormalHandles && handles . segmentHandlesArray . length > 1 ) {
112
142
updateHandles ( ) ;
113
143
updateCurvePath ( ) ;
144
+ updateVelocityPath ( ) ;
114
145
}
115
146
else {
116
147
const duration = config . enableAnimation ? 180 : 0 ;
117
148
const t = d3 . transition ( ) . duration ( duration ) . ease ( d3 . easeCubicOut ) ;
118
149
handles . updateHandles ( t ) ;
119
150
updateCurvePath ( t ) ;
151
+ updateVelocityPath ( t ) ;
120
152
}
121
153
break ;
122
154
@@ -129,11 +161,16 @@ window.addEventListener('message', function(event) {
129
161
updateHandleVisibility ( ) ;
130
162
break ;
131
163
164
+ case 'updateVelocityGraphVisibility' :
165
+ updateVelocityGraphVisibility ( ) ;
166
+ break ;
167
+
132
168
case 'applyPreferences' :
133
169
image . load ( config . setBackgroundImage ? config . backgroundImagePath : '' ) ;
134
- path . attr ( 'stroke' , config . curveColor )
170
+ curvePath . attr ( 'stroke' , config . curveColor )
135
171
. attr ( 'stroke-width' , config . curveThickness ) ;
136
172
updateCurvePath ( ) ;
173
+ updateVelocityPath ( ) ;
137
174
break ;
138
175
}
139
176
} ) ;
@@ -158,6 +195,7 @@ const svg = d3.select('#canvas')
158
195
if ( handles instanceof NormalHandles && x >= 0 && x <= 1 ) {
159
196
handles . curve . addCurve ( x , y , currentScaleX ( 1 ) - currentScaleX ( 0 ) ) ;
160
197
updateCurvePath ( ) ;
198
+ updateVelocityPath ( ) ;
161
199
updateHandles ( ) ;
162
200
}
163
201
} )
@@ -233,8 +271,17 @@ const line = d3.line()
233
271
. y ( d => originalScaleY ( d . y ) )
234
272
. curve ( curve ) ;
235
273
274
+ const velocityPath = zoomContainer . append ( 'path' )
275
+ . datum ( createCurvePathData ( 0 , 1 , true ) )
276
+ . attr ( 'fill' , 'none' )
277
+ . attr ( 'class' , 'velocity-path' )
278
+ . attr ( 'stroke-width' , config . curveThickness )
279
+ . attr ( 'd' , line ) ;
280
+
281
+ updateVelocityGraphVisibility ( ) ;
282
+
236
283
// カーブ
237
- const path = zoomContainer . append ( 'path' )
284
+ const curvePath = zoomContainer . append ( 'path' )
238
285
. datum ( createCurvePathData ( 0 , 1 ) )
239
286
. attr ( 'fill' , 'none' )
240
287
. attr ( 'stroke' , config . curveColor )
@@ -319,14 +366,8 @@ const zoom = d3.zoom()
319
366
const duration = config . enableAnimation ? 180 : 0 ;
320
367
const t = d3 . transition ( ) . duration ( duration ) . ease ( d3 . easeCubicOut ) ;
321
368
322
- const startGraphX = Math . max ( 0 , currentScaleX . invert ( - 200 ) ) ;
323
- const endGraphX = Math . min ( 1 , currentScaleX . invert ( width + 200 ) ) ;
324
-
325
- path . datum ( createCurvePathData ( startGraphX , endGraphX ) ) ;
326
- path . attr ( 'd' , d3 . line ( )
327
- . x ( d => originalScaleX ( d . x ) )
328
- . y ( d => originalScaleY ( d . y ) )
329
- . curve ( curve ) ) ;
369
+ updateCurvePath ( null , true ) ;
370
+ updateVelocityPath ( ) ;
330
371
331
372
if ( event . sourceEvent && event . sourceEvent . type === 'wheel' ) {
332
373
gridX . transition ( t ) . call ( axisX . scale ( currentScaleX ) ) ;
@@ -337,7 +378,9 @@ const zoom = d3.zoom()
337
378
gLabelY . transition ( t ) . call ( axisLabelY ( currentScaleY ) ) ;
338
379
zoomContainer . transition ( t )
339
380
. attr ( 'transform' , event . transform ) ;
340
- path . transition ( t )
381
+ curvePath . transition ( t )
382
+ . attr ( 'stroke-width' , config . curveThickness / event . transform . k ) ;
383
+ velocityPath . transition ( t )
341
384
. attr ( 'stroke-width' , config . curveThickness / event . transform . k ) ;
342
385
leftRect . transition ( t )
343
386
. attr ( 'width' , Math . max ( 0 , currentScaleX ( 0 ) ) ) ;
@@ -384,7 +427,9 @@ const fit = (customDuration = 700) => {
384
427
const t = d3 . transition ( ) . duration ( duration ) ;
385
428
svg . transition ( t )
386
429
. call ( zoom . transform , d3 . zoomIdentity ) ;
387
- path . transition ( t )
430
+ curvePath . transition ( t )
431
+ . attr ( 'stroke-width' , config . curveThickness ) ;
432
+ velocityPath . transition ( t )
388
433
. attr ( 'stroke-width' , config . curveThickness ) ;
389
434
}
390
435
@@ -431,7 +476,7 @@ $(window).on('keydown', event => {
431
476
command : 'goForwardId'
432
477
} , '*' ) ;
433
478
break ;
434
- }
479
+ }
435
480
} ) ;
436
481
437
482
$ ( window ) . on ( 'resize' , ( ) => {
@@ -471,7 +516,11 @@ $(window).on('resize', () => {
471
516
. attr ( 'height' , height ) ;
472
517
handles . rescaleX ( currentScaleX ) ;
473
518
handles . rescaleY ( currentScaleY ) ;
474
- path . attr ( 'd' , d3 . line ( )
519
+ curvePath . attr ( 'd' , d3 . line ( )
520
+ . x ( d => originalScaleX ( d . x ) )
521
+ . y ( d => originalScaleY ( d . y ) )
522
+ . curve ( curve ) ) ;
523
+ velocityPath . attr ( 'd' , d3 . line ( )
475
524
. x ( d => originalScaleX ( d . x ) )
476
525
. y ( d => originalScaleY ( d . y ) )
477
526
. curve ( curve ) ) ;
0 commit comments