Skip to content

Commit

Permalink
Merge pull request #276 from adobe/buildUpdates
Browse files Browse the repository at this point in the history
Build updates
  • Loading branch information
marshallpete committed May 1, 2024
2 parents a3f4d84 + a24010f commit 9d2d632
Show file tree
Hide file tree
Showing 83 changed files with 245 additions and 158 deletions.
9 changes: 8 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
"plugins": ["prettier", "@typescript-eslint", "jest", "jsdoc", "react"],
"rules": {
"react/jsx-uses-vars": "error",
"react/jsx-uses-react": "error"
"react/jsx-uses-react": "error",
"no-restricted-imports": [
"error",
{
"name": "types",
"message": "Please use relative path import for types instead (ex. ../types)."
}
]
}
}
7 changes: 3 additions & 4 deletions src/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ import useChartImperativeHandle from '@hooks/useChartImperativeHandle';
import useChartWidth from '@hooks/useChartWidth';
import { useResizeObserver } from '@hooks/useResizeObserver';
import { getColorValue } from '@specBuilder/specUtils';
import { RscChart } from 'RscChart';
import { v4 as uuid } from 'uuid';
import { View } from 'vega';

import { Provider, defaultTheme } from '@adobe/react-spectrum';
import { Theme } from '@react-types/provider';

import './Chart.css';
import { ChartData, ChartHandle, ChartProps } from './types';
import { RscChart } from './RscChart';
import { ChartData, ChartHandle, ChartProps, LineType } from './types';

