@carbon/charts 0.29.4 → 0.29.8
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 +32 -0
- package/bundle.js +1 -1
- package/components/axes/axis.d.ts +1 -0
- package/components/axes/axis.js +41 -14
- package/components/axes/axis.js.map +1 -1
- package/configuration.d.ts +2 -0
- package/configuration.js +2 -0
- package/configuration.js.map +1 -1
- package/demo/demo-data/bar.d.ts +13 -0
- package/demo/demo-data/bar.js +13 -0
- package/demo/demo-data/bar.js.map +1 -1
- package/demo/demo-data/bundle.js +1 -1
- package/demo/demo-data/index.js +5 -0
- package/demo/demo-data/index.js.map +1 -1
- package/demo/tsconfig.tsbuildinfo +661 -85
- package/interfaces/axis-scales.d.ts +11 -2
- package/interfaces/axis-scales.js.map +1 -1
- package/package.json +1 -1
- package/services/scales-cartesian.js +5 -1
- package/services/scales-cartesian.js.map +1 -1
- package/tools.d.ts +1 -0
- package/tools.js +2 -1
- package/tools.js.map +1 -1
- package/tsconfig.tsbuildinfo +621 -166
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ScaleTypes } from "./enums";
|
|
2
|
+
import { AxisDomain } from "d3";
|
|
2
3
|
/**
|
|
3
4
|
* options to configure a scale. not all options are used by all scales
|
|
4
5
|
*/
|
|
@@ -13,14 +14,22 @@ export interface AxisOptions {
|
|
|
13
14
|
* you would expect to only have 1 axis (dimension) being used as domain
|
|
14
15
|
* Domain usually represents labels, ordinal values, time intervals etc.
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
+
useAsGraphDomain?: boolean;
|
|
17
18
|
/**
|
|
18
19
|
* Whether the Axis should be used as the range
|
|
19
20
|
* axis of the chart. In the case of Cartesian Scales
|
|
20
21
|
* you would expect to only have 1 axis (dimension) being used as range
|
|
21
22
|
* Range usually follows a linear scale
|
|
22
23
|
*/
|
|
23
|
-
|
|
24
|
+
useAsGraphRange?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Whether the Axis should use the specified domain
|
|
27
|
+
* instead of it being dynamically generated based on data extents.
|
|
28
|
+
* The type of values should depend on the scale type.
|
|
29
|
+
* Example for continuous axis scale: [-100, 100]
|
|
30
|
+
* Example for discrete axis scale: ['Qty', 'More', 'Sold']
|
|
31
|
+
*/
|
|
32
|
+
domain?: AxisDomain[];
|
|
24
33
|
primary?: boolean;
|
|
25
34
|
secondary?: boolean;
|
|
26
35
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axis-scales.js","sourceRoot":"","sources":["axis-scales.ts"],"names":[],"mappings":"","sourcesContent":["import { ScaleTypes } from \"./enums\";\n\n/**\n * options to configure a scale. not all options are used by all scales\n */\nexport interface AxisOptions {\n\t/**\n\t * type of the scale used on axis\n\t */\n\tscaleType?: ScaleTypes;\n\t/**\n\t * Whether the Axis should be used as the domain\n\t * axis of the chart. In the case of Cartesian Scales\n\t * you would expect to only have 1 axis (dimension) being used as domain\n\t * Domain usually represents labels, ordinal values, time intervals etc.\n\t */\n\
|
|
1
|
+
{"version":3,"file":"axis-scales.js","sourceRoot":"","sources":["axis-scales.ts"],"names":[],"mappings":"","sourcesContent":["import { ScaleTypes } from \"./enums\";\nimport { AxisDomain } from \"d3\";\n\n/**\n * options to configure a scale. not all options are used by all scales\n */\nexport interface AxisOptions {\n\t/**\n\t * type of the scale used on axis\n\t */\n\tscaleType?: ScaleTypes;\n\t/**\n\t * Whether the Axis should be used as the domain\n\t * axis of the chart. In the case of Cartesian Scales\n\t * you would expect to only have 1 axis (dimension) being used as domain\n\t * Domain usually represents labels, ordinal values, time intervals etc.\n\t */\n\tuseAsGraphDomain?: boolean;\n\t/**\n\t * Whether the Axis should be used as the range\n\t * axis of the chart. In the case of Cartesian Scales\n\t * you would expect to only have 1 axis (dimension) being used as range\n\t * Range usually follows a linear scale\n\t */\n\tuseAsGraphRange?: boolean;\n\t/**\n\t * Whether the Axis should use the specified domain\n\t * instead of it being dynamically generated based on data extents.\n\t * The type of values should depend on the scale type.\n\t * Example for continuous axis scale: [-100, 100]\n\t * Example for discrete axis scale: ['Qty', 'More', 'Sold']\n\t */\n\tdomain?: AxisDomain[];\n\tprimary?: boolean;\n\tsecondary?: boolean;\n\t/**\n\t * optional title for the scales\n\t */\n\ttitle?: string;\n\t/**\n\t * tick configuration\n\t */\n\tticks?: {\n\t\t/**\n\t\t * number of ticks to show\n\t\t */\n\t\tnumber?: number;\n\t\t/**\n\t\t * minimum tick value\n\t\t */\n\t\tmin?: number;\n\t\t/**\n\t\t * maximum tick value\n\t\t */\n\t\tmax?: number;\n\t\t/**\n\t\t * minimum width of a tick\n\t\t * before getting rotated (in pixels)\n\t\t */\n\t\trotateIfSmallerThan?: number;\n\t\t/**\n\t\t * function to format the ticks\n\t\t */\n\t\tformatter?: Function;\n\t};\n}\n\n/**\n * customize the axes components\n */\nexport interface AxesOptions {\n\tleft?: AxisOptions;\n\tbottom?: AxisOptions;\n\tright?: AxisOptions;\n\ttop?: AxisOptions;\n}\n\n/**\n * customize time series scales\n */\nexport interface TimeScaleOptions {\n\taddSpaceOnEdges?: number;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -19,7 +19,7 @@ import { Tools } from "../tools";
|
|
|
19
19
|
import { scaleBand, scaleLinear, scaleTime, scaleLog } from "d3-scale";
|
|
20
20
|
import { min, extent } from "d3-array";
|
|
21
21
|
import { timeFormatDefaultLocale } from "d3-time-format";
|
|
22
|
-
import
|
|
22
|
+
import englishLocale from "d3-time-format/locale/en-US.json";
|
|
23
23
|
// Misc
|
|
24
24
|
import { differenceInYears, addYears, subYears, differenceInMonths, addMonths, subMonths, differenceInDays, addDays, subDays, differenceInHours, addHours, subHours, differenceInMinutes, addMinutes, subMinutes } from "date-fns";
|
|
25
25
|
var CartesianScales = /** @class */ (function (_super) {
|
|
@@ -190,6 +190,10 @@ var CartesianScales = /** @class */ (function (_super) {
|
|
|
190
190
|
}
|
|
191
191
|
// Get the extent of the domain
|
|
192
192
|
var domain;
|
|
193
|
+
// If domain is specified return that domain
|
|
194
|
+
if (axisOptions.domain) {
|
|
195
|
+
return axisOptions.domain;
|
|
196
|
+
}
|
|
193
197
|
// If the scale is stacked
|
|
194
198
|
if (axisOptions.stacked) {
|
|
195
199
|
domain = extent(labels.reduce(function (m, label, i) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scales-cartesian.js","sourceRoot":"","sources":["scales-cartesian.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mBAAmB;AACnB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACjF,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,aAAa;AACb,OAAO,EACN,SAAS,EACT,WAAW,EACX,SAAS,EACT,QAAQ,EACR,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,aAAa,MAAM,kCAAkC,CAAC;AAElE,OAAO;AACP,OAAO,EACN,iBAAiB,EACjB,QAAQ,EACR,QAAQ,EACR,kBAAkB,EAClB,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,OAAO,EACP,OAAO,EACP,iBAAiB,EACjB,QAAQ,EACR,QAAQ,EACR,mBAAmB,EACnB,UAAU,EACV,UAAU,EACV,MAAM,UAAU,CAAC;AAElB;IAAqC,mCAAO;IAA5C;QAAA,qEAyTC;QAxTU,gBAAU,GAAG;YACtB,GAAG,EAAE,IAAI;YACT,KAAK,EAAE,IAAI;YACX,MAAM,EAAE,IAAI;YACZ,IAAI,EAAE,IAAI;SACV,CAAC;QAEQ,YAAM,GAAG;YAClB,GAAG,EAAE,IAAI;YACT,KAAK,EAAE,IAAI;YACX,MAAM,EAAE,IAAI;YACZ,IAAI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AAC,MAAM,CAAC;QACnF,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC;QAE1C,2BAA2B;QAC3B,IAAI,SAAS,KAAK,UAAU,CAAC,IAAI,EAAE;YAClC,IAAM,UAAU,GAAG,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,IAAI,aAAa,CAAC;YAEjF,uBAAuB,CAAC,UAAU,CAAC,CAAC;SACpC;QAED,IAAI,KAAK,CAAC;QACV,IAAI,SAAS,KAAK,UAAU,CAAC,IAAI,EAAE;YAClC,KAAK,GAAG,SAAS,EAAE,CAAC;SACpB;aAAM,IAAI,SAAS,KAAK,UAAU,CAAC,GAAG,EAAE;YACxC,KAAK,GAAG,QAAQ,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;SAChD;aAAM,IAAI,SAAS,KAAK,UAAU,CAAC,MAAM,EAAE;YAC3C,KAAK,GAAG,SAAS,EAAE,CAAC;SACpB;aAAM;YACN,KAAK,GAAG,WAAW,EAAE,CAAC;SACtB;QAED,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CAAC;QAChD,OAAO,KAAK,CAAC;IACd,CAAC;IACF,sBAAC;AAAD,CAAC,AAzTD,CAAqC,OAAO,GAyT3C","sourcesContent":["// Internal Imports\nimport { Service } from \"./service\";\nimport { AxisPositions, CartesianOrientations, ScaleTypes } from \"../interfaces\";\nimport { Tools } from \"../tools\";\n\n// D3 Imports\nimport {\n\tscaleBand,\n\tscaleLinear,\n\tscaleTime,\n\tscaleLog\n} from \"d3-scale\";\nimport { min, extent } from \"d3-array\";\nimport { timeFormatDefaultLocale } from \"d3-time-format\";\nimport * as englishLocale from \"d3-time-format/locale/en-US.json\";\n\n// Misc\nimport {\n\tdifferenceInYears,\n\taddYears,\n\tsubYears,\n\tdifferenceInMonths,\n\taddMonths,\n\tsubMonths,\n\tdifferenceInDays,\n\taddDays,\n\tsubDays,\n\tdifferenceInHours,\n\taddHours,\n\tsubHours,\n\tdifferenceInMinutes,\n\taddMinutes,\n\tsubMinutes\n} from \"date-fns\";\n\nexport class CartesianScales extends Service {\n\tprotected scaleTypes = {\n\t\ttop: null,\n\t\tright: null,\n\t\tbottom: null,\n\t\tleft: null\n\t};\n\n\tprotected scales = {\n\t\ttop: null,\n\t\tright: null,\n\t\tbottom: null,\n\t\tleft: null\n\t};\n\n\tprotected domainAxisPosition: AxisPositions;\n\tprotected rangeAxisPosition: AxisPositions;\n\n\tprotected orientation: CartesianOrientations;\n\n\tgetDomainAxisPosition() {\n\t\treturn this.domainAxisPosition;\n\t}\n\n\tgetRangeAxisPosition() {\n\t\treturn this.rangeAxisPosition;\n\t}\n\n\tupdate(animate = true) {\n\t\tthis.determineOrientation();\n\t\tconst axisPositions = Object.keys(AxisPositions).map(axisPositionKey => AxisPositions[axisPositionKey]);\n\t\taxisPositions.forEach(axisPosition => {\n\t\t\tthis.scales[axisPosition] = this.createScale(axisPosition);\n\t\t});\n\t}\n\n\tdetermineOrientation() {\n\t\tconst options = this.model.getOptions();\n\n\t\t// Manually specifying positions here\n\t\t// In order to enforce a priority\n\t\t[\n\t\t\tAxisPositions.LEFT,\n\t\t\tAxisPositions.BOTTOM,\n\t\t\tAxisPositions.RIGHT,\n\t\t\tAxisPositions.TOP\n\t\t].forEach(axisPosition => {\n\t\t\tconst axisOptions = Tools.getProperty(options, \"axes\", axisPosition);\n\n\t\t\tif (axisOptions) {\n\t\t\t\tconst scaleType = axisOptions.scaleType || ScaleTypes.LINEAR;\n\t\t\t\tthis.scaleTypes[axisPosition] = scaleType;\n\n\t\t\t\tif (scaleType === ScaleTypes.LINEAR) {\n\t\t\t\t\tthis.rangeAxisPosition = axisPosition;\n\t\t\t\t} else {\n\t\t\t\t\tthis.domainAxisPosition = axisPosition;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tif (this.rangeAxisPosition === AxisPositions.LEFT && this.domainAxisPosition === AxisPositions.BOTTOM) {\n\t\t\tthis.orientation = CartesianOrientations.VERTICAL;\n\t\t} else {\n\t\t\tthis.orientation = CartesianOrientations.HORIZONTAL;\n\t\t}\n\t}\n\n\tgetOrientation() {\n\t\treturn this.orientation;\n\t}\n\n\tgetScaleByPosition(axisPosition: AxisPositions) {\n\t\treturn this.scales[axisPosition];\n\t}\n\n\tgetScaleTypeByPosition(axisPosition: AxisPositions) {\n\t\treturn this.scaleTypes[axisPosition];\n\t}\n\n\tgetDomainScale() {\n\t\treturn this.scales[this.domainAxisPosition];\n\t}\n\n\tgetRangeScale() {\n\t\treturn this.scales[this.rangeAxisPosition];\n\t}\n\n\t// Find the main x-axis out of the 2 x-axis on the chart (when 2D axis is used)\n\tgetMainXAxisPosition() {\n\t\tconst possibleXAxisPositions = [AxisPositions.BOTTOM, AxisPositions.TOP];\n\n\t\treturn [this.domainAxisPosition, this.rangeAxisPosition]\n\t\t\t.find(position => possibleXAxisPositions.indexOf(position) > -1);\n\t}\n\n\t// Find the main y-axis out of the 2 y-axis on the chart (when 2D axis is used)\n\tgetMainYAxisPosition() {\n\t\tconst possibleYAxisPositions = [AxisPositions.LEFT, AxisPositions.RIGHT];\n\n\t\treturn [this.domainAxisPosition, this.rangeAxisPosition]\n\t\t\t.find(position => possibleYAxisPositions.indexOf(position) > -1);\n\t}\n\n\tgetMainXScale() {\n\t\treturn this.scales[this.getMainXAxisPosition()];\n\t}\n\n\tgetMainYScale() {\n\t\treturn this.scales[this.getMainYAxisPosition()];\n\t}\n\n\tgetValueFromScale(axisPosition: AxisPositions, datum: any, index?: number) {\n\t\tconst value = isNaN(datum) ? datum.value : datum;\n\t\tconst scaleType = this.scaleTypes[axisPosition];\n\t\tconst scale = this.scales[axisPosition];\n\t\tif (scaleType === ScaleTypes.LABELS) {\n\t\t\tconst correspondingLabel = this.model.getDisplayData().labels[index];\n\t\t\treturn scale(correspondingLabel) + scale.step() / 2;\n\t\t} else if (scaleType === ScaleTypes.TIME) {\n\t\t\treturn scale(new Date(datum.date || datum.label));\n\t\t}\n\n\t\treturn scale(value);\n\t}\n\n\tgetDomainValue(d, i) {\n\t\treturn this.getValueFromScale(this.domainAxisPosition, d, i);\n\t}\n\n\tgetRangeValue(d, i) {\n\t\treturn this.getValueFromScale(this.rangeAxisPosition, d, i);\n\t}\n\n\t/** Uses the primary Y Axis to get data items associated with that value. */\n\tgetDataFromDomain(domainValue) {\n\t\tconst displayData = this.model.getDisplayData();\n\t\tconst activePoints = [];\n\t\tconst scaleType = this.scaleTypes[this.domainAxisPosition];\n\n\t\tswitch (scaleType) {\n\t\t\tcase ScaleTypes.LABELS:\n\t\t\t\t// based on labels we use the index to get the associated data\n\t\t\t\tconst index = displayData.labels.indexOf(domainValue);\n\n\t\t\t\tdisplayData.datasets.forEach(dataset => {\n\t\t\t\t\tactivePoints.push(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdatasetLabel: dataset.label,\n\t\t\t\t\t\t\tvalue: dataset.data[index],\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\tcase ScaleTypes.TIME:\n\t\t\t\t// time series we filter using the date\n\t\t\t\tconst domainKey = Object.keys(displayData.datasets[0].data[0]).filter(key => key !== \"value\" )[0];\n\n\t\t\t\tdisplayData.datasets.forEach(dataset => {\n\t\t\t\t\tconst sharedLabel = dataset.label;\n\n\t\t\t\t\t// filter the items in each dataset for the points associated with the Domain\n\t\t\t\t\tconst dataItems = dataset.data.filter(item => {\n\t\t\t\t\t\tconst date1 = new Date(item[domainKey]);\n\t\t\t\t\t\tconst date2 = new Date(domainValue);\n\t\t\t\t\t\treturn date1.getTime() === date2.getTime();\n\t\t\t\t\t});\n\n\t\t\t\t\t// assign the shared label on the data items and add them to the array\n\t\t\t\t\tdataItems.forEach(item => {\n\t\t\t\t\t\tactivePoints.push(\n\t\t\t\t\t\t\tObject.assign({datasetLabel: sharedLabel,\n\t\t\t\t\t\t\t\tvalue: item.value,\n\t\t\t\t\t\t\t}, item)\n\t\t\t\t\t\t);\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t}\n\t\treturn activePoints;\n\t}\n\n\tprotected getScaleDomain(axisPosition: AxisPositions) {\n\t\tconst options = this.model.getOptions();\n\t\tconst axisOptions = Tools.getProperty(options, \"axes\", axisPosition);\n\n\t\tconst { datasets, labels } = this.model.getDisplayData();\n\n\t\t// If scale is a LABELS scale, return some labels as the domain\n\t\tif (axisOptions && axisOptions.scaleType === ScaleTypes.LABELS) {\n\t\t\tif (labels) {\n\t\t\t\treturn labels;\n\t\t\t} else {\n\t\t\t\treturn this.model.getDisplayData().datasets[0].data.map((d, i) => i + 1);\n\t\t\t}\n\t\t}\n\n\t\t// Get the extent of the domain\n\t\tlet domain;\n\t\t// If the scale is stacked\n\t\tif (axisOptions.stacked) {\n\t\t\tdomain = extent(\n\t\t\t\tlabels.reduce((m, label: any, i) => {\n\t\t\t\t\tconst correspondingValues = datasets.map(dataset => {\n\t\t\t\t\t\treturn !isNaN(dataset.data[i]) ? dataset.data[i] : dataset.data[i].value;\n\t\t\t\t\t});\n\t\t\t\t\tconst totalValue = correspondingValues.reduce((a, b) => a + b, 0);\n\n\t\t\t\t\t// Save both the total value and the minimum\n\t\t\t\t\treturn m.concat(totalValue, min(correspondingValues));\n\t\t\t\t}, [])\n\t\t\t\t\t// Currently stack layouts in the library\n\t\t\t\t\t// Only support positive values\n\t\t\t\t\t.concat(0)\n\t\t\t);\n\t\t} else {\n\t\t\t// Get all the chart's data values in a flat array\n\t\t\tlet allDataValues = datasets.reduce((dataValues, dataset: any) => {\n\t\t\t\tdataset.data.forEach((datum: any) => {\n\t\t\t\t\tif (axisOptions.scaleType === ScaleTypes.TIME) {\n\t\t\t\t\t\tdataValues = dataValues.concat(datum.date);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tdataValues = dataValues.concat(isNaN(datum) ? datum.value : datum);\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\treturn dataValues;\n\t\t\t}, []);\n\n\t\t\tif (axisOptions.scaleType !== ScaleTypes.TIME) {\n\t\t\t\tallDataValues = allDataValues.concat(0);\n\t\t\t}\n\n\t\t\tdomain = extent(allDataValues);\n\t\t}\n\n\t\tif (axisOptions.scaleType === ScaleTypes.TIME) {\n\t\t\tconst spaceToAddToEdges = Tools.getProperty(options, \"timeScale\", \"addSpaceOnEdges\");\n\t\t\tif (spaceToAddToEdges) {\n\t\t\t\tconst startDate = new Date(domain[0]);\n\t\t\t\tconst endDate = new Date(domain[1]);\n\n\t\t\t\tif (differenceInYears(endDate, startDate) > 1) {\n\t\t\t\t\treturn [subYears(startDate, spaceToAddToEdges), addYears(endDate, spaceToAddToEdges)];\n\t\t\t\t}\n\n\t\t\t\tif (differenceInMonths(endDate, startDate) > 1) {\n\t\t\t\t\treturn [subMonths(startDate, spaceToAddToEdges), addMonths(endDate, spaceToAddToEdges)];\n\t\t\t\t}\n\n\t\t\t\tif (differenceInDays(endDate, startDate) > 1) {\n\t\t\t\t\treturn [subDays(startDate, spaceToAddToEdges), addDays(endDate, spaceToAddToEdges)];\n\t\t\t\t}\n\n\t\t\t\tif (differenceInHours(endDate, startDate) > 1) {\n\t\t\t\t\treturn [subHours(startDate, spaceToAddToEdges), addHours(endDate, spaceToAddToEdges)];\n\t\t\t\t}\n\n\t\t\t\tif (differenceInMinutes(endDate, startDate) > 1) {\n\t\t\t\t\treturn [subMinutes(startDate, spaceToAddToEdges), addMinutes(endDate, spaceToAddToEdges)];\n\t\t\t\t}\n\n\t\t\t\treturn [startDate, endDate];\n\t\t\t}\n\n\t\t\treturn [\n\t\t\t\tnew Date(domain[0]),\n\t\t\t\tnew Date(domain[1])\n\t\t\t];\n\t\t}\n\n\t\t// TODO - Work with design to improve logic\n\t\tdomain[1] = domain[1] * 1.1;\n\n\t\t// if the lower bound of the domain is less than 0, we want to add padding\n\t\tif (domain[0] < 0) {\n\t\t\tdomain[0] = domain[0] * 1.1;\n\t\t}\n\t\treturn domain;\n\t}\n\n\tprotected createScale(axisPosition: AxisPositions) {\n\t\tconst options = this.model.getOptions();\n\t\tconst axisOptions = Tools.getProperty(options, \"axes\", axisPosition);\n\n\t\tif (!axisOptions) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst scaleType = Tools.getProperty(axisOptions, \"scaleType\") || ScaleTypes.LINEAR;\n\t\tthis.scaleTypes[axisPosition] = scaleType;\n\n\t\t// Set the date/time locale\n\t\tif (scaleType === ScaleTypes.TIME) {\n\t\t\tconst timeLocale = Tools.getProperty(options, \"locale\", \"time\") || englishLocale;\n\n\t\t\ttimeFormatDefaultLocale(timeLocale);\n\t\t}\n\n\t\tlet scale;\n\t\tif (scaleType === ScaleTypes.TIME) {\n\t\t\tscale = scaleTime();\n\t\t} else if (scaleType === ScaleTypes.LOG) {\n\t\t\tscale = scaleLog().base(axisOptions.base || 10);\n\t\t} else if (scaleType === ScaleTypes.LABELS) {\n\t\t\tscale = scaleBand();\n\t\t} else {\n\t\t\tscale = scaleLinear();\n\t\t}\n\n\t\tscale.domain(this.getScaleDomain(axisPosition));\n\t\treturn scale;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"scales-cartesian.js","sourceRoot":"","sources":["scales-cartesian.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mBAAmB;AACnB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACjF,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,aAAa;AACb,OAAO,EACN,SAAS,EACT,WAAW,EACX,SAAS,EACT,QAAQ,EACR,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,aAAa,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SAAS,EAAE,CAAC;SACpB;aAAM;YACN,KAAK,GAAG,WAAW,EAAE,CAAC;SACtB;QAED,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CAAC;QAChD,OAAO,KAAK,CAAC;IACd,CAAC;IACF,sBAAC;AAAD,CAAC,AA/TD,CAAqC,OAAO,GA+T3C","sourcesContent":["// Internal Imports\nimport { Service } from \"./service\";\nimport { AxisPositions, CartesianOrientations, ScaleTypes } from \"../interfaces\";\nimport { Tools } from \"../tools\";\n\n// D3 Imports\nimport {\n\tscaleBand,\n\tscaleLinear,\n\tscaleTime,\n\tscaleLog\n} from \"d3-scale\";\nimport { min, extent } from \"d3-array\";\nimport { timeFormatDefaultLocale } from \"d3-time-format\";\nimport englishLocale from \"d3-time-format/locale/en-US.json\";\n\n// Misc\nimport {\n\tdifferenceInYears,\n\taddYears,\n\tsubYears,\n\tdifferenceInMonths,\n\taddMonths,\n\tsubMonths,\n\tdifferenceInDays,\n\taddDays,\n\tsubDays,\n\tdifferenceInHours,\n\taddHours,\n\tsubHours,\n\tdifferenceInMinutes,\n\taddMinutes,\n\tsubMinutes\n} from \"date-fns\";\n\nexport class CartesianScales extends Service {\n\tprotected scaleTypes = {\n\t\ttop: null,\n\t\tright: null,\n\t\tbottom: null,\n\t\tleft: null\n\t};\n\n\tprotected scales = {\n\t\ttop: null,\n\t\tright: null,\n\t\tbottom: null,\n\t\tleft: null\n\t};\n\n\tprotected domainAxisPosition: AxisPositions;\n\tprotected rangeAxisPosition: AxisPositions;\n\n\tprotected orientation: CartesianOrientations;\n\n\tgetDomainAxisPosition() {\n\t\treturn this.domainAxisPosition;\n\t}\n\n\tgetRangeAxisPosition() {\n\t\treturn this.rangeAxisPosition;\n\t}\n\n\tupdate(animate = true) {\n\t\tthis.determineOrientation();\n\t\tconst axisPositions = Object.keys(AxisPositions).map(axisPositionKey => AxisPositions[axisPositionKey]);\n\t\taxisPositions.forEach(axisPosition => {\n\t\t\tthis.scales[axisPosition] = this.createScale(axisPosition);\n\t\t});\n\t}\n\n\tdetermineOrientation() {\n\t\tconst options = this.model.getOptions();\n\n\t\t// Manually specifying positions here\n\t\t// In order to enforce a priority\n\t\t[\n\t\t\tAxisPositions.LEFT,\n\t\t\tAxisPositions.BOTTOM,\n\t\t\tAxisPositions.RIGHT,\n\t\t\tAxisPositions.TOP\n\t\t].forEach(axisPosition => {\n\t\t\tconst axisOptions = Tools.getProperty(options, \"axes\", axisPosition);\n\n\t\t\tif (axisOptions) {\n\t\t\t\tconst scaleType = axisOptions.scaleType || ScaleTypes.LINEAR;\n\t\t\t\tthis.scaleTypes[axisPosition] = scaleType;\n\n\t\t\t\tif (scaleType === ScaleTypes.LINEAR) {\n\t\t\t\t\tthis.rangeAxisPosition = axisPosition;\n\t\t\t\t} else {\n\t\t\t\t\tthis.domainAxisPosition = axisPosition;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tif (this.rangeAxisPosition === AxisPositions.LEFT && this.domainAxisPosition === AxisPositions.BOTTOM) {\n\t\t\tthis.orientation = CartesianOrientations.VERTICAL;\n\t\t} else {\n\t\t\tthis.orientation = CartesianOrientations.HORIZONTAL;\n\t\t}\n\t}\n\n\tgetOrientation() {\n\t\treturn this.orientation;\n\t}\n\n\tgetScaleByPosition(axisPosition: AxisPositions) {\n\t\treturn this.scales[axisPosition];\n\t}\n\n\tgetScaleTypeByPosition(axisPosition: AxisPositions) {\n\t\treturn this.scaleTypes[axisPosition];\n\t}\n\n\tgetDomainScale() {\n\t\treturn this.scales[this.domainAxisPosition];\n\t}\n\n\tgetRangeScale() {\n\t\treturn this.scales[this.rangeAxisPosition];\n\t}\n\n\t// Find the main x-axis out of the 2 x-axis on the chart (when 2D axis is used)\n\tgetMainXAxisPosition() {\n\t\tconst possibleXAxisPositions = [AxisPositions.BOTTOM, AxisPositions.TOP];\n\n\t\treturn [this.domainAxisPosition, this.rangeAxisPosition]\n\t\t\t.find(position => possibleXAxisPositions.indexOf(position) > -1);\n\t}\n\n\t// Find the main y-axis out of the 2 y-axis on the chart (when 2D axis is used)\n\tgetMainYAxisPosition() {\n\t\tconst possibleYAxisPositions = [AxisPositions.LEFT, AxisPositions.RIGHT];\n\n\t\treturn [this.domainAxisPosition, this.rangeAxisPosition]\n\t\t\t.find(position => possibleYAxisPositions.indexOf(position) > -1);\n\t}\n\n\tgetMainXScale() {\n\t\treturn this.scales[this.getMainXAxisPosition()];\n\t}\n\n\tgetMainYScale() {\n\t\treturn this.scales[this.getMainYAxisPosition()];\n\t}\n\n\tgetValueFromScale(axisPosition: AxisPositions, datum: any, index?: number) {\n\t\tconst value = isNaN(datum) ? datum.value : datum;\n\t\tconst scaleType = this.scaleTypes[axisPosition];\n\t\tconst scale = this.scales[axisPosition];\n\t\tif (scaleType === ScaleTypes.LABELS) {\n\t\t\tconst correspondingLabel = this.model.getDisplayData().labels[index];\n\t\t\treturn scale(correspondingLabel) + scale.step() / 2;\n\t\t} else if (scaleType === ScaleTypes.TIME) {\n\t\t\treturn scale(new Date(datum.date || datum.label));\n\t\t}\n\n\t\treturn scale(value);\n\t}\n\n\tgetDomainValue(d, i) {\n\t\treturn this.getValueFromScale(this.domainAxisPosition, d, i);\n\t}\n\n\tgetRangeValue(d, i) {\n\t\treturn this.getValueFromScale(this.rangeAxisPosition, d, i);\n\t}\n\n\t/** Uses the primary Y Axis to get data items associated with that value. */\n\tgetDataFromDomain(domainValue) {\n\t\tconst displayData = this.model.getDisplayData();\n\t\tconst activePoints = [];\n\t\tconst scaleType = this.scaleTypes[this.domainAxisPosition];\n\n\t\tswitch (scaleType) {\n\t\t\tcase ScaleTypes.LABELS:\n\t\t\t\t// based on labels we use the index to get the associated data\n\t\t\t\tconst index = displayData.labels.indexOf(domainValue);\n\n\t\t\t\tdisplayData.datasets.forEach(dataset => {\n\t\t\t\t\tactivePoints.push(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdatasetLabel: dataset.label,\n\t\t\t\t\t\t\tvalue: dataset.data[index],\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\tcase ScaleTypes.TIME:\n\t\t\t\t// time series we filter using the date\n\t\t\t\tconst domainKey = Object.keys(displayData.datasets[0].data[0]).filter(key => key !== \"value\" )[0];\n\n\t\t\t\tdisplayData.datasets.forEach(dataset => {\n\t\t\t\t\tconst sharedLabel = dataset.label;\n\n\t\t\t\t\t// filter the items in each dataset for the points associated with the Domain\n\t\t\t\t\tconst dataItems = dataset.data.filter(item => {\n\t\t\t\t\t\tconst date1 = new Date(item[domainKey]);\n\t\t\t\t\t\tconst date2 = new Date(domainValue);\n\t\t\t\t\t\treturn date1.getTime() === date2.getTime();\n\t\t\t\t\t});\n\n\t\t\t\t\t// assign the shared label on the data items and add them to the array\n\t\t\t\t\tdataItems.forEach(item => {\n\t\t\t\t\t\tactivePoints.push(\n\t\t\t\t\t\t\tObject.assign({datasetLabel: sharedLabel,\n\t\t\t\t\t\t\t\tvalue: item.value,\n\t\t\t\t\t\t\t}, item)\n\t\t\t\t\t\t);\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t}\n\t\treturn activePoints;\n\t}\n\n\tprotected getScaleDomain(axisPosition: AxisPositions) {\n\t\tconst options = this.model.getOptions();\n\t\tconst axisOptions = Tools.getProperty(options, \"axes\", axisPosition);\n\n\t\tconst { datasets, labels } = this.model.getDisplayData();\n\n\t\t// If scale is a LABELS scale, return some labels as the domain\n\t\tif (axisOptions && axisOptions.scaleType === ScaleTypes.LABELS) {\n\t\t\tif (labels) {\n\t\t\t\treturn labels;\n\t\t\t} else {\n\t\t\t\treturn this.model.getDisplayData().datasets[0].data.map((d, i) => i + 1);\n\t\t\t}\n\t\t}\n\n\t\t// Get the extent of the domain\n\t\tlet domain;\n\n\t\t// If domain is specified return that domain\n\t\tif (axisOptions.domain) {\n\t\t\treturn axisOptions.domain;\n\t\t}\n\n\t\t// If the scale is stacked\n\t\tif (axisOptions.stacked) {\n\t\t\tdomain = extent(\n\t\t\t\tlabels.reduce((m, label: any, i) => {\n\t\t\t\t\tconst correspondingValues = datasets.map(dataset => {\n\t\t\t\t\t\treturn !isNaN(dataset.data[i]) ? dataset.data[i] : dataset.data[i].value;\n\t\t\t\t\t});\n\t\t\t\t\tconst totalValue = correspondingValues.reduce((a, b) => a + b, 0);\n\n\t\t\t\t\t// Save both the total value and the minimum\n\t\t\t\t\treturn m.concat(totalValue, min(correspondingValues));\n\t\t\t\t}, [])\n\t\t\t\t\t// Currently stack layouts in the library\n\t\t\t\t\t// Only support positive values\n\t\t\t\t\t.concat(0)\n\t\t\t);\n\t\t} else {\n\t\t\t// Get all the chart's data values in a flat array\n\t\t\tlet allDataValues = datasets.reduce((dataValues, dataset: any) => {\n\t\t\t\tdataset.data.forEach((datum: any) => {\n\t\t\t\t\tif (axisOptions.scaleType === ScaleTypes.TIME) {\n\t\t\t\t\t\tdataValues = dataValues.concat(datum.date);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tdataValues = dataValues.concat(isNaN(datum) ? datum.value : datum);\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\treturn dataValues;\n\t\t\t}, []);\n\n\t\t\tif (axisOptions.scaleType !== ScaleTypes.TIME) {\n\t\t\t\tallDataValues = allDataValues.concat(0);\n\t\t\t}\n\n\t\t\tdomain = extent(allDataValues);\n\t\t}\n\n\t\tif (axisOptions.scaleType === ScaleTypes.TIME) {\n\t\t\tconst spaceToAddToEdges = Tools.getProperty(options, \"timeScale\", \"addSpaceOnEdges\");\n\t\t\tif (spaceToAddToEdges) {\n\t\t\t\tconst startDate = new Date(domain[0]);\n\t\t\t\tconst endDate = new Date(domain[1]);\n\n\t\t\t\tif (differenceInYears(endDate, startDate) > 1) {\n\t\t\t\t\treturn [subYears(startDate, spaceToAddToEdges), addYears(endDate, spaceToAddToEdges)];\n\t\t\t\t}\n\n\t\t\t\tif (differenceInMonths(endDate, startDate) > 1) {\n\t\t\t\t\treturn [subMonths(startDate, spaceToAddToEdges), addMonths(endDate, spaceToAddToEdges)];\n\t\t\t\t}\n\n\t\t\t\tif (differenceInDays(endDate, startDate) > 1) {\n\t\t\t\t\treturn [subDays(startDate, spaceToAddToEdges), addDays(endDate, spaceToAddToEdges)];\n\t\t\t\t}\n\n\t\t\t\tif (differenceInHours(endDate, startDate) > 1) {\n\t\t\t\t\treturn [subHours(startDate, spaceToAddToEdges), addHours(endDate, spaceToAddToEdges)];\n\t\t\t\t}\n\n\t\t\t\tif (differenceInMinutes(endDate, startDate) > 1) {\n\t\t\t\t\treturn [subMinutes(startDate, spaceToAddToEdges), addMinutes(endDate, spaceToAddToEdges)];\n\t\t\t\t}\n\n\t\t\t\treturn [startDate, endDate];\n\t\t\t}\n\n\t\t\treturn [\n\t\t\t\tnew Date(domain[0]),\n\t\t\t\tnew Date(domain[1])\n\t\t\t];\n\t\t}\n\n\t\t// TODO - Work with design to improve logic\n\t\tdomain[1] = domain[1] * 1.1;\n\n\t\t// if the lower bound of the domain is less than 0, we want to add padding\n\t\tif (domain[0] < 0) {\n\t\t\tdomain[0] = domain[0] * 1.1;\n\t\t}\n\t\treturn domain;\n\t}\n\n\tprotected createScale(axisPosition: AxisPositions) {\n\t\tconst options = this.model.getOptions();\n\t\tconst axisOptions = Tools.getProperty(options, \"axes\", axisPosition);\n\n\t\tif (!axisOptions) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst scaleType = Tools.getProperty(axisOptions, \"scaleType\") || ScaleTypes.LINEAR;\n\t\tthis.scaleTypes[axisPosition] = scaleType;\n\n\t\t// Set the date/time locale\n\t\tif (scaleType === ScaleTypes.TIME) {\n\t\t\tconst timeLocale = Tools.getProperty(options, \"locale\", \"time\") || englishLocale;\n\n\t\t\ttimeFormatDefaultLocale(timeLocale);\n\t\t}\n\n\t\tlet scale;\n\t\tif (scaleType === ScaleTypes.TIME) {\n\t\t\tscale = scaleTime();\n\t\t} else if (scaleType === ScaleTypes.LOG) {\n\t\t\tscale = scaleLog().base(axisOptions.base || 10);\n\t\t} else if (scaleType === ScaleTypes.LABELS) {\n\t\t\tscale = scaleBand();\n\t\t} else {\n\t\t\tscale = scaleLinear();\n\t\t}\n\n\t\tscale.domain(this.getScaleDomain(axisPosition));\n\t\treturn scale;\n\t}\n}\n"]}
|
package/tools.d.ts
CHANGED
package/tools.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Internal imports
|
|
2
2
|
import { CartesianOrientations } from "./interfaces";
|
|
3
|
-
import { debounce as lodashDebounce, merge as lodashMerge, cloneDeep as lodashCloneDeep, uniq as lodashUnique } from "lodash-es";
|
|
3
|
+
import { debounce as lodashDebounce, merge as lodashMerge, cloneDeep as lodashCloneDeep, uniq as lodashUnique, clamp as lodashClamp } from "lodash-es";
|
|
4
4
|
// Functions
|
|
5
5
|
export var Tools;
|
|
6
6
|
(function (Tools) {
|
|
@@ -9,6 +9,7 @@ export var Tools;
|
|
|
9
9
|
Tools.clone = lodashCloneDeep;
|
|
10
10
|
Tools.merge = lodashMerge;
|
|
11
11
|
Tools.removeArrayDuplicates = lodashUnique;
|
|
12
|
+
Tools.clamp = lodashClamp;
|
|
12
13
|
/**************************************
|
|
13
14
|
* DOM-related operations *
|
|
14
15
|
*************************************/
|
package/tools.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.js","sourceRoot":"","sources":["tools.ts"],"names":[],"mappings":"AAAA,mBAAmB;AACnB,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,EACN,QAAQ,IAAI,cAAc,EAC1B,KAAK,IAAI,WAAW,EACpB,SAAS,IAAI,eAAe,EAC5B,IAAI,IAAI,YAAY,EAIpB,MAAM,WAAW,CAAC;AAEnB,YAAY;AACZ,MAAM,KAAW,KAAK,CAgNrB;AAhND,WAAiB,KAAK;IACrB,qCAAqC;IACxB,cAAQ,GAAG,cAAc,CAAC;IAC1B,WAAK,GAAG,eAAe,CA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AAQ,EAAE;YACb,KAAmB,UAAQ,EAAR,qBAAQ,EAAR,sBAAQ,EAAR,IAAQ,EAAE;gBAAxB,IAAM,IAAI,iBAAA;gBACd,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,SAAS,EAAE;oBAC5D,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;iBAC1B;qBAAM;oBACN,OAAO,IAAI,CAAC;iBACZ;aACD;YACD,OAAO,QAAQ,CAAC;SAChB;QAED,OAAO,IAAI,CAAC;IACb,CAAC,CAAC;IASW,0CAAoC,GAAG,UAAC,mBAAuC,EAAE,WAAmC;QAChI,IAAI,WAAW,KAAK,qBAAqB,CAAC,UAAU,EAAE;YACrD,OAAO;gBACN,EAAE,EAAE,mBAAmB,CAAC,EAAE;gBAC1B,EAAE,EAAE,mBAAmB,CAAC,EAAE;gBAC1B,EAAE,EAAE,mBAAmB,CAAC,EAAE;gBAC1B,EAAE,EAAE,mBAAmB,CAAC,EAAE;aAC1B,CAAC;SACF;QAED,OAAO,mBAAmB,CAAC;IAC5B,CAAC,CAAC;IAEW,2BAAqB,GAAG,UAAC,mBAAuC,EAAE,WAAmC;QAC3G,IAAA,iFAA2F,EAAzF,UAAE,EAAE,UAAE,EAAE,UAAE,EAAE,UAA6E,CAAC;QAElG,OAAO,MAAI,EAAE,SAAI,EAAE,SAAI,EAAE,SAAI,EAAE,SAAI,EAAE,SAAI,EAAE,SAAI,EAAE,SAAI,EAAE,SAAI,EAAE,SAAI,EAAI,CAAC;IACvE,CAAC,CAAC;AACH,CAAC,EAhNgB,KAAK,KAAL,KAAK,QAgNrB","sourcesContent":["// Internal imports\nimport { CartesianOrientations } from \"./interfaces\";\n\nimport {\n\tdebounce as lodashDebounce,\n\tmerge as lodashMerge,\n\tcloneDeep as lodashCloneDeep,\n\tuniq as lodashUnique,\n\t// the imports below are needed because of typescript bug (error TS4029)\n\tCancelable,\n\tDebounceSettings\n} from \"lodash-es\";\n\n// Functions\nexport namespace Tools {\n\t// Export these functions from lodash\n\texport const debounce = lodashDebounce;\n\texport const clone = lodashCloneDeep;\n\texport const merge = lodashMerge;\n\texport const removeArrayDuplicates = lodashUnique;\n\n\t/**************************************\n\t * DOM-related operations *\n\t *************************************/\n\n\t/**\n\t * Get width & height of an element\n\t *\n\t * @export\n\t * @param {any} el element to get dimensions from\n\t * @returns an object containing the width and height of el\n\t */\n\texport function getDimensions(el) {\n\t\treturn {\n\t\t\twidth: parseFloat(el.style.width.replace(\"px\", \"\") || el.offsetWidth),\n\t\t\theight: parseFloat(el.style.height.replace(\"px\", \"\") || el.offsetHeight)\n\t\t};\n\t}\n\n\t/**\n\t * Returns an elements's x and y translations from attribute transform\n\t * @param {HTMLElement} element\n\t * @returns an object containing the x and y translations or null\n\t */\n\texport function getTranslationValues(elementRef: HTMLElement) {\n\t\t// regex to ONLY get values for translate (instead of all rotate, translate, skew, etc)\n\t\tconst translateRegex = /translate\\([0-9]+\\.?[0-9]*,[0-9]+\\.?[0-9]*\\)/;\n\n\t\tconst transformStr = elementRef.getAttribute(\"transform\").match(translateRegex);\n\t\t// check for the match\n\t\tif (transformStr[0]) {\n\t\t\tconst transforms = transformStr[0].replace(/translate\\(/, \"\").replace(/\\)/, \"\").split(\",\");\n\n\t\t\treturn {\n\t\t\t\t\ttx: transforms[0],\n\t\t\t\t\tty: transforms[1]\n\t\t\t\t};\n\t\t}\n\t\treturn null;\n\t}\n\n\t/**************************************\n\t * Formatting & calculations *\n\t *************************************/\n\n\t/**\n\t * Gets x and y coordinates from a HTML transform attribute\n\t *\n\t * @export\n\t * @param {any} string the transform attribute string ie. transform(x,y)\n\t * @returns Returns an object with x and y offsets of the transform\n\t */\n\texport function getTranformOffsets(string) {\n\t\tconst regExp = /\\(([^)]+)\\)/;\n\t\tconst match = regExp.exec(string)[1];\n\t\tconst xyString = match.split(\",\");\n\n\t\treturn {\n\t\t\tx: parseFloat(xyString[0]),\n\t\t\ty: parseFloat(xyString[1])\n\t\t};\n\t}\n\n\t/**\n\t * Capitalizes first letter of a string\n\t *\n\t * @export\n\t * @param {any} string the string whose first letter you'd like to capitalize\n\t * @returns The input string with its first letter capitalized\n\t */\n\texport function capitalizeFirstLetter(string) {\n\t\treturn string[0].toUpperCase() + string.slice(1);\n\t}\n\n\t/**\n\t * Get the percentage of a datapoint compared to the entire data-set.\n\t * Returns 1 significant digit if percentage is less than 1%.\n\t * @export\n\t * @param {any} item\n\t * @param {any} fullData\n\t * @returns The percentage in the form of a number\n\t */\n\texport function convertValueToPercentage(item, fullData) {\n\t\tconst percentage = item / fullData.reduce((accum, val) => accum + val.value, 0) * 100;\n\t\treturn percentage < 1 ? percentage.toPrecision(1) : Math.floor(percentage);\n\t}\n\n\t/**************************************\n\t * Object/array related checks *\n\t *************************************/\n\t/**\n\t * Get the difference between two arrays' items\n\t *\n\t * @export\n\t * @param {any[]} oldArray\n\t * @param {any[]} newArray\n\t * @returns The items missing in newArray from oldArray, and items added to newArray compared to oldArray\n\t */\n\texport function arrayDifferences(oldArray: any[], newArray: any[]) {\n\t\tconst difference = {\n\t\t\tmissing: [],\n\t\t\tadded: []\n\t\t};\n\n\t\toldArray.forEach(element => {\n\t\t\tif (newArray.indexOf(element) === -1) {\n\t\t\t\tdifference.missing.push(element);\n\t\t\t}\n\t\t});\n\n\t\tnewArray.forEach(element => {\n\t\t\tif (oldArray.indexOf(element) === -1) {\n\t\t\t\tdifference.added.push(element);\n\t\t\t}\n\t\t});\n\n\t\treturn difference;\n\t}\n\n\t/**\n\t * Lists out the duplicated keys in an array of data\n\t *\n\t * @export\n\t * @param {*} data - array of data\n\t * @returns A list of the duplicated keys in data\n\t */\n\texport function getDuplicateValues(arr: any) {\n\t\tconst values = [];\n\t\tconst duplicateValues = [];\n\n\t\tarr.forEach(value => {\n\t\t\tif (values.indexOf(value) !== -1 && duplicateValues.indexOf(value) === -1) {\n\t\t\t\tduplicateValues.push(value);\n\t\t\t}\n\n\t\t\tvalues.push(value);\n\t\t});\n\n\t\treturn duplicateValues;\n\t}\n\n\t// ================================================================================\n\t// D3 Extensions\n\t// ================================================================================\n\t/**\n\t * In D3, moves an element to the front of the canvas\n\t *\n\t * @export\n\t * @param {any} element\n\t * @returns The function to be used by D3 to push element to the top of the canvas\n\t */\n\texport function moveToFront(element) {\n\t\treturn element.each(function() {\n\t\t\tthis.parentNode.appendChild(this);\n\t\t});\n\t}\n\n\t// ================================================================================\n\t// Style Helpers\n\t// ================================================================================\n\n\texport const getProperty = (object, ...propPath) => {\n\t\tlet position = object;\n\t\tif (position) {\n\t\t\tfor (const prop of propPath) {\n\t\t\t\tif (position[prop] !== null && position[prop] !== undefined) {\n\t\t\t\t\tposition = position[prop];\n\t\t\t\t} else {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn position;\n\t\t}\n\n\t\treturn null;\n\t};\n\n\tinterface SVGPathCoordinates {\n\t\tx0: number;\n\t\tx1: number;\n\t\ty0: number;\n\t\ty1: number;\n\t}\n\n\texport const flipSVGCoordinatesBasedOnOrientation = (verticalCoordinates: SVGPathCoordinates, orientation?: CartesianOrientations) => {\n\t\tif (orientation === CartesianOrientations.HORIZONTAL) {\n\t\t\treturn {\n\t\t\t\ty0: verticalCoordinates.x0,\n\t\t\t\ty1: verticalCoordinates.x1,\n\t\t\t\tx0: verticalCoordinates.y0,\n\t\t\t\tx1: verticalCoordinates.y1\n\t\t\t};\n\t\t}\n\n\t\treturn verticalCoordinates;\n\t};\n\n\texport const generateSVGPathString = (verticalCoordinates: SVGPathCoordinates, orientation?: CartesianOrientations) => {\n\t\tconst { x0, x1, y0, y1 } = flipSVGCoordinatesBasedOnOrientation(verticalCoordinates, orientation);\n\n\t\treturn `M${x0},${y0}L${x0},${y1}L${x1},${y1}L${x1},${y0}L${x0},${y0}`;\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["tools.ts"],"names":[],"mappings":"AAAA,m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,OAAO,MAAI,EAAE,SAAI,EAAE,SAAI,EAAE,SAAI,EAAE,SAAI,EAAE,SAAI,EAAE,SAAI,EAAE,SAAI,EAAE,SAAI,EAAE,SAAI,EAAI,CAAC;IACvE,CAAC,CAAC;AACH,CAAC,EAjNgB,KAAK,KAAL,KAAK,QAiNrB","sourcesContent":["// Internal imports\nimport { CartesianOrientations } from \"./interfaces\";\n\nimport {\n\tdebounce as lodashDebounce,\n\tmerge as lodashMerge,\n\tcloneDeep as lodashCloneDeep,\n\tuniq as lodashUnique,\n\tclamp as lodashClamp,\n\t// the imports below are needed because of typescript bug (error TS4029)\n\tCancelable,\n\tDebounceSettings\n} from \"lodash-es\";\n\n// Functions\nexport namespace Tools {\n\t// Export these functions from lodash\n\texport const debounce = lodashDebounce;\n\texport const clone = lodashCloneDeep;\n\texport const merge = lodashMerge;\n\texport const removeArrayDuplicates = lodashUnique;\n\texport const clamp = lodashClamp;\n\n\t/**************************************\n\t * DOM-related operations *\n\t *************************************/\n\n\t/**\n\t * Get width & height of an element\n\t *\n\t * @export\n\t * @param {any} el element to get dimensions from\n\t * @returns an object containing the width and height of el\n\t */\n\texport function getDimensions(el) {\n\t\treturn {\n\t\t\twidth: parseFloat(el.style.width.replace(\"px\", \"\") || el.offsetWidth),\n\t\t\theight: parseFloat(el.style.height.replace(\"px\", \"\") || el.offsetHeight)\n\t\t};\n\t}\n\n\t/**\n\t * Returns an elements's x and y translations from attribute transform\n\t * @param {HTMLElement} element\n\t * @returns an object containing the x and y translations or null\n\t */\n\texport function getTranslationValues(elementRef: HTMLElement) {\n\t\t// regex to ONLY get values for translate (instead of all rotate, translate, skew, etc)\n\t\tconst translateRegex = /translate\\([0-9]+\\.?[0-9]*,[0-9]+\\.?[0-9]*\\)/;\n\n\t\tconst transformStr = elementRef.getAttribute(\"transform\").match(translateRegex);\n\t\t// check for the match\n\t\tif (transformStr[0]) {\n\t\t\tconst transforms = transformStr[0].replace(/translate\\(/, \"\").replace(/\\)/, \"\").split(\",\");\n\n\t\t\treturn {\n\t\t\t\ttx: transforms[0],\n\t\t\t\tty: transforms[1]\n\t\t\t};\n\t\t}\n\t\treturn null;\n\t}\n\n\t/**************************************\n\t * Formatting & calculations *\n\t *************************************/\n\n\t/**\n\t * Gets x and y coordinates from a HTML transform attribute\n\t *\n\t * @export\n\t * @param {any} string the transform attribute string ie. transform(x,y)\n\t * @returns Returns an object with x and y offsets of the transform\n\t */\n\texport function getTranformOffsets(string) {\n\t\tconst regExp = /\\(([^)]+)\\)/;\n\t\tconst match = regExp.exec(string)[1];\n\t\tconst xyString = match.split(\",\");\n\n\t\treturn {\n\t\t\tx: parseFloat(xyString[0]),\n\t\t\ty: parseFloat(xyString[1])\n\t\t};\n\t}\n\n\t/**\n\t * Capitalizes first letter of a string\n\t *\n\t * @export\n\t * @param {any} string the string whose first letter you'd like to capitalize\n\t * @returns The input string with its first letter capitalized\n\t */\n\texport function capitalizeFirstLetter(string) {\n\t\treturn string[0].toUpperCase() + string.slice(1);\n\t}\n\n\t/**\n\t * Get the percentage of a datapoint compared to the entire data-set.\n\t * Returns 1 significant digit if percentage is less than 1%.\n\t * @export\n\t * @param {any} item\n\t * @param {any} fullData\n\t * @returns The percentage in the form of a number\n\t */\n\texport function convertValueToPercentage(item, fullData) {\n\t\tconst percentage = item / fullData.reduce((accum, val) => accum + val.value, 0) * 100;\n\t\treturn percentage < 1 ? percentage.toPrecision(1) : Math.floor(percentage);\n\t}\n\n\t/**************************************\n\t * Object/array related checks *\n\t *************************************/\n\t/**\n\t * Get the difference between two arrays' items\n\t *\n\t * @export\n\t * @param {any[]} oldArray\n\t * @param {any[]} newArray\n\t * @returns The items missing in newArray from oldArray, and items added to newArray compared to oldArray\n\t */\n\texport function arrayDifferences(oldArray: any[], newArray: any[]) {\n\t\tconst difference = {\n\t\t\tmissing: [],\n\t\t\tadded: []\n\t\t};\n\n\t\toldArray.forEach(element => {\n\t\t\tif (newArray.indexOf(element) === -1) {\n\t\t\t\tdifference.missing.push(element);\n\t\t\t}\n\t\t});\n\n\t\tnewArray.forEach(element => {\n\t\t\tif (oldArray.indexOf(element) === -1) {\n\t\t\t\tdifference.added.push(element);\n\t\t\t}\n\t\t});\n\n\t\treturn difference;\n\t}\n\n\t/**\n\t * Lists out the duplicated keys in an array of data\n\t *\n\t * @export\n\t * @param {*} data - array of data\n\t * @returns A list of the duplicated keys in data\n\t */\n\texport function getDuplicateValues(arr: any) {\n\t\tconst values = [];\n\t\tconst duplicateValues = [];\n\n\t\tarr.forEach(value => {\n\t\t\tif (values.indexOf(value) !== -1 && duplicateValues.indexOf(value) === -1) {\n\t\t\t\tduplicateValues.push(value);\n\t\t\t}\n\n\t\t\tvalues.push(value);\n\t\t});\n\n\t\treturn duplicateValues;\n\t}\n\n\t// ================================================================================\n\t// D3 Extensions\n\t// ================================================================================\n\t/**\n\t * In D3, moves an element to the front of the canvas\n\t *\n\t * @export\n\t * @param {any} element\n\t * @returns The function to be used by D3 to push element to the top of the canvas\n\t */\n\texport function moveToFront(element) {\n\t\treturn element.each(function() {\n\t\t\tthis.parentNode.appendChild(this);\n\t\t});\n\t}\n\n\t// ================================================================================\n\t// Style Helpers\n\t// ================================================================================\n\n\texport const getProperty = (object, ...propPath) => {\n\t\tlet position = object;\n\t\tif (position) {\n\t\t\tfor (const prop of propPath) {\n\t\t\t\tif (position[prop] !== null && position[prop] !== undefined) {\n\t\t\t\t\tposition = position[prop];\n\t\t\t\t} else {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn position;\n\t\t}\n\n\t\treturn null;\n\t};\n\n\tinterface SVGPathCoordinates {\n\t\tx0: number;\n\t\tx1: number;\n\t\ty0: number;\n\t\ty1: number;\n\t}\n\n\texport const flipSVGCoordinatesBasedOnOrientation = (verticalCoordinates: SVGPathCoordinates, orientation?: CartesianOrientations) => {\n\t\tif (orientation === CartesianOrientations.HORIZONTAL) {\n\t\t\treturn {\n\t\t\t\ty0: verticalCoordinates.x0,\n\t\t\t\ty1: verticalCoordinates.x1,\n\t\t\t\tx0: verticalCoordinates.y0,\n\t\t\t\tx1: verticalCoordinates.y1\n\t\t\t};\n\t\t}\n\n\t\treturn verticalCoordinates;\n\t};\n\n\texport const generateSVGPathString = (verticalCoordinates: SVGPathCoordinates, orientation?: CartesianOrientations) => {\n\t\tconst { x0, x1, y0, y1 } = flipSVGCoordinatesBasedOnOrientation(verticalCoordinates, orientation);\n\n\t\treturn `M${x0},${y0}L${x0},${y1}L${x1},${y1}L${x1},${y0}L${x0},${y0}`;\n\t};\n}\n"]}
|