Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

Fix D3 format for some viz types #171

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,18 @@ export default function transformProps(chartProps) {
className = 'negative';
}

const formatValue = getNumberFormatter(yAxisFormat);
// SUP-146
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove comment

let metricFormat = yAxisFormat;
if (!yAxisFormat) {
for (let x = 0; x < chartProps.datasource.metrics.length; x++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to check if datasource exists and metrics exist

if (chartProps.datasource.metrics[x].metric_name == metric) {
metricFormat = chartProps.datasource.metrics[x].d3format;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d3format may be not set

}
}
}

const formatValue = getNumberFormatter(metricFormat);
// End SUP-146

return {
width,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,36 @@ export default function transformProps(chartProps) {
}))
: rawData;

// SUP-146
let d3NumberFormat;
let d3YAxisFormat;
let d3YAxis2Format;
if (chartProps.formData.vizType == "pie") {
for (let x = 0; x < chartProps.datasource.metrics.length; x++) {
if (chartProps.datasource.metrics[x].metric_name == chartProps.formData.metric) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the logic here can be extracted into a function?

d3NumberFormat = chartProps.datasource.metrics[x].d3format;
break;
}
}
} else if (chartProps.formData.vizType == "dual_line") {
for (let x = 0; x < chartProps.datasource.metrics.length; x++) {
if (chartProps.datasource.metrics[x].metric_name == chartProps.formData.metric) {
d3YAxisFormat = chartProps.datasource.metrics[x].d3format;
} else if (chartProps.datasource.metrics[x].metric_name == chartProps.formData.metric2) {
d3YAxis2Format = chartProps.datasource.metrics[x].d3format;
}
}
} else if (chartProps.formData.vizType == "line" ||chartProps.formData.vizType == "dist_bar" ||
chartProps.formData.vizType == "bar" || chartProps.formData.vizType == "area") {
for (let x = 0; x < chartProps.datasource.metrics.length; x++) {
if (chartProps.datasource.metrics[x].metric_name == chartProps.formData.metrics[0]) {
d3YAxisFormat = chartProps.datasource.metrics[x].d3format;
break;
}
}
}
//End SUP-146

return {
width,
height,
Expand All @@ -103,7 +133,7 @@ export default function transformProps(chartProps) {
leftMargin,
lineInterpolation,
maxBubbleSize: parseInt(maxBubbleSize, 10),
numberFormat,
numberFormat: d3NumberFormat ? d3NumberFormat : numberFormat,
onBrushEnd: isTruthy(sendTimeRange)
? timeRange => {
onAddFilter('__time_range', timeRange, false, true);
Expand All @@ -128,8 +158,8 @@ export default function transformProps(chartProps) {
xField: x,
xIsLogScale: xLogScale,
xTicksLayout,
yAxisFormat,
yAxis2Format,
yAxisFormat: d3YAxisFormat ? d3YAxisFormat : yAxisFormat,
yAxis2Format: d3YAxis2Format ? d3YAxis2Format : yAxis2Format,
yAxisBounds,
yAxisLabel,
yAxisShowMinMax: yAxisShowminmax,
Expand Down