Skip to content

Commit

Permalink
allow x-axis label truncation (re getredash#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
alison985 authored and jezdez committed Mar 5, 2018
1 parent ba062d2 commit 3087822
Show file tree
Hide file tree
Showing 3 changed files with 16 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
8 changes: 6 additions & 2 deletions client/app/visualizations/chart/plotly/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,20 @@ function getUnifiedXAxisValues(seriesList, sorted) {
return sorted ? sortBy(result, identity) : result;
}

const DEFAULT_XAXIS_LABEL_LENGTH = 300;

function preparePieData(seriesList, options) {
const {
cellWidth, cellHeight, xPadding, yPadding, cellsInRow, hasX,
} = calculateDimensions(seriesList, options);

const colorPalette = ColorPaletteArray.slice();
const xAxisLabelLength = parseInt(options.xAxisLabelLength, 10) || DEFAULT_XAXIS_LABEL_LENGTH;
return map(seriesList, (serie, index) => {
const xPosition = (index % cellsInRow) * cellWidth;
const yPosition = Math.floor(index / cellsInRow) * cellHeight;
const labels = map(serie.data, (row, rowIdx) => {
const rowX = hasX ? row.x : `Slice ${index}`;
const rowX = hasX ? row.x.substr(0, xAxisLabelLength) : `Slice ${index}`;
const rowOpts = options.seriesOptions[rowX];
if (rowOpts) {
colorPalette[rowIdx] = rowOpts.color;
Expand All @@ -193,7 +197,7 @@ function preparePieData(seriesList, options) {
});
return {
values: pluck(serie.data, 'y'),
labels: labels,
labels,
type: 'pie',
hole: 0.4,
marker: { colors: ColorPaletteArray },
Expand Down

0 comments on commit 3087822

Please sign in to comment.