Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #359: Truncate x-axis by default. #366

Merged
merged 1 commit into from
Apr 11, 2018
Merged
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
15 changes: 12 additions & 3 deletions client/app/visualizations/chart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,18 @@ function ChartEditor(ColorPalette, clientConfig) {
scope.options.legend = { enabled: true };
}

if (!has(scope.options, 'xAxisLabelLength')) {
scope.options.xAxisLabelLength = 300;
}
scope.$watch('options.globalSeriesType', (newType, oldType) => {
const defaultXAxisLength = 10;
Copy link

Choose a reason for hiding this comment

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

Why is this default set separately from DEFAULT_XAXIS_LABEL_LENGTH?

Copy link
Author

Choose a reason for hiding this comment

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

This default is used when someone is making a visualization for the first time whereas DEFAULT_XAXIS_LABEL_LENGTH is the fallback default when someone clears out the value of the label x-axis-label-length (found in chart-editor.html)

I think we can perhaps set DEFAULT_XAXIS_LABEL_LENGTH to 10 as well to be less confusing

Copy link

Choose a reason for hiding this comment

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

OK sounds good. On further reflection I wonder if pie charts and line charts should have different defaults.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I would say there is probably a better/clearer way to set separate defaults for pie vs line charts. Though I realized that would be a bigger PR and need slightly more time (and we wanted to get this ready soon). For now this workaround does the trick to give pie charts a different default and I'm happy to file a follow-up.

Copy link

Choose a reason for hiding this comment

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

Great. r+

if (!has(scope.options, 'xAxisLabelLength')) {
scope.options.xAxisLabelLength = defaultXAxisLength;
}
if (oldType !== newType) {
scope.options.xAxisLabelLength = defaultXAxisLength;
if (newType === 'pie') {
scope.options.xAxisLabelLength = 300;
}
}
}, true);

if (scope.columnNames) {
each(scope.options.columnMapping, (value, key) => {
Expand Down
3 changes: 2 additions & 1 deletion client/app/visualizations/chart/plotly/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ function prepareChartData(seriesList, options) {
const yValues = [];
const yErrorValues = [];
each(data, (row) => {
const x = normalizeValue(row.x);
const xAxisLabelLength = parseInt(options.xAxisLabelLength, 10) || DEFAULT_XAXIS_LABEL_LENGTH;
const x = normalizeValue(row.x).substr(0, xAxisLabelLength);
const y = normalizeValue(row.y);
const yError = normalizeValue(row.yError);
sourceData.set(x, {
Expand Down