-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMiniHueChart.svelte
142 lines (117 loc) · 3.48 KB
/
MiniHueChart.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<script>
import { scaleLinear } from 'd3-scale';
import chroma from "chroma-js";
import { getHcl, radians } from '../scripts/utility';
export let width =90
export let height =90
export let colors = ["#b7ffff", "#4e6bcd"]
export let xTicks = [ 0]
$: points = colors.map(color=>{
let h, c, l
({h, c, l} = getHcl(color))
return {color:color, h: h, c:c, l:l}
})
let yTicks = [ 0, 50, 100]
const padding = { top: 5, right: 5, bottom: 5, left: 5 };
$: steps = colors.length
$: xScale = scaleLinear()
.domain([-100, 100])
.range([padding.left, width - padding.right]);
$: yScale = scaleLinear()
.domain([-100, 100])
.range([height - padding.bottom, padding.top]);
const cX = (chroma, hue)=> {
let x = xScale(Math.sin(radians(hue))*chroma)
if(isNaN(x)) {x=xScale(0)}
return x
}
const cY = (chroma, hue)=> {
let y = yScale(Math.cos(radians(hue))*chroma)
if(isNaN(y)) {y=yScale(0)
}
return y
}
let r = (x2, y2) => {
const x1 = 0
const y1 = 0
return Math.sqrt((x2 - x1)^2 + (y2 - y1)^2)
}
let colorCircle = []
let angle = 15
for (let index = 0; index < 360/angle; index++) {
colorCircle[index] = [index*angle, 50, 75]
}
</script>
<div style="margin-bottom:-0.5em">
<svg
width={width+padding.left+padding.right}
height={height+padding.top+padding.bottom}
>
<g class="axis y-axis">
<g class="tick tick-{0}" transform="translate({padding.left}, {yScale(0)})">
<line x2="{width-padding.right-padding.left}"></line>
</g>
</g>
<g class="axis x-axis">
{#each xTicks as tick, i}
<g class="tick tick-{tick}" transform="translate({xScale(tick)}, {height} )">
<line y1="{-padding.top}" y2="-{height-padding.top}"></line>
</g>
{/each}
</g>
<g>
{#each colorCircle as swatch }
<circle
fill={'rgba(0, 0, 0, 0.1)'}
cx="{xScale(Math.sin(radians(swatch[0]))*points[1].c)}"
cy="{yScale(Math.cos(radians(swatch[0]))*points[1].c)}"
r={(2)}
/>
{/each}
</g>
<g>
{#each points as point, i}
<line x1={xScale(0)} y1={yScale(0)} x2={cX(point.c, point.h)} y2="{cY(point.c, point.h)}" stroke={"rgba(0, 0, 0, 0.3)"}
stroke-width={"1px"}></line>
<circle
fill={point.color}
cx="{cX(point.c, point.h)}"
cy="{cY(point.c, point.h)}"
r={(7)}
stroke={"rgba(0, 0, 0, 0.1)"}
stroke-width={'2px'}
/>
{/each}
</g>
</svg>
</div>
<style>
.tick {
font-size: .725em;
font-weight: 200;
}
.tick line {
stroke: #595959b5;
stroke-dasharray: 2;
}
.tick text {
fill: #595959;
text-anchor: start;
}
.tick.tick-0 line {
stroke-dasharray: 0;
}
.tick.tick-theta line {
stroke-dasharray: none;
}
.tick.tick-theta text {
text-anchor: middle;
stroke: white;
fill: #595959;
stroke-width:4px;
paint-order:stroke;
}
.x-axis .tick text {
text-anchor: middle;
}
</style>