-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b971085
commit b6a8362
Showing
4 changed files
with
126 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<script lang="ts"> | ||
import { colorPickerConfig, colorFromChannels } from "../lib/Color"; | ||
import focusStore from "../stores/focus-store"; | ||
import colorStore from "../stores/color-store"; | ||
import { scaleLinear } from "d3-scale"; | ||
export let xScale: any; | ||
export let yScale: any; | ||
export let plotHeight: number; | ||
export let plotWidth: number; | ||
export let colorSpace: string; | ||
export let dragging: boolean; | ||
export let axisColor: string; | ||
export let textColor: string; | ||
$: config = colorPickerConfig[colorSpace as keyof typeof colorPickerConfig]; | ||
$: xNonDimScale = scaleLinear().domain([0, 1]).range(xScale.domain()); | ||
$: yNonDimScale = scaleLinear().domain([0, 1]).range(yScale.domain()); | ||
$: focusedColors = $focusStore.focusedColors; | ||
$: colors = $colorStore.currentPal.colors; | ||
$: axisFormatter = | ||
colorPickerConfig[colorSpace as keyof typeof colorPickerConfig].axisLabel; | ||
$: points = { | ||
centerTop: { | ||
x: (xScale.range()[1] - xScale.range()[0]) / 2, | ||
y: yScale.range()[0], | ||
labelAdjust: { x: -5, y: 15 }, | ||
anchor: "end", | ||
label: `${config.yChannel}: ${axisFormatter(yScale.domain()[0])}`, | ||
}, | ||
centerBottom: { | ||
x: (xScale.range()[1] - xScale.range()[0]) / 2, | ||
y: yScale.range()[1], | ||
anchor: "start", | ||
labelAdjust: { x: 0, y: -3 }, | ||
label: axisFormatter(yScale.domain()[1]), | ||
}, | ||
centerLeft: { | ||
x: xScale.range()[0], | ||
y: (yScale.range()[1] - yScale.range()[0]) / 2, | ||
anchor: "start", | ||
labelAdjust: { x: 5, y: 15 }, | ||
label: axisFormatter(xScale.domain()[0]), | ||
}, | ||
centerRight: { | ||
x: xScale.range()[1], | ||
y: (yScale.range()[1] - yScale.range()[0]) / 2, | ||
anchor: "end", | ||
labelAdjust: { x: -5, y: 0 }, | ||
label: `${config.xChannel}: ${axisFormatter(xScale.domain()[1])}`, | ||
}, | ||
}; | ||
const bgResolution = 25; | ||
const avgNums = (nums: number[]) => | ||
nums.reduce((acc, x) => acc + x, 0) / nums.length; | ||
$: bg = $colorStore.currentPal.background; | ||
$: fillColor = (i: number, j: number) => { | ||
if (dragging && focusedColors.length === 1) { | ||
const avgColor = [ | ||
avgNums(focusedColors.map((x) => colors[x].toChannels()[0])), | ||
xNonDimScale(i / bgResolution), | ||
yNonDimScale(j / bgResolution), | ||
] as [number, number, number]; | ||
return colorFromChannels(avgColor, colorSpace as any).toHex(); | ||
} | ||
return bg.toHex(); | ||
}; | ||
</script> | ||
|
||
<!-- colorful background select --> | ||
{#each [...new Array(bgResolution)] as _, i} | ||
{#each [...new Array(bgResolution)] as _, j} | ||
<rect | ||
x={xScale(xNonDimScale(i / bgResolution))} | ||
y={yScale(yNonDimScale(j / bgResolution))} | ||
width={plotWidth / bgResolution} | ||
height={plotHeight / bgResolution} | ||
opacity="1" | ||
fill={fillColor(i, j)} | ||
/> | ||
{/each} | ||
{/each} | ||
|
||
<line | ||
x1={points.centerTop.x} | ||
y1={points.centerTop.y} | ||
x2={points.centerBottom.x} | ||
y2={points.centerBottom.y} | ||
stroke={axisColor} | ||
stroke-width="1" | ||
/> | ||
<line | ||
x1={points.centerLeft.x} | ||
y1={points.centerLeft.y} | ||
x2={points.centerRight.x} | ||
y2={points.centerRight.y} | ||
stroke={axisColor} | ||
stroke-width="1" | ||
/> | ||
{#each Object.values(points) as point} | ||
<text | ||
text-anchor={point.anchor} | ||
x={point.x + point.labelAdjust.x} | ||
y={point.y + point.labelAdjust.y} | ||
fill={textColor} | ||
> | ||
{point.label} | ||
</text> | ||
{/each} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters