|
9 | 9 | Layer, |
10 | 10 | Labels, |
11 | 11 | LinearGradient, |
| 12 | + Text, |
12 | 13 | Tooltip, |
| 14 | + Circle, |
| 15 | + Group, |
13 | 16 | } from 'layerchart'; |
14 | 17 | import { extent, group, mean, sum } from 'd3-array'; |
15 | 18 | import { scaleLinear, scaleLog, scaleThreshold, scaleTime } from 'd3-scale'; |
|
1182 | 1185 | </div> |
1183 | 1186 | </Preview> |
1184 | 1187 |
|
| 1188 | +<h2>Single stack with indicator</h2> |
| 1189 | + |
| 1190 | +<Preview data={dateSeriesData}> |
| 1191 | + <div class="h-[50px] p-4 border rounded-sm"> |
| 1192 | + <BarChart |
| 1193 | + data={[ |
| 1194 | + { |
| 1195 | + label: 'Severe thinness', |
| 1196 | + start: 15, |
| 1197 | + end: 16, |
| 1198 | + }, |
| 1199 | + { |
| 1200 | + label: 'Thinness', |
| 1201 | + start: 16, |
| 1202 | + end: 18.5, |
| 1203 | + }, |
| 1204 | + { |
| 1205 | + label: 'Normal', |
| 1206 | + start: 18.5, |
| 1207 | + end: 25, |
| 1208 | + }, |
| 1209 | + { |
| 1210 | + label: 'Overweight', |
| 1211 | + start: 25, |
| 1212 | + end: 30, |
| 1213 | + }, |
| 1214 | + { |
| 1215 | + label: 'Obese', |
| 1216 | + start: 30, |
| 1217 | + end: 35, |
| 1218 | + }, |
| 1219 | + { |
| 1220 | + label: 'Severe obese', |
| 1221 | + start: 35, |
| 1222 | + end: 40, |
| 1223 | + }, |
| 1224 | + ]} |
| 1225 | + x={['start', 'end']} |
| 1226 | + y={(d) => 1} |
| 1227 | + xBaseline={undefined} |
| 1228 | + xNice={false} |
| 1229 | + c="label" |
| 1230 | + cRange={[ |
| 1231 | + 'var(--color-blue-500)', |
| 1232 | + 'var(--color-blue-400)', |
| 1233 | + 'var(--color-teal-500)', |
| 1234 | + 'var(--color-yellow-500)', |
| 1235 | + 'var(--color-orange-500)', |
| 1236 | + 'var(--color-red-500)', |
| 1237 | + ]} |
| 1238 | + bandPadding={0} |
| 1239 | + orientation="horizontal" |
| 1240 | + props={{ |
| 1241 | + tooltip: { |
| 1242 | + context: { mode: 'bounds' }, |
| 1243 | + }, |
| 1244 | + }} |
| 1245 | + {renderContext} |
| 1246 | + {debug} |
| 1247 | + > |
| 1248 | + {#snippet axis({ context })} |
| 1249 | + <Axis placement="bottom" tickLength={0} ticks={[15, 16, 18.5, 25, 30, 35, 40]}> |
| 1250 | + {#snippet tickLabel({ props })} |
| 1251 | + <Text {...props} textAnchor={props.value === '40' ? 'end' : 'start'} /> |
| 1252 | + {/snippet} |
| 1253 | + </Axis> |
| 1254 | + {/snippet} |
| 1255 | + |
| 1256 | + {#snippet aboveMarks({ context })} |
| 1257 | + <Group x={context.xScale(26.5)} y={-4}> |
| 1258 | + {@const width = 12} |
| 1259 | + {@const height = 12} |
| 1260 | + <polygon |
| 1261 | + points="{-width / 2},0 0,{height} {width / 2},0" |
| 1262 | + class="fill-black stroke-white/50 dark:fill-white dark:stroke-black/50" |
| 1263 | + /> |
| 1264 | + </Group> |
| 1265 | + {/snippet} |
| 1266 | + |
| 1267 | + {#snippet tooltip({ context })} |
| 1268 | + <Tooltip.Root> |
| 1269 | + {#snippet children({ data })} |
| 1270 | + <Tooltip.List> |
| 1271 | + <Tooltip.Item label="Label:" value={data.label} /> |
| 1272 | + <Tooltip.Item label="Range:" value="{data.start} - {data.end}" /> |
| 1273 | + </Tooltip.List> |
| 1274 | + {/snippet} |
| 1275 | + </Tooltip.Root> |
| 1276 | + {/snippet} |
| 1277 | + </BarChart> |
| 1278 | + </div> |
| 1279 | +</Preview> |
| 1280 | + |
1185 | 1281 | <h2>Single axis (x)</h2> |
1186 | 1282 |
|
1187 | 1283 | <Preview data={dateSeriesData}> |
|
0 commit comments