villebro commented on code in PR #25869:
URL: https://github.com/apache/superset/pull/25869#discussion_r1866577704


##########
superset-frontend/package.json:
##########
@@ -137,11 +138,17 @@
     "d3-scale": "^2.1.2",
     "dayjs": "^1.11.13",
     "dom-to-image-more": "^3.2.0",
+    "echarts": "^5.4.1",
     "emotion-rgba": "0.0.12",
     "fast-glob": "^3.3.2",
     "fs-extra": "^11.2.0",
     "fuse.js": "^7.0.0",
     "geolib": "^2.0.24",
+    "geostyler": "^12.0.2",
+    "geostyler-data": "^1.0.0",
+    "geostyler-openlayers-parser": "^4.3.0",
+    "geostyler-style": "^7.5.0",
+    "geostyler-wfs-parser": "^2.0.3",

Review Comment:
   I agree with @justinpark that these deps (and the `ol` package below) should 
ideally exist in the plugin. However, I'm aware that due to limitations in the 
current plugin architecture, we aren't able to adequately decouple controls 
from the core codebase. This is something that will be considered when 
redesigning the plugin architecture.



##########
superset-frontend/packages/superset-ui-core/src/chart/types/QueryResponse.ts:
##########
@@ -31,6 +31,14 @@ export interface TimeseriesDataRecord extends DataRecord {
   __timestamp: number | string | Date | null;
 }
 
+export const isTimeseriesDataRecord = (
+  item: any,
+): item is TimeseriesDataRecord => Object.keys(item).includes('__timestamp');

Review Comment:
   nit: there is `DTTM_ALIAS` that should be referenced when referring to 
`__timestamp`.



