-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(axis): formatting different for label vs tooltip and legend (#750)
- Loading branch information
1 parent
7d91d8f
commit daff503
Showing
8 changed files
with
91 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+19.6 KB
...l-tests-for-all-stories-axes-label-formatting-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { text } from '@storybook/addon-knobs'; | ||
import numeral from 'numeral'; | ||
import React from 'react'; | ||
|
||
import { AreaSeries, Axis, Chart, CurveType, Position, ScaleType } from '../../src'; | ||
import { KIBANA_METRICS } from '../../src/utils/data_samples/test_dataset_kibana'; | ||
import { SB_SOURCE_PANEL } from '../utils/storybook'; | ||
|
||
export const Example = () => { | ||
const tickFormatBottom = text('tickFormat bottom', '0.0000'); | ||
const labelFormatBottom = text('labelFormat bottom', '0.0'); | ||
const tickFormatLeft = text('tickFormat left', '$ 0,0[.]00'); | ||
const labelFormatLeft = text('labelFormat left', '$ 0,0'); | ||
const start = KIBANA_METRICS.metrics.kibana_os_load[0].data[0][0]; | ||
const data = KIBANA_METRICS.metrics.kibana_os_load[0].data.slice(0, 20).map((d) => [(d[0] - start) / 30000, d[1]]); | ||
|
||
return ( | ||
<Chart className="story-chart"> | ||
<Axis | ||
id="bottom" | ||
title="Weight" | ||
position={Position.Bottom} | ||
tickFormat={(d) => numeral(d).format(tickFormatBottom)} | ||
labelFormat={(d) => numeral(d).format(labelFormatBottom)} | ||
/> | ||
<Axis | ||
id="left" | ||
title="Price" | ||
position={Position.Left} | ||
tickFormat={(d) => numeral(d).format(tickFormatLeft)} | ||
labelFormat={(d) => numeral(d).format(labelFormatLeft)} | ||
/> | ||
|
||
<AreaSeries | ||
id="areas" | ||
xScaleType={ScaleType.Linear} | ||
yScaleType={ScaleType.Linear} | ||
xAccessor={0} | ||
yAccessors={[1]} | ||
data={data} | ||
curve={CurveType.CURVE_MONOTONE_X} | ||
/> | ||
</Chart> | ||
); | ||
}; | ||
|
||
Example.story = { | ||
parameters: { | ||
options: { selectedPanel: SB_SOURCE_PANEL }, | ||
info: { | ||
text: `You can apply different formatter between tick values in the tooltip and legend by using | ||
different values for \`tickFormat\` and \`labelFormat\`. | ||
Use a [numeraljs](http://numeraljs.com/) format with the knobs to see the difference`, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters