Skip to content

Commit

Permalink
allow x-axis label truncation (re #249)
Browse files Browse the repository at this point in the history
  • Loading branch information
alison985 authored and Allen Short committed Feb 6, 2018
1 parent c34dc49 commit 5148787
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions client/app/visualizations/chart/chart-editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@
<i class="input-helper"></i> Show Labels
</label>
</div>

<div class="form-group">
<label class="control-label">Label Length</label>
<input name="x-axis-label-length" type="number" class="form-control" ng-model="options.xAxisLabelLength">
<span class="info">How many characters should X Axis Labels be truncated at in the legend?</span>
</div>
</div>

<div ng-if="currentTab == 'yAxis'" class="m-t-10 m-b-10">
Expand Down
4 changes: 4 additions & 0 deletions client/app/visualizations/chart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ function ChartEditor(ColorPalette, clientConfig) {
scope.options.legend = { enabled: true };
}

if (!has(scope.options, 'xAxisLabelLength')) {
scope.options.xAxisLabelLength = 300;
}

if (scope.columnNames) {
each(scope.options.columnMapping, (value, key) => {
if (scope.columnNames.length > 0 && !contains(scope.columnNames, key)) {
Expand Down
7 changes: 5 additions & 2 deletions client/app/visualizations/chart/plotly.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Plotly.setPlotConfig({
});

const DEFAULT_BOTTOM_MARGIN = 50;
const DEFAULT_XAXIS_LABEL_LENGTH = 300;

// The following colors will be used if you pick "Automatic" color.
const BaseColors = {
Expand Down Expand Up @@ -227,6 +228,7 @@ const PlotlyChart = () => ({


function recalculateOptions() {
const xAxisLabelLength = parseInt(scope.options.xAxisLabelLength, 10) || DEFAULT_XAXIS_LABEL_LENGTH;
scope.layout.margin.b = parseInt(scope.options.bottomMargin, 10) || DEFAULT_BOTTOM_MARGIN;

scope.data.length = 0;
Expand Down Expand Up @@ -279,8 +281,9 @@ const PlotlyChart = () => ({

each(series.data, (row, rowIdx) => {
plotlySeries.values.push(row.y);
plotlySeries.labels.push(hasX ? row.x : `Slice ${index}`);
const rowOpts = scope.options.seriesOptions[hasX ? row.x : `Slice ${index}`];
const rowX = row.x.toString().substr(0, xAxisLabelLength);
plotlySeries.labels.push(hasX ? rowX : `Slice ${index}`);
const rowOpts = scope.options.seriesOptions[hasX ? rowX : `Slice ${index}`];
plotlySeries.marker.colors[rowIdx] = rowOpts ? rowOpts.color : getColor(rowIdx);
});

Expand Down

0 comments on commit 5148787

Please sign in to comment.