cx 24.4.5 → 24.4.7

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.
@@ -1,18 +1,18 @@
1
- import {Axis} from './Axis';
2
- import {VDOM} from '../../ui/Widget';
3
- import {isUndefined} from '../../util/isUndefined';
4
- import {isArray} from '../../util/isArray';
1
+ import { Axis } from "./Axis";
2
+ import { VDOM } from "../../ui/Widget";
3
+ import { isUndefined } from "../../util/isUndefined";
4
+ import { isArray } from "../../util/isArray";
5
5
 
6
6
  export class CategoryAxis extends Axis {
7
-
8
7
  declareData() {
9
8
  super.declareData(...arguments, {
10
9
  inverted: undefined,
11
10
  uniform: undefined,
12
11
  names: undefined,
13
12
  values: undefined,
14
- minSize: undefined
15
- })
13
+ minSize: undefined,
14
+ categoryCount: undefined,
15
+ });
16
16
  }
17
17
 
18
18
  initInstance(context, instance) {
@@ -21,42 +21,44 @@ export class CategoryAxis extends Axis {
21
21
 
22
22
  explore(context, instance) {
23
23
  super.explore(context, instance);
24
- var {values, names, inverted, uniform, minSize} = instance.data;
24
+ var { values, names, inverted, uniform, minSize } = instance.data;
25
25
  instance.calculator.reset(inverted, uniform, values, names, minSize);
26
26
  }
27
27
 
28
+ reportData(context, instance) {
29
+ instance.set("categoryCount", instance.calculator.valueList.length);
30
+ }
31
+
28
32
  render(context, instance, key) {
29
- var {data, calculator} = instance;
33
+ var { data, calculator } = instance;
30
34
 
31
- if (!data.bounds.valid())
32
- return null;
35
+ if (!data.bounds.valid()) return null;
33
36
 
34
- var formatter = v => calculator.names[v] || v;
37
+ var formatter = (v) => calculator.names[v] || v;
35
38
 
36
- return <g key={key} className={data.classNames} style={data.style}>
37
- {this.renderTicksAndLabels(context, instance, formatter)}
38
- </g>
39
+ return (
40
+ <g key={key} className={data.classNames} style={data.style}>
41
+ {this.renderTicksAndLabels(context, instance, formatter)}
42
+ </g>
43
+ );
39
44
  }
40
-
41
-
42
45
  }
43
46
 
44
- CategoryAxis.prototype.baseClass = 'categoryaxis';
45
- CategoryAxis.prototype.anchors = '0 1 1 0';
47
+ CategoryAxis.prototype.baseClass = "categoryaxis";
48
+ CategoryAxis.prototype.anchors = "0 1 1 0";
46
49
  CategoryAxis.prototype.vertical = false;
47
50
  CategoryAxis.prototype.inverted = false;
48
51
  CategoryAxis.prototype.uniform = false;
49
52
  CategoryAxis.prototype.labelOffset = 10;
50
53
  CategoryAxis.prototype.labelRotation = 0;
51
- CategoryAxis.prototype.labelAnchor = 'auto';
52
- CategoryAxis.prototype.labelDx = 'auto';
53
- CategoryAxis.prototype.labelDy = 'auto';
54
+ CategoryAxis.prototype.labelAnchor = "auto";
55
+ CategoryAxis.prototype.labelDx = "auto";
56
+ CategoryAxis.prototype.labelDy = "auto";
54
57
  CategoryAxis.prototype.minSize = 1;
55
58
 
56
- Axis.alias('category', CategoryAxis);
59
+ Axis.alias("category", CategoryAxis);
57
60
 
58
61
  class CategoryScale {
59
-
60
62
  reset(inverted, uniform, values, names, minSize) {
61
63
  this.padding = 0.5;
62
64
  delete this.min;
@@ -72,9 +74,8 @@ class CategoryScale {
72
74
  this.names = {};
73
75
 
74
76
  if (values) {
75
- if (isArray(values))
76
- values.forEach(v=>this.acknowledge(v));
77
- else if (typeof values == 'object')
77
+ if (isArray(values)) values.forEach((v) => this.acknowledge(v));
78
+ else if (typeof values == "object")
78
79
  for (var k in values) {
79
80
  this.acknowledge(k);
80
81
  this.names[k] = values[k];
@@ -87,10 +88,8 @@ class CategoryScale {
87
88
  names.forEach((name, index) => {
88
89
  var value = values[index];
89
90
  this.names[value != null ? value : index] = name;
90
- })
91
- }
92
- else
93
- this.names = names;
91
+ });
92
+ } else this.names = names;
94
93
  }
95
94
  }
96
95
 
@@ -103,33 +102,27 @@ class CategoryScale {
103
102
  }
104
103
 
105
104
  map(v, offset = 0) {
106
-
107
105
  var index = this.valuesMap[v] || 0;
108
106
 
109
107
  return this.origin + (index + offset - this.min + this.padding) * this.factor;
110
108
  }
111
109
 
112
-
113
110
  measure(a, b) {
114
-
115
111
  this.a = a;
116
112
  this.b = b;
117
113
 
118
- if (this.min == null)
119
- this.min = this.minValue || 0;
114
+ if (this.min == null) this.min = this.minValue || 0;
120
115
 
121
- if (this.max == null)
122
- this.max = !isNaN(this.maxValue) ? this.maxValue : 100;
116
+ if (this.max == null) this.max = !isNaN(this.maxValue) ? this.maxValue : 100;
123
117
 
124
118
  var sign = this.inverted ? -1 : 1;
125
119
 
126
120
  if (this.max - this.min + 1 < this.minSize) {
127
- this.factor = sign * (this.b - this.a) / this.minSize;
128
- this.origin = (this.b + this.a) * 0.5 - this.factor * (this.max - this.min + 1) / 2;
129
- }
130
- else {
131
- this.factor = sign * (this.b - this.a) / (this.max - this.min + 2 * this.padding);
132
- this.origin = this.a * (1 + sign) / 2 + this.b * (1 - sign) / 2; //a || b
121
+ this.factor = (sign * (this.b - this.a)) / this.minSize;
122
+ this.origin = (this.b + this.a) * 0.5 - (this.factor * (this.max - this.min + 1)) / 2;
123
+ } else {
124
+ this.factor = (sign * (this.b - this.a)) / (this.max - this.min + 2 * this.padding);
125
+ this.origin = (this.a * (1 + sign)) / 2 + (this.b * (1 - sign)) / 2; //a || b
133
126
  }
134
127
  }
135
128
 
@@ -140,20 +133,19 @@ class CategoryScale {
140
133
  min: this.min,
141
134
  minSize: this.minSize,
142
135
  padding: this.padding,
143
- values: this.valueList.join(':'),
144
- names: JSON.stringify(this.names)
145
- }
136
+ values: this.valueList.join(":"),
137
+ names: JSON.stringify(this.names),
138
+ };
146
139
  }
147
140
 
148
141
  isSame(x) {
149
142
  var h = this.hash();
150
- var same = x && !Object.keys(h).some(k=>x[k] !== h[k]);
143
+ var same = x && !Object.keys(h).some((k) => x[k] !== h[k]);
151
144
  this.shouldUpdate = !same;
152
145
  return same;
153
146
  }
154
147
 
155
148
  acknowledge(value, width = 0, offset = 0) {
156
-
157
149
  var index = this.valuesMap[value];
158
150
  if (isUndefined(index)) {
159
151
  index = this.valueList.length;
@@ -165,7 +157,7 @@ class CategoryScale {
165
157
  this.minValue = index;
166
158
  this.padding = Math.max(this.padding, Math.abs(offset - width / 2));
167
159
  }
168
-
160
+
169
161
  if (this.maxValue == null || index > this.maxValue) {
170
162
  this.maxValue = index;
171
163
  this.padding = Math.max(this.padding, Math.abs(offset + width / 2));
@@ -173,36 +165,30 @@ class CategoryScale {
173
165
  }
174
166
 
175
167
  book(value, name) {
176
- if (this.uniform)
177
- value = 0;
168
+ if (this.uniform) value = 0;
178
169
 
179
170
  var stack = this.valueStacks[value];
180
171
  if (!stack)
181
172
  stack = this.valueStacks[value] = {
182
173
  index: {},
183
- count: 0
174
+ count: 0,
184
175
  };
185
- if (!stack.index.hasOwnProperty(name))
186
- stack.index[name] = stack.count++;
176
+ if (!stack.index.hasOwnProperty(name)) stack.index[name] = stack.count++;
187
177
  }
188
178
 
189
179
  locate(value, name) {
190
- if (this.uniform)
191
- value = 0;
180
+ if (this.uniform) value = 0;
192
181
 
193
182
  var stack = this.valueStacks[value];
194
- if (!stack)
195
- return [0, 1];
183
+ if (!stack) return [0, 1];
196
184
 
197
185
  return [stack.index[name], stack.count];
198
186
  }
199
187
 
200
188
  trackValue(v, offset = 0, constrain = false) {
201
189
  let index = Math.round((v - this.origin) / this.factor - offset + this.min - this.padding);
202
- if (index < this.min)
203
- index = this.min;
204
- if (index > this.max)
205
- index = this.max;
190
+ if (index < this.min) index = this.min;
191
+ if (index > this.max) index = this.max;
206
192
  return this.valueList[index];
207
193
  }
208
194
 
@@ -215,11 +201,12 @@ class CategoryScale {
215
201
  }
216
202
 
217
203
  getTicks(tickSizes) {
218
- return tickSizes.map(size => this.valueList);
204
+ return tickSizes.map((size) => this.valueList);
219
205
  }
220
206
 
221
207
  mapGridlines() {
222
- return Array.from({length: this.valueList.length + 1})
223
- .map((_, index) => this.origin + (index - 0.5 - this.min + this.padding) * this.factor);
208
+ return Array.from({ length: this.valueList.length + 1 }).map(
209
+ (_, index) => this.origin + (index - 0.5 - this.min + this.padding) * this.factor,
210
+ );
224
211
  }
225
- }
212
+ }
@@ -0,0 +1,11 @@
1
+ import assert from "assert";
2
+ import { createAccessorModelProxy } from "./createAccessorModelProxy";
3
+ import { getAccessor } from "./getAccessor";
4
+
5
+ describe("getAccessor", function () {
6
+ it("works with accessor chains", function () {
7
+ let m = createAccessorModelProxy();
8
+ let accessor = getAccessor(m.a.b);
9
+ assert(typeof accessor.set == "function");
10
+ });
11
+ });