@coinbase/cds-web 9.16.0 → 9.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -8,6 +8,12 @@ All notable changes to this project will be documented in this file.
8
8
 
9
9
  <!-- template-start -->
10
10
 
11
+ ## 9.17.0 (8/14/2026 PST)
12
+
13
+ #### 🚀 Updates
14
+
15
+ - Feat: support charts gradients for bars. [[#844](https://github.com/coinbase/cds/pull/844)]
16
+
11
17
  ## 9.16.0 (8/13/2026 PST)
12
18
 
13
19
  #### 🚀 Updates
@@ -1 +1 @@
1
- {"version":3,"file":"bar.d.ts","sourceRoot":"","sources":["../../../../src/visualizations/chart/utils/bar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iCAAiC,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,KAAK,EAAgB,YAAY,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGjD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAGlD;;;;;;;;;GASG;AACH,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG;IACvC;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB,GAC/B,QAAQ,oBAAoB,EAC5B,GAAG,MAAM,EACT,GAAG,MAAM,EACT,aAAa,IAAI,KAChB,MAKF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,GACrC,YAAY,aAAa,GAAG,IAAI,EAChC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,UAAU,EAAE,kBAAkB,CAAC;IAC/B,eAAe,EAAE,mBAAmB,EAAE,CAAC;IACvC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,MAAM,EAAE,oBAAoB,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,mBAAmB,CAAC,EAAE,YAAY,CAAC;CACpC;;;;;;;;;;;;;;;;;;IA9uBC,uFAAuF;cAC7E,MAAM;IAChB,mFAAmF;YAC3E,MAAM;IACd,8FAA8F;eACnF,CAAC,MAAM,EAAE,MAAM,CAAC;IAC3B,yEAAyE;qBACxD,OAAO;IAm7BzB"}
@@ -49,6 +49,15 @@ export declare const evaluateGradientAtValue: (
49
49
  dataValue: number,
50
50
  scale: ChartScaleFunction,
51
51
  ) => string | undefined;
52
+ /**
53
+ * Evaluates the opacity at a specific data value based on gradient stops.
54
+ * Returns undefined when no stops define opacity.
55
+ */
56
+ export declare const evaluateGradientOpacityAtValue: (
57
+ stops: GradientStop[],
58
+ dataValue: number,
59
+ scale: ChartScaleFunction,
60
+ ) => number | undefined;
52
61
  /**
53
62
  * Creates a gradient configuration for SVG components.
54
63
  * Processes a GradientDefinition into a renderable GradientConfig.
@@ -1 +1 @@
1
- {"version":3,"file":"gradient.d.ts","sourceRoot":"","sources":["../../../../src/visualizations/chart/utils/gradient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAK,E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kB,EAC5B,QAAQ,kBAAkB,EAC1B,QAAQ,kBAAkB,EAC1B,SAAQ,oBAAiC,KACxC,YAAY,EAAE,GAAG,SAsBnB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,GAAI,YAAY,UAAU,EAAE,WAAU,MAAU,KAAG,MAc1E,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc,GACzB,YAAY,UAAU,EACtB,eAAe,MAAM,EACrB,MAAM,MAAM,EACZ,aAAa,MAAM,EACnB,iBAAiB,MAAM,EACvB,OAAM,GAAG,GAAG,GAAS,KACpB,kBA0BF,CAAC"}
@@ -7,7 +7,7 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
7
7
  function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
8
8
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
9
9
  import { defaultAxisId as fallbackAxisId } from './axis';
10
- import { evaluateGradientAtValue } from './gradient';
10
+ import { evaluateGradientAtValue, evaluateGradientOpacityAtValue } from './gradient';
11
11
  import { defaultTransition } from './transition';
12
12
 
13
13
  /**
@@ -869,6 +869,7 @@ export function getBars(params) {
869
869
  // Skip bars that would have zero or negative height
870
870
  if (length <= 0) return;
871
871
  let barFill = (_s$color = s.color) !== null && _s$color !== void 0 ? _s$color : defaultFill;
872
+ let barFillOpacity = defaultFillOpacity;
872
873
 
873
874
  // Evaluate gradient if provided (using precomputed stops)
874
875
  const seriesGradientConfig = seriesGradients.find(g => (g === null || g === void 0 ? void 0 : g.seriesId) === s.id);
@@ -887,6 +888,10 @@ export function getBars(params) {
887
888
  if (evaluatedColor) {
888
889
  barFill = evaluatedColor;
889
890
  }
891
+ const evaluatedOpacity = evaluateGradientOpacityAtValue(seriesGradientConfig.stops, evalValue, seriesGradientConfig.scale);
892
+ if (evaluatedOpacity !== undefined) {
893
+ barFillOpacity = defaultFillOpacity !== undefined ? defaultFillOpacity * evaluatedOpacity : evaluatedOpacity;
894
+ }
890
895
  }
891
896
  allBars.push({
892
897
  seriesId: s.id,
@@ -894,6 +899,7 @@ export function getBars(params) {
894
899
  length,
895
900
  dataValue: value,
896
901
  fill: barFill,
902
+ fillOpacity: barFillOpacity,
897
903
  roundTop,
898
904
  roundBottom,
899
905
  shouldApplyGap,
@@ -943,7 +949,7 @@ export function getBars(params) {
943
949
  dataY: layout === 'vertical' ? bar.dataValue : categoryValue,
944
950
  origin: barOrigins[i],
945
951
  borderRadius,
946
- fillOpacity: defaultFillOpacity,
952
+ fillOpacity: bar.fillOpacity,
947
953
  stroke: defaultStroke,
948
954
  strokeWidth: defaultStrokeWidth,
949
955
  minSize: initialBarMinSizes[i],
@@ -63,21 +63,15 @@ const processGradientStops = (stops, scale) => {
63
63
  }).sort((a, b) => a.offset - b.offset);
64
64
  return normalizedStops;
65
65
  };
66
+ const GRADIENT_OFFSET_EPSILON = 1e-10;
66
67
 
67
68
  /**
68
- * Evaluates the color at a specific data value based on the gradient stops, ignoring opacity.
69
- * @param stops - The gradient stops configuration
70
- * @param dataValue - The data value to evaluate (for band scales, this is the index)
71
- * @param scale - The scale to use for value mapping (handles log scales correctly)
72
- * @returns The color string at this data value, or undefined if invalid
69
+ * Returns stop indices and blend progress for a data value.
70
+ * When startIndex === endIndex, use that stop directly; otherwise blend with t.
73
71
  */
74
- export const evaluateGradientAtValue = (stops, dataValue, scale) => {
72
+ const getGradientStopInterpolation = (stops, dataValue, scale) => {
75
73
  if (stops.length === 0) return;
76
74
 
77
- // Use srgb color space to match our linearGradient which uses srgb color space
78
- // https://www.w3.org/TR/SVG11/painting.html#ColorInterpolationProperty
79
- const colorSpace = 'srgb';
80
-
81
75
  // Use scale to map values to positions (handles log scales correctly)
82
76
  // For numeric scales: scale(value) returns pixel position
83
77
  // We normalize these positions to 0-1 based on the range
@@ -85,11 +79,11 @@ export const evaluateGradientAtValue = (stops, dataValue, scale) => {
85
79
  const [rangeMin, rangeMax] = Array.isArray(scaleRange) ? scaleRange : [scaleRange, scaleRange]; // fallback for band scales
86
80
 
87
81
  const rangeSpan = Math.abs(rangeMax - rangeMin);
88
- if (rangeSpan === 0) return stops[0].color;
82
+ if (rangeSpan === 0) return [0, 0, 0];
89
83
 
90
84
  // Map dataValue through scale to get position
91
85
  const dataPosition = scale(dataValue);
92
- if (dataPosition === undefined) return stops[0].color;
86
+ if (dataPosition === undefined) return [0, 0, 0];
93
87
 
94
88
  // Normalize to 0-1 based on range
95
89
  const normalizedValue = Math.max(0, Math.min(1, Math.abs(dataPosition - rangeMin) / rangeSpan));
@@ -98,38 +92,77 @@ export const evaluateGradientAtValue = (stops, dataValue, scale) => {
98
92
  const positions = stops.map(stop => stop.offset);
99
93
 
100
94
  // Find which segment we're in
101
- if (normalizedValue < positions[0]) {
102
- return stops[0].color;
103
- }
104
- if (normalizedValue >= positions[positions.length - 1]) {
105
- return stops[stops.length - 1].color;
106
- }
95
+ if (normalizedValue < positions[0]) return [0, 0, 0];
96
+ const lastIndex = stops.length - 1;
97
+ if (normalizedValue >= positions[lastIndex]) return [lastIndex, lastIndex, 0];
107
98
 
108
99
  // Check if normalizedValue matches any stop offset exactly (for hard transitions)
109
100
  for (let i = 0; i < stops.length; i++) {
110
- if (Math.abs(normalizedValue - stops[i].offset) < 1e-10) {
101
+ if (Math.abs(normalizedValue - stops[i].offset) < GRADIENT_OFFSET_EPSILON) {
111
102
  // Found exact match - check if there are multiple stops at this offset (hard transition)
112
- // Use the LAST color at this offset for hard transitions
103
+ // Use the LAST stop at this offset for hard transitions
113
104
  let lastIndexAtOffset = i;
114
- while (lastIndexAtOffset + 1 < stops.length && Math.abs(stops[lastIndexAtOffset + 1].offset - stops[i].offset) < 1e-10) {
105
+ while (lastIndexAtOffset + 1 < stops.length && Math.abs(stops[lastIndexAtOffset + 1].offset - stops[i].offset) < GRADIENT_OFFSET_EPSILON) {
115
106
  lastIndexAtOffset++;
116
107
  }
117
- return stops[lastIndexAtOffset].color;
108
+ return [lastIndexAtOffset, lastIndexAtOffset, 0];
118
109
  }
119
110
  }
120
111
 
121
- // Find the two colors to mix based on normalized positions
112
+ // Find the two stops to mix based on normalized positions
122
113
  for (let i = 0; i < positions.length - 1; i++) {
123
114
  const start = positions[i];
124
115
  const end = positions[i + 1];
125
116
  if (normalizedValue >= start && normalizedValue <= end) {
126
- const segmentProgress = (normalizedValue - start) / (end - start);
127
- return "color-mix(in ".concat(colorSpace, ", ").concat(stops[i + 1].color, " ").concat(segmentProgress * 100, "%, ").concat(stops[i].color, ")");
117
+ if (end === start) return [i, i, 0];
118
+ const t = (normalizedValue - start) / (end - start);
119
+ return [i, i + 1, t];
128
120
  }
129
121
  }
130
122
 
131
- // If we didn't reach any to be mixed, return the last color
132
- return stops[stops.length - 1].color;
123
+ // If we didn't reach any to be mixed, return the last stop
124
+ return [lastIndex, lastIndex, 0];
125
+ };
126
+
127
+ /**
128
+ * Evaluates the color at a specific data value based on the gradient stops, ignoring opacity.
129
+ * @param stops - The gradient stops configuration
130
+ * @param dataValue - The data value to evaluate (for band scales, this is the index)
131
+ * @param scale - The scale to use for value mapping (handles log scales correctly)
132
+ * @returns The color string at this data value, or undefined if invalid
133
+ */
134
+ export const evaluateGradientAtValue = (stops, dataValue, scale) => {
135
+ const interpolation = getGradientStopInterpolation(stops, dataValue, scale);
136
+ if (!interpolation) return;
137
+ const [startIndex, endIndex, t] = interpolation;
138
+
139
+ // Use srgb color space to match our linearGradient which uses srgb color space
140
+ // https://www.w3.org/TR/SVG11/painting.html#ColorInterpolationProperty
141
+ const colorSpace = 'srgb';
142
+ if (startIndex === endIndex) return stops[startIndex].color;
143
+
144
+ // Mix colors between the resolved stops
145
+ return "color-mix(in ".concat(colorSpace, ", ").concat(stops[endIndex].color, " ").concat(t * 100, "%, ").concat(stops[startIndex].color, ")");
146
+ };
147
+
148
+ /**
149
+ * Evaluates the opacity at a specific data value based on gradient stops.
150
+ * Returns undefined when no stops define opacity.
151
+ */
152
+ export const evaluateGradientOpacityAtValue = (stops, dataValue, scale) => {
153
+ var _stops$startIndex$opa, _stops$endIndex$opaci;
154
+ if (stops.length === 0) return;
155
+ if (stops.every(stop => {
156
+ var _stop$opacity2;
157
+ return ((_stop$opacity2 = stop.opacity) !== null && _stop$opacity2 !== void 0 ? _stop$opacity2 : 1) === 1;
158
+ })) return;
159
+ const interpolation = getGradientStopInterpolation(stops, dataValue, scale);
160
+ if (!interpolation) return;
161
+ const [startIndex, endIndex, t] = interpolation;
162
+ const startOpacity = (_stops$startIndex$opa = stops[startIndex].opacity) !== null && _stops$startIndex$opa !== void 0 ? _stops$startIndex$opa : 1;
163
+ if (startIndex === endIndex) return startOpacity;
164
+ const endOpacity = (_stops$endIndex$opaci = stops[endIndex].opacity) !== null && _stops$endIndex$opaci !== void 0 ? _stops$endIndex$opaci : 1;
165
+ return startOpacity + (endOpacity - startOpacity) * t;
133
166
  };
134
167
 
135
168
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coinbase/cds-web",
3
- "version": "9.16.0",
3
+ "version": "9.17.0",
4
4
  "description": "Coinbase Design System - Web",
5
5
  "repository": {
6
6
  "type": "git",
@@ -227,7 +227,7 @@
227
227
  "react-dom": "^18.0.0 || ~19.1.2"
228
228
  },
229
229
  "dependencies": {
230
- "@coinbase/cds-common": "^9.16.0",
230
+ "@coinbase/cds-common": "^9.17.0",
231
231
  "@coinbase/cds-icons": "^5.21.0",
232
232
  "@coinbase/cds-illustrations": "^4.48.0",
233
233
  "@coinbase/cds-lottie-files": "^3.3.4",