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

Commit

Permalink
fix: show only necessary tick labels on log scale (#19)
Browse files Browse the repository at this point in the history
* fix: show only necessary ticks on log scale and add storybook

* fix: storybook path
  • Loading branch information
kristw authored Mar 14, 2019
1 parent 1c0e682 commit 2f35d0c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/superset-ui-legacy-preset-chart-nvd3/src/NVD3Vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,11 @@ function nvd3Vis(element, props) {
.attr('width', width)
.call(chart);

// For log scale, only show 1, 10, 100, 1000, ...
if (yIsLogScale) {
chart.yAxis.tickFormat(d => (Math.log10(d) % 1 === 0 ? yAxisFormatter(d) : ''));
}

if (xLabelRotation > 0) {
// shift labels to the left so they look better
const xTicks = svg.select('.nv-x.nv-axis > g').selectAll('g');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* eslint-disable no-magic-numbers */
import React from 'react';
import { SuperChart } from '@superset-ui/chart';
import data from './data';

export default [
{
renderStory: () => (
<SuperChart
chartType="line"
chartProps={{
datasource: { verboseMap: {} },
formData: {
richTooltip: true,
vizType: 'line',
yAxisBounds: [1, 60000],
yAxisFormat: ',d',
yLogScale: true,
},
height: 400,
payload: { data },
width: 400,
}}
/>
),
storyName: 'Log scale',
storyPath: 'legacy-|preset-chart-nvd3|LineChartPlugin',
},
];
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { LineChartPlugin } from '../../../../../superset-ui-legacy-preset-chart-nvd3';
import Stories from './Stories';
import YAxisStories from './YAxisStories';
import LogStories from './LogStories';

new LineChartPlugin().configure({ key: 'line' }).register();

export default {
examples: [...Stories, ...YAxisStories],
examples: [...Stories, ...YAxisStories, ...LogStories],
};

0 comments on commit 2f35d0c

Please sign in to comment.