Skip to content

Commit

Permalink
build
Browse files Browse the repository at this point in the history
  • Loading branch information
emihul committed Jan 10, 2025
1 parent 3f67459 commit bc3175b
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 140 deletions.
19 changes: 11 additions & 8 deletions es/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
const Tooltip = _ref => {
let {
tooltip,
tooltipStyles,
tooltipCaretStyles
} = _ref;
return tooltip.item ? /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
style: {
style: _objectSpread({
display: tooltip.visible ? "block" : "none",
position: "fixed",
left: tooltip.position[0],
Expand All @@ -31,16 +36,15 @@ const Tooltip = _ref => {
borderRadius: "0.25rem",
fontSize: 14,
overflow: "hidden",
boxSizing: "border-box",
...tooltipStyles
}
boxSizing: "border-box"
}, tooltipStyles)
}, tooltip.item.customContent ? /*#__PURE__*/_react.default.createElement(_react.Fragment, null, tooltip.item.customContent) : /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement("span", {
style: {
display: "block",
overflow: "hidden"
}
}, tooltip.item.title), tooltip.item.number)), /*#__PURE__*/_react.default.createElement("div", {
style: {
style: _objectSpread({
display: tooltip.visible ? "block" : "none",
position: "fixed",
left: tooltip.caretPosition[0],
Expand All @@ -54,9 +58,8 @@ const Tooltip = _ref => {
borderRight: "0.5rem solid transparent",
borderTop: "0.5rem solid rgba(0,0,0,0.8)",
borderLeft: "0.5rem solid transparent",
boxSizing: "border-box",
...tooltipCaretStyles
}
boxSizing: "border-box"
}, tooltipCaretStyles)
})) : null;
};
Tooltip.propTypes = {
Expand Down
109 changes: 55 additions & 54 deletions es/Visualization.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,21 @@ var _Tooltip = _interopRequireDefault(require("./Tooltip"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
const Visualization = _ref => {
let {
item,
itemHeight = 54,
layout = "bars",
layout = 'bars',
treeGutter = 1,
disaggregate = true,
disaggregateBy = ["antall_kvinner", "antall_menn", "antall_ukjent_kjonn"],
disaggregateLabels = ["kvinner", "menn", "Ukjent kjonn"],
moreLabel = "Mer",
disaggregateBy = ['antall_kvinner', 'antall_menn', 'antall_ukjent_kjonn'],
disaggregateLabels = ['kvinner', 'menn', 'Ukjent kjonn'],
moreLabel = 'Mer',
colors = _utils.defaultColors,
tooltipContent,
tooltipStyles,
Expand All @@ -43,14 +48,13 @@ const Visualization = _ref => {
const sum = item.subItems.reduce((acc, cur) => {
if (cur.antall_personer) return acc + cur.antall_personer;else return acc + 0;
}, 0);
const treeData = item.subItems.map(cur => ({
...cur,
const treeData = item.subItems.map(cur => _objectSpread(_objectSpread({}, cur), {}, {
parent: item.parentId,
size: +cur.antall_personer,
total: +sum
})).concat([{
id: item.parentId,
parent: "",
parent: '',
antall_personer: +sum
}]);
const vLayout = (0, _d.treemap)().size([width - treeGutter * 2, height - treeGutter * 2]).padding(treeGutter);
Expand All @@ -65,56 +69,56 @@ const Visualization = _ref => {
const barAnimation3 = (0, _framerMotion.useAnimation)();
const textAnimation = (0, _framerMotion.useAnimation)();
const layoutChangeSequence = async () => {
const isBar = layout === "bars";
await textAnimation.start("isHidden");
await textAnimation.start(isBar ? "isBarPre" : "isTreePre");
const isBar = layout === 'bars';
await textAnimation.start('isHidden');
await textAnimation.start(isBar ? 'isBarPre' : 'isTreePre');
if (isBar) {
await barAnimation.start("isBar");
await barAnimation.start('isBar');
if (disaggregate) {
await Promise.all([barAnimation.start(disaggregate ? "isBarDisaggregated" : "isBar", {
await Promise.all([barAnimation.start(disaggregate ? 'isBarDisaggregated' : 'isBar', {
delay: 0,
duration: 0.2
}), barAnimation2.start(disaggregate ? "isBarDisaggregated" : "isBar", {
}), barAnimation2.start(disaggregate ? 'isBarDisaggregated' : 'isBar', {
delay: 0,
duration: 0.2
}), barAnimation3.start(disaggregate ? "isBarDisaggregated" : "isBar", {
}), barAnimation3.start(disaggregate ? 'isBarDisaggregated' : 'isBar', {
delay: 0,
duration: 0.2
})]);
}
return await textAnimation.start("isVisibleBar");
return await textAnimation.start('isVisibleBar');
} else {
if (disaggregate) {
await Promise.all([barAnimation.start("isBar", {
await Promise.all([barAnimation.start('isBar', {
delay: 0,
duration: 0.2
}), barAnimation2.start("isTree", {
}), barAnimation2.start('isTree', {
delay: 0,
duration: 0.2
}), barAnimation3.start("isTree", {
}), barAnimation3.start('isTree', {
delay: 0,
duration: 0.2
})]);
}
await barAnimation.start("isTree");
return await textAnimation.start("isVisibleTree");
await barAnimation.start('isTree');
return await textAnimation.start('isVisibleTree');
}
};
const widthChangeSequence = () => {
const isBar = layout === "bars";
textAnimation.start(isBar ? "isBarPre" : "isTreePre", {
const isBar = layout === 'bars';
textAnimation.start(isBar ? 'isBarPre' : 'isTreePre', {
duration: 0.1
});
barAnimation.start(isBar ? disaggregate ? "isBarDisaggregated" : "isBar" : "isTree", {
barAnimation.start(isBar ? disaggregate ? 'isBarDisaggregated' : 'isBar' : 'isTree', {
duration: 0.1
});
barAnimation2.start(isBar ? disaggregate ? "isBarDisaggregated" : "isBar" : "isTree", {
barAnimation2.start(isBar ? disaggregate ? 'isBarDisaggregated' : 'isBar' : 'isTree', {
duration: 0.1
});
barAnimation3.start(isBar ? disaggregate ? "isBarDisaggregated" : "isBar" : "isTree", {
barAnimation3.start(isBar ? disaggregate ? 'isBarDisaggregated' : 'isBar' : 'isTree', {
duration: 0.1
});
textAnimation.start("isVisibleBar", {
textAnimation.start('isVisibleBar', {
duration: 0.1
});
};
Expand Down Expand Up @@ -385,30 +389,30 @@ const Visualization = _ref => {
layoutChangeSequence();
}, [layout]);
(0, _react.useEffect)(() => {
if (layout === "tree") return;
if (layout === 'tree') return;
if (disaggregate) {
barAnimation.start("isBarDisaggregated", {
barAnimation.start('isBarDisaggregated', {
duration: 0.2,
delay: 0
});
barAnimation2.start("isBarDisaggregated", {
barAnimation2.start('isBarDisaggregated', {
duration: 0.2,
delay: 0
});
barAnimation3.start("isBarDisaggregated", {
barAnimation3.start('isBarDisaggregated', {
duration: 0.2,
delay: 0
});
} else {
barAnimation.start("isBar", {
barAnimation.start('isBar', {
duration: 0.2,
delay: 0
});
barAnimation2.start("isBar", {
barAnimation2.start('isBar', {
duration: 0.2,
delay: 0
});
barAnimation3.start("isBar", {
barAnimation3.start('isBar', {
duration: 0.2,
delay: 0
});
Expand All @@ -425,16 +429,16 @@ const Visualization = _ref => {
return /*#__PURE__*/_react.default.createElement("div", {
ref: viz,
style: {
position: "relative"
position: 'relative'
}
}, /*#__PURE__*/_react.default.createElement("svg", {
width: width,
height: height
}, datapoints.map((subItem, i) => {
const moreCount = subItem.data.data.count;
const title = subItem.data.data.retning === "uno_id2nus" ? subItem.data.data.nus_navn : subItem.data.data.retning === "uno_id2styrk08" ? subItem.data.data.styrk08_navn : subItem.data.data.retning === "nus_kortnavn2styrk08" ? subItem.data.data.styrk08_navn : subItem.data.data.retning === "uno_id2nus_kortnavn" ? subItem.data.data.nus_kortnavn : subItem.data.data.retning === "nus2styrk08" ? subItem.data.data.styrk08_navn : subItem.data.data.retning === "styrk082nus" ? subItem.data.data.nus_navn : "Mer";
const title = subItem.data.data.retning === 'uno_id2nus' ? subItem.data.data.nus_navn : subItem.data.data.retning === 'uno_id2styrk08' ? subItem.data.data.styrk08_navn : subItem.data.data.retning === 'nus_kortnavn2styrk08' ? subItem.data.data.styrk08_navn : subItem.data.data.retning === 'uno_id2nus_kortnavn' ? subItem.data.data.nus_kortnavn : subItem.data.data.retning === 'nus2styrk08' ? subItem.data.data.styrk08_navn : subItem.data.data.retning === 'styrk082nus' ? subItem.data.data.nus_navn : 'Mer';
let hideLabel = false;
if (title && title.replace(/"/g, "") === "Mer") {
if (title && title.replace(/"/g, '') === 'Mer') {
hideLabel = !moreCount;
}
return /*#__PURE__*/_react.default.createElement("g", {
Expand All @@ -447,10 +451,9 @@ const Visualization = _ref => {
height: itemHeight,
fill: "transparent",
style: {
pointerEvents: "none"
pointerEvents: 'none'
}
}), /*#__PURE__*/_react.default.createElement(_framerMotion.motion.rect, {
rx: "10",
custom: {
subItem,
i
Expand All @@ -460,7 +463,7 @@ const Visualization = _ref => {
variants: barVariants2,
onMouseEnter: evt => {
const title = subItem.data.data.styrk08_navn || subItem.data.data.tittel;
const number = disaggregate && layout === "bars" ? subItem.data.data[disaggregateBy[1]] + " " + disaggregateLabels[1] : subItem.data.data.antall_personer + " personer";
const number = disaggregate && layout === 'bars' ? subItem.data.data[disaggregateBy[1]] + ' ' + disaggregateLabels[1] : subItem.data.data.antall_personer + ' personer';
tooltip.show(evt, {
title,
number,
Expand All @@ -469,7 +472,6 @@ const Visualization = _ref => {
},
onMouseLeave: evt => tooltip.hide(evt)
}), /*#__PURE__*/_react.default.createElement(_framerMotion.motion.rect, {
rx: "10",
custom: {
subItem,
i
Expand All @@ -479,7 +481,7 @@ const Visualization = _ref => {
variants: barVariants3,
onMouseEnter: evt => {
const title = subItem.data.data.styrk08_navn || subItem.data.data.tittel;
const number = disaggregate && layout === "bars" ? subItem.data.data[disaggregateBy[2]] + " " + disaggregateLabels[2] : subItem.data.data.antall_personer + " personer";
const number = disaggregate && layout === 'bars' ? subItem.data.data[disaggregateBy[2]] + ' ' + disaggregateLabels[2] : subItem.data.data.antall_personer + ' personer';
tooltip.show(evt, {
title,
number,
Expand All @@ -488,7 +490,6 @@ const Visualization = _ref => {
},
onMouseLeave: evt => tooltip.hide(evt)
}), /*#__PURE__*/_react.default.createElement(_framerMotion.motion.rect, {
rx: "10",
custom: {
subItem,
i
Expand All @@ -497,8 +498,8 @@ const Visualization = _ref => {
animate: barAnimation,
variants: barVariants1,
onMouseEnter: evt => {
const cleanTitle = title.replace(/"/g, "");
const number = layout === "bars" ? disaggregate ? subItem.data.data[disaggregateBy[0]] + " " + disaggregateLabels[0] : subItem.data.data.antall_personer + " personer" : Math.round(100 / subItem.data.data.total * subItem.data.data.antall_personer * 10) / 10 + "%";
const cleanTitle = title.replace(/"/g, '');
const number = layout === 'bars' ? disaggregate ? subItem.data.data[disaggregateBy[0]] + ' ' + disaggregateLabels[0] : subItem.data.data.antall_personer + ' personer' : Math.round(100 / subItem.data.data.total * subItem.data.data.antall_personer * 10) / 10 + '%';
tooltip.show(evt, {
title: cleanTitle,
number,
Expand All @@ -509,7 +510,7 @@ const Visualization = _ref => {
}), !hideLabel && /*#__PURE__*/_react.default.createElement("foreignObject", {
fontSize: "14",
style: {
pointerEvents: "none",
pointerEvents: 'none',
overflow: 'visible',
width: '100%',
height: '100%'
Expand All @@ -523,15 +524,15 @@ const Visualization = _ref => {
i
},
style: {
width: "100%",
height: "100%",
overflow: "hidden",
textOverflow: "ellipsis",
whiteSpace: "nowrap",
color: layout === "bars" ? colors.text : colors.textTree,
padding: layout === "bars" ? 0 : "0.25rem"
width: '100%',
height: '100%',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
color: layout === 'bars' ? colors.text : colors.textTree,
padding: layout === 'bars' ? 0 : '0.25rem'
}
}, moreCount ? "+".concat(moreCount, " ") : "", title ? title.replace(/"/g, "") === "Mer" ? moreLabel : title.replace(/"/g, "") : null)));
}, moreCount ? "+".concat(moreCount, " ") : '', title ? title.replace(/"/g, '') === 'Mer' ? moreLabel : title.replace(/"/g, '') : null)));
})), /*#__PURE__*/_react.default.createElement(_Tooltip.default, {
tooltip: tooltip,
disaggregate: disaggregate,
Expand All @@ -543,7 +544,7 @@ const Visualization = _ref => {
Visualization.propTypes = {
item: _propTypes.default.object,
itemHeight: _propTypes.default.number,
layout: _propTypes.default.oneOf(["bars", "tree"]),
layout: _propTypes.default.oneOf(['bars', 'tree']),
treeGutter: _propTypes.default.number,
disaggregate: _propTypes.default.bool,
disaggregateBy: _propTypes.default.arrayOf(_propTypes.default.string),
Expand Down
Loading

0 comments on commit bc3175b

Please sign in to comment.