aminghadersohi commented on code in PR #42910:
URL: https://github.com/apache/superset/pull/42910#discussion_r4387287415


##########
superset-frontend/src/explore/components/controls/IntervalColorsControl/legacyColors.ts:
##########
@@ -0,0 +1,91 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import {
+  getCategoricalSchemeRegistry,
+  validateNumber,
+} from '@superset-ui/core';
+
+export const parseIntervalBounds = (intervals?: string): number[] =>
+  (intervals ?? '')
+    .split(',')
+    .map(part => part.trim())
+    .filter(part => part !== '')
+    .map(Number)
+    .filter(bound => Number.isFinite(bound));
+
+/**
+ * Resolves the legacy `interval_color_indices` control (comma-separated,
+ * 1-indexed positions into the chosen categorical color scheme) into real
+ * hex colors, one per interval band (`boundCount` entries). Shared by the
+ * control panel (display-only fallback while a legacy chart is being edited)
+ * and by `handleDeprecatedControls` (which, on request, migrates the value
+ * into `interval_colors`).
+ */
+export const resolveLegacyIntervalColors = (
+  boundCount: number,
+  legacyIntervalColorIndices: string | undefined,
+  colorScheme: string | undefined,
+): string[] => {
+  // Non-strict lookup mirrors the Gauge renderer: an unregistered scheme
+  // falls back to the registry's default scheme.
+  const schemeColors =
+    getCategoricalSchemeRegistry().get(colorScheme)?.colors ?? [];
+  // Parse with the exact same semantics `getIntervalBoundsAndColors` in
+  // Gauge/transformProps.ts uses for this same legacy fallback (via
+  // `parseNumbersList`, not reimported here to avoid pulling the whole
+  // `@superset-ui/plugin-chart-echarts` package -- and every chart plugin it
+  // eagerly registers -- into `explore/store.ts`'s import graph): one
+  // unparseable (or blank) token discards every legacy index for the whole
+  // list, rather than resolving the other tokens independently. A more
+  // lenient parser here would let this one-time migration (and this
+  // display-only preview) disagree with how an untouched legacy chart has
+  // always rendered -- see #42910 review thread on this file.
+  let indices: number[];
+  try {
+    indices = (legacyIntervalColorIndices ?? '').split(',').map(part => {
+      if (validateNumber(part)) throw new Error('All values must be numeric');
+      return Number(part);
+    });
+  } catch {
+    indices = [];
+  }
+  // An index past the static palette can only be resolved against the
+  // renderer's render-time palette (which grows under USE_ANALOGOUS_COLORS),
+  // so wrapping it modulo the static scheme would show -- and, once a row is
+  // edited, persist -- a different color than the chart renders. Leave every
+  // band unresolved so such charts keep rendering through the renderer's own
+  // legacy path.
+  if (
+    indices.slice(0, boundCount).some(index => index > schemeColors.length)
+  ) {

Review Comment:
   `oxfmt` keeps this condition on one line (it fits in 80 columns), so running 
the repo's formatter rewrites these three lines.
   
   ```suggestion
     if (indices.slice(0, boundCount).some(index => index > 
schemeColors.length)) {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to