Skip to content

Commit f4e3d15

Browse files
committed
self-review
1 parent aa1ff57 commit f4e3d15

File tree

5 files changed

+35
-22
lines changed

5 files changed

+35
-22
lines changed

src/apps/weblib/interface.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,10 @@ struct IntFDataTable final : Data::DataTable
480480
std::vector<const char *> aggregatingRawNames(
481481
aggregating.size());
482482

483-
externalData.values.aggregator(
484-
create_unique_ptr(intf.createData(&res), &object_free)
485-
.get(),
483+
auto &&dataPtr = create_unique_ptr(intf.createData(&res),
484+
&object_free);
485+
486+
externalData.values.aggregator(dataPtr.get(),
486487
filter.getFun1(),
487488
filter.getFun2(),
488489
aggregateBy.size(),

src/apps/weblib/ts-api/data.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ import { CPointer } from './cvizzu.types'
88

99
type DataTypes = D.DimensionValue | D.MeasureValue
1010
export class Data {
11-
private _cData: CData
12-
private _cChart: CChart | undefined
13-
private readonly _needDetach: boolean
14-
private _filters: Map<CPointer, string>
11+
private readonly _cData: CData
12+
private readonly _cChart: CChart | undefined
13+
private readonly _dataOwned: boolean
14+
private readonly _filters: Map<CPointer, D.OutFilterCallback>
1515

16-
constructor(cData: CData, cChart: CChart | undefined = undefined, needDetach: boolean = true) {
16+
constructor(cData: CData, cChart: CChart | undefined = undefined, dataOwned: boolean = true) {
1717
this._cData = cData
1818
this._cChart = cChart
19-
this._needDetach = needDetach
19+
this._dataOwned = dataOwned
2020
this._filters = new Map()
2121
}
2222

2323
detach(): void {
24-
if (this._needDetach) {
24+
if (this._dataOwned) {
2525
this._cData.free()
2626
}
2727
}
@@ -30,7 +30,7 @@ export class Data {
3030
return this._cData.getMetaInfo()
3131
}
3232

33-
getFilterByPtr(ptr: CPointer): string | null {
33+
getFilterByPtr(ptr: CPointer): D.OutFilterCallback | null {
3434
return this._filters.get(ptr) ?? null
3535
}
3636

@@ -278,22 +278,25 @@ export class Data {
278278
this._cData.addMeasure(name, unit, numbers)
279279
}
280280

281-
private _setFilter(filter: D.FilterCallback | string | null): void {
281+
private _setFilter(filter: D.FilterCallback | D.OutFilterCallback | null): void {
282282
if (this._cChart === undefined) {
283283
throw new Error('chart is not attached')
284284
}
285-
if (typeof filter === 'function') {
286-
const callback = (cRecord: CRecord): boolean => filter(new DataRecord(cRecord))
287-
this._cChart.setFilter(callback)
288-
} else if (filter === null) {
285+
if (filter === null) {
289286
this._cChart.setFilter(null)
290-
} else if (typeof filter === 'string') {
287+
} else if (typeof filter === 'function' && filter.length == 1) {
288+
const callback = (cRecord: CRecord): boolean =>
289+
(filter as D.FilterCallback)(new DataRecord(cRecord))
290+
this._cChart.setFilter(callback)
291+
} else if (typeof filter === 'function' && filter.length == 0) {
291292
this._filters.set(
292293
this._cChart.setFilter(
293294
(): boolean => false,
294-
this._filters.delete.bind(this._filters)
295+
(ptr: CPointer) => {
296+
this._filters.delete(ptr)
297+
}
295298
),
296-
filter
299+
filter as D.OutFilterCallback
297300
)
298301
} else {
299302
throw new Error('data filter is not a function or null')

src/apps/weblib/ts-api/vizzu.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ export interface FeatureOptions {
5151
export interface OtherSource {
5252
series: Data.SeriesMetaInfo[]
5353
aggregate: (
54-
filter1: string | null,
55-
filter2: string | null,
54+
filter1: Data.OutFilterCallback | null,
55+
filter2: Data.OutFilterCallback | null,
5656
groupBy: Data.SeriesList,
5757
series: Data.SeriesList
5858
) => Data.Set

src/apps/weblib/typeschema-api/data.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,13 @@ definitions:
315315
required: [record]
316316
return: { type: boolean }
317317

318+
OutFilterCallback:
319+
type: function
320+
description: A function returns a specific value for source data
321+
arguments:
322+
required: []
323+
return: { type: any }
324+
318325
SeriesMetaInfo:
319326
$ref: SeriesInfo
320327

@@ -337,7 +344,7 @@ definitions:
337344
generation. If the callback returns false, the record will not be shown on the chart.
338345
oneOf:
339346
- $ref: FilterCallback
340-
- type: string
347+
- $ref: OutFilterCallback
341348
nullable: true
342349

343350
TableBySeries:

tools/ci/type/gen-dts.cjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ class DTSGenerator {
222222
}
223223
const returns = definition.return ? this._getType(name, definition.return) : 'void'
224224
return `(${args}) => ${returns}`
225+
} else if (definition.type === 'any') {
226+
return 'unknown'
225227
} else if (definition.$ref) {
226228
this._validateDef(definition, '$ref', '$template')
227229
const refType = this._getRef(definition.$ref)

0 commit comments

Comments
 (0)