Skip to content

Commit 6235eae

Browse files
committed
fix: misc layer more visible, wavefirn scaling improvements
1 parent ea18ca0 commit 6235eae

File tree

5 files changed

+28
-13
lines changed

5 files changed

+28
-13
lines changed

src/components/DurationBox/index.js renamed to src/components/DurationBoxes/index.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export const DurationBox = ({
5454
onClick,
5555
onRemoveBox,
5656
onClickBox,
57+
isMiscLayer = false,
5758
label = "",
5859
}) => {
5960
const [toolMode] = useToolMode()
@@ -63,18 +64,27 @@ export const DurationBox = ({
6364
return (
6465
<Container onClick={onClick} width={width} color={color} active={active}>
6566
{durations.map(
66-
({ start: startTime, end: endTime, label: durationLabel }, i) => {
67+
(
68+
{
69+
start: startTime,
70+
end: endTime,
71+
label: durationLabel,
72+
color: durationColor,
73+
},
74+
i
75+
) => {
6776
const startX =
6877
((startTime - visibleTimeStart) / visibleDuration) * width
6978
const endX = ((endTime - visibleTimeStart) / visibleDuration) * width
7079

7180
if (endX < 0) return null
7281
if (isNaN(startX) || isNaN(endX)) return null
82+
console.log({ durationColor, color })
7383

7484
return (
7585
<Box
7686
key={i}
77-
color={color}
87+
color={durationColor || color}
7888
x={startX}
7989
width={endX - startX}
8090
onClick={() => onClickBox(i)}
@@ -92,9 +102,11 @@ export const DurationBox = ({
92102
)
93103
}
94104
)}
95-
{label && (
105+
{(label || (isMiscLayer && durations.length === 0)) && (
96106
<Label colors={colors} key="label">
97-
{label}
107+
{isMiscLayer && durations.length === 0
108+
? "click to create durations"
109+
: label}
98110
</Label>
99111
)}
100112
</Container>

src/components/MainLayout/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useState } from "react"
22
import { styled } from "@material-ui/core/styles"
33
import useTimeRange from "../../hooks/use-time-range.js"
44
import ControllableWave from "../ControllableWave"
5-
import DurationBox from "../DurationBox"
5+
import DurationBoxes from "../DurationBoxes"
66
import useEventCallback from "use-event-callback"
77
import { setIn, getIn } from "seamless-immutable"
88
import useColors from "../../hooks/use-colors"
@@ -74,14 +74,15 @@ export const MainLayout = ({
7474
)
7575
})
7676
const onDragDurationEnd = useEventCallback(() => {
77+
setSelectedDurationIndex(draggedDurationIndex)
7778
setDraggedDurationIndex(null)
7879
})
7980
const onCreateTimestamp = useEventCallback((time) => {
8081
onChangeTimestamps(
8182
timestamps.concat([
8283
{
8384
time,
84-
color: "#f00",
85+
color: "#888",
8586
},
8687
])
8788
)
@@ -164,7 +165,7 @@ export const MainLayout = ({
164165
/>
165166
{durationGroups.map((dg, i) => {
166167
return (
167-
<DurationBox
168+
<DurationBoxes
168169
onClick={() => setActiveDurationGroup(i)}
169170
onClickBox={(di) => {
170171
setSelectedDurationIndex(di)
@@ -176,6 +177,7 @@ export const MainLayout = ({
176177
color={dg.color}
177178
width={width}
178179
label={dg.label}
180+
isMiscLayer={dg.misc}
179181
durations={dg.durations}
180182
visibleTimeStart={visibleTimeStart}
181183
visibleTimeEnd={visibleTimeEnd}

src/components/Wave/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const userSelectOffStyle = {
1313

1414
const Container = styled("div")({})
1515

16-
const reduceForVisibleDuration = (data, startTime, visibleDuration) => {
16+
const reduceForVisibleDuration = (data, startTime, visibleDuration, width) => {
1717
const firstInnerIndex = data.findIndex(([t]) => t >= startTime)
1818
let visibleSamples = data
1919
.slice(firstInnerIndex)
@@ -24,7 +24,7 @@ const reduceForVisibleDuration = (data, startTime, visibleDuration) => {
2424

2525
data = data.slice(Math.max(0, firstInnerIndex - 1), lastInnerIndex + 1)
2626

27-
const minDistance = visibleDuration / 200
27+
const minDistance = visibleDuration / (width / 4)
2828
const points = [data[0]]
2929
let lastAddedPointIndex = 0
3030
for (let i = 1; i < data.length; i++) {
@@ -143,7 +143,7 @@ export const Wave = ({
143143
/>
144144
)
145145
})}
146-
{durationGroups.flatMap(({ durations, color }, dgi) => {
146+
{durationGroups.flatMap(({ durations, color: dgColor }, dgi) => {
147147
return durations.map((duration, di) => {
148148
const { x: startX } = transformMatrix.applyToPoint(
149149
duration.start,
@@ -154,7 +154,7 @@ export const Wave = ({
154154
return (
155155
<rect
156156
key={`${dgi},${di}`}
157-
fill={colorAlpha(color, 0.2)}
157+
fill={colorAlpha(duration.color || dgColor, 0.2)}
158158
x={startX}
159159
y={0}
160160
width={endX - startX}
@@ -171,7 +171,8 @@ export const Wave = ({
171171
points={reduceForVisibleDuration(
172172
curve.data,
173173
startTimeOnGraph,
174-
visibleDuration
174+
visibleDuration,
175+
width
175176
)
176177
.map(([t, y]) => {
177178
const p = transformMatrix.applyToPoint(t, y)

src/hooks/use-get-random-color-using-hash.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const colorsToCycle = [
1515
export default () => {
1616
const themeColors = useColors()
1717
return useEventCallback((label) => {
18-
if (!label) return colorsToCycle[0]
18+
if (!label) return themeColors.fg
1919
let hashNumber = 0
2020
for (let i = 0; i < label.length; i++) {
2121
hashNumber += label.charCodeAt(i)

0 commit comments

Comments
 (0)