From 8c4c3cb143828ddb4669105732ef090002c57124 Mon Sep 17 00:00:00 2001 From: yangzhanmei <15809244435@163.com> Date: Thu, 9 Sep 2021 11:09:28 +0800 Subject: [PATCH] fix: sort when data undefined and refactor sort test (#237) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: :sparkles: add a demo page for test * Feat update g4.0 & optimize project config (#7) * feat: core first commit and update g-4.0 and lint fix * feat: add test demo & optimize scroll * feat: remove antv/util and process build script * feat: change entry name & rename dist * feat: make spec more readable * feat: add helper utils * perf: optimize scroll * fix: canvas blur when DPR changed (#10) * fix: cannot get current row data when click cell text (#12) * chore: add lint check for pre commit and push (#13) * chore: add lint check for pre commit and push * chore: ci adjust * refactor: ♻️ sync the logic of drill down (#16) * refactor: :recycle: sync the logic of drill down * fix: :green_heart: fix lint and change the rules of eslint' * chore:🛠 update lint rules and test stage (#17) * refactor: :recycle: sync the logic of drill down * fix: :green_heart: fix lint and change the rules of eslint' * feat: :seedling: add option builder * chore: :construction_worker: fix lint * chore: :wrench: add test stage pre-push * feat: tooltip refactor (#11) * feat: tooltip refactor * feat: modify comment * feat: modify tooltip classname and change components * feat: add intTooltip in options * fix: initTooltip's use * feat: delete normal-tooltip and strategy-tooltip class and decoupling calculation logic * fix: strategy-sheet initTooltip and some code refactor * refactor: some code type * refactor: code lint * refactor: code lint * style: code lint * style: change css of operator * feat: add tooltipComponent in options Co-authored-by: 蒺藜 * tooltip: fix TooltipCallback return type & add test & change to new way to use & add docs (#19) * feat: tooltip refactor * feat: modify comment * feat: modify tooltip classname and change components * feat: add intTooltip in options * fix: initTooltip's use * feat: delete normal-tooltip and strategy-tooltip class and decoupling calculation logic * fix: strategy-sheet initTooltip and some code refactor * refactor: some code type * refactor: code lint * refactor: code lint * style: code lint * style: change css of operator * feat: add tooltipComponent in options * fix: tooltipCallback return type * test: add tooltip test * feat: delete old way of show tooltip and change to new way * docs: add tooltip options Co-authored-by: 蒺藜 * Optimize render logic (#18) * fix: empty icon condition take place extra the area * fix: safety config and drill-down logic optimized * fix: drill-down tooltip * fix: filter null fieldValue * fix: calculate col width correctly * fix: remove code annotation header * feat: add max scroll bar height limit (#21) * fix: optimize warn lint (#23) * fix: optimize warn lint * fix: text file lint fix * fix: parse int scroll offset for resolve text shake close #20 (#24) * fix: parse int scroll offset for resolve text shake close #20 * fix: parseint x and y * fix: replace chinese comment * tree row header not allow null/undefined node (#26) * fix: tre row header not allow null/undefined node * fix: fix lint warn * fix: format header label and add default col hierarchy height (#27) * fix: show table structure when miss cols/values (#28) * fix: show table structure when miss cols/values * fix: lint optimize * feat: ✨ Add the export and header components (#29) * feat: :sparkles: Allow users to customize the drill-down level * fix: :bug: Replace the default id separator of node * feat: :sparkles: Export the mouse event for cell click events * feat: :sparkles: Add the header component * feat: :sparkles: Add export components * chore: :bulb: translate the comments * fix: resolve table blur when browser zoom (#35) * fix: measure number text width not correct (#37) * fix: error type fixed (#38) * fix: error type fixed * fix: upgrade lint config * fix: optimize the type * fix: cannot get correctly row data for tree hierarchy type (#39) * chore: add ding talk pr notify (#42) * fix: get wrong thumb offset top when container height changed (#43) * fix: get wrong thumb offset top when container height changed * fix: lint warning * fix: remove useless notify option (#44) * fix: adjust pr notify event (#45) * feat: adjust tree menu layout (#47) * fix: disable mobile rerender for zoom (#46) * fix: :bug: solve the issue of copy failure of detail table without c… (#48) * fix: :bug: solve the issue of copy failure of detail table without column. this close #32, close #31 * fix: :poop: [export]replace the success message with the error message * fix: [export] solve the type error (#49) * fix: :bug: solve the issue of copy failure of detail table without column. this close #32, close #31 * fix: :poop: [export]replace the success message with the error message * fix: :poop: [export] solve the type error * refactor: :recycle: add the function to get the state of derivedData (#50) * feat: ✨ enable users to customize the layout by specific rows or columns header labels (#51) * feat: :sparkles: enable users to customize the layout by specific rows or columns header labels * test: :white_check_mark: add a test for the feautre of custom layout * revert: :rewind: revert bd740b93c9d3b326c1bdfb2ffc27fafed3f0a921 This reverts commit bd740b93c9d3b326c1bdfb2ffc27fafed3f0a921. * refactor: 🏗️ reorganize the file structure of components (#52) * refactor: :building_construction: reorganize the file structure of components * chore: :wrench: set alias for webpack, jest and tsconfig * feat: make render more rational (#55) * fix: remove place-holder related logic * fix: unregister scrollbar event listener * feat: render cell with delay and unregister wheel event correctly * fix: cells don't need cache&remove cells in panelGroup when leave the screen * feat: ✨ enable users to customize the layout by specific rows or columns header labels (#57) * feat: :sparkles: enable users to customize the layout by specific rows or columns header labels * test: :white_check_mark: add a test for the feautre of custom layout * test: :white_check_mark: update the test for cutom header cell * chore: 🔧 update webpack4 to webpack5 (#58) * chore: :wrench: update webpack4 to webpack5 * chore: :wrench: update the lint.yml * fix(cell): :bug: text max width calculate error (#59) * feat: refactor the interaction (#14) * feature: interaction first * feat: interaction first * feat: 取消HoverBox * feat: 建立stateShape来统一管理show或者hide * feat: del hover box * feat: del cell-hover * feat: cell-selection * feat: corner-header-text-click 改为event监听 * feat: delHeaderHover * feat: resize * feat: col-selection * feat: row-header-text-click * feat: del _ * feat: event独立 * feat: events抽离 and datacell-muti-selection * feat: events抽离 and datacell-muti-selection * feat: col-row-select * change summary to summaries and add some mock data (#30) * feat: tooltip refactor * feat: modify comment * feat: modify tooltip classname and change components * feat: add intTooltip in options * fix: initTooltip's use * feat: delete normal-tooltip and strategy-tooltip class and decoupling calculation logic * fix: strategy-sheet initTooltip and some code refactor * refactor: some code type * refactor: code lint * refactor: code lint * style: code lint * style: change css of operator * feat: add tooltipComponent in options * fix: tooltipCallback return type * test: add tooltip test * feat: delete old way of show tooltip and change to new way * docs: add tooltip options * feat: change summary to summaries and add some mock data Co-authored-by: 蒺藜 * feat: cell-click and col row click tooltip * feat: col-muti-tooltip * feat: tooltip适配 * feat: tooltip * feat: 适配挂行头 * fix: interceptevent控制放在base-spread-sheet * fix: lint * feat: keep-hover state以及 hover独立拆分 * feat: getAllPanelCells修复为过滤不在视图内的cell, hover的十字样式 * feat: test * feat: test * feat: 准备把cellIndex改为colIndex * feat: fix some commit and 准备调试draw * fix: 修复格式问题,准备适配keep-hover * fix: fix som commits * fix: 修复一些commit问题 * fix: 修复commit问题 * fix: lint * fix: lint * feat: add todo Co-authored-by: maosong.wz Co-authored-by: yangzhanmei <15809244435@163.com> Co-authored-by: 蒺藜 * optimize core logic (#60) * fix: remove strategy related things * feat: convergence S2Options & S2DataConfig * feat: convergence S2Options & S2DataConfig * feat: adapt freezeRowHeader and mode with better logic * feat: merge interaction core codes * fix: adjust some logic * fix: adjust some logic * feat: ✨ add pagination (#61) * feat: :sparkles: add pagination * fix: :bug: import LruCache * ci: :green_heart: fix ci * ci: :green_heart: delete useless values * fix: 🐛 stop automatically changing numbers to dates when copying … (#64) * fix: :bug: stop automatically changing numbers to dates when copying data * refactor: :recycle: code optimization * fix: new data transform and fetch * feat: merge data-set and pivot into data-set * feat: add pivot-data-set * feat: only keep SpreadSheet(old files will deleted when covered) * feat: move valueInCols to Fields * feat: reconstruct facet logic * fix: visible cell min index * feat: render pressure in 100W and 10W data * feat: adapt all data scene in single measure * fix: tree mode error * feat: re-design header layout * feat: adjust file structure * feat: data-set get data need be array * feat: ✨ add the tabular mode (#65) * feat: :sparkles: add tabular sheet * feat: :sparkles: draw custom data cell for tabular sheet * fix: :bug: enable the tooltip to render custom element * refactor: :recycle: redefine the interface and constant for interaction * fix: :bug: solved the issue that the wwidth of the data cell could not be adpative * feat: :sparkles: draw the background of merged cells * feat: :sparkles: add Class of MergedCells * feat: :sparkles: add events for the MergedCells * feat: :sparkles: draw text for merged cells * feat: :sparkles: draw merged cells by setting options * chore: :wrench: update the lerna configuration * chore: :wrench: update the package.json * chore: :green_heart: fix ci * chore: :white_check_mark: add the test case for cells merging * chore: :green_heart: fix ci * feat: complete data accuracy * feat: add getMultiData to get row/col data * feat: update derived values config * feat: new layout design * fix: fix some type problem * fix: fix undefined * refactor: :building_construction: reorganize the file structure of interface (#69) * Rename S2Options.ts to s2Options.ts * Rename S2DataConfig.ts to s2DataConfig.ts * fix: get multi data add isTotals to query * feat: remove all backup files * feat: adjust grand total node key field * fix: lint error * fix: lint error * feat: get cell data only return a single data * test: ✅ add unit test for pivot dataset (#70) * chore: add test config * test: add test for pivotDataset * fix: row tree type cell wrong leaf nodes * fix: row tree type cell wrong leaf nodes * test: ✅ add more unit test (#71) * chore: add test config * test: add test for pivotDataset * chore: add test script * chore: refine package.json, remove duplicated config * test: add test for i18n * test: add test for store * chore: refine test structure * test: ✅ add unit test for pivot dataset (#70) * chore: add test config * test: add test for pivotDataset * fix: row tree type cell wrong leaf nodes * fix: row tree type cell wrong leaf nodes * chore: update test regex * chore: add test script * chore: refine package.json, remove duplicated config * test: add test for i18n * test: add test for store * chore: refine test structure * test: ✅ add unit test for pivot dataset (#70) * chore: add test config * test: add test for pivotDataset * chore: update test regex Co-authored-by: brucetoo * fix: cannot get correct row data (#72) * chore: ✅ add unit test for state (#73) * fix: fix test files path in scripts * test: add test for state * fix: add colRealWidthInfo type in StoreKey, remove corresponding constant variable * test: 增加交互式测试脚本 (#74) * chore: update test-live script (#75) * Tree row support part drill down (#76) * feat: prepare drill-down spec * feat: add drill-down support * feat: handle tree row collapse state * feat: limit drill down data by drillItemsNum * fix: lint error * fix: add rowNode cell test * feat: remove something * fix: cr problems * fix: cr problems * fix: cr problem * feat: hide measure col (#82) * fix: all lint error(for use) * feat: hide measure in col * fix: path import order * fix: total node rows use origin rows config * refactor: optimize base sheet type (#85) * refactor: optimize base sheet type * refactor: add events constant file * feat: 增加lodash.get类型判断 (#91) * add sort feature and test (#81) * feat: add sort * test: add sort spread test * fix: compat sort and data-set * test: add some sort tests * style: lodash import change * feat: add totalData in pviot data set * test: add total test in pviot data set * fix: get values of row tree * test: complete pivot data set test * test: add data sort's totalData * refactor: rename sortByField to sortByMeasure * feat: add measure is total col or row when sort and refactor some function * refactor: optimize sort action function * test: add data-set-operate test and sort action test * test: add totalData item * test: optimize sort sheet test * test: optimize pivot sort data test about query muilty data with total value * test: add pivot sort data unit test * refactor: totalData safety * refactor: add comments about sort priority * refactor: merge add extra value of data and totalData * refactor: rename pivot data set test * refactor: change sortByMeasure to TOTAL_VALUE when sort by total * fix: change node's isTotals when row tree hierarchy * style: lint * refactor: optimize data set code (#94) * test: optimize data accuracy test (#95) * feat: row header support custom tree (#100) * feat: support custom row tree * feat: optimize custom tree process * feat: optimize code logic * feat: optimize code logic * 明细表基本流程 (#99) * fix: using rollup-typescript2 * feat: detail table refactor * feat: delete unused table mode file * feat: add series number for table mode * feat: update package-lock.json * feat: 合并最新代码 * feat: add unit test and fix pr * fix: table hierarchy unit test Co-authored-by: xinhui.zxh * refactor(scroll): 🚀 optimize scroll performace (#101) * refactor(scroll): 🚀 optimize scroll performace * fix: cannot scroll * fix: optimize test * refactor: optimize scroll performace for scroll bar * fix: type issue * fix: wheel types (#107) * ✨ 迁移指标切换组件 (#108) * feat: 迁移 dimension switch 组件 * fix: 样式修改 * refactor: unify classnames * refactor: add className props * test: add ut for dimension switch * test: add ut for dimension switch hook * feat: ✨ refactor the default theme and add new themes (#109) * refactor: :building_construction: reorgnaize the file structure of the constant * refactor: :recycle: redefine the theme token * refactor: :recycle: replace the theme token for pivot table * fix: :bug: replace the new theme token * fix: :bug: solve the issue that the canvas draw empty cells * refactor: :recycle: redesign the theme tokon based on the palette * chore: :green_heart: fix some lint issues * feat: :sparkles: add the opacity for the theme token * style: :lipstick: tweak the style of the corner cell * feat: :sparkles: allow custom the text alignment in grid mode * chore: :white_check_mark: add the test for the text util * refactor: update the theme interface * style: :lipstick: tweak the default style * style: :lipstick: tweak the style of the colHeader * chore: :white_check_mark: add the test for theme switch * feat: :sparkles: add the simple-blue palette * fix: :bug: tweak the style of interaction * fix: :pencil2: tweak the corner width * test: :white_check_mark: fix test error * fix: :bug: fix the test crush * fix: :pencil2: fix the theme type * chore: :speech_balloon: update the anotation of the palettesemantic * chore: fix some issues of code style * refactor: fix the type define of padding * Refact layout hooks (#112) * feat: refactor layout hooks * fix: table spec not work * feat: adapt layout hooks and add spec * feat: add spec * feat: support tree/grid mode * fix: change to GetCellMeta * fix: merge data process * fix: coordinate hook use 70px * fix: fix pr problems * fix: global jest dep AND scroll bug (#114) * fix: global jest dep AND scroll bug * fix: merge data-process Co-authored-by: wengyidong.wyd * 明细表适配主题 (#115) * fix: table mode number align * fix: cell and sheet type circular references * fix: 明细表适配 theme * fix: update build-table-hierarchy-spec snapshot && fix corner style * fix: update d.ts file path * fix: 明细表主题适配调整 Co-authored-by: xinhui.zxh * fix: data coordinate wrong (#116) * refactor: ♻️ optimize type definitions and the theme map of the interation (#117) * refactor: :recycle: optimize type definitions and the theme map of the interaction * refactor: :speech_balloon: rename the CellTypes * refactor: :recycle: optimize the getCellType function * refactor: :recycle: unified the constant naming * fix: 🐛 solve the state error of interaction (#119) * refactor: :recycle: optimize type definitions and the theme map of the interaction * refactor: :speech_balloon: rename the CellTypes * refactor: :recycle: optimize the getCellType function * refactor: :recycle: unified the constant naming * fix: :bug: fix the type error * style: :lipstick: tweak the style of interaction state * fix: :bug: solved the issue of generating wrong colIndex * chore: :art: optimize the code logic * chore: :pencil2: fix typos and reorgnize the constant of the interaction * fix: prettier all files (#121) Co-authored-by: wengyidong.wyd * feat: sort action process (#122) * refactor: ♻️ merge the state into the store as an attribute (#124) * refactore: :recycle: merger the state class into the store as an attribute * chore: :white_check_mark: add the test for the state-controller util * refactor: :recycle: reorganize the file struncture of event type * fix: :bug: replace the wrong refer (#125) * feat: prettier files (#123) * feat: prettier files * chore: fix lint * chore: run lint globally Co-authored-by: yingying.xwy * feat: add copy feat and add S2Range interface (#120) * feat: add copy feat and add S2Range interface * fix: 工具函数移动 以及修复空cell导致的问题 * fix: 工具函数移动 以及修复空cell导致的问题 * fix: delete useless code * fix: 二维数组格式优化 * fix: add enable switch * fix: change name 'S2Range' to 'S2CellBrushRange' Co-authored-by: wengyidong.wyd * feat: add standard data (#126) * feat: add standard data process * fix: remove some words * feat: ✨ add the hover event for the row cell and the col cell (#128) * feat: :sparkles: add hover event for the row cell and the col cell * refactor: :recycle: optimize the code * fix: circular dependency (#130) * feat(interaction): ✨ selected cells spotlight (#129) * feat(interaction): selected cells spotlight * fix: remove console * refactor(interfaction): 置灰非选中项 适配 单/多/刷选, 行列头批量选中 * refactor(interfaction): 交互层从 Spreadsheet 独立出来 * refactor(interfaction): 交互层从 Spreadsheet 独立出来 * refactor: 初步移除 derivedValues 配置 (#113) * fix: fix typo * fix: fieldValue类型重命名 * test: add test file * feat: 初步干掉 derivedValues配置 * test: 为 condition 添加单测 * refactor: 重命名衍生指标字段 * refactor: 适配 theme * refactor: 移除单元格绘制部分的衍生指标逻辑 * test: 修复单测配置更新方式 * fix: 修复icon在右侧时margin计算 * refactor: change import path * refactor: 移除无用文件 * refactor: 修复测试报错 * refactor: 移除sheet中衍生指标方法 * refactor: refine layout logic * fix: fix content content area logic * test: add ut for sheet usage * fix: rename getIconPosition to getIconLayoutPoistion * fix: fix text condition logic * refactor: extract icon into constant file * feat: add cb for filter display item * feat: add mapding callback for tooltio display * refactor: deal with multiple data item when shows tooltip * refactor: simplify facet config declaration * test: correct test datacfg * fix: fix import issue in detal row cell * refactor: remove unused cfg, add annotation for util function * refactor(types): optimize code and large type errors (#132) * refactor(types): optimize large type errors * refactor(types): rename theme cell unselect => outOfTheSpotlight * refactor(types): remove type * refactor(types): modify name and type * refactor(tooltip): remove tooltip repeat funcs (#135) * refactor(tooltip): remove tooltip repeat funcs * refactor(tooltip): i18n * refactor(tooltip): group tooltip options * refactor(tooltip): dont't calculate when disable tooltip * refactor(tooltip): rename ev => event * refactor: ♻️ reorganize the logic of the state switching (#138) * refactor: :recycle: reorganize the logic of the interaction state change and adapted the click event * refactor: :recycle: add type definition and optimize the brush selection * fix(theme): :pencil2: fix type error * refactor: :art: optimize the state change of row-column-click * fix: :bug: solve the issue that the incomplete multi-select cells in the row and column headers * refactor: :art: optimaze the logic of data-cell-multi-selection * fix: :bug: solve the issue that the col-row-multi-selection doesn't work * fix: :bug: solve the hover interaction state changing for the rowHeader and colHeader * feat: :sparkles: highlight all the header cells to which the hovering cell belongs * refactor: art: optimize the call logic of some state-contronller functions * fea: :sparkles: add hover highlight switcher * refactor(interfaction): rewrite brush selection close #118 (#139) * refactor(interfaction): rewrite brush selection close #118 * refactor(interfaction): remove chunk * fix(interfaction): cannot stop brush when get cell info faild * fix(interfaction): remove draw * fix(interfaction): resolve conflect * fix(interfaction): rename brush stage * fix: :bug: fix the hover highlighting error for the detail table (#142) * feat(interaction): support unselect cell by esc keyborad (#143) * feat(interaction): support unselect cell by esc keyborad * fix(interaction): remove annotation * fix(interaction): miss keyborad key * fix(interaction): remove useless import * fix(interaction): optimize init prepare select mask * fix: table mode sort icon and linkFieldIds (#137) * fix: add table data cell for links and fix sort icon * fix: build table hierarchy test * fix: ts error * fix: rm duplicate type * fix: rm console and update render method * fix: revert code * refactor: extract renderIcon func * fix: icon re-selectin Co-authored-by: xinhui.zxh * refactor(cell): unify cell functions (#136) * refactor: fix updateShapeAttr type define * refactor: refine getCellType to getter * refactor: add header cell class * refactor: rename detail row cell to detail data cell * refactor: refine function declaration in data cell * refactor: refine merge cell constructor * refactor: unify stateShapes * refactor: refactor render util function * refactor: unify interaction state * refactor: extract link text variable to theme config * refactor: rename interactive shape * chore: close loop for test:live * fix: remove blue color, add link field color into brand colors * fix: 🐛 optimize some details of the interaction when scrolling (#148) * fix: :bug: keep the selected state when the selected data cells scroll out of the viewport * fix: :bug: hde the tooltip when scrolling * fix: :bug: cancel the hover state of header cells when scrolling * fix: :art: optimize the highlight state for the row header cells in tree mode * fix: :bug: fix the test of merge-cells-spec * feat(interaction): support brush selection mouse slides off the table (#146) * fix(interaction): support brush selection mouse slides off the table * fix(interaction): rename * fix(interaction): add common resizer func * fix(interaction): add brush selection intercept * fix(interaction): update mouse on the tooltip judgement * fix(interaction): remove useless vars * fix(interaction): remove useless store key * feat: add unselected style for conditions (#149) * refactor: fix updateShapeAttr type define * refactor: refine getCellType to getter * refactor: add header cell class * refactor: rename detail row cell to detail data cell * refactor: refine function declaration in data cell * refactor: refine merge cell constructor * refactor: unify stateShapes * refactor: refactor render util function * refactor: unify interaction state * refactor: extract link text variable to theme config * refactor: rename interactive shape * chore: close loop for test:live * fix: remove blue color, add link field color into brand colors * refactor(condition): extract condition type into single file * refactor(condition): extract condition class * fix(interaction): brush selection shake (#152) * fix(interaction): fix brush selection cell shake * fix(interaction): remove console * chore: no console (#153) * chore: :fire: remove useless color schema (#155) * fix: brush selection range mask not show when rerender (#156) * refactor: ♻️ refactor the render logic of series-number (#151) * refactor: :recycle: refactor the render logic of series-number * fix: :bug: fix the error theme referrence of the border of series number cell * refactor: :art: simplify the render condition for series-number cells * feat: adapt condition arch (#157) Co-authored-by: xinhui.zxh * feat: hd adapter (#154) * feat: hd adapter * fix: mouse on the canvas compatible with hd mode * fix: remove pagination const * fix: update tooltip class prefix * fix: add common class prefix * fix: alias * fix(interaction): unbind all interaction event when destroyed (#160) * fix(interaction): unbind all interaction event when destroyed * fix(interaction): remove extra deps * fix(interaction): remove useless var * fix(dataset): getDimensionValues return empty when second field in compact mode. (#162) * refactor(intetraction): optimize interfaction event implement (#164) * feat: get tooltip data of new interaction and optimize tooltip display, add spread-sheet tooltip test (#158) * refactor: optimize summary display * fix: change tooltip get data of new interaction * docs: add todo message in util/tooltip * refactor: optimize tooltip's display * feat: get tooltip data of new interaction * test: spread-sheet add tooltip test * refactor: code optimize * test: add tooltip demo checked * refactor: optimize tooltip data get and test * refactor: optimize code in tooltip util * refactor: optimize precision and import write * fix: display name when field is in values * refactor: add new line in basic * Complete internal table sort (#167) * feat: quick sort for table fact AND make eventemitter typesafe * fix: complete eventemitter type AND add RANGE_SORTED event emit * fix: some PR issue * fix: some PR issue Co-authored-by: wengyidong.wyd * fix: fix some error emitter type (#170) * feat: ✨ add selected state for the header cells (#165) * fix: :bug: fix the wrong selected cells numbers in detail table mode * fix: :art: cancle the selected state when users click the column cells or row cells again * refactor: :art: optimize the logic of hover state for header cells * feat: :sparkles: add selected state for the header celss * refactor: :recycle: merge the col-row-multi-selection into the row-column-click event * chore: :fire: remove the col-row-multi-selection * fix: :bug: fix the wrong selected state theme of header cells * refactor: :zap: reading the cells from the cache when clear all the interaction state style * fix: :bug: change the state for all the selected header cells including rendered and not rendered * fix: :bug: fix the multi-select * chore: :art: optimize the code logic of multi-click * fix: proofread scroll offset before each render (#171) * feat: refine drawText logic (#163) * refactor: rename defaultConditionValues * feat: make icon follow text * test: add test for text and icon alignment * fix: fix condition priority for indicate values * refactor: reorganize file structure * feat: refine drawTextShape logic * feat: compatible with table mode * chore: add annotation * test: fix unit test * fix: custom cell use getFormattedFieldValue instead of getData * refactor: unify import path, rename icon function * fix: import type * refactor: update annotation * feat: ✨ enable user to register custom interaction & refactor the interaction (#174) * refactor: :building_construction: reorganize the file struncture of interaction * refactor: :recycle: rename the constant and interface of interaction * feat: :sparkles: enable user to register custom interaction * style: :art: optimaiz the code style * chore: :recycle: rename the InterceptInteraction to Intercept * test(cross-table): tests for data-process (#172) * test: add transform indexes data test * test:交叉表核心数据流程测试 * test(cross-table): 交叉表核心数据流程测试 * fix: rm useless file * test(spreadsheet): 修改数据引用方式 * fix: table mode scroll error (#175) Co-authored-by: xinhui.zxh * refactor: group event (#173) * refactor: group event * fix: some import error * fix: rename interaction name * fix: miss InterceptType * fix: move to basic * fix: import error * fix: add base event abstract * fix: correct corner cell width (#179) * chore: change the sort event name (#183) * fix: sort event name change * fix: sort event name change Co-authored-by: wengyidong.wyd * refactor(list-table): rm table facet row hierarchy (#182) * chore: 🏗️ move the tooltip and hd-adapter into the ui and update the LICENSE (#180) * chore: :page_facing_up: update the LICENSE * chore: :building_construction: move the tooltip and hd-adapter into the ui * chore: :memo: add i18n for the group order * feat: add prettierrc in eslintrc file (#184) * feat: add prettierrc in eslintrc file * fix: lock prettier version * fix: 2.3.2 Co-authored-by: wengyidong.wyd * refactor: optimize interaction and cell logic (#185) * refactor: optimize interaction and cell logic * refactor: optimize text padding logic * fix: theme issue for table mode (#181) * fix: table mode scroll error * fix: table mode theme * fix: table row cell style * fix: rm console Co-authored-by: xinhui.zxh * feat: refine interval condition (#178) * feat: add interval condition for data cell * test: add unit test for condition state controller * fix: fix interval max scale * refactor: refactor code style according to feedback * fix: restrict scale range * refactor: extract mini chart fill color into palette * test: add test for conditions * fix: no overlap when drawing multiple lines in corner cell * fix: fix interactive bg stroke uncover issue * fix: :bug: fix some rendering issues (#192) * fix(spread-sheet-spec):bug: correct the wrong param of valueInCols * fix: :bug: fix the wrong color schema of the canves background * fix: :bug: fix the empty error * feat: :sparkles: add the background for the row header and column header * style: :lipstick: tweak the position of the text of corner cells * test(list-table): add table mode spreadsheet spec (#189) * test(list-table): add list-table data process spec * test(list-table): add table mode spreadsheet spec * fix(list-table): rm test script * feat:click or multi click row or col show total by values (#190) * refactor: get selected data and summaries * fix: get selected indexes when row * fix: multi click show tooltip when value in row * refactor: change any type to unknow Co-authored-by: 蒺藜 * fix(pivot-table): invalid valueInCol config (#194) * fix(pivot-table): invalid valueInCol config * fix(pivot-table): not rerender data * fix(pivot-table): revert readonly * fix(pivot-table): revert readonly * fix(pivot-table): reduce optinal * fix(pivot-table): optmize render func logic * fix(pivot-table): fix cannot select row data cells in tree mode (#197) * fix(pivot-table): fix cannot select row data cells in tree mode * fix(pivot-table): revert default hierarchy type * fix(pivot-table): rename * fix(pivot-table): only select current row data cell * feat: add link field interaction (#196) * feat: add interaction for linked row text * feat: gray link field shape when unselected it * feat: add interaction for linked table row cell * fix: fix update options issue when merge with array * test: add tree mode * refactor: extract variable * feat(interaction): remove useless corrner cell click interaction (#203) * refactor(list-table): rm table facet row hierarchy (#207) * style: 💄 tweak the style of total cells and subTotal cells (#204) * feat: :sparkles: add total params for the node * chore: :fire: remove the useless file * style: :lipstick: adust the coordina for the row header cells * fix: :bug: change the cell type for the table-series-cell * style: :lipstick: ajust the coordinate for the total nodes in column header * style: :lipstick: tweak the style of total cells * style: :lipstick: tewak the style for subTotal cells * fix(theme-spec): :bug: fix the wrong param * fix: :bug: remove the header background * chore(pivot-facet): :art: optimize the function * fix(interaction): optimize brush selection empty data cell effect (#206) * fix(interaction): optimize brush selection empty data cell effect * fix(interaction): remove console * feat: ✨ add hover state for the resize area (#208) * chore: :white_check_mark: merge the theme-spec into spread-sheet-spec * feat: :sparkles: add the interface definition for the resizeArea * feat: :sparkles: add hover state for the resize area * style: :zap: opimaize the code style * style: :art: optimize the code style * feat(pivot-mode): compate with total data in raw data scene (#202) * feat(pivot-mode): compate with total data in raw data scene * fix(pivot-mode): mainly totaldata * feat: get tooltip data compatible with table (#201) * refactor: get selected data and summaries * fix: get selected indexes when row * fix: multi click show tooltip when value in row * refactor: change any type to unknow * feat: get tooltip data compatible with table * refactor: code write * refactor: merge name * refactor: modify state style's value * refactor: handle name in getSummaryName Co-authored-by: 蒺藜 * fix(interaction): support empty data cell & calc count (#209) * feat: frozen Cols and Rows for table mode (#200) * feat: add forzen api * feat: add frozen col impl * feat: add trailing col and row * feat: revert comment * feat: add colTrailingGrou[ * feat: update tableCornerCell * feat: fix else in tooltip * feat: fix import err * feat: use splitLine style for table mode * feat: extract addCell * fix: extract method to table facet * fix: add clip * feat: extract facet util * fix: rm red bg for col * fix: prettier files * fix: prettier tests * fix: revert row change * fix: cr issues Co-authored-by: xinhui.zxh * refactor(scrollBar): scroll bar theme and scroll behavior (#210) * fix: :white_check_mark: fix some tests error * tests(data-process): fix error spec (#211) * fix: frozen util test (#214) Co-authored-by: xinhui.zxh * test: fix unit test (#213) * fix: fix some type and lint error (#212) * fix: fix some type and lint error * fix: remove at all * fix: cache node modules * fix: remove lock file * chore: upgrade jest version (#216) * chore: upgrade jest version * chore: extract jest config file from package.json * chore: remove redundant file * chore: optimize bundle size (#217) * chore: optimize bundle size * fix: error theme name * test: add interaction test (#218) * chore(tests): fix the failed tests (#219) * chore(tests): :white_check_mark: fix the failed testes and rename the tests to __tests__ * fix: :bug: solved the wrong hover state of column header cells * chore: :wrench: update the assignee-reviewers * chore: :wrench: update the reviewer assignees * chore: simpify sheet live demo test (#221) * chore: upgrade jest version * chore: extract jest config file from package.json * chore: remove redundant file * test: remove unused mock data files * test: simpify link field test * test: remove meaningless test file * test: remove unused files * test: simplify interaction test * test: simplify other pivot sheet * chore: update the README (#222) * fix: sort data when undefined and refactor sort test * refactor: optimize sort test desc * fix: readme merge * refactor: optimize code written * refactor: optimize map to lodash * chore: update the data-sort.json Co-authored-by: yingying.xwy Co-authored-by: Bruce too Co-authored-by: Jinke Li Co-authored-by: 蒺藜 Co-authored-by: visaWang <18603479221@163.com> Co-authored-by: maosong.wz Co-authored-by: brucetoo Co-authored-by: Wenjun Xu <906626481@qq.com> Co-authored-by: Xinhui Co-authored-by: xinhui.zxh Co-authored-by: YardWill Co-authored-by: wengyidong.wyd Co-authored-by: qubaomingg <675861708@qq.com> --- .../s2-core/__tests__/data/data-sort.json | 349 ++++++++++++++++++ packages/s2-core/__tests__/data/data-sort.ts | 342 ----------------- .../__tests__/spreadsheet/sort-sheet-spec.tsx | 75 ++-- .../unit/data-set/pivot-sort-data-spec.ts | 123 +++--- .../s2-core/src/data-set/pivot-data-set.ts | 2 +- packages/s2-core/src/utils/sort-action.ts | 20 +- 6 files changed, 473 insertions(+), 438 deletions(-) create mode 100644 packages/s2-core/__tests__/data/data-sort.json delete mode 100644 packages/s2-core/__tests__/data/data-sort.ts diff --git a/packages/s2-core/__tests__/data/data-sort.json b/packages/s2-core/__tests__/data/data-sort.json new file mode 100644 index 0000000000..41dbf6ba77 --- /dev/null +++ b/packages/s2-core/__tests__/data/data-sort.json @@ -0,0 +1,349 @@ +{ + "originData": [ + { + "area":"东北", + "province":"吉林", + "city":"白山", + "type":"办公用品", + "sub_type":"纸张", + "cost":"2", + "price":"8" + }, + { + "area":"东北", + "province":"吉林", + "city":"白山", + "type":"办公用品", + "sub_type":"笔", + "cost":"3", + "price":"9" + }, + { + "area":"东北", + "province":"辽宁", + "city":"抚顺", + "type":"办公用品", + "sub_type":"纸张", + "cost":"2", + "price":"9" + }, + { + "area":"东北", + "province":"辽宁", + "city":"抚顺", + "type":"办公用品", + "sub_type":"笔", + "cost":"5", + "price":"12" + }, + { + "area":"东北", + "province":"辽宁", + "city":"抚顺", + "type":"家具产品", + "sub_type":"办公装饰品", + "cost":"6", + "price":"4" + }, + { + "area":"东北", + "province":"辽宁", + "city":"抚顺", + "type":"家具产品", + "sub_type":"餐桌", + "cost":"5", + "price":"1" + }, + { + "area":"东北", + "province":"辽宁", + "city":"朝阳", + "type":"家具产品", + "sub_type":"办公装饰品", + "cost":"32", + "price":"4" + }, + { + "area":"东北", + "province":"辽宁", + "city":"朝阳", + "type":"办公用品", + "sub_type":"纸张", + "cost":"52", + "price":"4" + }, + { + "area":"东北", + "province":"辽宁", + "city":"朝阳", + "type":"办公用品", + "sub_type":"笔", + "cost":"52", + "price":"4" + }, + { + "area":"东北", + "province":"辽宁", + "city":"朝阳", + "type":"家具产品", + "sub_type":"餐桌", + "cost":"5", + "price":"2" + }, + { + "area":"东北", + "province":"吉林", + "city":"白山", + "type":"家具产品", + "sub_type":"办公装饰品", + "cost":"4", + "price":"4" + }, + { + "area":"东北", + "province":"吉林", + "city":"白山", + "type":"家具产品", + "sub_type":"餐桌", + "cost":"8", + "price":"14" + }, + { + "area":"东北", + "province":"吉林", + "city":"丹东", + "type":"家具产品", + "sub_type":"办公装饰品", + "cost":"6", + "price":"2" + }, + { + "area":"东北", + "province":"吉林", + "city":"丹东", + "type":"家具产品", + "sub_type":"餐桌", + "cost":"14", + "price":"9" + }, + { + "area":"东北", + "province":"吉林", + "city":"丹东", + "type":"办公用品", + "sub_type":"纸张", + "cost":"6", + "price":"1" + }, + { + "area":"东北", + "province":"吉林", + "city":"丹东", + "type":"办公用品", + "sub_type":"笔", + "cost":"64", + "price":"1" + }, + { + "area":"中南", + "province":"广东", + "city":"汕头", + "type":"办公用品", + "sub_type":"纸张", + "cost":"6", + "price":"5" + }, + { + "area":"中南", + "province":"广东", + "city":"汕头", + "type":"办公用品", + "sub_type":"笔", + "cost":"64", + "price":"52" + }, + { + "area":"中南", + "province":"广东", + "city":"广州", + "type":"办公用品", + "sub_type":"纸张", + "cost":"6", + "price":"5" + }, + { + "area":"中南", + "province":"广东", + "city":"广州", + "type":"办公用品", + "sub_type":"笔", + "cost":"-", + "price":"5" + }, + { + "area":"中南", + "province":"广东", + "city":"汕头", + "type":"家具产品", + "sub_type":"办公装饰品", + "cost":"2", + "price":"3" + }, + { + "area":"中南", + "province":"广东", + "city":"汕头", + "type":"家具产品", + "sub_type":"餐桌", + "cost":"32", + "price":"3" + }, + { + "area":"中南", + "province":"广东", + "city":"广州", + "type":"家具产品", + "sub_type":"办公装饰品", + "cost":"42", + "price":"13" + }, + { + "area":"中南", + "province":"广东", + "city":"广州", + "type":"家具产品", + "sub_type":"餐桌", + "cost":"2", + "price":"34" + } + ], + "fields": { + "rows":[ + "area", + "province", + "city" + ], + "columns":[ + "type", + "sub_type" + ], + "values":[ + "cost", + "price" + ] + }, + "meta": [ + { + "field":"price", + "name":"价格" + }, + { + "field":"city", + "name":"城市" + }, + { + "field":"area", + "name":"区域" + }, + { + "field":"province", + "name":"省份" + }, + { + "field":"cost", + "name":"成本" + } + ], + "totalData": [ + { + "price":"100", + "cost":"200" + }, + { + "area":"东北", + "cost":"14", + "price":"24" + }, + { + "area":"东北", + "type":"办公用品", + "cost":"23", + "price":"27" + }, + { + "area":"东北", + "type":"办公用品", + "sub_type":"笔", + "cost":"26", + "price":"39" + }, + { + "area":"东北", + "province":"吉林", + "cost":"30", + "price":"40" + }, + { + "area":"东北", + "province":"辽宁", + "cost":"31", + "price":"39" + }, + { + "area":"东北", + "province":"吉林", + "city":"白山", + "cost":"10", + "price":"20" + }, + { + "area":"东北", + "province":"吉林", + "city":"丹东", + "cost":"12", + "price":"21" + }, + { + "area":"东北", + "province":"吉林", + "type":"办公用品", + "sub_type":"笔", + "cost":"11", + "price":"12" + }, + { + "area":"东北", + "province":"吉林", + "type":"办公用品", + "sub_type":"纸张", + "cost":"10", + "price":"13" + }, + { + "type":"办公用品", + "cost":"22", + "price":"34" + }, + { + "type":"家具产品", + "cost":"55", + "price":"66" + }, + { + "area":"东北", + "type":"办公用品", + "province":"辽宁", + "city":"抚顺", + "cost":"1", + "price":"3" + }, + { + "area":"东北", + "type":"办公用品", + "province":"辽宁", + "city":"朝阳", + "cost":"33", + "price":"22" + } + ] +} diff --git a/packages/s2-core/__tests__/data/data-sort.ts b/packages/s2-core/__tests__/data/data-sort.ts deleted file mode 100644 index bc28610c5b..0000000000 --- a/packages/s2-core/__tests__/data/data-sort.ts +++ /dev/null @@ -1,342 +0,0 @@ -export const originData = [ - { - area: '东北', - province: '吉林', - city: '白山', - type: '办公用品', - sub_type: '纸张', - cost: '2', - price: '8', - }, - { - area: '东北', - province: '吉林', - city: '白山', - type: '办公用品', - sub_type: '笔', - cost: '3', - price: '9', - }, - { - area: '东北', - province: '辽宁', - city: '抚顺', - type: '办公用品', - sub_type: '纸张', - cost: '2', - price: '9', - }, - { - area: '东北', - province: '辽宁', - city: '抚顺', - type: '办公用品', - sub_type: '笔', - cost: '5', - price: '12', - }, - { - area: '东北', - province: '辽宁', - city: '抚顺', - type: '家具产品', - sub_type: '办公装饰品', - cost: '6', - price: '4', - }, - { - area: '东北', - province: '辽宁', - city: '抚顺', - type: '家具产品', - sub_type: '餐桌', - cost: '5', - price: '1', - }, - { - area: '东北', - province: '辽宁', - city: '朝阳', - type: '家具产品', - sub_type: '办公装饰品', - cost: '32', - price: '4', - }, - { - area: '东北', - province: '辽宁', - city: '朝阳', - type: '办公用品', - sub_type: '纸张', - cost: '52', - price: '4', - }, - { - area: '东北', - province: '辽宁', - city: '朝阳', - type: '办公用品', - sub_type: '笔', - cost: '52', - price: '4', - }, - { - area: '东北', - province: '辽宁', - city: '朝阳', - type: '家具产品', - sub_type: '餐桌', - cost: '5', - price: '2', - }, - { - area: '东北', - province: '吉林', - city: '白山', - type: '家具产品', - sub_type: '办公装饰品', - cost: '4', - price: '4', - }, - { - area: '东北', - province: '吉林', - city: '白山', - type: '家具产品', - sub_type: '餐桌', - cost: '8', - price: '14', - }, - { - area: '东北', - province: '吉林', - city: '丹东', - type: '家具产品', - sub_type: '办公装饰品', - cost: '6', - price: '2', - }, - { - area: '东北', - province: '吉林', - city: '丹东', - type: '家具产品', - sub_type: '餐桌', - cost: '14', - price: '9', - }, - { - area: '东北', - province: '吉林', - city: '丹东', - type: '办公用品', - sub_type: '纸张', - cost: '6', - price: '1', - }, - { - area: '东北', - province: '吉林', - city: '丹东', - type: '办公用品', - sub_type: '笔', - cost: '64', - price: '1', - }, - { - area: '中南', - province: '广东', - city: '汕头', - type: '办公用品', - sub_type: '纸张', - cost: '6', - price: '5', - }, - { - area: '中南', - province: '广东', - city: '汕头', - type: '办公用品', - sub_type: '笔', - cost: '64', - price: '52', - }, - { - area: '中南', - province: '广东', - city: '广州', - type: '办公用品', - sub_type: '纸张', - cost: '6', - price: '5', - }, - { - area: '中南', - province: '广东', - city: '广州', - type: '办公用品', - sub_type: '笔', - cost: '-', - price: '5', - }, - { - area: '中南', - province: '广东', - city: '汕头', - type: '家具产品', - sub_type: '办公装饰品', - cost: '2', - price: '3', - }, - { - area: '中南', - province: '广东', - city: '汕头', - type: '家具产品', - sub_type: '餐桌', - cost: '32', - price: '3', - }, - { - area: '中南', - province: '广东', - city: '广州', - type: '家具产品', - sub_type: '办公装饰品', - cost: '42', - price: '13', - }, - { - area: '中南', - province: '广东', - city: '广州', - type: '家具产品', - sub_type: '餐桌', - cost: '2', - price: '34', - }, -]; - -export const dataCfg = { - fields: { - rows: ['area', 'province', 'city'], - columns: ['type', 'sub_type'], - values: ['cost', 'price'], - }, - meta: [ - { - field: 'price', - name: '价格', - }, - { - field: 'city', - name: '城市', - }, - { - field: 'area', - name: '区域', - }, - { - field: 'province', - name: '省份', - }, - { - field: 'cost', - name: '成本', - }, - ], - data: originData, -}; - -export const totalData = [ - { - price: '100', - cost: '200', - }, - { - area: '东北', - cost: '14', - price: '24', - }, - { - area: '东北', - type: '办公用品', - cost: '23', - price: '27', - }, - { - area: '东北', - type: '办公用品', - sub_type: '笔', - cost: '26', - price: '39', - }, - { - area: '东北', - province: '吉林', - cost: '30', - price: '40', - }, - { - area: '东北', - province: '辽宁', - cost: '31', - price: '39', - }, - { - area: '东北', - province: '吉林', - city: '白山', - cost: '10', - price: '20', - }, - { - area: '东北', - province: '吉林', - city: '丹东', - cost: '12', - price: '21', - }, - { - area: '东北', - province: '吉林', - type: '办公用品', - sub_type: '笔', - cost: '11', - price: '12', - }, - { - area: '东北', - province: '吉林', - type: '办公用品', - sub_type: '纸张', - cost: '10', - price: '13', - }, - { - type: '办公用品', - cost: '22', - price: '34', - }, - { - type: '家具产品', - cost: '55', - price: '66', - }, - { - area: '东北', - type: '办公用品', - province: '辽宁', - city: '抚顺', - cost: '1', - price: '3', - }, - { - area: '东北', - type: '办公用品', - province: '辽宁', - city: '朝阳', - cost: '33', - price: '22', - }, -]; diff --git a/packages/s2-core/__tests__/spreadsheet/sort-sheet-spec.tsx b/packages/s2-core/__tests__/spreadsheet/sort-sheet-spec.tsx index 919237879b..1c6c96e79b 100644 --- a/packages/s2-core/__tests__/spreadsheet/sort-sheet-spec.tsx +++ b/packages/s2-core/__tests__/spreadsheet/sort-sheet-spec.tsx @@ -1,14 +1,16 @@ -import React from 'react'; +import React, { useState } from 'react'; import ReactDOM from 'react-dom'; +import { Switch } from 'antd'; import { act } from 'react-dom/test-utils'; import { S2DataConfig, TOTAL_VALUE } from '../../src'; -import { totalData } from '../data/data-sort'; +import SORT_DATA from '../data/data-sort.json'; import { getContainer } from '../util/helpers'; import { SheetEntry } from '../util/sheet-entry'; -import { CustomTooltip } from './custom/custom-tooltip'; const dataCfg: Partial = { - totalData, + data: SORT_DATA.originData, + meta: SORT_DATA.meta, + totalData: SORT_DATA.totalData, sortParams: [ // use sortMethod to sort // { sortFieldId: 'type', sortMethod: 'DESC' }, @@ -157,33 +159,46 @@ const dataCfg: Partial = { ], }; -const options = { - tooltip: { - showTooltip: false, - renderTooltip: (spreadsheet) => { - return new CustomTooltip(spreadsheet); - }, - }, - totals: { - row: { - showGrandTotals: true, - showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, - subTotalsDimensions: ['area', 'province'], - }, - col: { - showGrandTotals: true, - showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, - subTotalsDimensions: ['type'], - }, - }, -}; - function MainLayout() { - return ; + const [isTotals, setIsTotals] = useState(false); + const [mergedOptions, setMergedOptions] = useState({}); + + const onTotalsChange = (checked) => { + setIsTotals(checked); + setMergedOptions({ + totals: { + row: { + showGrandTotals: checked, + showSubTotals: checked, + reverseLayout: checked, + reverseSubLayout: checked, + subTotalsDimensions: ['area', 'province'], + }, + col: { + showGrandTotals: checked, + showSubTotals: checked, + reverseLayout: checked, + reverseSubLayout: checked, + subTotalsDimensions: ['type'], + }, + }, + }); + }; + + return ( + + } + /> + ); } describe('spreadsheet normal spec', () => { diff --git a/packages/s2-core/__tests__/unit/data-set/pivot-sort-data-spec.ts b/packages/s2-core/__tests__/unit/data-set/pivot-sort-data-spec.ts index 2d24c27e8a..95161ca066 100644 --- a/packages/s2-core/__tests__/unit/data-set/pivot-sort-data-spec.ts +++ b/packages/s2-core/__tests__/unit/data-set/pivot-sort-data-spec.ts @@ -1,7 +1,7 @@ import { S2DataConfig } from 'src/common/interface'; import { SpreadSheet } from 'src/sheet-type'; import { PivotDataSet } from 'src/data-set/pivot-data-set'; -import { dataCfg as mockDataCfg, totalData } from '../../data/data-sort'; +import SORT_DATA from '../../data/data-sort.json'; import { getIntersections, filterUndefined } from '@/utils/data-set-operate'; jest.mock('src/sheet-type'); @@ -17,8 +17,8 @@ describe('Pivot Sort Test', () => { dataSet = new PivotDataSet(new MockSpreadSheet()); }); - const getColTest = () => { - test('returns the correct col data', () => { + const getColTest = (msg) => { + test(`should get correct col ${msg || ''}`, () => { expect(dataSet?.getDimensionValues('type')).toEqual([ '家具产品', '办公用品', @@ -34,8 +34,8 @@ describe('Pivot Sort Test', () => { }); }; - const getRowTest = () => { - test('returns the correct row data', () => { + const getRowTest = (msg) => { + test(`should get correct row ${msg || ''}`, () => { expect(dataSet?.getDimensionValues('area')).toEqual(['中南', '东北']); expect(dataSet?.getDimensionValues('province', { area: '东北' })).toEqual( @@ -51,8 +51,8 @@ describe('Pivot Sort Test', () => { }); }; - const getValueWhenInColTest = () => { - test('returns the correct value data when value in the colum', () => { + const getValueWhenInColTest = (msg) => { + test(`should get correct values ${msg} and value in col`, () => { expect( dataSet?.getDimensionValues('$$extra$$', { sub_type: '办公装饰品', @@ -62,8 +62,8 @@ describe('Pivot Sort Test', () => { }); }; - const getValueWhenInRowTest = () => { - test('returns the correct value data when value in the row', () => { + const getValueWhenInRowTest = (msg) => { + test(`should get correct values ${msg} and value in row`, () => { expect( dataSet?.getDimensionValues('$$extra$$', { area: '中南', @@ -74,25 +74,24 @@ describe('Pivot Sort Test', () => { }); }; - const getTestListWhenInCol = () => { - getColTest(); - getRowTest(); - getValueWhenInColTest(); + const getTestListWhenInCol = (msg) => { + getColTest(msg); + getRowTest(msg); + getValueWhenInColTest(msg); }; - const getTestListWhenInRow = () => { - getColTest(); - getRowTest(); - getValueWhenInRowTest(); + const getTestListWhenInRow = (msg) => { + getColTest(msg); + getRowTest(msg); + getValueWhenInRowTest(msg); }; - const getTestListWhenInColByMeasure = () => { - test('returns the dimension values when measure in the column', () => { - // TODO 检查排序 - // expect(dataSet?.getDimensionValues('type')).toEqual([ - // '办公用品', - // '家具产品', - // ]); + const getTestListWhenInColByMeasure = (msg) => { + test(`should get correct col data ${msg} and value in col`, () => { + expect(dataSet?.getDimensionValues('type')).toEqual([ + '办公用品', + '家具产品', + ]); expect( dataSet?.getDimensionValues('sub_type', { type: '家具产品' }), @@ -103,15 +102,15 @@ describe('Pivot Sort Test', () => { ).toEqual(['笔', '纸张']); }); - getValueWhenInColTest(); + getValueWhenInColTest(msg); }; - const getTestListWhenInRowByMeasure = () => { - test('returns the correct dimension values when measure in the row', () => { - // expect(dataSet?.getDimensionValues('type')).toEqual([ - // '办公用品', - // '家具产品', - // ]); + const getTestListWhenInRowByMeasure = (msg) => { + test(`should get correct row data ${msg} and value in row`, () => { + expect(dataSet?.getDimensionValues('type')).toEqual([ + '办公用品', + '家具产品', + ]); expect( dataSet?.getDimensionValues('sub_type', { type: '家具产品' }), @@ -122,7 +121,7 @@ describe('Pivot Sort Test', () => { ).toEqual(['笔', '纸张']); }); - getValueWhenInRowTest(); + getValueWhenInRowTest(msg); }; const getDimensionSortTest = (valueInCols: boolean) => { @@ -141,10 +140,11 @@ describe('Pivot Sort Test', () => { }; dataSet.setDataCfg(dataCfg); }); + const msg = 'when sort by method'; if (valueInCols) { - getTestListWhenInCol(); + getTestListWhenInCol(msg); } else { - getTestListWhenInRow(); + getTestListWhenInRow(msg); } }); @@ -168,10 +168,11 @@ describe('Pivot Sort Test', () => { }; dataSet.setDataCfg(dataCfg); }); + const msg = 'when sort by list'; if (valueInCols) { - getTestListWhenInCol(); + getTestListWhenInCol(msg); } else { - getTestListWhenInRow(); + getTestListWhenInRow(msg); } }); @@ -210,11 +211,11 @@ describe('Pivot Sort Test', () => { }; dataSet.setDataCfg(dataCfg); }); - + const msg = 'when sort by list and have query'; if (valueInCols) { - getTestListWhenInCol(); + getTestListWhenInCol(msg); } else { - getTestListWhenInRow(); + getTestListWhenInRow(msg); } }); @@ -275,10 +276,11 @@ describe('Pivot Sort Test', () => { }; dataSet.setDataCfg(dataCfg); }); + const msg = 'when sort by measure'; if (valueInCols) { - getTestListWhenInColByMeasure(); + getTestListWhenInColByMeasure(msg); } else { - getTestListWhenInRowByMeasure(); + getTestListWhenInRowByMeasure(msg); } }); @@ -303,7 +305,7 @@ describe('Pivot Sort Test', () => { }; dataSet.setDataCfg(dataCfg); }); - test('should get correct row city data', () => { + test('should get correct row city when sort by measure if lack data', () => { expect( dataSet?.getDimensionValues('city', { area: '中南', @@ -370,13 +372,15 @@ describe('Pivot Sort Test', () => { }, }, ], - totalData, + totalData: SORT_DATA.totalData, }; dataSet.setDataCfg(dataCfg); }); - - getColTest(); - getRowTest(); + const msg = 'when sort by measure which is $$total$$'; + if (valueInCols) { + getColTest(msg); + getRowTest(msg); + } }); describe('Test For Dimension Sort By SortFunc', () => { @@ -392,7 +396,7 @@ describe('Pivot Sort Test', () => { sortParams: [ { sortFieldId: 'type', - sortFunc: (params) => sortFunc(params, false), + sortFunc: (params) => sortFunc(params), }, { sortFieldId: 'sub_type', @@ -418,10 +422,11 @@ describe('Pivot Sort Test', () => { }; dataSet.setDataCfg(dataCfg); }); + const msg = 'when sort by sortFunc'; if (valueInCols) { - getTestListWhenInColByMeasure(); + getTestListWhenInColByMeasure(msg); } else { - getTestListWhenInRowByMeasure(); + getTestListWhenInRowByMeasure(msg); } }); @@ -456,11 +461,11 @@ describe('Pivot Sort Test', () => { }; dataSet.setDataCfg(dataCfg); }); - + const msg = 'when sort by measure and sortFunc'; if (valueInCols) { - getTestListWhenInColByMeasure(); + getTestListWhenInColByMeasure(msg); } else { - getTestListWhenInRowByMeasure(); + getTestListWhenInRowByMeasure(msg); } }); }; @@ -468,9 +473,11 @@ describe('Pivot Sort Test', () => { describe('Test For Value In Cols And Row Gird Hierarchy', () => { beforeEach(() => { dataCfg = { - ...mockDataCfg, + data: SORT_DATA.originData, + meta: SORT_DATA.meta, + totalData: SORT_DATA.totalData, fields: { - ...mockDataCfg?.fields, + ...SORT_DATA.fields, valueInCols: true, }, }; @@ -483,9 +490,11 @@ describe('Pivot Sort Test', () => { describe('Test For Value In Rows And Row Gird Hierarchy', () => { beforeEach(() => { dataCfg = { - ...mockDataCfg, + data: SORT_DATA.originData, + meta: SORT_DATA.meta, + totalData: SORT_DATA.totalData, fields: { - ...mockDataCfg?.fields, + ...SORT_DATA.fields, valueInCols: false, }, }; @@ -510,7 +519,7 @@ describe('Pivot Sort Test', () => { dataSet.setDataCfg(dataCfg); }); - test('returns the correct row data', () => { + test('should get correct row when row is tree hierarchy', () => { const data1 = filterUndefined( getIntersections( [...(dataSet as PivotDataSet)?.sortedDimensionValues?.get('area')], diff --git a/packages/s2-core/src/data-set/pivot-data-set.ts b/packages/s2-core/src/data-set/pivot-data-set.ts index 957e1dd543..f4edb67635 100644 --- a/packages/s2-core/src/data-set/pivot-data-set.ts +++ b/packages/s2-core/src/data-set/pivot-data-set.ts @@ -224,7 +224,7 @@ export class PivotDataSet extends BaseDataSet { }); this.sortedDimensionValues.set( sortFieldId, - new Set([...result, ...originValues]), + new Set([...result, ...originValues]), // 这里是控制顺序的,优先result ); }); }; diff --git a/packages/s2-core/src/utils/sort-action.ts b/packages/s2-core/src/utils/sort-action.ts index b1c9e0e496..2ad7e5f901 100644 --- a/packages/s2-core/src/utils/sort-action.ts +++ b/packages/s2-core/src/utils/sort-action.ts @@ -1,7 +1,7 @@ -import { Data, DataItem, SortMethod } from 'src/common/interface'; +import { SortMethod } from 'src/common/interface'; import { DataType, SortActionParams } from 'src/data-set/interface'; -import { keys, has, uniq } from 'lodash'; -import { EXTRA_FIELD, SortMethodType, TOTAL_VALUE } from '@/common/constant'; +import { keys, has, uniq, isPlainObject, map } from 'lodash'; +import { EXTRA_FIELD, TOTAL_VALUE } from '@/common/constant'; import { sortByItems } from '@/utils/data-set-operate'; /** @@ -70,11 +70,15 @@ export const sortByCustom = (params: SortActionParams): string[] => { export const sortByMethod = (params: SortActionParams): string[] => { const { sortParam, measureValues, originValues } = params; const { sortByMeasure, query, sortFieldId, sortMethod } = sortParam; - const result = sortAction( - measureValues, - sortMethod, - sortByMeasure === TOTAL_VALUE ? query[EXTRA_FIELD] : sortByMeasure, - )?.map((item) => item[sortFieldId]); + const result = map( + sortAction( + measureValues, + sortMethod, + sortByMeasure === TOTAL_VALUE ? query[EXTRA_FIELD] : sortByMeasure, + ), + (item) => (isPlainObject(item) ? item?.[sortFieldId] : item), + ); + return mergeDataWhenASC(result, originValues, sortMethod === 'ASC'); };