(
data: SeriesData,
coordSys: Cartesian2D | Polar,
api: ExtensionAPI
)
| 266 | } |
| 267 | |
| 268 | function getVisualGradient( |
| 269 | data: SeriesData, |
| 270 | coordSys: Cartesian2D | Polar, |
| 271 | api: ExtensionAPI |
| 272 | ) { |
| 273 | const visualMetaList = data.getVisual('visualMeta'); |
| 274 | if (!visualMetaList || !visualMetaList.length || !data.count()) { |
| 275 | // When data.count() is 0, gradient range can not be calculated. |
| 276 | return; |
| 277 | } |
| 278 | |
| 279 | if (coordSys.type !== 'cartesian2d') { |
| 280 | if (__DEV__) { |
| 281 | console.warn('Visual map on line style is only supported on cartesian2d.'); |
| 282 | } |
| 283 | return; |
| 284 | } |
| 285 | |
| 286 | let coordDim: 'x' | 'y'; |
| 287 | let visualMeta; |
| 288 | |
| 289 | for (let i = visualMetaList.length - 1; i >= 0; i--) { |
| 290 | const dimInfo = data.getDimensionInfo(visualMetaList[i].dimension); |
| 291 | coordDim = (dimInfo && dimInfo.coordDim) as 'x' | 'y'; |
| 292 | // Can only be x or y |
| 293 | if (coordDim === 'x' || coordDim === 'y') { |
| 294 | visualMeta = visualMetaList[i]; |
| 295 | break; |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | if (!visualMeta) { |
| 300 | if (__DEV__) { |
| 301 | console.warn('Visual map on line style only support x or y dimension.'); |
| 302 | } |
| 303 | return; |
| 304 | } |
| 305 | |
| 306 | // If the area to be rendered is bigger than area defined by LinearGradient, |
| 307 | // the canvas spec prescribes that the color of the first stop and the last |
| 308 | // stop should be used. But if two stops are added at offset 0, in effect |
| 309 | // browsers use the color of the second stop to render area outside |
| 310 | // LinearGradient. So we can only infinitesimally extend area defined in |
| 311 | // LinearGradient to render `outerColors`. |
| 312 | |
| 313 | const axis = coordSys.getAxis(coordDim); |
| 314 | |
| 315 | // dataToCoord mapping may not be linear, but must be monotonic. |
| 316 | const colorStops: ColorStop[] = zrUtil.map(visualMeta.stops, function (stop) { |
| 317 | // offset will be calculated later. |
| 318 | return { |
| 319 | coord: axis.toGlobalCoord(axis.dataToCoord(stop.value)), |
| 320 | color: stop.color |
| 321 | } as ColorStop; |
| 322 | }); |
| 323 | const stopLen = colorStops.length; |
| 324 | const outerColors = visualMeta.outerColors.slice(); |
| 325 |
no test coverage detected
searching dependent graphs…