-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(ui): add common-chart-options (#50)
* feactor(ui): add common-chart-options * refactor(ui): move charts folder into component, remove console.debug, improve xAxisData function
- Loading branch information
Showing
32 changed files
with
555 additions
and
575 deletions.
There are no files selected for viewing
File renamed without changes.
24 changes: 24 additions & 0 deletions
24
ui/src/components/charts/confusion-matrix-chart/options.js
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,24 @@ | ||
import * as commonChartOptions from '@Helpers/common-chart-options'; | ||
|
||
export default function confusionMatrixOptions(dataset, labelClass, colors) { | ||
let dataMax = 0; | ||
const heatmapData = dataset.toReversed().reduce((accumulator, datas, yIndex) => accumulator.concat(datas.map((data, xIndex) => { | ||
if (data > dataMax) { | ||
dataMax = data; | ||
} | ||
return [xIndex, yIndex, data]; | ||
})), []); | ||
|
||
const options = { | ||
...commonChartOptions.yAxisOptions.categoryType(labelClass.yAxisLabel), | ||
...commonChartOptions.xAxisOptions.categoryType(labelClass.xAxisLabel), | ||
...commonChartOptions.gridOptions.heatmapChart(), | ||
...commonChartOptions.commonOptions.heatmapChart(), | ||
...commonChartOptions.visualMapOptions.heatmapChart(dataMax, colors), | ||
series: { | ||
...commonChartOptions.seriesOptions.heatmapChart(heatmapData), | ||
}, | ||
}; | ||
|
||
return options; | ||
} |
File renamed without changes.
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,37 @@ | ||
import { numberFormatter } from '@Src/constants'; | ||
import { CHART_COLOR } from '@Helpers/common-chart-options'; | ||
import * as commonChartOptions from '@Helpers/common-chart-options'; | ||
|
||
export default function lineChartOptions(title, color, currentDataset, referenceDataset) { | ||
const currentDatasetFormatted = currentDataset.map(({ timestamp, value }) => [timestamp, numberFormatter().format(value)]); | ||
|
||
const series = [ | ||
commonChartOptions.seriesOptions.lineChart(title, CHART_COLOR.LINE_CHART_COLOR, currentDatasetFormatted), | ||
]; | ||
|
||
if (referenceDataset) { | ||
const referenceDatasetFormatted = referenceDataset.map(({ timestamp, value }) => [timestamp, numberFormatter().format(value)]); | ||
|
||
const referenceLine = { | ||
...commonChartOptions.seriesOptions.lineChart('Reference', CHART_COLOR.REFERENCE, referenceDatasetFormatted), | ||
endLabel: { | ||
show: true, | ||
color: CHART_COLOR.REFERENCE, | ||
formatter: ({ value }) => `Reference\n${value[1]}`, | ||
}, | ||
color: CHART_COLOR.REFERENCE, | ||
}; | ||
|
||
referenceLine.lineStyle.type = 'dotted'; | ||
series.push(referenceLine); | ||
} | ||
|
||
return { | ||
color: [color], | ||
...commonChartOptions.tooltipOptions(), | ||
...commonChartOptions.yAxisOptions.valueType(), | ||
...commonChartOptions.xAxisOptions.timeType(), | ||
...commonChartOptions.gridOptions.lineChart(), | ||
series, | ||
}; | ||
} |
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
42 changes: 42 additions & 0 deletions
42
...els/Details/binary-classification/current/data-quality/data-point-distribution/options.js
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,42 @@ | ||
import { CHART_COLOR } from '@Helpers/common-chart-options'; | ||
import { numberFormatter } from '@Src/constants'; | ||
import * as commonChartOptions from '@Helpers/common-chart-options'; | ||
|
||
export default function chartOptions(title, referenceDataset, currentDataset) { | ||
const yAxisLabel = currentDataset.map(({ name }) => name); | ||
|
||
const referenceData = referenceDataset.map(({ count, percentage }) => ({ percentage, count, value: count })); | ||
const currentData = currentDataset.map(({ count, percentage }) => ({ percentage, count, value: count })); | ||
|
||
const options = { | ||
...commonChartOptions.gridOptions.barChart(), | ||
...commonChartOptions.xAxisOptions.valueType(), | ||
...commonChartOptions.yAxisOptions.categoryType(yAxisLabel), | ||
...commonChartOptions.commonOptions.barChart(), | ||
series: [ | ||
{ | ||
...commonChartOptions.seriesOptions.barChart(title, CHART_COLOR.REFERENCE_LIGHT, referenceData), | ||
color: CHART_COLOR.REFERENCE_LIGHT, | ||
label: { | ||
show: true, | ||
position: 'insideRight', | ||
fontWeight: 'bold', | ||
formatter: (el) => (el.data.count > 0) ? `${el.data.count} (${numberFormatter().format(el.data.percentage)}%)` : '', | ||
}, | ||
}, | ||
{ | ||
...commonChartOptions.seriesOptions.barChart(title, CHART_COLOR.CURRENT_LIGHT_LIGHT, currentData), | ||
color: CHART_COLOR.CURRENT_LIGHT, | ||
label: { | ||
show: true, | ||
position: 'insideRight', | ||
fontWeight: 'bold', | ||
color: CHART_COLOR.CURRENT_DARK, | ||
formatter: (el) => (el.data.count > 0) ? `${el.data.count} (${numberFormatter().format(el.data.percentage)}%)` : '', | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
return options; | ||
} |
71 changes: 0 additions & 71 deletions
71
...ls/Details/binary-classification/current/data-quality/data-point-distribution/options.jsx
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...ls/binary-classification/current/data-quality/data-quality-list/numerical/chart/index.jsx
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
57 changes: 16 additions & 41 deletions
57
...s/binary-classification/current/data-quality/data-quality-list/numerical/chart/options.js
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 |
---|---|---|
@@ -1,49 +1,24 @@ | ||
import { numberFormatter } from '@Src/constants'; | ||
import * as commonChartOptions from '@Helpers/common-chart-options'; | ||
|
||
export default function chartOptions(dataset, referenceColor, currentColor) { | ||
const dataFormatted = dataset.buckets.map((value) => numberFormatter().format(value)); | ||
const lastElementData = dataFormatted.pop(); | ||
const xAxisData = dataFormatted.map((el, idx) => `[${dataFormatted[idx]}${(idx < dataFormatted.length - 1) ? `-${dataFormatted[idx + 1]})` : (idx === dataFormatted.length - 1) ? `-${lastElementData}]` : ''} `); | ||
const { length, [length - 1]: last, ...rest } = dataset.buckets.map((value) => numberFormatter().format(value)); | ||
|
||
return { | ||
grid: { | ||
top: 10, | ||
bottom: 0, | ||
left: 25, | ||
right: 5, | ||
containLabel: true, | ||
}, | ||
xAxis: { | ||
type: 'category', | ||
data: xAxisData, | ||
axisTick: { show: false }, | ||
axisLine: { show: false }, | ||
splitLine: { show: false }, | ||
axisLabel: { | ||
fontSize: 12, | ||
interval: 0, | ||
rotate: 20, | ||
color: '#9b99a1', | ||
}, | ||
}, | ||
yAxis: { | ||
type: 'value', | ||
axisLabel: { | ||
fontSize: 9, | ||
color: '#9b99a1', | ||
}, | ||
}, | ||
const values = Object.values(rest); | ||
|
||
const xAxisData = values.map((el, idx) => `[${el}${(idx < values.length - 1) ? `-${values[idx + 1]})` : (idx === values.length - 1) ? `-${last}]` : ''} `); | ||
|
||
const options = { | ||
...commonChartOptions.gridOptions.barChart(), | ||
...commonChartOptions.xAxisOptions.categoryType(xAxisData), | ||
...commonChartOptions.yAxisOptions.valueType(), | ||
series: [ | ||
{ | ||
data: dataset.referenceValues, | ||
type: 'bar', | ||
itemStyle: { color: referenceColor }, | ||
}, | ||
{ | ||
data: dataset.currentValues, | ||
type: 'bar', | ||
itemStyle: { color: currentColor }, | ||
}, | ||
commonChartOptions.seriesOptions.barChart('reference', referenceColor, dataset.referenceValues), | ||
commonChartOptions.seriesOptions.barChart('current', currentColor, dataset.currentValues), | ||
], | ||
}; | ||
|
||
options.xAxis.axisLabel.rotate = 20; | ||
|
||
return options; | ||
} |
5 changes: 3 additions & 2 deletions
5
ui/src/container/models/Details/binary-classification/current/model-quality/charts.jsx
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
30 changes: 30 additions & 0 deletions
30
...s/Details/binary-classification/reference/data-quality/data-point-distribution/options.js
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,30 @@ | ||
import { CHART_COLOR } from '@Helpers/common-chart-options'; | ||
import { numberFormatter } from '@Src/constants'; | ||
import * as commonChartOptions from '@Helpers/common-chart-options'; | ||
|
||
export default function chartOptions(title, dataset) { | ||
const yAxisLabel = dataset.map(({ name }) => name); | ||
|
||
const referenceData = dataset.map(({ count, percentage }) => ({ percentage, count, value: count })); | ||
|
||
const options = { | ||
...commonChartOptions.gridOptions.barChart(), | ||
...commonChartOptions.xAxisOptions.valueType(), | ||
...commonChartOptions.yAxisOptions.categoryType(yAxisLabel), | ||
...commonChartOptions.commonOptions.barChart(), | ||
series: [ | ||
{ | ||
...commonChartOptions.seriesOptions.barChart(title, CHART_COLOR.REFERENCE_LIGHT, referenceData), | ||
color: CHART_COLOR.REFERENCE_LIGHT, | ||
label: { | ||
show: true, | ||
position: 'insideRight', | ||
fontWeight: 'bold', | ||
formatter: (el) => (el.data.count > 0) ? `${el.data.count} (${numberFormatter().format(el.data.percentage)}%)` : '', | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
return options; | ||
} |
58 changes: 0 additions & 58 deletions
58
.../Details/binary-classification/reference/data-quality/data-point-distribution/options.jsx
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
.../binary-classification/reference/data-quality/data-quality-list/numerical/chart/index.jsx
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.