Skip to content

Commit

Permalink
improve bundle sizes (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 authored Nov 25, 2020
1 parent c68b234 commit c037826
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 64 deletions.
25 changes: 25 additions & 0 deletions src/plugins/vis_type_xy/public/config/get_agg_id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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.
*/

/**
* Get agg id from accessor
*
* For now this is determined by the esaggs column name. Could be cleaned up in the future.
*/
export const getAggId = (accessor: string) => (accessor ?? '').split('-').pop() ?? '';
8 changes: 1 addition & 7 deletions src/plugins/vis_type_xy/public/config/get_aspects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { DatatableColumn } from '../../../expressions/public';

import { Aspect, Dimension, Aspects, Dimensions } from '../types';
import { getFormatService } from '../services';
import { getAggId } from './get_agg_id';

export function getEmptyAspect(): Aspect {
return {
Expand Down Expand Up @@ -79,13 +80,6 @@ function getAspectsFromDimension(
return column && getAspect(column, dimensions);
}

/**
* Get agg id from accessor
*
* For now this is determined by the esaggs column name. Could be cleaned up in the future.
*/
export const getAggId = (accessor: string) => (accessor ?? '').split('-').pop() ?? '';

const getAspect = (
{ id: accessor, name: title }: DatatableColumn,
{ accessor: column, format, params, aggType }: Dimension
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/vis_type_xy/public/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
*/

export { getConfig } from './get_config';
export { getAggId } from './get_aspects';
export { getAggId } from './get_agg_id';
50 changes: 3 additions & 47 deletions src/plugins/vis_type_xy/public/editor/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,9 @@ import { AxisMode, ChartMode, InterpolationMode, ThresholdLineStyle, ScaleType }
import { ChartType } from '../../common';
import { LabelRotation } from '../../../charts/public';

export const getPositions = () => [
{
text: i18n.translate('visTypeXy.legendPositions.topText', {
defaultMessage: 'Top',
}),
value: Position.Top,
},
{
text: i18n.translate('visTypeXy.legendPositions.leftText', {
defaultMessage: 'Left',
}),
value: Position.Left,
},
{
text: i18n.translate('visTypeXy.legendPositions.rightText', {
defaultMessage: 'Right',
}),
value: Position.Right,
},
{
text: i18n.translate('visTypeXy.legendPositions.bottomText', {
defaultMessage: 'Bottom',
}),
value: Position.Bottom,
},
];
export { getScaleTypes } from './scale_types';

export { getPositions } from './positions';

export const getChartTypes = () => [
{
Expand Down Expand Up @@ -108,27 +85,6 @@ export const getInterpolationModes = () => [
},
];

export const getScaleTypes = () => [
{
text: i18n.translate('visTypeXy.scaleTypes.linearText', {
defaultMessage: 'Linear',
}),
value: ScaleType.Linear,
},
{
text: i18n.translate('visTypeXy.scaleTypes.logText', {
defaultMessage: 'Log',
}),
value: ScaleType.Log,
},
{
text: i18n.translate('visTypeXy.scaleTypes.squareRootText', {
defaultMessage: 'Square root',
}),
value: ScaleType.SquareRoot,
},
];

export const getAxisModes = () => [
{
text: i18n.translate('visTypeXy.axisModes.normalText', {
Expand Down
1 change: 0 additions & 1 deletion src/plugins/vis_type_xy/public/editor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@

export * from './common_config';
export * from './collections';
export * from './components';
48 changes: 48 additions & 0 deletions src/plugins/vis_type_xy/public/editor/positions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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 { i18n } from '@kbn/i18n';
import { Position } from '@elastic/charts';

export const getPositions = () => [
{
text: i18n.translate('visTypeXy.legendPositions.topText', {
defaultMessage: 'Top',
}),
value: Position.Top,
},
{
text: i18n.translate('visTypeXy.legendPositions.leftText', {
defaultMessage: 'Left',
}),
value: Position.Left,
},
{
text: i18n.translate('visTypeXy.legendPositions.rightText', {
defaultMessage: 'Right',
}),
value: Position.Right,
},
{
text: i18n.translate('visTypeXy.legendPositions.bottomText', {
defaultMessage: 'Bottom',
}),
value: Position.Bottom,
},
];
43 changes: 43 additions & 0 deletions src/plugins/vis_type_xy/public/editor/scale_types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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 { i18n } from '@kbn/i18n';

import { ScaleType } from '../types';

export const getScaleTypes = () => [
{
text: i18n.translate('visTypeXy.scaleTypes.linearText', {
defaultMessage: 'Linear',
}),
value: ScaleType.Linear,
},
{
text: i18n.translate('visTypeXy.scaleTypes.logText', {
defaultMessage: 'Log',
}),
value: ScaleType.Log,
},
{
text: i18n.translate('visTypeXy.scaleTypes.squareRootText', {
defaultMessage: 'Square root',
}),
value: ScaleType.SquareRoot,
},
];
12 changes: 5 additions & 7 deletions src/plugins/vis_type_xy/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@ export {
HistogramParams,
DateHistogramParams,
} from './types';
export {
getPositions,
getScaleTypes,
TruncateLabelsOption,
ValidationVisOptionsProps,
} from './editor';
export type { ValidationVisOptionsProps } from './editor/components/common/validation_wrapper';
export { TruncateLabelsOption } from './editor/components/common/truncate_labels';
export { getPositions } from './editor/positions';
export { getScaleTypes } from './editor/scale_types';
export { xyVisTypes } from './vis_types';
export { getAggId } from './config';
export { getAggId } from './config/get_agg_id';

// Export common types
export * from '../common';
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/vis_type_xy/public/vis_renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { ExpressionRenderDefinition } from '../../expressions/public';
import { VisualizationContainer } from '../../visualizations/public';

import { XyVisType } from '../common';
import { SplitChartWarning } from './components';
import { SplitChartWarning } from './components/split_chart_warning';
import { VisComponentType } from './vis_component';
import { RenderValue, visName } from './xy_vis_fn';

Expand Down

0 comments on commit c037826

Please sign in to comment.