From fba50948645faceee3be2150e5f4b782205ccea0 Mon Sep 17 00:00:00 2001 From: Krist Wongsuphasawat Date: Thu, 14 Mar 2019 10:51:32 -0700 Subject: [PATCH] fix: show only necessary tick labels on log scale (#19) * fix: show only necessary ticks on log scale and add storybook * fix: storybook path --- .../src/NVD3Vis.js | 5 ++++ .../Line/LogStories.jsx | 29 +++++++++++++++++++ .../legacy-preset-chart-nvd3/Line/index.js | 3 +- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-nvd3/Line/LogStories.jsx diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-preset-chart-nvd3/src/NVD3Vis.js b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-preset-chart-nvd3/src/NVD3Vis.js index 33ba4a7ecee78..dc82da8abb102 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-preset-chart-nvd3/src/NVD3Vis.js +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-preset-chart-nvd3/src/NVD3Vis.js @@ -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'); diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-nvd3/Line/LogStories.jsx b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-nvd3/Line/LogStories.jsx new file mode 100644 index 0000000000000..04300569146d9 --- /dev/null +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-nvd3/Line/LogStories.jsx @@ -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: () => ( + + ), + storyName: 'Log scale', + storyPath: 'legacy-|preset-chart-nvd3|LineChartPlugin', + }, +]; diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-nvd3/Line/index.js b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-nvd3/Line/index.js index 27d3d28737e44..c4515957f1a53 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-nvd3/Line/index.js +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-nvd3/Line/index.js @@ -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], };