mirror of https://github.com/buster-so/buster.git
Merge pull request #97 from buster-so/staging
use colors in tooltip cache
This commit is contained in:
commit
6f2976ef78
|
@ -41,12 +41,12 @@ pub async fn ensure_stored_values_schema(organization_id: &Uuid) -> Result<()> {
|
|||
// Create schema and table using raw SQL
|
||||
let schema_name = organization_id.to_string().replace("-", "_");
|
||||
let create_schema_sql = format!(
|
||||
"CREATE SCHEMA IF NOT EXISTS {}_values",
|
||||
"CREATE SCHEMA IF NOT EXISTS values_{}",
|
||||
schema_name
|
||||
);
|
||||
|
||||
let create_table_sql = format!(
|
||||
"CREATE TABLE IF NOT EXISTS {}_values.values_v1 (
|
||||
"CREATE TABLE IF NOT EXISTS values_{}.values_v1 (
|
||||
value text NOT NULL,
|
||||
dataset_id uuid NOT NULL,
|
||||
column_name text NOT NULL,
|
||||
|
@ -60,7 +60,7 @@ pub async fn ensure_stored_values_schema(organization_id: &Uuid) -> Result<()> {
|
|||
|
||||
let create_index_sql = format!(
|
||||
"CREATE INDEX IF NOT EXISTS values_v1_embedding_idx
|
||||
ON {}_values.values_v1
|
||||
ON values_{}.values_v1
|
||||
USING ivfflat (embedding vector_cosine_ops)",
|
||||
schema_name
|
||||
);
|
||||
|
|
|
@ -169,7 +169,8 @@ export const useOptions = ({
|
|||
columnSettings,
|
||||
datasetOptions,
|
||||
hasMismatchedTooltipsAndMeasures,
|
||||
disableTooltip
|
||||
disableTooltip,
|
||||
colors
|
||||
});
|
||||
|
||||
const options: ChartProps<ChartJSChartType>['options'] = useMemo(() => {
|
||||
|
|
|
@ -32,6 +32,7 @@ interface UseTooltipOptionsProps {
|
|||
datasetOptions: DatasetOption[];
|
||||
hasMismatchedTooltipsAndMeasures: boolean;
|
||||
disableTooltip: boolean;
|
||||
colors: string[];
|
||||
}
|
||||
|
||||
export const useTooltipOptions = ({
|
||||
|
@ -44,7 +45,8 @@ export const useTooltipOptions = ({
|
|||
columnSettings,
|
||||
selectedAxis,
|
||||
datasetOptions,
|
||||
disableTooltip
|
||||
disableTooltip,
|
||||
colors
|
||||
}: UseTooltipOptionsProps): DeepPartial<TooltipOptions> => {
|
||||
const tooltipCache = useRef<Record<string, string>>({});
|
||||
|
||||
|
@ -53,6 +55,10 @@ export const useTooltipOptions = ({
|
|||
[columnLabelFormats]
|
||||
);
|
||||
|
||||
const colorsStringCache = useMemo(() => {
|
||||
return colors.map((c) => String(c)).join('');
|
||||
}, [colors]);
|
||||
|
||||
const mode: TooltipOptions['mode'] = useMemo(() => {
|
||||
if (selectedChartType === 'scatter') {
|
||||
return 'nearest';
|
||||
|
@ -107,7 +113,12 @@ export const useTooltipOptions = ({
|
|||
}, [useGlobalPercentage, selectedChartType, columnSettings, tooltipKeys]);
|
||||
|
||||
const memoizedExternal = useMemoizedFn((context: TooltipContext) => {
|
||||
const key = createTooltipCacheKey(context.chart, keyToUsePercentage, columnLabelFormatsString);
|
||||
const key = createTooltipCacheKey(
|
||||
context.chart,
|
||||
keyToUsePercentage,
|
||||
columnLabelFormatsString,
|
||||
colorsStringCache
|
||||
);
|
||||
const matchedCacheItem = tooltipCache.current[key];
|
||||
const result = externalTooltip(
|
||||
context,
|
||||
|
@ -149,7 +160,8 @@ export const useTooltipOptions = ({
|
|||
const createTooltipCacheKey = (
|
||||
chart: ChartJSOrUndefined,
|
||||
keyToUsePercentage: string[],
|
||||
columnLabelFormatsString: string
|
||||
columnLabelFormatsString: string,
|
||||
colorsStringCache: string
|
||||
) => {
|
||||
if (!chart?.tooltip) return '';
|
||||
|
||||
|
@ -159,7 +171,8 @@ const createTooltipCacheKey = (
|
|||
chart.tooltip.title.join(''),
|
||||
chart.tooltip.body?.map((b) => b.lines.join('')).join(''),
|
||||
keyToUsePercentage.join(''),
|
||||
columnLabelFormatsString
|
||||
columnLabelFormatsString,
|
||||
colorsStringCache
|
||||
];
|
||||
|
||||
return parts.join('');
|
||||
|
|
Loading…
Reference in New Issue