Skip to content

Commit 3087822

Browse files
alison985jezdez
authored andcommitted
allow x-axis label truncation (re #249)
1 parent ba062d2 commit 3087822

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

client/app/visualizations/chart/chart-editor.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@
188188
<i class="input-helper"></i> Show Labels
189189
</label>
190190
</div>
191+
192+
<div class="form-group">
193+
<label class="control-label">Label Length</label>
194+
<input name="x-axis-label-length" type="number" class="form-control" ng-model="options.xAxisLabelLength">
195+
<span class="info">How many characters should X Axis Labels be truncated at in the legend?</span>
196+
</div>
191197
</div>
192198

193199
<div ng-if="currentTab == 'yAxis'" class="m-t-10 m-b-10">

client/app/visualizations/chart/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ function ChartEditor(ColorPalette, clientConfig) {
251251
scope.options.legend = { enabled: true };
252252
}
253253

254+
if (!has(scope.options, 'xAxisLabelLength')) {
255+
scope.options.xAxisLabelLength = 300;
256+
}
257+
254258
if (scope.columnNames) {
255259
each(scope.options.columnMapping, (value, key) => {
256260
if (scope.columnNames.length > 0 && !contains(scope.columnNames, key)) {

client/app/visualizations/chart/plotly/utils.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,20 @@ function getUnifiedXAxisValues(seriesList, sorted) {
175175
return sorted ? sortBy(result, identity) : result;
176176
}
177177

178+
const DEFAULT_XAXIS_LABEL_LENGTH = 300;
179+
178180
function preparePieData(seriesList, options) {
179181
const {
180182
cellWidth, cellHeight, xPadding, yPadding, cellsInRow, hasX,
181183
} = calculateDimensions(seriesList, options);
182184

185+
const colorPalette = ColorPaletteArray.slice();
186+
const xAxisLabelLength = parseInt(options.xAxisLabelLength, 10) || DEFAULT_XAXIS_LABEL_LENGTH;
183187
return map(seriesList, (serie, index) => {
184188
const xPosition = (index % cellsInRow) * cellWidth;
185189
const yPosition = Math.floor(index / cellsInRow) * cellHeight;
186190
const labels = map(serie.data, (row, rowIdx) => {
187-
const rowX = hasX ? row.x : `Slice ${index}`;
191+
const rowX = hasX ? row.x.substr(0, xAxisLabelLength) : `Slice ${index}`;
188192
const rowOpts = options.seriesOptions[rowX];
189193
if (rowOpts) {
190194
colorPalette[rowIdx] = rowOpts.color;
@@ -193,7 +197,7 @@ function preparePieData(seriesList, options) {
193197
});
194198
return {
195199
values: pluck(serie.data, 'y'),
196-
labels: labels,
200+
labels,
197201
type: 'pie',
198202
hole: 0.4,
199203
marker: { colors: ColorPaletteArray },

0 commit comments

Comments
 (0)