@humanforest/charts 0.3.4 → 0.3.6

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@humanforest/charts",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src"
@@ -24,7 +24,7 @@
24
24
  "vue": "^3.5.22"
25
25
  },
26
26
  "dependencies": {
27
- "@humanforest/tokens": "^0.3.4"
27
+ "@humanforest/tokens": "^0.3.6"
28
28
  },
29
29
  "publishConfig": {
30
30
  "access": "public"
@@ -138,9 +138,6 @@ const barFor = (v: number | null) => {
138
138
  // A reading of zero keeps a hairline. Zero is a real measurement and a gap is the absence of
139
139
  // one; collapsing the bar to nothing would render the two identically.
140
140
  height: `max(${(to - from) * 100}%, 1px)`,
141
- // The cap goes on the free end, so a bar below the baseline rounds downward rather than into
142
- // the axis it grows from.
143
- negative: v < 0,
144
141
  };
145
142
  };
146
143
 
@@ -163,7 +160,8 @@ const endpointTop = computed(() => {
163
160
  The 2px gap is fixed, so the bucket count sets how thin the bars get: n buckets across w
164
161
  pixels leaves (w - 2(n - 1)) / n each. A tile 280px wide holds 12 buckets at 21px and 60 at
165
162
  2.7px — still bars; past roughly 60 the gap outweighs the bar and the row reads as a
166
- texture, where the measure belongs to a line instead. -->
163
+ texture, where the measure belongs to a line instead. Each bar is rounded at both ends:
164
+ no baseline is drawn for a square end to sit on. -->
167
165
  <div v-if="mark === 'bar'" class="flex w-full items-end gap-0.5" :class="fill ? 'absolute inset-0' : 'h-full'" aria-hidden="true">
168
166
  <span
169
167
  v-for="(v, i) in data"
@@ -172,8 +170,7 @@ const endpointTop = computed(() => {
172
170
  >
173
171
  <span
174
172
  v-if="barFor(v)"
175
- class="absolute inset-x-0 bg-current"
176
- :class="barFor(v)!.negative ? 'rounded-b-[3px]' : 'rounded-t-[3px]'"
173
+ class="absolute inset-x-0 rounded-[3px] bg-current"
177
174
  :style="{ bottom: barFor(v)!.bottom, height: barFor(v)!.height }"
178
175
  />
179
176
  </span>
@@ -97,7 +97,7 @@ export function forestTooltip<Datum extends Record<string, unknown>>(
97
97
  const present = keys.filter((k) => k in d);
98
98
  const title = opts.titleFormatter ? opts.titleFormatter(d) : Object.values(d)[0];
99
99
  const rows: ForestTipRow[] = present.map((k, i) => {
100
- const item = categories[k];
100
+ const item = categories[k]!;
101
101
  const raw = d[k];
102
102
  return {
103
103
  swatch: typeof item.color === 'string' ? item.color : `var(--vis-color${i})`,
@@ -35,8 +35,8 @@ export function fromCategories<Datum extends Record<string, unknown>>(
35
35
  : Array.isArray(item.color) && typeof item.color[0] === 'string' ? item.color[0]
36
36
  : `var(--vis-color${i})`;
37
37
  return {
38
- colors: keys.map((k, i) => colorOf(categories[k], i)),
39
- legendItems: keys.map((k, i) => ({ ...categories[k], color: colorOf(categories[k], i) })),
38
+ colors: keys.map((k, i) => colorOf(categories[k]!, i)),
39
+ legendItems: keys.map((k, i) => ({ ...categories[k]!, color: colorOf(categories[k]!, i) })),
40
40
  yAccessors: keys.map((k) => (d: Datum) => d[k] as number | null | undefined),
41
41
  xAccessor: xKey ? (d) => d[xKey] as number : (_d, i) => i,
42
42
  };
package/src/resolveVar.ts CHANGED
@@ -16,6 +16,6 @@
16
16
  /** The computed value of a `var(--x)` string. Non-var strings pass through untouched. */
17
17
  export function resolveVar(value: string, context: Element = document.documentElement): string {
18
18
  if (typeof window === 'undefined' || !value.startsWith('var(--')) return value;
19
- const name = value.slice(4, -1).split(',')[0].trim();
19
+ const name = value.slice(4, -1).split(',')[0]!.trim();
20
20
  return getComputedStyle(context).getPropertyValue(name).trim() || value;
21
21
  }
@@ -118,9 +118,9 @@ export function useCellScale<D>(options: CellScaleOptions<D>) {
118
118
  const stops = swatches.value;
119
119
  // A flat domain has no gradient to express — everything sits at the top stop rather than
120
120
  // dividing by zero.
121
- if (hi <= lo) return stops[stops.length - 1];
121
+ if (hi <= lo) return stops[stops.length - 1]!;
122
122
  const t = Math.min(1, Math.max(0, (v - lo) / (hi - lo)));
123
- return stops[Math.min(stops.length - 1, Math.floor(t * stops.length))];
123
+ return stops[Math.min(stops.length - 1, Math.floor(t * stops.length))]!;
124
124
  }
125
125
  const states = unref(options.states) ?? {};
126
126
  const key = options.state!(d as D) as string;