@carbon/charts 0.54.13 → 0.55.1
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 +30 -0
- package/build/demo/data/heatmap.d.ts +34 -0
- package/build/src/components/essentials/color-scale-legend.d.ts +7 -1
- package/build/src/model/heatmap.d.ts +2 -2
- package/bundle.js +1 -1
- package/components/axes/toolbar.js +11 -7
- package/components/axes/toolbar.js.map +1 -1
- package/components/essentials/color-scale-legend.d.ts +7 -1
- package/components/essentials/color-scale-legend.js +108 -114
- package/components/essentials/color-scale-legend.js.map +1 -1
- package/components/essentials/modal.js +5 -5
- package/components/essentials/modal.js.map +1 -1
- package/demo/data/bundle.js +1 -1
- package/demo/data/heatmap.d.ts +34 -0
- package/demo/data/heatmap.js +18 -0
- package/demo/data/heatmap.js.map +1 -1
- package/demo/data/index.js +5 -0
- package/demo/data/index.js.map +1 -1
- package/demo/tsconfig.tsbuildinfo +3 -3
- package/model/heatmap.d.ts +2 -2
- package/model/heatmap.js +12 -24
- package/model/heatmap.js.map +1 -1
- package/package.json +2 -2
- package/tsconfig.tsbuildinfo +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"color-scale-legend.js","sourceRoot":"","sources":["color-scale-legend.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mBAAmB;AACnB,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,KAAK,aAAa,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,aAAa;AACb,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CA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AC,eAAe;oBACjB,CAAC,CAAC,CAAC,eAAe,CAAC,UACf,CACN;iBACA,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC;iBAC3B,MAAM,CAAC,MAAM,CAAC;iBACd,IAAI,CAAC,OAAK,CAAC,OAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;YAEhC,IAAI,CAAC,KAAK,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC;YACtC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,CAAC;SAChC;aAAM;YACN,MAAM,KAAK,CAAC,6CAA6C,CAAC,CAAC;SAC3D;QAED,0DAA0D;QAC1D,IAAI,KAAK,IAAI,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE;YACjD,IAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,0BAA0B,CAAC,CAAC;YACjD,IAAA;;oBAAK,CAEV;YACH,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,MAAI,OAAO,CAAC,CAAC;SAChC;IACF,CAAC;IAED,kCAAO,GAAP;QACC,0BAA0B;QAC1B,IAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QAC5C,cAAc,CAAC,mBAAmB,CACjC,MAAM,CAAC,IAAI,CAAC,eAAe,EAC3B,IAAI,CAAC,kBAAkB,CACvB,CAAC;IACH,CAAC;IACF,uBAAC;AAAD,CAAC,AArVD,CAAsC,MAAM,GAqV3C","sourcesContent":["// Internal Imports\nimport { Tools } from '../../tools';\nimport { ColorLegendType, Events, RenderTypes } from '../../interfaces';\nimport * as Configuration from '../../configuration';\nimport { Legend } from './legend';\nimport { DOMUtils } from '../../services';\n\n// D3 imports\nimport { axisBottom } from 'd3-axis';\nimport { scaleBand, scaleLinear } from 'd3-scale';\nimport { interpolateRound, quantize } from 'd3-interpolate';\n\nexport class ColorScaleLegend extends Legend {\n\ttype = 'color-legend';\n\trenderType = RenderTypes.SVG;\n\n\tprivate gradient_id =\n\t\t'gradient-id-' + Math.floor(Math.random() * 99999999999);\n\n\tinit() {\n\t\tconst eventsFragment = this.services.events;\n\n\t\t// Highlight correct circle on legend item hovers\n\t\teventsFragment.addEventListener(\n\t\t\tEvents.Axis.RENDER_COMPLETE,\n\t\t\tthis.handleAxisComplete\n\t\t);\n\t}\n\n\thandleAxisComplete = (event: CustomEvent) => {\n\t\tconst svg = this.getComponentContainer();\n\n\t\tconst { width } = DOMUtils.getSVGElementSize(svg, {\n\t\t\tuseAttrs: true,\n\t\t});\n\n\t\tconst isDataLoading = Tools.getProperty(\n\t\t\tthis.getOptions(),\n\t\t\t'data',\n\t\t\t'loading'\n\t\t);\n\n\t\tif (width > Configuration.legend.color.barWidth && !isDataLoading) {\n\t\t\tconst title = Tools.getProperty(\n\t\t\t\tthis.getOptions(),\n\t\t\t\t'heatmap',\n\t\t\t\t'colorLegend',\n\t\t\t\t'title'\n\t\t\t);\n\n\t\t\tconst { cartesianScales } = this.services;\n\t\t\t// Get available chart area\n\t\t\tconst mainXScale = cartesianScales.getMainXScale();\n\n\t\t\tconst xDimensions = mainXScale.range();\n\n\t\t\t// Align legend with the axis\n\t\t\tif (xDimensions[0] > 1) {\n\t\t\t\tsvg.select('g.legend').attr(\n\t\t\t\t\t'transform',\n\t\t\t\t\t`translate(${xDimensions[0]}, 0)`\n\t\t\t\t);\n\n\t\t\t\tif (title) {\n\t\t\t\t\tconst {\n\t\t\t\t\t\twidth: textWidth,\n\t\t\t\t\t} = DOMUtils.getSVGElementSize(\n\t\t\t\t\t\tsvg.select('g.legend-title').select('text'),\n\t\t\t\t\t\t{ useBBox: true }\n\t\t\t\t\t);\n\n\t\t\t\t\t// -9 since LEFT y-axis labels are moved towards the left by 9 by d3\n\t\t\t\t\tconst availableSpace = xDimensions[0] - textWidth - 9;\n\n\t\t\t\t\t// If space is available align the the label with the axis labels\n\t\t\t\t\tif (availableSpace > 1) {\n\t\t\t\t\t\tsvg.select('g.legend-title').attr(\n\t\t\t\t\t\t\t'transform',\n\t\t\t\t\t\t\t`translate(${availableSpace}, 0)`\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Move the legend down by 16 pixels to display legend text on top\n\t\t\t\t\t\tsvg.select('g.legend').attr(\n\t\t\t\t\t\t\t'transform',\n\t\t\t\t\t\t\t`translate(${xDimensions[0]}, 16)`\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\t// Align legend title with start of axis\n\t\t\t\t\t\tsvg.select('g.legend-title').attr(\n\t\t\t\t\t\t\t'transform',\n\t\t\t\t\t\t\t`translate(${xDimensions[0]}, 0)`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n\n\trender(animate = false) {\n\t\tconst options = this.getOptions();\n\n\t\tconst customColors = Tools.getProperty(\n\t\t\toptions,\n\t\t\t'color',\n\t\t\t'gradient',\n\t\t\t'colors'\n\t\t);\n\n\t\tconst colorScaleType = Tools.getProperty(\n\t\t\toptions,\n\t\t\t'heatmap',\n\t\t\t'colorLegend',\n\t\t\t'type'\n\t\t);\n\n\t\tlet colorPairingOption = Tools.getProperty(\n\t\t\toptions,\n\t\t\t'color',\n\t\t\t'pairing',\n\t\t\t'option'\n\t\t);\n\n\t\tconst title = Tools.getProperty(\n\t\t\toptions,\n\t\t\t'heatmap',\n\t\t\t'colorLegend',\n\t\t\t'title'\n\t\t);\n\n\t\tconst customColorsEnabled = !Tools.isEmpty(customColors);\n\t\tconst domain = this.model.getValueDomain();\n\n\t\tconst svg = this.getComponentContainer();\n\n\t\t// Clear DOM if loading\n\t\tconst isDataLoading = Tools.getProperty(\n\t\t\tthis.getOptions(),\n\t\t\t'data',\n\t\t\t'loading'\n\t\t);\n\n\t\tif (isDataLoading) {\n\t\t\tsvg.html('');\n\t\t\treturn;\n\t\t}\n\n\t\tconst legend = DOMUtils.appendOrSelect(svg, 'g.legend');\n\t\tconst axis = DOMUtils.appendOrSelect(legend, 'g.legend-axis');\n\n\t\tconst { width } = DOMUtils.getSVGElementSize(svg, {\n\t\t\tuseAttrs: true,\n\t\t});\n\n\t\tlet barWidth = Configuration.legend.color.barWidth;\n\t\tif (width <= Configuration.legend.color.barWidth) {\n\t\t\tbarWidth = width;\n\t\t}\n\n\t\tif (title) {\n\t\t\tconst legendTitleGroup = DOMUtils.appendOrSelect(\n\t\t\t\tsvg,\n\t\t\t\t'g.legend-title'\n\t\t\t);\n\t\t\tconst legendTitle = DOMUtils.appendOrSelect(\n\t\t\t\tlegendTitleGroup,\n\t\t\t\t'text'\n\t\t\t);\n\t\t\tlegendTitle.text(title).attr('dy', '0.7em');\n\n\t\t\t// Move the legend down by 16 pixels to display legend text on top\n\t\t\tlegend.attr('transform', `translate(0, 16)`);\n\t\t}\n\n\t\t// If domain consists of negative and positive values, use diverging palettes\n\t\tconst colorScheme = domain[0] < 0 && domain[1] > 0 ? 'diverge' : 'mono';\n\n\t\t// Use default color pairing options if not in defined range\n\t\tif (\n\t\t\tcolorPairingOption < 1 &&\n\t\t\tcolorPairingOption > 4 &&\n\t\t\tcolorScheme === 'mono'\n\t\t) {\n\t\t\tcolorPairingOption = 1;\n\t\t} else if (\n\t\t\tcolorPairingOption < 1 &&\n\t\t\tcolorPairingOption > 2 &&\n\t\t\tcolorScheme === 'diverge'\n\t\t) {\n\t\t\tcolorPairingOption = 1;\n\t\t}\n\n\t\tlet colorPairing = [];\n\t\t// Carbon charts has 11 colors for a single monochromatic palette & 17 for a divergent palette\n\t\tlet colorGroupingLength = colorScheme === 'diverge' ? 17 : 11;\n\n\t\tif (!customColorsEnabled) {\n\t\t\t// Add class names to list and the amount based on the color scheme\n\t\t\tfor (let i = 1; i < colorGroupingLength + 1; i++) {\n\t\t\t\tcolorPairing.push(\n\t\t\t\t\tcolorScaleType === ColorLegendType.LINEAR\n\t\t\t\t\t\t? `stop-color-${colorScheme}-${colorPairingOption}-${i}`\n\t\t\t\t\t\t: `fill-${colorScheme}-${colorPairingOption}-${i}`\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\t// Use custom colors\n\t\t\tcolorPairing = customColors;\n\t\t}\n\n\t\tif (colorScaleType === ColorLegendType.LINEAR) {\n\t\t\tconst stopLengthPercentage = 100 / (colorPairing.length - 1);\n\n\t\t\t// Generate the gradient\n\t\t\tconst linearGradient = DOMUtils.appendOrSelect(\n\t\t\t\tlegend,\n\t\t\t\t'linearGradient'\n\t\t\t);\n\t\t\tlinearGradient\n\t\t\t\t.attr('id', `${this.gradient_id}-legend`)\n\t\t\t\t.selectAll('stop')\n\t\t\t\t.data(colorPairing)\n\t\t\t\t.enter()\n\t\t\t\t.append('stop')\n\t\t\t\t.attr('offset', (_, i) => `${i * stopLengthPercentage}%`)\n\t\t\t\t.attr('class', (_, i) => colorPairing[i])\n\t\t\t\t.attr('stop-color', (d) => d);\n\n\t\t\t// Create the legend container\n\t\t\tconst rectangle = DOMUtils.appendOrSelect(legend, 'rect');\n\t\t\trectangle\n\t\t\t\t.attr('width', barWidth)\n\t\t\t\t.attr('height', Configuration.legend.color.barHeight)\n\t\t\t\t.style('fill', `url(#${this.gradient_id}-legend)`);\n\n\t\t\t// Create scale & ticks\n\t\t\tconst linearScale = scaleLinear()\n\t\t\t\t.domain(domain)\n\t\t\t\t.range([0, barWidth]);\n\t\t\tdomain.splice(1, 0, (domain[0] + domain[1]) / 2);\n\n\t\t\tconst xAxis = axisBottom(linearScale)\n\t\t\t\t.tickSize(0)\n\t\t\t\t.tickValues(domain);\n\n\t\t\t// Align axes at the bottom of the rectangle and delete the domain line\n\t\t\taxis.attr(\n\t\t\t\t'transform',\n\t\t\t\t`translate(0,${Configuration.legend.color.axisYTranslation})`\n\t\t\t).call(xAxis);\n\n\t\t\t// Remove domain\n\t\t\taxis.select('.domain').remove();\n\n\t\t\t// Align text to fit in container\n\t\t\taxis.style('text-anchor', 'start');\n\t\t} else if (colorScaleType === ColorLegendType.QUANTIZE) {\n\t\t\t// Generate equal chunks between range to act as ticks\n\t\t\tconst interpolator = interpolateRound(domain[0], domain[1]);\n\t\t\tconst quant = quantize(interpolator, colorPairing.length);\n\n\t\t\t// If divergent && non-custom color, remove 0/white from being displayed\n\t\t\tif (!customColorsEnabled && colorScheme === 'diverge') {\n\t\t\t\tcolorPairing.splice(colorPairing.length / 2, 1);\n\t\t\t}\n\n\t\t\tconst colorScaleBand = scaleBand()\n\t\t\t\t.domain(colorPairing)\n\t\t\t\t.range([0, barWidth]);\n\n\t\t\t// Render the quantized rectangles\n\t\t\tconst rectangle = DOMUtils.appendOrSelect(\n\t\t\t\tlegend,\n\t\t\t\t'g.quantized-rect'\n\t\t\t);\n\n\t\t\trectangle\n\t\t\t\t.selectAll('rect')\n\t\t\t\t.data(colorScaleBand.domain())\n\t\t\t\t.join('rect')\n\t\t\t\t.attr('x', (d) => colorScaleBand(d))\n\t\t\t\t.attr('y', 0)\n\t\t\t\t.attr('width', Math.max(0, colorScaleBand.bandwidth()) - 1)\n\t\t\t\t.attr('height', Configuration.legend.color.barHeight)\n\t\t\t\t.attr('class', (d) => d)\n\t\t\t\t.attr('fill', (d) => d);\n\n\t\t\tconst xAxis = axisBottom(colorScaleBand)\n\t\t\t\t.tickSize(0)\n\t\t\t\t.tickValues(colorPairing)\n\t\t\t\t.tickFormat((_, i) => {\n\t\t\t\t\t// Display every other tick to create space\n\t\t\t\t\tif (\n\t\t\t\t\t\t!customColorsEnabled &&\n\t\t\t\t\t\t((i + 1) % 2 === 0 || i === colorPairing.length - 1)\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Use the quant interpolators as ticks\n\t\t\t\t\treturn quant[i].toString();\n\t\t\t\t});\n\n\t\t\t// Align axis to match bandwidth start after initial (white)\n\t\t\tconst axisTranslation = colorScaleBand.bandwidth() / 2;\n\t\t\taxis.attr(\n\t\t\t\t'transform',\n\t\t\t\t`translate(${\n\t\t\t\t\t!customColorsEnabled && colorScheme === 'diverge' ? '-' : ''\n\t\t\t\t}${axisTranslation}, ${\n\t\t\t\t\tConfiguration.legend.color.axisYTranslation\n\t\t\t\t})`\n\t\t\t).call(xAxis);\n\n\t\t\t// Append the last tick\n\t\t\tconst firstTick = axis.select('g.tick').clone(true);\n\t\t\tfirstTick\n\t\t\t\t.attr(\n\t\t\t\t\t'transform',\n\t\t\t\t\t`translate(${\n\t\t\t\t\t\tbarWidth +\n\t\t\t\t\t\t(!customColorsEnabled && colorScheme === 'diverge'\n\t\t\t\t\t\t\t? axisTranslation\n\t\t\t\t\t\t\t: -axisTranslation)\n\t\t\t\t\t}, 0)`\n\t\t\t\t)\n\t\t\t\t.classed('final-tick', true)\n\t\t\t\t.select('text')\n\t\t\t\t.text(quant[quant.length - 1]);\n\n\t\t\taxis.enter().append(firstTick.node());\n\t\t\taxis.select('.domain').remove();\n\t\t} else {\n\t\t\tthrow Error('Entered color legend type is not supported.');\n\t\t}\n\n\t\t// Translate last axis tick if barWidth equals chart width\n\t\tif (width <= Configuration.legend.color.barWidth) {\n\t\t\tconst lastTick = axis.select('g.tick:last-of-type text');\n\t\t\tconst { width } = DOMUtils.getSVGElementSize(lastTick, {\n\t\t\t\tuseBBox: true,\n\t\t\t});\n\t\t\tlastTick.attr('x', `-${width}`);\n\t\t}\n\t}\n\n\tdestroy() {\n\t\t// Remove legend listeners\n\t\tconst eventsFragment = this.services.events;\n\t\teventsFragment.removeEventListener(\n\t\t\tEvents.Axis.RENDER_COMPLETE,\n\t\t\tthis.handleAxisComplete\n\t\t);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"color-scale-legend.js","sourceRoot":"","sources":["color-scale-legend.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mBAAmB;AACnB,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,KAAK,aAAa,M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AAK,OAAA,CAAC,EAAD,CAAC,CAAC,CAAC;QAEzB,OAAO,CAAC,CAAC,mBAAmB,IAAI,WAAW,CAAC,KAAK,MAAM;YACtD,CAAC,CAAC,cAAc,CAAC,SAAS,EAAE,GAAG,CAAC;YAChC,CAAC,CAAC,CAAC,CAAC;IACN,CAAC;IAED,kCAAO,GAAP;QACC,0BAA0B;QAC1B,IAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QAC5C,cAAc,CAAC,mBAAmB,CACjC,MAAM,CAAC,IAAI,CAAC,eAAe,EAC3B,IAAI,CAAC,uBAAuB,CAC5B,CAAC;IACH,CAAC;IACF,uBAAC;AAAD,CAAC,AA9UD,CAAsC,MAAM,GA8U3C","sourcesContent":["// Internal Imports\nimport { Tools } from '../../tools';\nimport { ColorLegendType, Events, RenderTypes } from '../../interfaces';\nimport * as Configuration from '../../configuration';\nimport { Legend } from './legend';\nimport { DOMUtils } from '../../services';\n\n// D3 imports\nimport { axisBottom } from 'd3-axis';\nimport { scaleBand, scaleLinear } from 'd3-scale';\nimport { interpolateNumber, quantize } from 'd3-interpolate';\n\nexport class ColorScaleLegend extends Legend {\n\ttype = 'color-legend';\n\trenderType = RenderTypes.SVG;\n\n\tprivate gradient_id =\n\t\t'gradient-id-' + Math.floor(Math.random() * 99999999999);\n\n\tinit() {\n\t\tconst eventsFragment = this.services.events;\n\n\t\t// Highlight correct circle on legend item hovers\n\t\teventsFragment.addEventListener(\n\t\t\tEvents.Axis.RENDER_COMPLETE,\n\t\t\tthis.handleAxisCompleteEvent\n\t\t);\n\t}\n\n\t// Position legend after axis have rendered\n\thandleAxisCompleteEvent = (event: CustomEvent) => {\n\t\tconst svg = this.getComponentContainer();\n\n\t\tconst { width } = DOMUtils.getSVGElementSize(svg, {\n\t\t\tuseAttrs: true,\n\t\t});\n\n\t\tconst isDataLoading = Tools.getProperty(\n\t\t\tthis.getOptions(),\n\t\t\t'data',\n\t\t\t'loading'\n\t\t);\n\n\t\tif (width > Configuration.legend.color.barWidth && !isDataLoading) {\n\t\t\tconst title = Tools.getProperty(\n\t\t\t\tthis.getOptions(),\n\t\t\t\t'heatmap',\n\t\t\t\t'colorLegend',\n\t\t\t\t'title'\n\t\t\t);\n\n\t\t\tconst { cartesianScales } = this.services;\n\n\t\t\t// Get axis width & start/end positions\n\t\t\tconst mainXScale = cartesianScales.getMainXScale();\n\t\t\tconst xDimensions = mainXScale.range();\n\n\t\t\t// Align legend with the axis\n\t\t\tif (xDimensions[0] > 1) {\n\t\t\t\tsvg.select('g.legend').attr(\n\t\t\t\t\t'transform',\n\t\t\t\t\t`translate(${xDimensions[0]}, 0)`\n\t\t\t\t);\n\n\t\t\t\tif (title) {\n\t\t\t\t\tconst {\n\t\t\t\t\t\twidth: textWidth,\n\t\t\t\t\t} = DOMUtils.getSVGElementSize(\n\t\t\t\t\t\tsvg.select('g.legend-title').select('text'),\n\t\t\t\t\t\t{ useBBox: true }\n\t\t\t\t\t);\n\n\t\t\t\t\t// D3 moves the LEFT y-axis labels by 9\n\t\t\t\t\tconst availableSpace = xDimensions[0] - textWidth - 9;\n\n\t\t\t\t\t// If space is available, align the label with the axis labels\n\t\t\t\t\tif (availableSpace > 1) {\n\t\t\t\t\t\tsvg.select('g.legend-title').attr(\n\t\t\t\t\t\t\t'transform',\n\t\t\t\t\t\t\t`translate(${availableSpace}, 0)`\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Move the legend down by 16 pixels to display legend text on top\n\t\t\t\t\t\tsvg.select('g.legend').attr(\n\t\t\t\t\t\t\t'transform',\n\t\t\t\t\t\t\t`translate(${xDimensions[0]}, 16)`\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\t// Align legend title with start of axis\n\t\t\t\t\t\tsvg.select('g.legend-title').attr(\n\t\t\t\t\t\t\t'transform',\n\t\t\t\t\t\t\t`translate(${xDimensions[0]}, 0)`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Default state\n\t\t\tsvg.select('g.legend-title').attr('transform', `translate(0, 0)`);\n\t\t}\n\t};\n\n\trender(animate = false) {\n\t\tconst options = this.getOptions();\n\t\tconst svg = this.getComponentContainer();\n\t\tconst { width } = DOMUtils.getSVGElementSize(svg, {\n\t\t\tuseAttrs: true,\n\t\t});\n\n\t\tconst customColors = Tools.getProperty(\n\t\t\toptions,\n\t\t\t'color',\n\t\t\t'gradient',\n\t\t\t'colors'\n\t\t);\n\n\t\tconst colorScaleType = Tools.getProperty(\n\t\t\toptions,\n\t\t\t'heatmap',\n\t\t\t'colorLegend',\n\t\t\t'type'\n\t\t);\n\n\t\tlet colorPairingOption = Tools.getProperty(\n\t\t\toptions,\n\t\t\t'color',\n\t\t\t'pairing',\n\t\t\t'option'\n\t\t);\n\n\t\tconst title = Tools.getProperty(\n\t\t\toptions,\n\t\t\t'heatmap',\n\t\t\t'colorLegend',\n\t\t\t'title'\n\t\t);\n\n\t\t// Clear DOM if loading\n\t\tconst isDataLoading = Tools.getProperty(\n\t\t\tthis.getOptions(),\n\t\t\t'data',\n\t\t\t'loading'\n\t\t);\n\n\t\tif (isDataLoading) {\n\t\t\tsvg.html('');\n\t\t\treturn;\n\t\t}\n\n\t\tconst customColorsEnabled = !Tools.isEmpty(customColors);\n\t\tconst domain = this.model.getValueDomain();\n\n\t\tconst useDefaultBarWidth = !(\n\t\t\twidth <= Configuration.legend.color.barWidth\n\t\t);\n\t\tconst barWidth = useDefaultBarWidth\n\t\t\t? Configuration.legend.color.barWidth\n\t\t\t: width;\n\n\t\tconst legendGroupElement = DOMUtils.appendOrSelect(svg, 'g.legend');\n\t\tconst axisElement = DOMUtils.appendOrSelect(\n\t\t\tlegendGroupElement,\n\t\t\t'g.legend-axis'\n\t\t);\n\n\t\t// Render title if it exists\n\t\tif (title) {\n\t\t\tconst legendTitleGroup = DOMUtils.appendOrSelect(\n\t\t\t\tsvg,\n\t\t\t\t'g.legend-title'\n\t\t\t);\n\t\t\tconst legendTitle = DOMUtils.appendOrSelect(\n\t\t\t\tlegendTitleGroup,\n\t\t\t\t'text'\n\t\t\t);\n\t\t\tlegendTitle.text(title).attr('dy', '0.7em');\n\n\t\t\t// Move the legend down by 16 pixels to display legend text on top\n\t\t\tlegendGroupElement.attr('transform', `translate(0, 16)`);\n\t\t}\n\n\t\t// If domain consists of negative and positive values, use diverging palettes\n\t\tconst colorScheme = domain[0] < 0 && domain[1] > 0 ? 'diverge' : 'mono';\n\n\t\t// Use default color pairing options if not in defined range\n\t\tif (\n\t\t\tcolorPairingOption < 1 &&\n\t\t\tcolorPairingOption > 4 &&\n\t\t\tcolorScheme === 'mono'\n\t\t) {\n\t\t\tcolorPairingOption = 1;\n\t\t} else if (\n\t\t\tcolorPairingOption < 1 &&\n\t\t\tcolorPairingOption > 2 &&\n\t\t\tcolorScheme === 'diverge'\n\t\t) {\n\t\t\tcolorPairingOption = 1;\n\t\t}\n\n\t\tlet colorPairing = [];\n\t\t// Carbon charts has 11 colors for a single monochromatic palette & 17 for a divergent palette\n\t\tlet colorGroupingLength = colorScheme === 'diverge' ? 17 : 11;\n\n\t\tif (!customColorsEnabled) {\n\t\t\t// Add class names to list and the amount based on the color scheme\n\t\t\tfor (let i = 1; i < colorGroupingLength + 1; i++) {\n\t\t\t\tcolorPairing.push(\n\t\t\t\t\tcolorScaleType === ColorLegendType.LINEAR\n\t\t\t\t\t\t? `stop-color-${colorScheme}-${colorPairingOption}-${i}`\n\t\t\t\t\t\t: `fill-${colorScheme}-${colorPairingOption}-${i}`\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\t// Use custom colors\n\t\t\tcolorPairing = customColors;\n\t\t}\n\n\t\t// Generate equal chunks between range to act as ticks\n\t\tconst interpolator = interpolateNumber(domain[0], domain[1]);\n\t\tconst quant = quantize(interpolator, 3);\n\n\t\t// Create scale & ticks\n\t\tconst linearScale = scaleLinear().domain(domain).range([0, barWidth]);\n\n\t\tconst legendAxis = axisBottom(linearScale)\n\t\t\t.tickSize(0)\n\t\t\t.tickValues(quant);\n\n\t\tswitch (colorScaleType) {\n\t\t\tcase ColorLegendType.LINEAR:\n\t\t\t\tthis.drawLinear(colorPairing, legendGroupElement, barWidth);\n\t\t\t\tbreak;\n\t\t\tcase ColorLegendType.QUANTIZE:\n\t\t\t\tconst rangeStart = this.drawQuantize(\n\t\t\t\t\tcolorPairing,\n\t\t\t\t\tcolorScheme,\n\t\t\t\t\tcustomColorsEnabled,\n\t\t\t\t\tlegendGroupElement,\n\t\t\t\t\tbarWidth\n\t\t\t\t);\n\t\t\t\t// Using range provided by drawQuantize for alignment purposes\n\t\t\t\tlinearScale.range([rangeStart, barWidth]);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow Error('Entered color legend type is not supported.');\n\t\t}\n\n\t\t// Align axes at the bottom of the rectangle and delete the domain line\n\t\taxisElement\n\t\t\t.attr(\n\t\t\t\t'transform',\n\t\t\t\t`translate(0,${Configuration.legend.color.axisYTranslation})`\n\t\t\t)\n\t\t\t.call(legendAxis);\n\n\t\t// Remove auto generated axis bottom line\n\t\taxisElement.select('.domain').remove();\n\n\t\t// Translate first/last axis tick if barWidth equals chart width\n\t\t// Ensures text is not clipped when default bar width (300px) is not used\n\t\taxisElement\n\t\t\t.select('g.tick:last-of-type text')\n\t\t\t.style('text-anchor', useDefaultBarWidth ? 'middle' : 'end');\n\t\taxisElement\n\t\t\t.select('g.tick:first-of-type text')\n\t\t\t.style('text-anchor', useDefaultBarWidth ? 'middle' : 'start');\n\t}\n\n\t// Renders gradient legend\n\tdrawLinear(colorPairing, legendGroupElement, barWidth) {\n\t\tconst stopLengthPercentage = 100 / (colorPairing.length - 1);\n\n\t\t// Generate the gradient\n\t\tconst linearGradient = DOMUtils.appendOrSelect(\n\t\t\tlegendGroupElement,\n\t\t\t'linearGradient'\n\t\t);\n\t\t// Rendering gradient\n\t\tlinearGradient\n\t\t\t.attr('id', `${this.gradient_id}-legend`)\n\t\t\t.selectAll('stop')\n\t\t\t.data(colorPairing)\n\t\t\t.enter()\n\t\t\t.append('stop')\n\t\t\t.attr('offset', (_, i) => `${i * stopLengthPercentage}%`)\n\t\t\t.attr('class', (_, i) => colorPairing[i])\n\t\t\t.attr('stop-color', (d) => d);\n\n\t\t// Create the legend container\n\t\tconst rectangle = DOMUtils.appendOrSelect(legendGroupElement, 'rect');\n\t\trectangle\n\t\t\t.attr('width', barWidth)\n\t\t\t.attr('height', Configuration.legend.color.barHeight)\n\t\t\t.style('fill', `url(#${this.gradient_id}-legend)`);\n\t}\n\n\t/**\n\t * Renders quantized legend\n\t * @returns number (range start)\n\t */\n\tdrawQuantize(\n\t\tcolorPairing,\n\t\tcolorScheme,\n\t\tcustomColorsEnabled,\n\t\tlegendGroupElement,\n\t\tbarWidth\n\t) {\n\t\t// If divergent && non-custom color, remove 0/white from being displayed\n\t\tif (!customColorsEnabled && colorScheme === 'diverge') {\n\t\t\tcolorPairing.splice(colorPairing.length / 2, 1);\n\t\t}\n\n\t\tconst colorScaleBand = scaleBand()\n\t\t\t.domain(colorPairing)\n\t\t\t.range([0, barWidth]);\n\n\t\t// Render the quantized rectangles\n\t\tconst rectangle = DOMUtils.appendOrSelect(\n\t\t\tlegendGroupElement,\n\t\t\t'g.quantized-rect'\n\t\t);\n\n\t\trectangle\n\t\t\t.selectAll('rect')\n\t\t\t.data(colorScaleBand.domain())\n\t\t\t.join('rect')\n\t\t\t.attr('x', (d) => colorScaleBand(d))\n\t\t\t.attr('y', 0)\n\t\t\t.attr('width', Math.max(0, colorScaleBand.bandwidth() - 1))\n\t\t\t.attr('height', Configuration.legend.color.barHeight)\n\t\t\t.attr('class', (d) => d)\n\t\t\t.attr('fill', (d) => d);\n\n\t\treturn (!customColorsEnabled && colorScheme) === 'mono'\n\t\t\t? colorScaleBand.bandwidth() - 1\n\t\t\t: 0;\n\t}\n\n\tdestroy() {\n\t\t// Remove legend listeners\n\t\tconst eventsFragment = this.services.events;\n\t\teventsFragment.removeEventListener(\n\t\t\tEvents.Axis.RENDER_COMPLETE,\n\t\t\tthis.handleAxisCompleteEvent\n\t\t);\n\t}\n}\n"]}
|
|
@@ -52,12 +52,12 @@ var Modal = /** @class */ (function (_super) {
|
|
|
52
52
|
var options = this.model.getOptions();
|
|
53
53
|
var chartprefix = Tools.getProperty(options, 'style', 'prefix');
|
|
54
54
|
var tableArray = this.model.getTabularDataArray();
|
|
55
|
-
return "\n\t\t<div class=\"bx--modal-container\">\n\t\t\t<div class=\"bx--modal-header\">\n\t\t\t\t<p class=\"bx--modal-header__label bx--type-delta\" id=\"modal-title\">Tabular representation</p>\n\t\t\t\t<p class=\"bx--modal-header__heading bx--type-beta\" id=\"modal-description\">" + options.title + "</p>\n\t\t\t\t<button class=\"bx--modal-close\" type=\"button\" data-modal-close aria-label=\"close modal\" data-modal-primary-focus>\n\t\t\t\t\t<svg focusable=\"false\" preserveAspectRatio=\"xMidYMid meet\" xmlns=\"http://www.w3.org/2000/svg\" fill=\"currentColor\" aria-label=\"Close\" width=\"20\" height=\"20\" viewBox=\"0 0 32 32\" role=\"img\" class=\"bx--modal-close__icon\">\n\t\t\t\t\t\t<path d=\"M24 9.4L22.6 8 16 14.6 9.4 8 8 9.4 14.6 16 8 22.6 9.4 24 16 17.4 22.6 24 24 22.6 17.4 16 24 9.4z\"></path>\n\t\t\t\t\t</svg>\n\t\t\t\t</button>\n\t\t\t</div>\n\t\t\t<div class=\"bx--modal-content\"
|
|
56
|
-
.map(function (heading) { return "<th scope=\"col\">\n\t\t\t\t\t\t\t\t<div class=\"bx--table-header-label\">" + heading + "</div>\n\t\t\t\t\t\t\t</th>"; })
|
|
57
|
-
.join('') + "\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</thead>\n\t\t\t\t\t<tbody>" + tableArray
|
|
55
|
+
return "\n\t\t<div class=\"bx--modal-container cds--modal-container\">\n\t\t\t<div class=\"bx--modal-header cds--modal-header\">\n\t\t\t\t<p class=\"bx--modal-header__label bx--type-delta cds--modal-header__label cds--type-delta\" id=\"modal-title\">Tabular representation</p>\n\n\t\t\t\t<p class=\"bx--modal-header__heading bx--type-beta cds--modal-header__heading cds--type-beta\" id=\"modal-description\">" + options.title + "</p>\n\n\t\t\t\t<button class=\"bx--modal-close cds--modal-close\" type=\"button\" data-modal-close aria-label=\"close modal\" data-modal-primary-focus>\n\t\t\t\t\t<svg focusable=\"false\" preserveAspectRatio=\"xMidYMid meet\" xmlns=\"http://www.w3.org/2000/svg\" fill=\"currentColor\" aria-label=\"Close\" width=\"20\" height=\"20\" viewBox=\"0 0 32 32\" role=\"img\" class=\"bx--modal-close__icon cds--modal-close__icon\">\n\t\t\t\t\t\t<path d=\"M24 9.4L22.6 8 16 14.6 9.4 8 8 9.4 14.6 16 8 22.6 9.4 24 16 17.4 22.6 24 24 22.6 17.4 16 24 9.4z\"></path>\n\t\t\t\t\t</svg>\n\t\t\t\t</button>\n\t\t\t</div>\n\n\t\t\t<div class=\"bx--modal-content cds--modal-content\">\n\t\t\t\t<table class=\"bx--data-table bx--data-table--no-border cds--data-table cds--data-table--no-border\">\n\t\t\t\t\t<thead>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t" + get(tableArray, 0)
|
|
56
|
+
.map(function (heading) { return "<th scope=\"col\">\n\t\t\t\t\t\t\t\t<div class=\"bx--table-header-label cds--table-header-label\">" + heading + "</div>\n\t\t\t\t\t\t\t</th>"; })
|
|
57
|
+
.join('') + "\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</thead>\n\n\t\t\t\t\t<tbody>" + tableArray
|
|
58
58
|
.slice(1)
|
|
59
59
|
.map(function (row) { return "\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t" + row.map(function (column) { return "<td>" + column + "</td>"; }).join('') + "\n\t\t\t\t\t\t\t</tr>"; })
|
|
60
|
-
.join('') + "\n\t\t\t\t\t</tbody>\n\t\t\t\t</table>\n\t\t\t</div>\n\t\t\t<div class=\"bx--modal-footer\">\n\t\t\t <div class=\"" + settings.prefix + "--" + chartprefix + "-modal-footer-spacer\"></div>\n\t\t\t <button class=\"bx--btn bx--btn--primary\" type=\"button\" data-modal-primary-focus>Download as CSV</button>\n\t\t\t</div>\n\t\t</div>";
|
|
60
|
+
.join('') + "\n\t\t\t\t\t</tbody>\n\t\t\t\t</table>\n\t\t\t</div>\n\n\t\t\t<div class=\"bx--modal-footer cds--modal-footer\">\n\t\t\t <div class=\"" + settings.prefix + "--" + chartprefix + "-modal-footer-spacer\"></div>\n\t\t\t <button class=\"bx--btn bx--btn--primary cds--btn cds--btn--primary\" type=\"button\" data-modal-primary-focus>Download as CSV</button>\n\t\t\t</div>\n\t\t</div>";
|
|
61
61
|
};
|
|
62
62
|
Modal.prototype.render = function () {
|
|
63
63
|
var options = this.model.getOptions();
|
|
@@ -70,7 +70,7 @@ var Modal = /** @class */ (function (_super) {
|
|
|
70
70
|
this.isEventListenerAdded = true;
|
|
71
71
|
this.modal
|
|
72
72
|
.attr('data-modal', true)
|
|
73
|
-
.attr('class', 'bx--modal')
|
|
73
|
+
.attr('class', 'bx--modal cds--modal')
|
|
74
74
|
.attr('role', 'dialog')
|
|
75
75
|
.attr('aria-modal', true)
|
|
76
76
|
.attr('aria-labelledby', 'modal-title')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modal.js","sourceRoot":"","sources":["modal.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,eAAe;AACf,OAAO,EAAE,KAAK,IAAI,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAElE,yCAAyC;AACzC,OAAO,QAAQ,MAAM,0CAA0C,CAAC;AAEhE,aAAa;AACb,O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AC,KAAK,CAAC,UAAU,EAAE,CAAC;QACxC,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE;YAC/B,2BAA2B;YAC3B,IAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC;YAC1D,IAAM,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;YAClE,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,cAAc,CACnC,MAAM,EACN,SAAO,QAAQ,CAAC,MAAM,UAAK,WAAW,YAAS,CAC/C,CAAC;YAEF,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACzB,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC;YACjC,IAAI,CAAC,KAAK;iBACR,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC;iBACxB,IAAI,CAAC,OAAO,EAAE,sBAAsB,CAAC;iBACrC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC;iBACtB,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC;iBACxB,IAAI,CAAC,iBAAiB,EAAE,aAAa,CAAC;iBACtC,IAAI,CAAC,kBAAkB,EAAE,mBAAmB,CAAC;iBAC7C,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC;SACvB;IACF,CAAC;IAED,uBAAO,GAAP;QACC,+BAA+B;QAC/B,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC5B,IAAI,CAAC,oBAAoB,GAAG,KAAK,CAAC;IACnC,CAAC;IACF,YAAC;AAAD,CAAC,AA7HD,CAA2B,SAAS,GA6HnC","sourcesContent":["import { Component } from '../component';\nimport { Tools } from '../../tools';\nimport { DOMUtils } from '../../services';\nimport { ChartModel } from '../../model/model';\nimport { Events } from '../../interfaces';\n\n// Carbon modal\nimport { Modal as CarbonModalComponent } from 'carbon-components';\n\n// import the settings for the css prefix\nimport settings from 'carbon-components/es/globals/js/settings';\n\n// D3 Imports\nimport { select } from 'd3-selection';\n\nimport { get } from 'lodash-es';\n\nexport class Modal extends Component {\n\ttype = 'modal';\n\n\t// flag for checking whether tooltip event listener is added or not\n\tisEventListenerAdded = false;\n\tmodal: any;\n\n\tconstructor(model: ChartModel, services: any, configs?: any) {\n\t\tsuper(model, services, configs);\n\n\t\tthis.init();\n\t}\n\n\thandleShowModal = () => {\n\t\tthis.modal.html(this.getModalHTML());\n\t\tthis.modal\n\t\t\t.select('div.bx--modal-footer button.bx--btn')\n\t\t\t.on('click', () => this.model.exportToCSV());\n\n\t\tconst modalInstance = CarbonModalComponent.create(this.modal.node());\n\t\tmodalInstance.show();\n\t};\n\n\taddEventListeners() {\n\t\t// listen to show-modal Custom Events to render the modal\n\t\tthis.services.events.addEventListener(\n\t\t\tEvents.Modal.SHOW,\n\t\t\tthis.handleShowModal\n\t\t);\n\t}\n\n\tremoveEventListeners() {\n\t\t// remove show-modal Custom Events\n\t\tthis.services.events.removeEventListener(\n\t\t\tEvents.Modal.SHOW,\n\t\t\tthis.handleShowModal\n\t\t);\n\t}\n\n\tgetModalHTML() {\n\t\tconst options = this.model.getOptions();\n\n\t\tconst chartprefix = Tools.getProperty(options, 'style', 'prefix');\n\n\t\tconst tableArray = this.model.getTabularDataArray();\n\n\t\treturn `\n\t\t<div class=\"bx--modal-container cds--modal-container\">\n\t\t\t<div class=\"bx--modal-header cds--modal-header\">\n\t\t\t\t<p class=\"bx--modal-header__label bx--type-delta cds--modal-header__label cds--type-delta\" id=\"modal-title\">Tabular representation</p>\n\n\t\t\t\t<p class=\"bx--modal-header__heading bx--type-beta cds--modal-header__heading cds--type-beta\" id=\"modal-description\">${\n\t\t\t\t\toptions.title\n\t\t\t\t}</p>\n\n\t\t\t\t<button class=\"bx--modal-close cds--modal-close\" type=\"button\" data-modal-close aria-label=\"close modal\" data-modal-primary-focus>\n\t\t\t\t\t<svg focusable=\"false\" preserveAspectRatio=\"xMidYMid meet\" xmlns=\"http://www.w3.org/2000/svg\" fill=\"currentColor\" aria-label=\"Close\" width=\"20\" height=\"20\" viewBox=\"0 0 32 32\" role=\"img\" class=\"bx--modal-close__icon cds--modal-close__icon\">\n\t\t\t\t\t\t<path d=\"M24 9.4L22.6 8 16 14.6 9.4 8 8 9.4 14.6 16 8 22.6 9.4 24 16 17.4 22.6 24 24 22.6 17.4 16 24 9.4z\"></path>\n\t\t\t\t\t</svg>\n\t\t\t\t</button>\n\t\t\t</div>\n\n\t\t\t<div class=\"bx--modal-content cds--modal-content\">\n\t\t\t\t<table class=\"bx--data-table bx--data-table--no-border cds--data-table cds--data-table--no-border\">\n\t\t\t\t\t<thead>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t${get(tableArray, 0)\n\t\t\t\t\t\t\t\t.map(\n\t\t\t\t\t\t\t\t\t(heading) => `<th scope=\"col\">\n\t\t\t\t\t\t\t\t<div class=\"bx--table-header-label cds--table-header-label\">${heading}</div>\n\t\t\t\t\t\t\t</th>`\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t.join('')}\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</thead>\n\n\t\t\t\t\t<tbody>${tableArray\n\t\t\t\t\t\t.slice(1)\n\t\t\t\t\t\t.map(\n\t\t\t\t\t\t\t(row) => `\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t${row.map((column) => `<td>${column}</td>`).join('')}\n\t\t\t\t\t\t\t</tr>`\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.join('')}\n\t\t\t\t\t</tbody>\n\t\t\t\t</table>\n\t\t\t</div>\n\n\t\t\t<div class=\"bx--modal-footer cds--modal-footer\">\n\t\t\t <div class=\"${settings.prefix}--${chartprefix}-modal-footer-spacer\"></div>\n\t\t\t <button class=\"bx--btn bx--btn--primary cds--btn cds--btn--primary\" type=\"button\" data-modal-primary-focus>Download as CSV</button>\n\t\t\t</div>\n\t\t</div>`;\n\t}\n\n\trender() {\n\t\tconst options = this.model.getOptions();\n\t\tif (!this.isEventListenerAdded) {\n\t\t\t// Grab the tooltip element\n\t\t\tconst holder = select(this.services.domUtils.getHolder());\n\t\t\tconst chartprefix = Tools.getProperty(options, 'style', 'prefix');\n\t\t\tthis.modal = DOMUtils.appendOrSelect(\n\t\t\t\tholder,\n\t\t\t\t`div.${settings.prefix}--${chartprefix}--modal`\n\t\t\t);\n\n\t\t\tthis.addEventListeners();\n\t\t\tthis.isEventListenerAdded = true;\n\t\t\tthis.modal\n\t\t\t\t.attr('data-modal', true)\n\t\t\t\t.attr('class', 'bx--modal cds--modal')\n\t\t\t\t.attr('role', 'dialog')\n\t\t\t\t.attr('aria-modal', true)\n\t\t\t\t.attr('aria-labelledby', 'modal-title')\n\t\t\t\t.attr('aria-describedby', 'modal-description')\n\t\t\t\t.attr('tabindex', -1);\n\t\t}\n\t}\n\n\tdestroy() {\n\t\t// remove tooltip eventListener\n\t\tthis.removeEventListeners();\n\t\tthis.isEventListenerAdded = false;\n\t}\n}\n"]}
|