@platforma-sdk/model 1.58.22 → 1.59.3

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.
@@ -29,7 +29,11 @@ import type { PColumnDataUniversal } from "../render";
29
29
  export type AxesVault = Map<CanonicalizedJson<AxisId>, AxisSpecNormalized>;
30
30
 
31
31
  /** Create id for column copy with added keys in axes domains */
32
- const colId = (id: PObjectId, domains: (Record<string, string> | undefined)[]) => {
32
+ const colId = (
33
+ id: PObjectId,
34
+ domains: (Record<string, string> | undefined)[],
35
+ contextDomains: (Record<string, string> | undefined)[],
36
+ ) => {
33
37
  let wid = id.toString();
34
38
  domains?.forEach((domain) => {
35
39
  if (domain) {
@@ -39,6 +43,14 @@ const colId = (id: PObjectId, domains: (Record<string, string> | undefined)[]) =
39
43
  }
40
44
  }
41
45
  });
46
+ contextDomains?.forEach((contextDomain) => {
47
+ if (contextDomain) {
48
+ for (const [k, v] of Object.entries(contextDomain)) {
49
+ wid += k;
50
+ wid += v;
51
+ }
52
+ }
53
+ });
42
54
  return wid;
43
55
  };
44
56
 
@@ -122,6 +134,15 @@ function getAdditionalColumnsForColumn<T extends Omit<PColumn<PColumnDataUnivers
122
134
  allAddedDomainValues.add(item);
123
135
  }
124
136
  });
137
+ const cd1 = column.spec.axesSpec[idx].contextDomain;
138
+ const cd2 = axisId.contextDomain;
139
+ Object.entries(cd2 ?? {}).forEach(([key, value]) => {
140
+ if (cd1?.[key] === undefined) {
141
+ const item = JSON.stringify(["ctx:" + key, value]);
142
+ addedSet.add(item);
143
+ allAddedDomainValues.add(item);
144
+ }
145
+ });
125
146
  return {
126
147
  ...axisId,
127
148
  annotations: column.spec.axesSpec[idx].annotations,
@@ -139,6 +160,7 @@ function getAdditionalColumnsForColumn<T extends Omit<PColumn<PColumnDataUnivers
139
160
  const id = colId(
140
161
  column.id,
141
162
  idsList.map((id) => id.domain),
163
+ idsList.map((id) => id.contextDomain),
142
164
  );
143
165
 
144
166
  const label = readAnnotation(column.spec, Annotation.Label) ?? "";
package/src/render/api.ts CHANGED
@@ -423,6 +423,10 @@ export class ResultPool implements ColumnProvider, AxisLabelProvider {
423
423
  continue;
424
424
  }
425
425
 
426
+ if (!matchDomain(spec.contextDomain, oth.contextDomain)) {
427
+ continue;
428
+ }
429
+
426
430
  for (let i = 0; i < spec.axesSpec.length; ++i) {
427
431
  const qAx = spec.axesSpec[i];
428
432
  const tAx = oth.axesSpec[i];
@@ -435,6 +439,9 @@ export class ResultPool implements ColumnProvider, AxisLabelProvider {
435
439
  if (!matchDomain(qAx.domain, tAx.domain)) {
436
440
  continue out;
437
441
  }
442
+ if (!matchDomain(qAx.contextDomain, tAx.contextDomain)) {
443
+ continue out;
444
+ }
438
445
  }
439
446
 
440
447
  result.push(data.obj);
@@ -457,7 +464,8 @@ export class ResultPool implements ColumnProvider, AxisLabelProvider {
457
464
  spec.axesSpec.length === 1 &&
458
465
  spec.axesSpec[0].name === axis.name &&
459
466
  spec.axesSpec[0].type === axis.type &&
460
- matchDomain(axis.domain, spec.axesSpec[0].domain)
467
+ matchDomain(axis.domain, spec.axesSpec[0].domain) &&
468
+ matchDomain(axis.contextDomain, spec.axesSpec[0].contextDomain)
461
469
  ) {
462
470
  if (column.obj.data.resourceType.name !== "PColumnData/Json") {
463
471
  throw Error(`Expected JSON column for labels, got: ${column.obj.data.resourceType.name}`);
@@ -149,19 +149,25 @@ function fallbackIdDeriver(originalId: PObjectId, axisFilters?: AxisFilterByIdx[
149
149
  function hasAnchors(selector: unknown): selector is AnchoredPColumnSelector {
150
150
  if (!selector || typeof selector !== "object") return false;
151
151
  const potentialAnchored = selector as Record<string, any>;
152
- const domainHasAnchors =
153
- potentialAnchored["domain"] &&
154
- typeof potentialAnchored["domain"] === "object" &&
155
- Object.values(potentialAnchored["domain"]).some(
156
- (v: unknown) => typeof v === "object" && v !== null && "anchor" in v,
157
- );
152
+ const hasAnchorValues = (obj: unknown) =>
153
+ obj &&
154
+ typeof obj === "object" &&
155
+ Object.values(obj).some((v: unknown) => typeof v === "object" && v !== null && "anchor" in v);
156
+ const domainHasAnchors = hasAnchorValues(potentialAnchored["domain"]);
157
+ const contextDomainHasAnchors = hasAnchorValues(potentialAnchored["contextDomain"]);
158
158
  const axesHaveAnchors =
159
159
  potentialAnchored["axes"] &&
160
160
  Array.isArray(potentialAnchored["axes"]) &&
161
161
  potentialAnchored["axes"].some(
162
162
  (a: unknown) => typeof a === "object" && a !== null && "anchor" in a,
163
163
  );
164
- return !!potentialAnchored["domainAnchor"] || domainHasAnchors || axesHaveAnchors;
164
+ return (
165
+ !!potentialAnchored["domainAnchor"] ||
166
+ !!potentialAnchored["contextDomainAnchor"] ||
167
+ domainHasAnchors ||
168
+ contextDomainHasAnchors ||
169
+ axesHaveAnchors
170
+ );
165
171
  }
166
172
 
167
173
  /**