interface PlaceholderContentProps {
data: ChartData[];
Expand All @@ -51,7 +51,7 @@ export const Chart = forwardRef<ChartHandle, ChartProps>(
height = 300,
hiddenSeries = [],
highlightedSeries,
lineTypes = DEFAULT_LINE_TYPES,
lineTypes = DEFAULT_LINE_TYPES as LineType[],
lineWidths = ['M'],
loading,
locale = DEFAULT_LOCALE,
Expand Down Expand Up @@ -82,7 +82,6 @@ export const Chart = forwardRef<ChartHandle, ChartProps>(
useChartImperativeHandle(forwardedRef, { chartView, title });

const containerRef = useResizeObserver<HTMLDivElement>((_target, entry) => {

if (typeof width !== 'number') {
setContainerWidth(entry.contentRect.width);
}
Expand Down
6 changes: 3 additions & 3 deletions src/RscChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ import {
sanitizeRscChartChildren,
setSelectedSignals,
} from '@utils';
import { VegaChart } from 'VegaChart';
import { renderToStaticMarkup } from 'react-dom/server';
import { Item } from 'vega';
import { Handler, Options as TooltipOptions } from 'vega-tooltip';

import { ActionButton, Dialog, DialogTrigger, View as SpectrumView } from '@adobe/react-spectrum';

import './Chart.css';
import { ChartHandle, Datum, LegendDescription, MarkBounds, RscChartProps } from './types';
import { VegaChart } from './VegaChart';
import { ChartHandle, Datum, LegendDescription, LineType, MarkBounds, RscChartProps } from './types';

interface ChartDialogProps {
datum: Datum | null;
Expand Down Expand Up @@ -75,7 +75,7 @@ export const RscChart = forwardRef<ChartHandle, RscChartProps>(
debug = false,
hiddenSeries = [],
highlightedSeries,
lineTypes = DEFAULT_LINE_TYPES,
lineTypes = DEFAULT_LINE_TYPES as LineType[],
lineWidths = ['M'],
locale = DEFAULT_LOCALE,
opacities,
Expand Down
7 changes: 4 additions & 3 deletions src/VegaChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import { FC, useEffect, useMemo, useRef } from 'react';
import { TABLE } from '@constants';
import { useDebugSpec } from '@hooks/useDebugSpec';
import { extractValues, isVegaData } from '@specBuilder/specUtils';
import { expressionFunctions, formatTimeDurationLabels } from 'expressionFunctions';
import { ChartData, ChartProps } from 'types';
import { getLocale } from 'utils/locale';
import { Config, Padding, Renderers, Spec, View } from 'vega';
import embed from 'vega-embed';
import { Options as TooltipOptions } from 'vega-tooltip';

import { expressionFunctions, formatTimeDurationLabels } from './expressionFunctions';
import { ChartData, ChartProps } from './types';
import { getLocale } from './utils/locale';

export interface VegaChartProps {
config: Config;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
3 changes: 1 addition & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import { LineType } from 'types';

// prop defaults
export const ANNOTATION_FONT_SIZE = 12;
Expand All @@ -25,7 +24,7 @@ export const DEFAULT_GRANULARITY = 'day';
export const DEFAULT_LABEL_ALIGN = 'center';
export const DEFAULT_LABEL_FONT_WEIGHT = 'normal';
export const DEFAULT_LABEL_ORIENTATION = 'horizontal';
export const DEFAULT_LINE_TYPES: LineType[] = ['solid', 'dashed', 'dotted', 'dotDash', 'longDash', 'twoDash'];
export const DEFAULT_LINE_TYPES = ['solid', 'dashed', 'dotted', 'dotDash', 'longDash', 'twoDash'];
export const DEFAULT_LINEAR_DIMENSION = 'x';
export const DEFAULT_LOCALE = 'en-US';
export const DEFAULT_METRIC = 'value';
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useChartHeight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
import { useMemo } from 'react';

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

export default function useChartHeight(containerHeight: number, maxHeight: number, minHeight: number, height: Height) {
return useMemo(() => {
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useChartImperativeHandle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
*/
import { MutableRefObject, Ref, useImperativeHandle } from 'react';

import { ChartHandle } from 'types';
import { View } from 'vega';

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

interface ChartImperativeHandleProps {
chartView: MutableRefObject<View | undefined>;
title?: string;
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useChartProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
* governing permissions and limitations under the License.
*/
import { useDarkMode } from 'storybook-dark-mode';
import { ChartProps } from 'types';

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

export default function useChartProps(props: ChartProps): ChartProps {
const darkMode = useDarkMode();
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useLegend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
import { createElement, useMemo, useState } from 'react';

import { getElement } from '@utils';
import { ChartChildElement, LegendDescription, LegendElement } from 'types';

import { Chart } from '../Chart';
import { Legend } from '../components/Legend';
import { ChartChildElement, LegendDescription, LegendElement } from '../types';

interface UseLegendProps {
hiddenSeriesState: string[];
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/usePopoverAnchorStyle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
*/
import { CSSProperties, useMemo } from 'react';

import { MarkBounds } from 'types';
import { Padding, View } from 'vega';

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

export default function usePopoverAnchorStyle(
popoverIsOpen: boolean,
view: View | undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/usePopovers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
import { createElement, useMemo } from 'react';

import { getAllElements } from '@utils';
import { ChartChildElement, ChartPopoverElement, PopoverHandler } from 'types';

import { Chart } from '../Chart';
import { ChartPopover } from '../components/ChartPopover';
import { ChartChildElement, ChartPopoverElement, PopoverHandler } from '../types';

type MappedPopover = { name: string; element: ChartPopoverElement };

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useSpec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
*/
import { useMemo } from 'react';

import { SanitizedSpecProps } from 'types';
import { Spec } from 'vega';

import { buildSpec } from '../specBuilder';
import { initializeSpec } from '../specBuilder/specUtils';
import { SanitizedSpecProps } from '../types';

export default function useSpec({
backgroundColor,
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useTooltips.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import { createElement, useMemo } from 'react';

import { ChartTooltip } from '@components/ChartTooltip';
import { getAllElements } from '@utils';
import { ChartChildElement, ChartTooltipElement, TooltipHandler } from 'types';

import { Chart } from '../Chart';
import { ChartChildElement, ChartTooltipElement, TooltipHandler } from '../types';

type MappedTooltip = { name: string; element: ChartTooltipElement };

Expand Down
2 changes: 1 addition & 1 deletion src/specBuilder/area/areaSpecBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import {
TABLE,
} from '@constants';
import { defaultSignals } from '@specBuilder/specTestUtils';
import { AreaSpecProps } from 'types';
import { Data, GroupMark, Spec } from 'vega';

import { AreaSpecProps } from '../../types';
import { initializeSpec } from '../specUtils';
import { addArea, addAreaMarks, addData, addSignals, setScales } from './areaSpecBuilder';

Expand Down
4 changes: 2 additions & 2 deletions src/specBuilder/area/areaSpecBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
SELECTED_ITEM,
SELECTED_SERIES,
} from '@constants';
import { getTooltipProps } from '@specBuilder/marks/markUtils';
import {
addHighlightedSeriesSignalEvents,
getControlledHoverSignal,
Expand All @@ -30,13 +31,12 @@ import {
import { spectrumColors } from '@themes';
import { sanitizeMarkChildren, toCamelCase } from '@utils';
import { produce } from 'immer';
import { AreaProps, AreaSpecProps, ColorScheme, MarkChildElement, ScaleType } from 'types';
import { Data, Mark, Scale, Signal, Spec } from 'vega';

import { AreaProps, AreaSpecProps, ColorScheme, MarkChildElement, ScaleType } from '../../types';
import { addTimeTransform, getFilteredTableData, getTableData, getTransformSort } from '../data/dataUtils';
import { addContinuousDimensionScale, addFieldToFacetScaleDomain, addMetricScale } from '../scale/scaleSpecBuilder';
import { getAreaMark, getX } from './areaUtils';
import { getTooltipProps } from '@specBuilder/marks/markUtils';

export const addArea = produce<Spec, [AreaProps & { colorScheme?: ColorScheme; index?: number }]>(
(
Expand Down
3 changes: 2 additions & 1 deletion src/specBuilder/area/areaUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import {
getInteractive,
getTooltip,
} from '@specBuilder/marks/markUtils';
import { ColorFacet, ColorScheme, MarkChildElement, ScaleType } from 'types';
import { AreaMark, NumericValueRef, ProductionRule } from 'vega';

import { ColorFacet, ColorScheme, MarkChildElement, ScaleType } from '../../types';

export interface AreaMarkProps {
name: string;
color: ColorFacet;
Expand Down
2 changes: 1 addition & 1 deletion src/specBuilder/axis/axisLabelUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* governing permissions and limitations under the License.
*/
import { getD3FormatSpecifierFromNumberFormat } from '@specBuilder/specUtils';
import { AxisSpecProps, Granularity, Label, LabelAlign, NumberFormat, Orientation, Position } from 'types';
import {
Align,
Baseline,
Expand All @@ -24,6 +23,7 @@ import {
TickCount,
} from 'vega';

import { AxisSpecProps, Granularity, Label, LabelAlign, NumberFormat, Orientation, Position } from '../../types';
import { isVerticalAxis } from './axisUtils';

/**
Expand Down
4 changes: 2 additions & 2 deletions src/specBuilder/axis/axisReferenceLineUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import {
DEFAULT_LABEL_FONT_WEIGHT,
DEFAULT_LABEL_ORIENTATION,
} from '@constants';
import { DATE_PATH } from 'svgPaths';
import { AxisSpecProps, ReferenceLineProps } from 'types';
import { DATE_PATH } from '@svgPaths';

import { AxisSpecProps, ReferenceLineProps } from '../../types';
import {
getPositionRule,
getReferenceLineRuleMark,
Expand Down
9 changes: 8 additions & 1 deletion src/specBuilder/axis/axisReferenceLineUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { ReferenceLine } from '@components/ReferenceLine';
import { DEFAULT_LABEL_FONT_WEIGHT } from '@constants';
import { getColorValue, getPathFromIcon } from '@specBuilder/specUtils';
import { toArray } from '@utils';
import { AxisChildElement, AxisSpecProps, Children, Position, ReferenceLineElement, ReferenceLineProps } from 'types';
import {
EncodeEntry,
FontWeight,
Expand All @@ -29,6 +28,14 @@ import {
TextMark,
} from 'vega';

import {
AxisChildElement,
AxisSpecProps,
Children,
Position,
ReferenceLineElement,
ReferenceLineProps,
} from '../../types';
import { isVerticalAxis } from './axisUtils';

export const getReferenceLinesFromChildren = (
Expand Down
2 changes: 1 addition & 1 deletion src/specBuilder/axis/axisSpecBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import { createElement } from 'react';

import { ReferenceLine } from '@components/ReferenceLine';
import { DEFAULT_LABEL_FONT_WEIGHT, FILTERED_TABLE } from '@constants';
import { SubLabel } from 'types';
import { Axis, GroupMark, ProductionRule, Scale, Signal, TextValueRef } from 'vega';

import { SubLabel } from '../../types';
import {
addAxes,
addAxesMarks,
Expand Down
2 changes: 1 addition & 1 deletion src/specBuilder/axis/axisSpecBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import {
import { getGenericSignal } from '@specBuilder/signal/signalSpecBuilder';
import { sanitizeAxisChildren } from '@utils';
import { produce } from 'immer';
import { AxisProps, AxisSpecProps, ColorScheme, Label, Orientation, Position } from 'types';
import { Axis, Data, GroupMark, Mark, ScaleType, Signal, Spec } from 'vega';

import { AxisProps, AxisSpecProps, ColorScheme, Label, Orientation, Position } from '../../types';
import { getAxisLabelsEncoding, getControlledLabelAnchorValues, getLabelValue } from './axisLabelUtils';
import {
getReferenceLineMarks,
Expand Down
3 changes: 2 additions & 1 deletion src/specBuilder/axis/axisTestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import {
DEFAULT_LABEL_FONT_WEIGHT,
DEFAULT_LABEL_ORIENTATION,
} from '@constants';
import { AxisSpecProps } from 'types';
import { Mark } from 'vega';

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

export const defaultXBaselineMark: Mark = {
name: 'xBaseline',
type: 'rule',
Expand Down
3 changes: 2 additions & 1 deletion src/specBuilder/axis/axisTrellisUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import { AxisSpecProps } from 'types';
import { Axis, GroupMark, Spec } from 'vega';

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

/**
* Checks the spec to see if it is a trellised chart
* @param spec
Expand Down
3 changes: 1 addition & 2 deletions src/specBuilder/axis/axisUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import { SubLabel } from 'types';

import { SubLabel } from '../../types';
import { defaultAxisProps, defaultXBaselineMark, defaultYBaselineMark } from './axisTestUtils';
import { getBaselineRule, getDefaultAxis, getSubLabelAxis } from './axisUtils';

Expand Down
2 changes: 1 addition & 1 deletion src/specBuilder/axis/axisUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import { AxisSpecProps, Position } from 'types';
import { Axis, Mark, Scale, SignalRef } from 'vega';

import { AxisSpecProps, Position } from '../../types';
import {
getAxisLabelsEncoding,
getLabelAnchorValues,
Expand Down
3 changes: 1 addition & 2 deletions src/specBuilder/axisAnnotation/axisAnnotationUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import { AxisAnnotationSpecProps } from 'types';

import { AxisAnnotationSpecProps } from '../../types';
import {
addAxisAnnotationAxis,
addAxisAnnotationData,
Expand Down

0 comments on commit 9d2d632

Please sign in to comment.