Skip to content

Commit

Permalink
remove buildVegaScales due to split it to smaller modules
Browse files Browse the repository at this point in the history
Signed-off-by: Anan Zhuang <ananzh@amazon.com>
  • Loading branch information
ananzh committed Jul 22, 2024
1 parent e695b45 commit 745baf2
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { buildVegaLiteEncoding, buildVegaScales } from './encoding';
import { buildVegaLiteEncoding } from './encoding';

describe('encoding.ts', () => {
describe('buildVegaLiteEncoding', () => {
Expand All @@ -28,25 +28,4 @@ describe('encoding.ts', () => {
expect(result.color!.type).toBe('nominal');
});
});

describe('buildVegaScales', () => {
it('should build correct scales for x and y axes', () => {
const dimensions = { x: [{}], y: [{}] };
const formats = {};
const result = buildVegaScales(dimensions, formats);

expect(result.length).toBe(2);
expect(result[0].name).toBe('xscale');
expect(result[1].name).toBe('yscale');
});

it('should include size scale when z dimension is present', () => {
const dimensions = { x: [{}], y: [{}], z: [{}] };
const formats = {};
const result = buildVegaScales(dimensions, formats);

expect(result.length).toBe(3);
expect(result[2].name).toBe('size');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -73,43 +73,6 @@ export const buildVegaLiteEncoding = (dimensions: any, formats: AxisFormats): Ve
return encoding;
};

/**
* Builds scale configurations for Vega specifications.
*
* @param {any} dimensions - The dimensions of the data.
* @param {any} formats - The formatting information for axes.
* @returns {VegaScale[]} The Vega scale configurations.
*/
export const buildVegaScales = (dimensions: any, formats: any): VegaScale[] => {
const scales: VegaScale[] = [
{
name: 'xscale',
type: 'band',
domain: { data: 'source', field: 'x', filter: 'datum.split == parent.split' },
range: 'width',
padding: 0.2,
},
{
name: 'yscale',
type: 'linear',
domain: { data: 'source', field: 'y', filter: 'datum.split == parent.split' },
range: 'height',
nice: true,
zero: true,
},
];

if (dimensions.z) {
scales.push({
name: 'size',
type: 'linear',
domain: { data: 'source', field: 'z' },
});
}

return scales;
};

/**
* Builds encoding for an axis.
*
Expand Down

0 comments on commit 745baf2

Please sign in to comment.