Skip to content

Commit

Permalink
Feat setting scale (#416)
Browse files Browse the repository at this point in the history
* fix: type

* feat: setting scales
  • Loading branch information
islxyqwe authored Sep 30, 2024
1 parent e24c87a commit d15ac9a
Show file tree
Hide file tree
Showing 11 changed files with 674 additions and 348 deletions.
25 changes: 9 additions & 16 deletions packages/graphic-walker/src/components/leafletRenderer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { forwardRef, useMemo } from 'react';
import type { DraggableFieldState, IChannelScales, IConfigScale, IRow, IVisualConfigNew, IVisualLayout, VegaGlobalConfig } from '../../interfaces';
import type { DraggableFieldState, IChannelScales, IConfigScaleSet, IRow, IVisualConfigNew, IVisualLayout, VegaGlobalConfig } from '../../interfaces';
import POIRenderer from './POIRenderer';
import ChoroplethRenderer from './ChoroplethRenderer';

Expand All @@ -11,10 +11,7 @@ export interface ILeafletRendererProps {
visualLayout: IVisualLayout;
data: IRow[];
scales?: IChannelScales;
scale?: {
opacity: IConfigScale;
size: IConfigScale;
};
scale?: IConfigScaleSet;
}

export interface ILeafletRendererRef {}
Expand Down Expand Up @@ -48,17 +45,13 @@ const LeafletRenderer = forwardRef<ILeafletRendererRef, ILeafletRendererProps>(f
const longitude = useMemo(() => lng ?? lngField, [lng, lngField]);
const scales = useMemo(() => {
const cs = channelScaleRaw ?? {};
if (scale?.opacity) {
cs.opacity = {
...(cs.opacity ?? {}),
...scale.opacity,
};
}
if (scale?.size) {
cs.size = {
...(cs.size ?? {}),
...scale.size,
};
if (scale) {
for (const key of Object.keys(scale)) {
cs[key] = {
...(cs[key] ?? {}),
...scale[key],
};
}
}
return cs;
}, [channelScaleRaw, scale]);
Expand Down
2 changes: 1 addition & 1 deletion packages/graphic-walker/src/components/rangeslider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const Slider = React.forwardRef<React.ElementRef<typeof SliderPrimitive.Root>, R
<SliderPrimitive.Root
ref={ref}
minStepsBetweenThumbs={1}
className={cn('relative flex w-full touch-none select-none items-center', className)}
className={cn('relative flex w-full touch-none select-none items-center data-[disabled]:opacity-50', className)}
{...props}
>
<SliderPrimitive.Track className="relative h-1.5 w-full grow overflow-hidden rounded-full bg-primary/20">
Expand Down
87 changes: 65 additions & 22 deletions packages/graphic-walker/src/components/ui/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,60 @@ const DialogOverlay = React.forwardRef<React.ElementRef<typeof DialogPrimitive.O
);
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;

const DialogContent = React.forwardRef<React.ElementRef<typeof DialogPrimitive.Content>, React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>>(
({ className, children, ...props }, ref) => (
<DialogPortal container={React.useContext(portalContainerContext)}>
<DialogOverlay />
<DialogPrimitive.Content
ref={ref}
className={cn(
'fixed left-[50%] top-[50%] z-50 grid w-[98%] sm:w-[80%] lg:w-[880px] translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg overflow-hidden',
className
)}
{...props}
>
<ScrollArea className="overscroll-none max-h-[calc(min(800px,90vh))] w-full relative p-6">{children}</ScrollArea>
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
<Cross2Icon className="h-4 w-4" />
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
</DialogPrimitive.Content>
</DialogPortal>
)
);
const DialogContent = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & {
containerClassName?: string;
}
>(({ className, containerClassName, children, ...props }, ref) => (
<DialogPortal container={React.useContext(portalContainerContext)}>
<DialogOverlay />
<DialogPrimitive.Content
ref={ref}
className={cn(
'fixed left-[50%] top-[50%] z-50 grid w-[98%] sm:w-[80%] lg:w-[880px] translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg overflow-hidden',
className
)}
{...props}
>
<ScrollArea className={cn('overscroll-none max-h-[calc(min(800px,90vh))] w-full relative p-6', containerClassName)}>{children}</ScrollArea>
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
<Cross2Icon className="h-4 w-4" />
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
</DialogPrimitive.Content>
</DialogPortal>
));

DialogContent.displayName = DialogPrimitive.Content.displayName;

const DialogNormalContent = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & {
containerClassName?: string;
}
>(({ className, containerClassName, children, ...props }, ref) => (
<DialogPortal container={React.useContext(portalContainerContext)}>
<DialogOverlay />
<DialogPrimitive.Content
ref={ref}
className={cn(
'fixed left-[50%] top-[50%] z-50 grid w-[98%] sm:w-[80%] lg:w-[880px] translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg overflow-hidden',
className
)}
{...props}
>
{children}
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
<Cross2Icon className="h-4 w-4" />
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
</DialogPrimitive.Content>
</DialogPortal>
));

DialogNormalContent.displayName = DialogPrimitive.Content.displayName;

const DialogHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
<div className={cn('flex flex-col space-y-1.5 text-center sm:text-left', className)} {...props} />
);
Expand All @@ -74,4 +105,16 @@ const DialogDescription = React.forwardRef<
>(({ className, ...props }, ref) => <DialogPrimitive.Description ref={ref} className={cn('text-sm text-muted-foreground', className)} {...props} />);
DialogDescription.displayName = DialogPrimitive.Description.displayName;

export { Dialog, DialogPortal, DialogOverlay, DialogTrigger, DialogClose, DialogContent, DialogHeader, DialogFooter, DialogTitle, DialogDescription };
export {
Dialog,
DialogPortal,
DialogOverlay,
DialogTrigger,
DialogClose,
DialogContent,
DialogNormalContent,
DialogHeader,
DialogFooter,
DialogTitle,
DialogDescription,
};
32 changes: 32 additions & 0 deletions packages/graphic-walker/src/components/ui/number-input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as React from 'react';

import { cn } from '@/utils';
import { useRefControledState } from '@/hooks';

export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {}

const NumberInput = React.forwardRef<HTMLInputElement, InputProps>(({ className, type, value, onChange, ...props }, ref) => {
const [uncontrolledValue, setUncontrolledValue] = useRefControledState(value);

return (
<input
type="number"
className={cn(
'flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50',
className
)}
ref={ref}
value={uncontrolledValue}
onChange={(e) => {
setUncontrolledValue(e.target.value);
}}
onBlur={(e) => {
onChange?.(e);
}}
{...props}
/>
);
});
NumberInput.displayName = 'NumberInput';

export { NumberInput };
Loading

0 comments on commit d15ac9a

Please sign in to comment.