-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve data explorer widgets (#1857)
* Improve rendering of echarts widgets in data explorer * Migrate heatmap widget to echarts renderer * Add revision to correlation charts * Remove unused echarts-stats module * Remove unused css files, add license header * Improve rendering of tooltips and labels * Fix reloading behaviour in time selector * Fix format
- Loading branch information
1 parent
038a4da
commit 8e4d866
Showing
50 changed files
with
1,537 additions
and
971 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
ui/src/app/core-ui/echarts-transform/histogram.transform.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* 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 { | ||
DataTransformOption, | ||
ExternalDataTransform, | ||
ExternalDataTransformResultItem, | ||
} from 'echarts/types/src/data/helper/transform'; | ||
|
||
import { bin } from 'd3-array'; | ||
import { OptionSourceDataArrayRows } from 'echarts/types/src/util/types'; | ||
|
||
export interface HistogramConfig extends DataTransformOption { | ||
field: string; | ||
autoBin: boolean; | ||
numberOfBins: number; | ||
autoDomain: boolean; | ||
domainMin: number; | ||
domainMax: number; | ||
} | ||
|
||
export const HistogramTransform: ExternalDataTransform<HistogramConfig> = { | ||
type: 'sp:histogram', | ||
|
||
transform: function ( | ||
params, | ||
): ExternalDataTransformResultItem | ExternalDataTransformResultItem[] { | ||
const upstream = params.upstream; | ||
const clonedData = upstream.cloneRawData(); | ||
const field = params.config['field']; | ||
const autoBin = params.config['autoBin']; | ||
const numberOfBins = +params.config['numberOfBins']; | ||
const autoDomain = params.config['autoDomain']; | ||
const domainMin = +params.config['domainMin']; | ||
const domainMax = +params.config['domainMax']; | ||
const dimension = upstream.getDimensionInfo(field); | ||
const values = (clonedData as any).map(row => row[dimension.index]); | ||
values.shift(); | ||
|
||
let bins = bin(); | ||
if (!autoBin && numberOfBins) { | ||
bins = bins.thresholds(numberOfBins); | ||
} | ||
if (!autoDomain && domainMin && domainMax) { | ||
bins = bins.domain([domainMin, domainMax]); | ||
} | ||
const d3h = bins(values); | ||
const source: OptionSourceDataArrayRows = []; | ||
const hist: number[] = d3h.map(item => item.length); | ||
const binEdges = d3h.map(item => item.x0); | ||
if (d3h.length) { | ||
binEdges.push(d3h.at(-1).x1); | ||
} | ||
hist.forEach((val, index) => { | ||
source.push([binEdges[index] + '-' + binEdges[index + 1], val]); | ||
}); | ||
|
||
return { | ||
data: source, | ||
dimensions: ['edge', 'hist'], | ||
}; | ||
}, | ||
}; |
75 changes: 75 additions & 0 deletions
75
ui/src/app/core-ui/echarts-transform/round-values.transform.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* 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 { | ||
DataTransformOption, | ||
ExternalDataTransform, | ||
ExternalDataTransformResultItem, | ||
} from 'echarts/types/src/data/helper/transform'; | ||
import { DataExplorerField } from '@streampipes/platform-services'; | ||
import { OptionSourceDataArrayRows } from 'echarts/types/src/util/types'; | ||
|
||
export interface RoundValuesConfig extends DataTransformOption { | ||
fields: DataExplorerField[]; | ||
roundingValue: number; | ||
} | ||
|
||
export const RoundValuesTransform: ExternalDataTransform<RoundValuesConfig> = { | ||
type: 'sp:round', | ||
|
||
transform: function ( | ||
params, | ||
): ExternalDataTransformResultItem | ExternalDataTransformResultItem[] { | ||
const fields: string[] = ( | ||
params.config['fields'] as DataExplorerField[] | ||
) | ||
.filter(f => f.fieldCharacteristics.numeric) | ||
.map(f => f.fullDbName); | ||
const roundingValue = +params.config['roundingValue']; | ||
const upstream = params.upstream; | ||
|
||
const dimsDef = upstream.cloneAllDimensionInfo(); | ||
|
||
const roundColumnIndices = dimsDef | ||
.filter(dim => fields.indexOf(dim.name) > -1) | ||
.map(dim => dim.index); | ||
|
||
const data = upstream.cloneRawData() as OptionSourceDataArrayRows; | ||
const result = data.map((row, index) => { | ||
if (index == 0) { | ||
return row; | ||
} else { | ||
return row.map((value, index) => { | ||
if (roundColumnIndices.indexOf(index) > -1) { | ||
return ( | ||
Math.round((value as number) / roundingValue) * | ||
roundingValue | ||
); | ||
} else { | ||
return value; | ||
} | ||
}); | ||
} | ||
}); | ||
result.shift(); | ||
return { | ||
dimensions: upstream.cloneAllDimensionInfo(), | ||
data: result, | ||
}; | ||
}, | ||
}; |
75 changes: 75 additions & 0 deletions
75
ui/src/app/core-ui/echarts-transform/value-distribution.transform.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* 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 { | ||
DataTransformOption, | ||
ExternalDataTransform, | ||
ExternalDataTransformResultItem, | ||
} from 'echarts/types/src/data/helper/transform'; | ||
|
||
export interface ValueDistributionConfig extends DataTransformOption { | ||
field: string; | ||
resolution: number; | ||
} | ||
|
||
export const ValueDistributionTransform: ExternalDataTransform<ValueDistributionConfig> = | ||
{ | ||
type: 'sp:value-distribution', | ||
|
||
transform: function ( | ||
params, | ||
): ExternalDataTransformResultItem | ExternalDataTransformResultItem[] { | ||
const upstream = params.upstream; | ||
const clonedData = upstream.cloneRawData(); | ||
const field = params.config['field']; | ||
const resolution = +params.config['resolution']; | ||
const dimension = upstream.getDimensionInfo(field); | ||
|
||
const dataResult = []; | ||
const allValues = (clonedData as any).map( | ||
row => row[dimension.index], | ||
); | ||
allValues.shift(); | ||
const total = allValues.length; | ||
let currentCount = 0; | ||
allValues.sort((a, b) => a - b); | ||
let start = allValues[0]; | ||
for (let i = 0; i < allValues.length; i++) { | ||
const value = allValues[i]; | ||
if (value < start + +resolution) { | ||
currentCount += 1; | ||
} | ||
if (value >= start + resolution || i + 1 === allValues.length) { | ||
const currentRange = | ||
'>' + | ||
start.toFixed(2) + | ||
(i + 1 < allValues.length | ||
? '<' + allValues[i + 1].toFixed(2) | ||
: ''); | ||
dataResult.push([currentRange, 0, currentCount / total]); | ||
currentCount = 0; | ||
start = allValues[i + 1]; | ||
} | ||
} | ||
|
||
return { | ||
data: dataResult, | ||
dimensions: ['category', 'group', field], | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.