##########
superset-frontend/plugins/plugin-chart-cartodiagram/package.json:
##########
@@ -0,0 +1,51 @@
+{
+  "name": "@superset-ui/plugin-chart-cartodiagram",
+  "version": "0.0.1",
+  "description": "An OpenLayers map that displays charts for single features.",
+  "sideEffects": false,
+  "main": "lib/index.js",
+  "module": "esm/index.js",
+  "files": [
+    "esm",
+    "lib"
+  ],
+  "repository": {
+    "type": "git",
+    "url": "git+https://github.com/apache-superset/superset-ui.git";
+  },
+  "keywords": [
+    "superset"
+  ],
+  "license": "Apache-2.0",
+  "bugs": {
+    "url": "https://github.com/apache-superset/superset-ui/issues";
+  },
+  "homepage": "https://github.com/apache-superset/superset-ui#readme";,
+  "contributors": [
+    "terrestris GmbH & Co. KG <[email protected]> 
(https://www.terrestris.de)",
+    "meggsimum - Büro für Geoinformatik <[email protected]> 
(https://meggsimum.de)"
+  ],
+  "publishConfig": {
+    "access": "public"
+  },
+  "dependencies": {
+    "@types/geojson": "^7946.0.10",
+    "geojson": "^0.5.0",
+    "lodash": "^4.17.21",
+    "ol": "^7.1.0"

Review Comment:
   I see we are already adding `ol` in the main `package.json`. Therefore, 
should this not be in `peerDependencies`? Or is there some reason we 
specifically need `^7.1.0` here? It'd be nice if we can reuse the main 
dependency here, too, as in the future we want to decouple these deps from the 
core package to the plugins.



##########
superset-frontend/packages/superset-ui-core/src/chart/types/QueryResponse.ts:
##########
@@ -31,6 +31,14 @@ export interface TimeseriesDataRecord extends DataRecord {
   __timestamp: number | string | Date | null;
 }
 
+export const isTimeseriesDataRecord = (
+  item: any,
+): item is TimeseriesDataRecord => Object.keys(item).includes('__timestamp');
+
+export const isTimeseriesDataRecordList = (
+  items: any[],
+): items is TimeseriesDataRecord[] => items.every(isTimeseriesDataRecord);
+

Review Comment:
   Are these still needed? I checked out the codebase, but I wasn't able to 
find any references to these functions. Maybe they were needed before? The 
reason I ask is because we're slowly deprecating the concept of dedicated 
Timeseries charts (most charts should just support any type of base axis).



##########
superset-frontend/plugins/plugin-chart-cartodiagram/src/plugin/buildQuery.ts:
##########
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { QueryFormData, getChartBuildQueryRegistry } from '@superset-ui/core';
+
+/**
+ * The buildQuery function is used to create an instance of QueryContext that's
+ * sent to the chart data endpoint. In addition to containing information of 
which
+ * datasource to use, it specifies the type (e.g. full payload, samples, 
query) and
+ * format (e.g. CSV or JSON) of the result and whether or not to force refresh 
the data from
+ * the datasource as opposed to using a cached copy of the data, if available.
+ *
+ * More importantly though, QueryContext contains a property `queries`, which 
is an array of
+ * QueryObjects specifying individual data requests to be made. A QueryObject 
specifies which
+ * columns, metrics and filters, among others, to use during the query. 
Usually it will be enough
+ * to specify just one query based on the baseQueryObject, but for some more 
advanced use cases
+ * it is possible to define post processing operations in the QueryObject, or 
multiple queries
+ * if a viz needs multiple different result sets.
+ */

Review Comment:
   ```suggestion
   ```



##########
superset-frontend/plugins/plugin-chart-cartodiagram/src/plugin/transformProps.ts:
##########
@@ -0,0 +1,92 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { ChartProps, getChartTransformPropsRegistry } from '@superset-ui/core';
+import {
+  getChartConfigs,
+  parseSelectedChart,
+} from '../util/transformPropsUtil';
+
+export default function transformProps(chartProps: ChartProps) {
+  /**
+   * This function is called after a successful response has been
+   * received from the chart data endpoint, and is used to transform
+   * the incoming data prior to being sent to the Visualization.
+   *
+   * The transformProps function is also quite useful to return
+   * additional/modified props to your data viz component. The formData
+   * can also be accessed from your CartodiagramPlugin.tsx file, but
+   * doing supplying custom props here is often handy for integrating third
+   * party libraries that rely on specific props.
+   *
+   * A description of properties in `chartProps`:
+   * - `height`, `width`: the height/width of the DOM element in which
+   *   the chart is located
+   * - `formData`: the chart data request payload that was sent to the
+   *   backend.
+   * - `queriesData`: the chart data response payload that was received
+   *   from the backend. Some notable properties of `queriesData`:
+   *   - `data`: an array with data, each row with an object mapping
+   *     the column/alias to its value. Example:
+   *     `[{ col1: 'abc', metric1: 10 }, { col1: 'xyz', metric1: 20 }]`
+   *   - `rowcount`: the number of rows in `data`
+   *   - `query`: the query that was issued.
+   *
+   * Please note: the transformProps function gets cached when the
+   * application loads. When making changes to the `transformProps`
+   * function during development with hot reloading, changes won't
+   * be seen until restarting the development server.
+   */

Review Comment:
   Let's remove the boilerplate comments
   ```suggestion
   ```



##########
superset-frontend/plugins/plugin-chart-table/src/utils/extent.ts:
##########
@@ -16,7 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-

Review Comment:
   Nit: I assume this is a mistake - let's avoid touching unrelated files.



##########
superset-frontend/plugins/plugin-chart-cartodiagram/src/CartodiagramPlugin.tsx:
##########
@@ -0,0 +1,59 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { createRef, useState } from 'react';
+import { styled, useTheme } from '@superset-ui/core';
+import OlMap from 'ol/Map';
+import {
+  CartodiagramPluginProps,
+  CartodiagramPluginStylesProps,
+} from './types';
+
+import OlChartMap from './components/OlChartMap';
+
+import 'ol/ol.css';
+
+// The following Styles component is a <div> element, which has been styled 
using Emotion
+// For docs, visit https://emotion.sh/docs/styled
+
+// Theming variables are provided for your use via a ThemeProvider
+// imported from @superset-ui/core. For variables available, please visit
+// 
https://github.com/apache-superset/superset-ui/blob/master/packages/superset-ui-core/src/style/index.ts
+
+const Styles = styled.div<CartodiagramPluginStylesProps>`
+  height: ${({ height }) => height}px;
+  width: ${({ width }) => width}px;
+`;
+
+export default function CartodiagramPlugin(props: CartodiagramPluginProps) {
+  const { height, width } = props;
+  const theme = useTheme();
+
+  const rootElem = createRef<HTMLDivElement>();
+
+  const [mapId] = useState(
+    `cartodiagram-plugin-${Math.floor(Math.random() * 1000)}`,
+  );

Review Comment:
   nit: if it's all the same, maybe throw a few extra zeros here to minimize 
the risk of a collision (I can only assume suffixing it with 0-999999 won't 
cause issues vs 0-999)



##########
superset-frontend/plugins/plugin-chart-echarts/package.json:
##########
@@ -25,13 +25,13 @@
   ],
   "dependencies": {
     "d3-array": "^1.2.0",
-    "echarts": "^5.4.1",
     "lodash": "^4.17.21",
     "moment": "^2.30.1"
   },
   "peerDependencies": {
     "@superset-ui/chart-controls": "*",
     "@superset-ui/core": "*",
+    "echarts": "*",

Review Comment:
   I vaguely remember there having been a discussion about why this was needed 
as a core dependency. Is this really necessary, or can we leave `echarts` as a 
dependency only on the ECharts plugin?



##########
superset-frontend/plugins/plugin-chart-cartodiagram/src/plugin/controlPanel.ts:
##########
@@ -0,0 +1,203 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { t, validateNonEmpty } from '@superset-ui/core';
+import { ControlPanelConfig } from '@superset-ui/chart-controls';
+import { selectedChartMutator } from '../util/controlPanelUtil';
+
+import { MAX_ZOOM_LEVEL, MIN_ZOOM_LEVEL } from '../util/zoomUtil';
+
+const config: ControlPanelConfig = {
+  /**
+   * The control panel is split into two tabs: "Data" and
+   * "Customize". The controls that define the inputs to
+   * the chart data request, such as columns and metrics, usually
+   * reside within "Data", while controls that affect the visual
+   * appearance or functionality of the chart are under the
+   * "Customize" section.
+   */
+
+  // For control input types, see: 
superset-frontend/src/explore/components/controls/index.js

Review Comment:
   ```suggestion
   ```



##########
superset-frontend/plugins/plugin-chart-cartodiagram/src/plugin/index.ts:
##########
@@ -0,0 +1,77 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { t, ChartMetadata, ChartPlugin } from '@superset-ui/core';
+import buildQuery from './buildQuery';
+import controlPanel from './controlPanel';
+import transformProps from './transformProps';
+import thumbnail from '../images/thumbnail.png';
+import example1 from '../images/example1.png';
+import example2 from '../images/example2.png';
+import { CartodiagramPluginConstructorOpts } from '../types';
+import { getLayerConfig } from '../util/controlPanelUtil';
+
+export default class CartodiagramPlugin extends ChartPlugin {
+  /**
+   * The constructor is used to pass relevant metadata and callbacks that get
+   * registered in respective registries that are used throughout the library
+   * and application. A more thorough description of each property is given in
+   * the respective imported file.
+   *
+   * It is worth noting that `buildQuery` and is optional, and only needed for
+   * advanced visualizations that require either post processing operations
+   * (pivoting, rolling aggregations, sorting etc) or submitting multiple 
queries.
+   */

Review Comment:
   ```suggestion
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to