Skip to content

An open source alternative to Tableau. Embeddable visual analytic

fix: modal bugs and bin nice number

ObservedObserver3e07a3b4ace5
diff --git a/packages/graphic-walker/src/components/dataTable/index.tsx b/packages/graphic-walker/src/components/dataTable/index.tsx
index 7adc7596..146e61f8 100644
--- a/packages/graphic-walker/src/components/dataTable/index.tsx
+++ b/packages/graphic-walker/src/components/dataTable/index.tsx
@@ -20,16 +20,6 @@ const Container = styled.div`
box-sizing: content-box;
border-collapse: collapse;
font-size: 12px;
- thead {
- th {
- }
- th.number {
- border-top: 3px solid #5cdbd3;
- }
- th.text {
- border-top: 3px solid #69c0ff;
- }
- }
tbody {
td {
}
@@ -52,17 +42,17 @@ function getHeaderType(field: IMutField): "number" | "text" {
}
function getHeaderClassNames(field: IMutField) {
- return field.analyticType === "dimension" ? "border-t-4 border-blue-400" : "border-t-4 border-teal-400";
+ return field.analyticType === "dimension" ? "border-t-4 border-blue-400" : "border-t-4 border-purple-400";
}
function getSemanticColors(field: IMutField): string {
switch (field.semanticType) {
case "nominal":
- return "bg-indigo-100 text-indigo-800";
+ return "bg-sky-100 text-sky-800";
case "ordinal":
- return "bg-purple-100 text-purple-800";
+ return "bg-indigo-100 text-indigo-800";
case "quantitative":
- return "bg-green-100 text-green-800";
+ return "bg-purple-100 text-purple-800";
case "temporal":
return "bg-yellow-100 text-yellow-800";
default:
@@ -129,7 +119,7 @@ const DataTable: React.FC<DataTableProps> = (props) => {
<span
className={
"cursor-pointer inline-flex px-2.5 py-0.5 text-xs font-medium mt-1 rounded-full text-xs text-white " +
- (field.analyticType === "dimension" ? "bg-blue-500" : "bg-teal-500")
+ (field.analyticType === "dimension" ? "bg-blue-500" : "bg-purple-500")
}
>
{field.analyticType}
diff --git a/packages/graphic-walker/src/components/dataTypeIcon.tsx b/packages/graphic-walker/src/components/dataTypeIcon.tsx
index b4298bcc..183f4887 100644
--- a/packages/graphic-walker/src/components/dataTypeIcon.tsx
+++ b/packages/graphic-walker/src/components/dataTypeIcon.tsx
@@ -6,7 +6,7 @@ const DataTypeIcon: React.FC<{ dataType: IMutField["semanticType"]; analyticType
props
) => {
const { dataType, analyticType } = props;
- const color = analyticType === "dimension" ? "text-blue-500" : "text-green-500";
+ const color = analyticType === "dimension" ? "text-blue-500" : "text-purple-500";
const iconClassName = `w-3 inline-block mr-0.5 ${color}`;
switch (dataType) {
case "quantitative":
diff --git a/packages/graphic-walker/src/fields/datasetFields/dimFields.tsx b/packages/graphic-walker/src/fields/datasetFields/dimFields.tsx
index adef304f..0413ec79 100644
--- a/packages/graphic-walker/src/fields/datasetFields/dimFields.tsx
+++ b/packages/graphic-walker/src/fields/datasetFields/dimFields.tsx
@@ -1,46 +1,54 @@
-import React from 'react';
-import { Draggable, DroppableProvided } from '@kanaries/react-beautiful-dnd';
-import { observer } from 'mobx-react-lite';
-import { useGlobalStore } from '../../store';
-import DataTypeIcon from '../../components/dataTypeIcon';
-import { FieldPill } from './fieldPill';
+import React from "react";
+import { Draggable, DroppableProvided } from "@kanaries/react-beautiful-dnd";
+import { observer } from "mobx-react-lite";
+import { useGlobalStore } from "../../store";
+import DataTypeIcon from "../../components/dataTypeIcon";
+import { FieldPill } from "./fieldPill";
interface Props {
provided: DroppableProvided;
}
-const DimFields: React.FC<Props> = props => {
+const DimFields: React.FC<Props> = (props) => {
const { provided } = props;
const { vizStore } = useGlobalStore();
const dimensions = vizStore.draggableFieldState.dimensions;
- return <div {...provided.droppableProps} ref={provided.innerRef}>
- {dimensions.map((f, index) => (
- <Draggable key={f.dragId} draggableId={f.dragId} index={index}>
- {(provided, snapshot) => {
-
- return (
- <>
- <FieldPill
- className="pt-0.5 pb-0.5 pl-2 pr-2 mx-0 m-1 text-xs hover:bg-blue-100 rounded-full truncate border border-transparent"
- ref={provided.innerRef}
- isDragging={snapshot.isDragging}
- {...provided.draggableProps}
- {...provided.dragHandleProps}
- >
- <DataTypeIcon dataType={f.semanticType} analyticType={f.analyticType} /> {f.name}&nbsp;
- </FieldPill>
- {
- <FieldPill className={`pt-0.5 pb-0.5 pl-2 pr-2 mx-0 m-1 text-xs hover:bg-blue-100 rounded-full border-blue-400 border truncate ${snapshot.isDragging ? '' : 'hidden'}`}
- isDragging={snapshot.isDragging}
+ return (
+ <div {...provided.droppableProps} ref={provided.innerRef}>
+ {dimensions.map((f, index) => (
+ <Draggable key={f.dragId} draggableId={f.dragId} index={index}>
+ {(provided, snapshot) => {
+ return (
+ <>
+ <FieldPill
+ className={`pt-0.5 pb-0.5 pl-2 pr-2 mx-0 m-1 text-xs hover:bg-blue-100 rounded-full truncate border border-transparent ${
+ snapshot.isDragging ? "bg-blue-100" : ""
+ }`}
+ ref={provided.innerRef}
+ isDragging={snapshot.isDragging}
+ {...provided.draggableProps}
+ {...provided.dragHandleProps}
>
- <DataTypeIcon dataType={f.semanticType} analyticType={f.analyticType} /> {f.name}&nbsp;
+ <DataTypeIcon dataType={f.semanticType} analyticType={f.analyticType} /> {f.name}
+ &nbsp;
</FieldPill>
- }
- </>
- );
- }}
- </Draggable>
- ))}
- </div>
-}
+ {
+ <FieldPill
+ className={`pt-0.5 pb-0.5 pl-2 pr-2 mx-0 m-1 text-xs hover:bg-blue-100 rounded-full border-blue-400 border truncate ${
+ snapshot.isDragging ? "bg-blue-100" : "hidden"
+ }`}
+ isDragging={snapshot.isDragging}
+ >
+ <DataTypeIcon dataType={f.semanticType} analyticType={f.analyticType} />{" "}
+ {f.name}&nbsp;
+ </FieldPill>
+ }
+ </>
+ );
+ }}
+ </Draggable>
+ ))}
+ </div>
+ );
+};
export default observer(DimFields);
diff --git a/packages/graphic-walker/src/fields/datasetFields/meaFields.tsx b/packages/graphic-walker/src/fields/datasetFields/meaFields.tsx
index 99c2cd47..694a8e62 100644
--- a/packages/graphic-walker/src/fields/datasetFields/meaFields.tsx
+++ b/packages/graphic-walker/src/fields/datasetFields/meaFields.tsx
@@ -6,8 +6,6 @@ import DataTypeIcon from "../../components/dataTypeIcon";
import { FieldPill } from "./fieldPill";
import DropdownContext, { IDropdownContextOption } from "../../components/dropdownContext";
-
-
interface Props {
provided: DroppableProvided;
}
@@ -19,23 +17,23 @@ const MeaFields: React.FC<Props> = (props) => {
const MEA_ACTION_OPTIONS = useMemo<IDropdownContextOption[]>(() => {
return [
{
- value: 'bin',
- label: 'Bin',
+ value: "bin",
+ label: "Bin",
},
{
- value: 'log10',
- label: 'Log10',
- }
- ]
- }, [])
+ value: "log10",
+ label: "Log10",
+ },
+ ];
+ }, []);
- const fieldActionHandler = useCallback((selectedValue: any, index: number) => {
- if (selectedValue === 'bin') {
- vizStore.createBinField("measures", index);
- } else if (selectedValue === 'log10') {
- vizStore.createLogField("measures", index);
+ const fieldActionHandler = useCallback((selectedValue: any, opIndex: number, meaIndex: number) => {
+ if (selectedValue === "bin") {
+ vizStore.createBinField("measures", meaIndex);
+ } else if (selectedValue === "log10") {
+ vizStore.createLogField("measures", meaIndex);
}
- }, [])
+ }, []);
return (
<div {...provided.droppableProps} ref={provided.innerRef}>
{measures.map((f, index) => (
@@ -43,9 +41,17 @@ const MeaFields: React.FC<Props> = (props) => {
{(provided, snapshot) => {
return (
<div className="block">
- <DropdownContext disable={snapshot.isDragging} options={MEA_ACTION_OPTIONS} onSelect={fieldActionHandler}>
+ <DropdownContext
+ disable={snapshot.isDragging}
+ options={MEA_ACTION_OPTIONS}
+ onSelect={(v, opIndex) => {
+ fieldActionHandler(v, opIndex, index);
+ }}
+ >
<FieldPill
- className={`pt-0.5 pb-0.5 pl-2 pr-2 mx-0 m-1 text-xs hover:bg-blue-100 rounded-full truncate border border-transparent ${snapshot.isDragging ? 'bg-blue-100' : ''}`}
+ className={`pt-0.5 pb-0.5 pl-2 pr-2 mx-0 m-1 text-xs hover:bg-purple-100 rounded-full truncate border border-transparent ${
+ snapshot.isDragging ? "bg-purple-100" : ""
+ }`}
isDragging={snapshot.isDragging}
ref={provided.innerRef}
{...provided.draggableProps}
@@ -57,8 +63,8 @@ const MeaFields: React.FC<Props> = (props) => {
</DropdownContext>
{
<FieldPill
- className={`pt-0.5 pb-0.5 pl-2 pr-2 mx-0 m-1 text-xs hover:bg-blue-100 rounded-full border-blue-400 border truncate ${
- snapshot.isDragging ? "bg-blue-100" : "hidden"
+ className={`pt-0.5 pb-0.5 pl-2 pr-2 mx-0 m-1 text-xs hover:bg-purple-100 rounded-full border-purple-400 border truncate ${
+ snapshot.isDragging ? "bg-purple-100" : "hidden"
}`}
isDragging={snapshot.isDragging}
>
diff --git a/packages/graphic-walker/src/insightBoard/index.tsx b/packages/graphic-walker/src/insightBoard/index.tsx
index 56b9cdfa..28170743 100644
--- a/packages/graphic-walker/src/insightBoard/index.tsx
+++ b/packages/graphic-walker/src/insightBoard/index.tsx
@@ -12,6 +12,9 @@ const InsightBoard: React.FC = (props) => {
const onCloseModal = useCallback(() => {
commonStore.setShowInsightBoard(false);
}, []);
+ if (!showInsightBoard) {
+ return null;
+ }
return (
<Modal onClose={onCloseModal} show={showInsightBoard}>
<InsightMainBoard
diff --git a/packages/graphic-walker/src/utils/index.ts b/packages/graphic-walker/src/utils/index.ts
index bb9f0c32..29d22be7 100644
--- a/packages/graphic-walker/src/utils/index.ts
+++ b/packages/graphic-walker/src/utils/index.ts
@@ -258,3 +258,22 @@ export function extendCountField(
fields: nextFields,
};
}
+
+export function getRange (nums: number[]): [number, number] {
+ let _min = Infinity;
+ let _max = -Infinity;
+ for (let i = 0; i < nums.length; i++) {
+ _min = Math.min(_min, nums[i]);
+ _max = Math.max(_max, nums[i]);
+ }
+ return [_min, _max];
+}
+
+export function makeNumbersBeautiful (nums: number[]): number[] {
+ const [min, max] = getRange(nums);
+ const range = max - min;
+ const step = Math.pow(10, Math.floor(Math.log10(range)));
+ return nums.map((num) => {
+ return Math.round(num / step) * step;
+ })
+}
\ No newline at end of file
diff --git a/packages/graphic-walker/src/utils/normalization.ts b/packages/graphic-walker/src/utils/normalization.ts
index 78dcc241..eb325057 100644
--- a/packages/graphic-walker/src/utils/normalization.ts
+++ b/packages/graphic-walker/src/utils/normalization.ts
@@ -140,12 +140,13 @@ export function makeBinField(dataSource: IRow[], fid: string, binFid: string, bi
if (val < _min) _min = val;
}
const step = (_max - _min) / binSize;
+ const beaStep = Math.max(-Math.round(Math.log10(_max - _min)) + 2, 0)
return dataSource.map((r) => {
let bIndex = Math.floor((r[fid] - _min) / step);
if (bIndex === binSize) bIndex = binSize - 1;
return {
...r,
- [binFid]: bIndex * step + _min,
+ [binFid]: Number(((bIndex * step + _min)).toFixed(beaStep)),
};
});
}
diff --git a/packages/graphic-walker/src/vis/theme.ts b/packages/graphic-walker/src/vis/theme.ts
index ddc7a5ee..fbe442a0 100644
--- a/packages/graphic-walker/src/vis/theme.ts
+++ b/packages/graphic-walker/src/vis/theme.ts
@@ -26,5 +26,19 @@ export const DEFAULT_THEME = {
],
diverging: ["#7b3294", "#c2a5cf", "#f7f7f7", "#a6dba0", "#008837"],
heatmap: ["#000000", "#7b3294", "#c2a5cf", "#f7f7f7", "#a6dba0", "#008837"],
+ ramp: [
+ "#EBCCFF",
+ "#CCB0FF",
+ "#AE95FF",
+ "#907BFF",
+ "#7262FD",
+ "#5349E0",
+ "#2F32C3",
+ "#001BA7",
+ "#00068C"
+ ],
+ },
+ scale: {
+ continuous: { range: ["#f7fbff", "#08306b"] },
},
};