From b03a47c38f6a0faebfb45daacf55bc2eb5e2be01 Mon Sep 17 00:00:00 2001 From: Andrew Michael McNutt Date: Mon, 5 Feb 2024 19:57:09 -0800 Subject: [PATCH] remove rotate from scatter, restore it as a left panel control --- src/components/Tooltip.svelte | 2 +- src/content-modules/Controls.svelte | 2 + src/controls/Rotate.svelte | 179 +++++++++++++++++++++++ src/controls/SetColorSpace.svelte | 6 +- src/lib/Color.ts | 1 + src/scatterplot/ColorScatterPlot.svelte | 187 +----------------------- 6 files changed, 188 insertions(+), 189 deletions(-) create mode 100644 src/controls/Rotate.svelte diff --git a/src/components/Tooltip.svelte b/src/components/Tooltip.svelte index 3455b090..5ca55dbb 100644 --- a/src/components/Tooltip.svelte +++ b/src/components/Tooltip.svelte @@ -86,7 +86,7 @@ > {#if allowDrag}
{ e.preventDefault(); diff --git a/src/content-modules/Controls.svelte b/src/content-modules/Controls.svelte index 0e1cfd1d..84cf6e58 100644 --- a/src/content-modules/Controls.svelte +++ b/src/content-modules/Controls.svelte @@ -9,6 +9,7 @@ import AdjustColor from "../controls/AdjustColor.svelte"; import AddColor from "../controls/AddColor.svelte"; import ColorChannelPicker from "../components/ColorChannelPicker.svelte"; + import Rotate from "../controls/Rotate.svelte"; $: currentPal = $colorStore.palettes[$colorStore.currentPal]; $: colors = currentPal.colors; @@ -34,6 +35,7 @@ + diff --git a/src/controls/Rotate.svelte b/src/controls/Rotate.svelte new file mode 100644 index 00000000..eabccf4f --- /dev/null +++ b/src/controls/Rotate.svelte @@ -0,0 +1,179 @@ + + +{#if focusedColors.length > 0 && colorSpace !== "hsl" && colorSpace !== "hsv" && colorSpace !== "lch"} +
+
+
Rotate
+ + +
+
+
Around which point?
+
+ + {#if zeroRotationSpaces.has(colorSpace)} + + {/if} + + {#each focusedColors as colorIdx} + + {/each} +
+
+ Rotate about the + + Axis +
+
+
+
+
+
+
+ + +
+
+{/if} diff --git a/src/controls/SetColorSpace.svelte b/src/controls/SetColorSpace.svelte index 6d05304d..58a7ea44 100644 --- a/src/controls/SetColorSpace.svelte +++ b/src/controls/SetColorSpace.svelte @@ -6,9 +6,9 @@ export let colorSpace: string; export let onChange: (e: any) => void; // const notAllowed = new Set(["rgb", "hsv", "hsl", "srgb", "lch", "oklch"]); - const notAllowed = new Set(["rgb", "lch", "oklch", "srgb"]); + // const notAllowed = new Set(["rgb", "lch", "oklch", "srgb"]); + const notAllowed = new Set(["rgb", "oklch", "srgb", "jzazbz", "oklab"]); // const onChange = (e: any) => colorStore.setColorSpace(e); - $: options = Object.keys(colorPickerConfig) .filter((x) => !notAllowed.has(x)) .sort(); @@ -23,7 +23,7 @@ class:font-bold={space === colorSpace} on:click={() => onChange(space)} > - {space} + {space.toUpperCase()} {/each}
diff --git a/src/lib/Color.ts b/src/lib/Color.ts index c06e810d..7ed34144 100644 --- a/src/lib/Color.ts +++ b/src/lib/Color.ts @@ -275,6 +275,7 @@ class LCH extends Color { domains = { l: [100, 0], c: [0, 150], h: [360, 0] } as Domain; stepSize: Channels = [1, 1, 1]; dimensionToChannel = { x: "c", y: "h", z: "l" }; + isPolar = true; axisLabel = (num: number) => `${Math.round(num)}`; } diff --git a/src/scatterplot/ColorScatterPlot.svelte b/src/scatterplot/ColorScatterPlot.svelte index 3e931a98..2313231c 100644 --- a/src/scatterplot/ColorScatterPlot.svelte +++ b/src/scatterplot/ColorScatterPlot.svelte @@ -266,78 +266,6 @@ class: "pointer-events-none", }; - $: initialRotationColors = [] as Color[]; - $: initialRotatePos = { x: 0, y: 0 }; - $: rotatePivotCenter = { x: 0, y: 0 }; - $: rotatePosition = { x: 0, y: 0 }; - - function rotateStart(e: any) { - // console.log("rotate start"); - startDragging(); - interactionMode = "rotate"; - initialRotationColors = [...colors]; - // const pos = toXY(e); - initialRotatePos = { - x: e.target.getBBox().x, - y: e.target.getBBox().y, - }; - rotatePivotCenter = screenSpaceAvg( - focusedColors - .map((x) => initialRotationColors[x]) - .map((el) => ({ - x: x(el), - y: y(el), - })) - ); - rotateUpdate(e); - } - - function rotateUpdate(e: any) { - // console.log("rotate update"); - let currentPos = toXY(e); - currentPos = { - x: currentPos.x - svgContainer.getBoundingClientRect().x, - y: currentPos.y - svgContainer.getBoundingClientRect().y, - }; - rotatePosition = currentPos; - let newAngle = Math.atan2( - currentPos.y - rotatePivotCenter.y, - currentPos.x - rotatePivotCenter.x - ); - const initialAngle = Math.atan2( - initialRotatePos.y - rotatePivotCenter.y, - initialRotatePos.x - rotatePivotCenter.x - ); - let angle = newAngle - initialAngle; - angle = angle < 0 ? angle + 2 * Math.PI : angle; - const xc = rotatePivotCenter.x; - const yc = rotatePivotCenter.y; - const newColors = focusedColors - .map((x) => initialRotationColors[x]) - .map((color) => { - const x1 = x(color); - const y1 = y(color); - const x3 = - Math.cos(angle) * (x1 - xc) - Math.sin(angle) * (y1 - yc) + xc; - const y3 = - Math.sin(angle) * (x1 - xc) + Math.cos(angle) * (y1 - yc) + yc; - const newChannels = [...color.toChannels()] as [number, number, number]; - newChannels[config.xChannelIndex] = scales.xInv(x3, y3); - newChannels[config.yChannelIndex] = scales.yInv(x3, y3); - return color.fromChannels(newChannels); - }); - const outColors = [...initialRotationColors]; - newColors.forEach((color, idx) => { - outColors[focusedColors[idx]] = color; - }); - onColorsChange(outColors); - } - function rotateEnd() { - // console.log("rotate end"); - interactionMode = "idle"; - stopDragging(); - } - let puttingPreview: false | Color = false; function puttingUpdate(e: any) { @@ -364,57 +292,6 @@ }, 10); puttingPreview = false; } - - $: handles = [ - // { - // type: "stretch", - // label: "left", - // x: pos.xPos - 15, - // y: pos.yPos + pos.selectionHeight / 2, - // }, - // { - // type: "stretch", - // label: "right", - // x: pos.xPos + pos.selectionWidth + 5, - // y: pos.yPos + pos.selectionHeight / 2, - // }, - // { - // type: "stretch", - // label: "top", - // x: pos.xPos + pos.selectionWidth / 2, - // y: pos.yPos - 15, - // }, - // { - // type: "stretch", - // label: "bottom", - // x: pos.xPos + pos.selectionWidth / 2, - // y: pos.yPos + pos.selectionHeight + 5, - // }, - { - type: "rotate", - label: "", - x: pos.xPos, - y: pos.yPos, - }, - { - type: "rotate", - label: "", - x: pos.xPos, - y: pos.yPos + pos.selectionHeight, - }, - { - type: "rotate", - label: "", - x: pos.xPos + pos.selectionWidth, - y: pos.yPos, - }, - { - type: "rotate", - label: "", - x: pos.xPos + pos.selectionWidth, - y: pos.yPos + pos.selectionHeight, - }, - ]; let svgContainer: any; @@ -441,14 +318,10 @@ on:touchstart|preventDefault={selectionStart(false)} on:touchmove|preventDefault={interactionMode === "drag" ? dragUpdate(false) - : interactionMode === "rotate" - ? rotateUpdate - : selectionUpdate(false)} + : selectionUpdate(false)} on:touchend|preventDefault={interactionMode === "drag" ? dragEnd(false) - : interactionMode === "rotate" - ? rotateEnd - : selectionEnd(false)} + : selectionEnd(false)} /> dragStart(e)} /> {/if} - {#if focusedColors.length > 1} - {#each handles as handle} - {#if handle.type === "stretch"} - - {/if} - {#if handle.type === "rotate"} - - {/if} - {/each} - {#if interactionMode === "rotate"} - - - {/if} - {/if} {#if interactionMode === "select"} @@ -616,15 +444,6 @@ on:touchend|preventDefault={dragEnd(false)} /> {/if} - {#if interactionMode === "rotate"} - - {/if} {#if scatterPlotMode === "putting"} {#if puttingPreview}
- -