@cfasim-ui/docs 0.4.13 → 0.4.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -208,6 +208,54 @@ LineChart's `x-tick-format` (e.g. `"iso"`, `"month-year"`, an
208
208
  `Intl.DateTimeFormatOptions` object, or a `(ms, unit?) => string`
209
209
  function).
210
210
 
211
+ ### Crowded categorical labels
212
+
213
+ Non-date categorical labels are also thinned when they don't all fit:
214
+ the chart estimates label width from character count and font size,
215
+ then strides through the categories so adjacent labels never overlap.
216
+ Every bar still renders — only the tick labels are skipped.
217
+
218
+ <ComponentDemo>
219
+ <BarChart
220
+ data-testid="thinned-bar-chart"
221
+ :data="[3, 5, 8, 12, 18, 24, 31, 27, 22, 16, 11, 7, 4, 2]"
222
+ :categories="['2.11', '2.33', '2.56', '2.78', '3.00', '3.22', '3.44', '3.67', '3.89', '4.11', '4.33', '4.56', '4.78', '5.00']"
223
+ :width="380"
224
+ :height="220"
225
+ x-label="R₀"
226
+ y-label="Frequency"
227
+ />
228
+
229
+ <template #code>
230
+
231
+ ```vue
232
+ <BarChart
233
+ :data="[3, 5, 8, 12, 18, 24, 31, 27, 22, 16, 11, 7, 4, 2]"
234
+ :categories="[
235
+ '2.11',
236
+ '2.33',
237
+ '2.56',
238
+ '2.78',
239
+ '3.00',
240
+ '3.22',
241
+ '3.44',
242
+ '3.67',
243
+ '3.89',
244
+ '4.11',
245
+ '4.33',
246
+ '4.56',
247
+ '4.78',
248
+ '5.00',
249
+ ]"
250
+ :height="220"
251
+ x-label="R₀"
252
+ y-label="Frequency"
253
+ />
254
+ ```
255
+
256
+ </template>
257
+ </ComponentDemo>
258
+
211
259
  ### Logarithmic value axis
212
260
 
213
261
  Set `value-scale-type="log"` to switch the value axis to base-10 log
@@ -547,10 +547,29 @@ const categoryTickItems = computed<CategoryTickItem[]>(() => {
547
547
  const out: CategoryTickItem[] = [];
548
548
  const fmt = (label: string, i: number) =>
549
549
  props.categoryFormat ? props.categoryFormat(label, i) : label;
550
+ const formatted = new Array<string>(n);
551
+ let maxLen = 0;
550
552
  for (let i = 0; i < n; i++) {
553
+ formatted[i] = fmt(categoryLabels.value[i], i);
554
+ if (formatted[i].length > maxLen) maxLen = formatted[i].length;
555
+ }
556
+ // Skip labels when slots are too narrow (or short) to fit them
557
+ // without overlap. Vertical orientation measures horizontal label
558
+ // width (≈ chars × fontSize × 0.6); horizontal orientation just
559
+ // measures stacked line height (≈ fontSize × 1.2).
560
+ const fontSize = props.tickLabelStyle?.fontSize ?? TICK_LABEL_FONT_SIZE;
561
+ const minGap = 8;
562
+ const needPerLabel = isVertical.value
563
+ ? maxLen * fontSize * 0.6 + minGap
564
+ : fontSize * 1.2 + minGap;
565
+ const stride =
566
+ slotSize.value > 0
567
+ ? Math.max(1, Math.ceil(needPerLabel / slotSize.value))
568
+ : 1;
569
+ for (let i = 0; i < n; i += stride) {
551
570
  const center = slotStart(i) + slotSize.value / 2;
552
571
  out.push({
553
- label: fmt(categoryLabels.value[i], i),
572
+ label: formatted[i],
554
573
  pos: center,
555
574
  anchor: "middle",
556
575
  });
package/index.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.4.13",
2
+ "version": "0.4.14",
3
3
  "package": "@cfasim-ui/docs",
4
4
  "content": {
5
5
  "components": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cfasim-ui/docs",
3
- "version": "0.4.13",
3
+ "version": "0.4.14",
4
4
  "description": "LLM-friendly component and chart documentation for cfasim-ui",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {