1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { __extends } from "tslib";
/**
* Linear continuous scale
* http://en.wikipedia.org/wiki/Level_of_measurement
*/
// FIXME only one data
import Scale from './Scale.js';
import OrdinalMeta from '../data/OrdinalMeta.js';
import * as scaleHelper from './helper.js';
import { isArray, map, isObject, isString } from 'zrender/lib/core/util.js';
var OrdinalScale = /** @class */function (_super) {
__extends(OrdinalScale, _super);
function OrdinalScale(setting) {
var _this = _super.call(this, setting) || this;
_this.type = 'ordinal';
var ordinalMeta = _this.getSetting('ordinalMeta');
// Caution: Should not use instanceof, consider ec-extensions using
// import approach to get OrdinalMeta class.
if (!ordinalMeta) {
ordinalMeta = new OrdinalMeta({});
}
if (isArray(ordinalMeta)) {
ordinalMeta = new OrdinalMeta({
categories: map(ordinalMeta, function (item) {
return isObject(item) ? item.value : item;
})
});
}
_this._ordinalMeta = ordinalMeta;
_this._extent = _this.getSetting('extent') || [0, ordinalMeta.categories.length - 1];
return _this;
}
OrdinalScale.prototype.parse = function (val) {
// Caution: Math.round(null) will return `0` rather than `NaN`
if (val == null) {
return NaN;
}
return isString(val) ? this._ordinalMeta.getOrdinal(val)
// val might be float.
: Math.round(val);
};
OrdinalScale.prototype.contain = function (rank) {
rank = this.parse(rank);
return scaleHelper.contain(rank, this._extent) && this._ordinalMeta.categories[rank] != null;
};
/**
* Normalize given rank or name to linear [0, 1]
* @param val raw ordinal number.
* @return normalized value in [0, 1].
*/
OrdinalScale.prototype.normalize = function (val) {
val = this._getTickNumber(this.parse(val));
return scaleHelper.normalize(val, this._extent);
};
/**
* @param val normalized value in [0, 1].
* @return raw ordinal number.
*/
OrdinalScale.prototype.scale = function (val) {
val = Math.round(scaleHelper.scale(val, this._extent));
return this.getRawOrdinalNumber(val);
};
OrdinalScale.prototype.getTicks = function () {
var ticks = [];
var extent = this._extent;
var rank = extent[0];
while (rank <= extent[1]) {
ticks.push({
value: rank
});
rank++;
}
return ticks;
};
OrdinalScale.prototype.getMinorTicks = function (splitNumber) {
// Not support.
return;
};
/**
* @see `Ordinal['_ordinalNumbersByTick']`
*/
OrdinalScale.prototype.setSortInfo = function (info) {
if (info == null) {
this._ordinalNumbersByTick = this._ticksByOrdinalNumber = null;
return;
}
var infoOrdinalNumbers = info.ordinalNumbers;
var ordinalsByTick = this._ordinalNumbersByTick = [];
var ticksByOrdinal = this._ticksByOrdinalNumber = [];
// Unnecessary support negative tick in `realtimeSort`.
var tickNum = 0;
var allCategoryLen = this._ordinalMeta.categories.length;
for (var len = Math.min(allCategoryLen, infoOrdinalNumbers.length); tickNum < len; ++tickNum) {
var ordinalNumber = infoOrdinalNumbers[tickNum];
ordinalsByTick[tickNum] = ordinalNumber;
ticksByOrdinal[ordinalNumber] = tickNum;
}
// Handle that `series.data` only covers part of the `axis.category.data`.
var unusedOrdinal = 0;
for (; tickNum < allCategoryLen; ++tickNum) {
while (ticksByOrdinal[unusedOrdinal] != null) {
unusedOrdinal++;
}
;
ordinalsByTick.push(unusedOrdinal);
ticksByOrdinal[unusedOrdinal] = tickNum;
}
};
OrdinalScale.prototype._getTickNumber = function (ordinal) {
var ticksByOrdinalNumber = this._ticksByOrdinalNumber;
// also support ordinal out of range of `ordinalMeta.categories.length`,
// where ordinal numbers are used as tick value directly.
return ticksByOrdinalNumber && ordinal >= 0 && ordinal < ticksByOrdinalNumber.length ? ticksByOrdinalNumber[ordinal] : ordinal;
};
/**
* @usage
* ```js
* const ordinalNumber = ordinalScale.getRawOrdinalNumber(tickVal);
*
* // case0
* const rawOrdinalValue = axisModel.getCategories()[ordinalNumber];
* // case1
* const rawOrdinalValue = this._ordinalMeta.categories[ordinalNumber];
* // case2
* const coord = axis.dataToCoord(ordinalNumber);
* ```
*
* @param {OrdinalNumber} tickNumber index of display
*/
OrdinalScale.prototype.getRawOrdinalNumber = function (tickNumber) {
var ordinalNumbersByTick = this._ordinalNumbersByTick;
// tickNumber may be out of range, e.g., when axis max is larger than `ordinalMeta.categories.length`.,
// where ordinal numbers are used as tick value directly.
return ordinalNumbersByTick && tickNumber >= 0 && tickNumber < ordinalNumbersByTick.length ? ordinalNumbersByTick[tickNumber] : tickNumber;
};
/**
* Get item on tick
*/
OrdinalScale.prototype.getLabel = function (tick) {
if (!this.isBlank()) {
var ordinalNumber = this.getRawOrdinalNumber(tick.value);
var cateogry = this._ordinalMeta.categories[ordinalNumber];
// Note that if no data, ordinalMeta.categories is an empty array.
// Return empty if it's not exist.
return cateogry == null ? '' : cateogry + '';
}
};
OrdinalScale.prototype.count = function () {
return this._extent[1] - this._extent[0] + 1;
};
OrdinalScale.prototype.unionExtentFromData = function (data, dim) {
this.unionExtent(data.getApproximateExtent(dim));
};
/**
* @override
* If value is in extent range
*/
OrdinalScale.prototype.isInExtentRange = function (value) {
value = this._getTickNumber(value);
return this._extent[0] <= value && this._extent[1] >= value;
};
OrdinalScale.prototype.getOrdinalMeta = function () {
return this._ordinalMeta;
};
OrdinalScale.prototype.calcNiceTicks = function () {};
OrdinalScale.prototype.calcNiceExtent = function () {};
OrdinalScale.type = 'ordinal';
return OrdinalScale;
}(Scale);
Scale.registerClass(OrdinalScale);
export default OrdinalScale;