MCPcopy
hub / github.com/apache/echarts / SortOrderComparator

Class SortOrderComparator

src/data/helper/dataValueHelper.ts:143–190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

141}
142
143export class SortOrderComparator {
144 private _incomparable: number;
145 private _resultLT: -1 | 1;
146 /**
147 * @param order by default: 'asc'
148 * @param incomparable by default: Always on the tail.
149 * That is, if 'asc' => 'max', if 'desc' => 'min'
150 * See the definition of "incomparable" in [SORT_COMPARISON_RULE].
151 */
152 constructor(order: 'asc' | 'desc', incomparable: 'min' | 'max') {
153 const isDesc = order === 'desc';
154 this._resultLT = isDesc ? 1 : -1;
155 if (incomparable == null) {
156 incomparable = isDesc ? 'min' : 'max';
157 }
158 this._incomparable = incomparable === 'min' ? -Infinity : Infinity;
159 }
160 // See [SORT_COMPARISON_RULE].
161 // Performance sensitive.
162 evaluate(lval: unknown, rval: unknown): -1 | 0 | 1 {
163 // Most cases is 'number', and typeof maybe 10 times faseter than parseFloat.
164 let lvalFloat = isNumber(lval) ? lval : numericToNumber(lval);
165 let rvalFloat = isNumber(rval) ? rval : numericToNumber(rval);
166 const lvalNotNumeric = isNaN(lvalFloat as number);
167 const rvalNotNumeric = isNaN(rvalFloat as number);
168
169 if (lvalNotNumeric) {
170 lvalFloat = this._incomparable;
171 }
172 if (rvalNotNumeric) {
173 rvalFloat = this._incomparable;
174 }
175 if (lvalNotNumeric && rvalNotNumeric) {
176 const lvalIsStr = isString(lval);
177 const rvalIsStr = isString(rval);
178 if (lvalIsStr) {
179 lvalFloat = rvalIsStr ? lval as unknown as number : 0;
180 }
181 if (rvalIsStr) {
182 rvalFloat = lvalIsStr ? rval as unknown as number : 0;
183 }
184 }
185
186 return lvalFloat < rvalFloat ? this._resultLT
187 : lvalFloat > rvalFloat ? (-this._resultLT as -1 | 1)
188 : 0;
189 }
190}
191
192class FilterEqualityComparator implements FilterComparator {
193 private _isEQ: boolean;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…